Search in sources :

Example 1 with Locale

use of com.sun.star.lang.Locale in project languagetool by languagetool-org.

the class MainTest method testDoProofreading.

@Test
public void testDoProofreading() {
    Main prog = new Main(null);
    Main.setTestMode(true);
    String testString = "To jest trudne zdanie. A to następne.  A to przedostatnie jest. Test ostatniego.";
    Locale plLoc = new Locale("pl", "PL", "");
    PropertyValue[] prop = new PropertyValue[0];
    for (int i = 0; i <= testString.length(); i++) {
        ProofreadingResult paRes = prog.doProofreading("1", testString, plLoc, i, testString.length(), prop);
        assertEquals("1", paRes.aDocumentIdentifier);
        assertTrue(paRes.nStartOfNextSentencePosition >= i);
        if (i < "To jest trudne zdanie. ".length()) {
            assertEquals("To jest trudne zdanie. ".length(), paRes.nStartOfNextSentencePosition);
            assertEquals(0, paRes.nStartOfSentencePosition);
        }
    }
    ProofreadingResult paRes1 = prog.doProofreading("1", testString, plLoc, 0, testString.length(), prop);
    assertEquals("1", paRes1.aDocumentIdentifier);
    assertEquals(23, paRes1.nStartOfNextSentencePosition);
    assertEquals(0, paRes1.nStartOfSentencePosition);
    //that was causing NPE but not anymore:
    String testString2 = "To jest „nowy problem”. A to inny jeszcze( „problem. Co jest „?";
    ProofreadingResult paRes2 = prog.doProofreading("1", testString2, plLoc, 0, testString2.length(), prop);
    assertEquals("1", paRes2.aDocumentIdentifier);
    assertEquals(24, paRes2.nStartOfNextSentencePosition);
    assertEquals(0, paRes2.nStartOfSentencePosition);
}
Also used : Locale(com.sun.star.lang.Locale) PropertyValue(com.sun.star.beans.PropertyValue) ProofreadingResult(com.sun.star.linguistic2.ProofreadingResult) Test(org.junit.Test)

Example 2 with Locale

use of com.sun.star.lang.Locale in project languagetool by languagetool-org.

the class MainTest method testVariants.

@Test
public void testVariants() {
    Main prog = new Main(null);
    Main.setTestMode(true);
    String testString = "Sigui quina siga la teva intenció. Això és una prova.";
    // LibreOffice config for languages with variants
    Locale cavaLoc = new Locale("qlt", "ES", "ca-ES-valencia");
    PropertyValue[] prop = new PropertyValue[0];
    for (int i = 0; i <= testString.length(); i++) {
        ProofreadingResult paRes = prog.doProofreading("1", testString, cavaLoc, i, testString.length(), prop);
        assertEquals("1", paRes.aDocumentIdentifier);
        assertTrue(paRes.nStartOfNextSentencePosition >= i);
        if (i < "Sigui quina siga la teva intenció. ".length()) {
            assertEquals("Sigui quina siga la teva intenció. ".length(), paRes.nStartOfNextSentencePosition);
            assertEquals(0, paRes.nStartOfSentencePosition);
        //The test result depends on the CONFIG_FILE
        //assertEquals(2, paRes.aErrors.length);
        }
    }
    Locale caLoc = new Locale("ca", "ES", "");
    ProofreadingResult paRes = prog.doProofreading("1", testString, caLoc, 0, testString.length(), prop);
    assertEquals("1", paRes.aDocumentIdentifier);
//assertEquals(1, paRes.aErrors.length);
}
Also used : Locale(com.sun.star.lang.Locale) PropertyValue(com.sun.star.beans.PropertyValue) ProofreadingResult(com.sun.star.linguistic2.ProofreadingResult) Test(org.junit.Test)

Example 3 with Locale

use of com.sun.star.lang.Locale in project jabref by JabRef.

the class OOBibBase method insertReferenceMark.

private void insertReferenceMark(String name, String citationText, XTextCursor position, boolean withText, OOBibStyle style) throws UnknownPropertyException, WrappedTargetException, PropertyVetoException, IllegalArgumentException, UndefinedCharacterFormatException, CreationException {
    // Check if there is "page info" stored for this citation. If so, insert it into
    // the citation text before inserting the citation:
    Optional<String> pageInfo = getCustomProperty(name);
    String citText;
    if ((pageInfo.isPresent()) && !pageInfo.get().isEmpty()) {
        citText = style.insertPageInfo(citationText, pageInfo.get());
    } else {
        citText = citationText;
    }
    Object bookmark;
    try {
        bookmark = mxDocFactory.createInstance("com.sun.star.text.ReferenceMark");
    } catch (Exception e) {
        throw new CreationException(e.getMessage());
    }
    // Name the reference
    XNamed xNamed = UnoRuntime.queryInterface(XNamed.class, bookmark);
    xNamed.setName(name);
    if (withText) {
        position.setString(citText);
        XPropertySet xCursorProps = UnoRuntime.queryInterface(XPropertySet.class, position);
        // Set language to [None]:
        xCursorProps.setPropertyValue("CharLocale", new Locale("zxx", "", ""));
        if (style.isFormatCitations()) {
            String charStyle = style.getCitationCharacterFormat();
            try {
                xCursorProps.setPropertyValue(CHAR_STYLE_NAME, charStyle);
            } catch (UnknownPropertyException | PropertyVetoException | IllegalArgumentException | WrappedTargetException ex) {
                throw new UndefinedCharacterFormatException(charStyle);
            }
        }
    } else {
        position.setString("");
    }
    // get XTextContent interface
    XTextContent xTextContent = UnoRuntime.queryInterface(XTextContent.class, bookmark);
    position.getText().insertTextContent(position, xTextContent, true);
    // Check if we should italicize the "et al." string in citations:
    boolean italicize = style.getBooleanCitProperty(OOBibStyle.ITALIC_ET_AL);
    if (italicize) {
        String etAlString = style.getStringCitProperty(OOBibStyle.ET_AL_STRING);
        int index = citText.indexOf(etAlString);
        if (index >= 0) {
            italicizeOrBold(position, true, index, index + etAlString.length());
        }
    }
    position.collapseToEnd();
}
Also used : Locale(com.sun.star.lang.Locale) XNamed(com.sun.star.container.XNamed) WrappedTargetException(com.sun.star.lang.WrappedTargetException) UnknownPropertyException(com.sun.star.beans.UnknownPropertyException) UnknownPropertyException(com.sun.star.beans.UnknownPropertyException) PropertyVetoException(com.sun.star.beans.PropertyVetoException) IllegalArgumentException(com.sun.star.lang.IllegalArgumentException) IllegalTypeException(com.sun.star.beans.IllegalTypeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WrappedTargetException(com.sun.star.lang.WrappedTargetException) BootstrapException(com.sun.star.comp.helper.BootstrapException) DisposedException(com.sun.star.lang.DisposedException) NoSuchElementException(com.sun.star.container.NoSuchElementException) MalformedURLException(java.net.MalformedURLException) UndefinedParagraphFormatException(org.jabref.logic.openoffice.UndefinedParagraphFormatException) IOException(java.io.IOException) NotRemoveableException(com.sun.star.beans.NotRemoveableException) PropertyExistException(com.sun.star.beans.PropertyExistException) Point(com.sun.star.awt.Point) XPropertySet(com.sun.star.beans.XPropertySet) PropertyVetoException(com.sun.star.beans.PropertyVetoException) XTextContent(com.sun.star.text.XTextContent) IllegalArgumentException(com.sun.star.lang.IllegalArgumentException)

Aggregations

Locale (com.sun.star.lang.Locale)3 PropertyValue (com.sun.star.beans.PropertyValue)2 ProofreadingResult (com.sun.star.linguistic2.ProofreadingResult)2 Test (org.junit.Test)2 Point (com.sun.star.awt.Point)1 IllegalTypeException (com.sun.star.beans.IllegalTypeException)1 NotRemoveableException (com.sun.star.beans.NotRemoveableException)1 PropertyExistException (com.sun.star.beans.PropertyExistException)1 PropertyVetoException (com.sun.star.beans.PropertyVetoException)1 UnknownPropertyException (com.sun.star.beans.UnknownPropertyException)1 XPropertySet (com.sun.star.beans.XPropertySet)1 BootstrapException (com.sun.star.comp.helper.BootstrapException)1 NoSuchElementException (com.sun.star.container.NoSuchElementException)1 XNamed (com.sun.star.container.XNamed)1 DisposedException (com.sun.star.lang.DisposedException)1 IllegalArgumentException (com.sun.star.lang.IllegalArgumentException)1 WrappedTargetException (com.sun.star.lang.WrappedTargetException)1 XTextContent (com.sun.star.text.XTextContent)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1