Search in sources :

Example 1 with PropertyValue

use of com.sun.star.beans.PropertyValue in project languagetool by languagetool-org.

the class Main method createOOoError.

/**
   * Creates a SingleGrammarError object for use in LO/OO.
   */
private SingleProofreadingError createOOoError(RuleMatch ruleMatch, int startIndex) {
    SingleProofreadingError aError = new SingleProofreadingError();
    aError.nErrorType = TextMarkupType.PROOFREADING;
    // the API currently has no support for formatting text in comments
    aError.aFullComment = ruleMatch.getMessage().replaceAll("<suggestion>", "\"").replaceAll("</suggestion>", "\"").replaceAll("([\r]*\n)", " ");
    // not all rules have short comments
    if (!StringTools.isEmpty(ruleMatch.getShortMessage())) {
        aError.aShortComment = ruleMatch.getShortMessage();
    } else {
        aError.aShortComment = aError.aFullComment;
    }
    aError.aShortComment = org.languagetool.gui.Tools.shortenComment(aError.aShortComment);
    int numSuggestions = ruleMatch.getSuggestedReplacements().size();
    String[] allSuggestions = ruleMatch.getSuggestedReplacements().toArray(new String[numSuggestions]);
    if (numSuggestions > MAX_SUGGESTIONS) {
        aError.aSuggestions = Arrays.copyOfRange(allSuggestions, 0, MAX_SUGGESTIONS);
    } else {
        aError.aSuggestions = allSuggestions;
    }
    aError.nErrorStart = ruleMatch.getFromPos() + startIndex;
    aError.nErrorLength = ruleMatch.getToPos() - ruleMatch.getFromPos();
    aError.aRuleIdentifier = ruleMatch.getRule().getId();
    // older version will simply ignore the property:
    if (ruleMatch.getRule().getUrl() != null) {
        aError.aProperties = new PropertyValue[] { new PropertyValue("FullCommentURL", -1, ruleMatch.getRule().getUrl().toString(), PropertyState.DIRECT_VALUE) };
    } else {
        aError.aProperties = new PropertyValue[0];
    }
    return aError;
}
Also used : PropertyValue(com.sun.star.beans.PropertyValue) SingleProofreadingError(com.sun.star.linguistic2.SingleProofreadingError)

Example 2 with PropertyValue

use of com.sun.star.beans.PropertyValue 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 3 with PropertyValue

use of com.sun.star.beans.PropertyValue 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 4 with PropertyValue

use of com.sun.star.beans.PropertyValue in project translationstudio8 by heartsome.

the class AbstractOpenOfficeDocumentConverter method toPropertyValues.

/**
	 * To property values.
	 * @param properties
	 *            the properties
	 * @return the property value[]
	 */
@SuppressWarnings("unchecked")
protected static PropertyValue[] toPropertyValues(Map properties) {
    PropertyValue[] propertyValues = new PropertyValue[properties.size()];
    int i = 0;
    for (Iterator iter = properties.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iter.next();
        Object value = entry.getValue();
        if (value instanceof Map) {
            // recursively convert nested Map to PropertyValue[]
            Map subProperties = (Map) value;
            value = toPropertyValues(subProperties);
        }
        propertyValues[i++] = property((String) entry.getKey(), value);
    }
    return propertyValues;
}
Also used : Iterator(java.util.Iterator) PropertyValue(com.sun.star.beans.PropertyValue) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with PropertyValue

use of com.sun.star.beans.PropertyValue in project translationstudio8 by heartsome.

the class AbstractOpenOfficeDocumentConverter method property.

/**
	 * Property.
	 * @param name
	 *            the name
	 * @param value
	 *            the value
	 * @return the property value
	 */
protected static PropertyValue property(String name, Object value) {
    PropertyValue property = new PropertyValue();
    property.Name = name;
    property.Value = value;
    return property;
}
Also used : PropertyValue(com.sun.star.beans.PropertyValue)

Aggregations

PropertyValue (com.sun.star.beans.PropertyValue)5 Locale (com.sun.star.lang.Locale)2 ProofreadingResult (com.sun.star.linguistic2.ProofreadingResult)2 Test (org.junit.Test)2 SingleProofreadingError (com.sun.star.linguistic2.SingleProofreadingError)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1