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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations