id
int32 0
165k
| repo
stringlengths 7
58
| path
stringlengths 12
218
| func_name
stringlengths 3
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 1
value | code
stringlengths 73
34.1k
| code_tokens
list | docstring
stringlengths 3
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 105
339
|
|---|---|---|---|---|---|---|---|---|---|---|---|
19,100
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/patterns/Unifier.java
|
Unifier.isUnified
|
public final boolean isUnified(AnalyzedToken matchToken,
Map<String, List<String>> uFeatures, boolean lastReading, boolean isMatched) {
if (inUnification) {
if (isMatched) {
uniMatched |= isSatisfied(matchToken, uFeatures);
}
uniAllMatched = uniMatched;
if (lastReading) {
startNextToken();
uniMatched = false;
}
return uniAllMatched && getFinalUnificationValue(uFeatures);
} else {
if (isMatched) {
isSatisfied(matchToken, uFeatures);
}
}
if (lastReading) {
inUnification = true;
uniMatched = false;
startUnify();
}
return true;
}
|
java
|
public final boolean isUnified(AnalyzedToken matchToken,
Map<String, List<String>> uFeatures, boolean lastReading, boolean isMatched) {
if (inUnification) {
if (isMatched) {
uniMatched |= isSatisfied(matchToken, uFeatures);
}
uniAllMatched = uniMatched;
if (lastReading) {
startNextToken();
uniMatched = false;
}
return uniAllMatched && getFinalUnificationValue(uFeatures);
} else {
if (isMatched) {
isSatisfied(matchToken, uFeatures);
}
}
if (lastReading) {
inUnification = true;
uniMatched = false;
startUnify();
}
return true;
}
|
[
"public",
"final",
"boolean",
"isUnified",
"(",
"AnalyzedToken",
"matchToken",
",",
"Map",
"<",
"String",
",",
"List",
"<",
"String",
">",
">",
"uFeatures",
",",
"boolean",
"lastReading",
",",
"boolean",
"isMatched",
")",
"{",
"if",
"(",
"inUnification",
")",
"{",
"if",
"(",
"isMatched",
")",
"{",
"uniMatched",
"|=",
"isSatisfied",
"(",
"matchToken",
",",
"uFeatures",
")",
";",
"}",
"uniAllMatched",
"=",
"uniMatched",
";",
"if",
"(",
"lastReading",
")",
"{",
"startNextToken",
"(",
")",
";",
"uniMatched",
"=",
"false",
";",
"}",
"return",
"uniAllMatched",
"&&",
"getFinalUnificationValue",
"(",
"uFeatures",
")",
";",
"}",
"else",
"{",
"if",
"(",
"isMatched",
")",
"{",
"isSatisfied",
"(",
"matchToken",
",",
"uFeatures",
")",
";",
"}",
"}",
"if",
"(",
"lastReading",
")",
"{",
"inUnification",
"=",
"true",
";",
"uniMatched",
"=",
"false",
";",
"startUnify",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Tests if the token sequence is unified.
<p>Usage note: to test if the sequence of tokens is unified (i.e.,
shares a group of features, such as the same gender, number,
grammatical case etc.), you need to test all tokens but the last one
in the following way: call {@code isUnified()} for every reading of a token,
and set {@code lastReading} to {@code true}. For the last token, check the
truth value returned by this method. In previous cases, it may actually be
discarded before the final check. See {@link AbstractPatternRule} for
an example.</p>
To make it work in XML rules, the Elements built based on {@code <token>}s inside
the unify block have to be processed in a special way: namely the last Element has to be
marked as the last one (by using {@link PatternToken#setLastInUnification}).
@param matchToken {@link AnalyzedToken} token to unify
@param lastReading true when the matchToken is the last reading in the {@link AnalyzedTokenReadings}
@param isMatched true if the reading matches the element in the pattern rule,
otherwise the reading is not considered in the unification
@return true if the tokens in the sequence are unified
|
[
"Tests",
"if",
"the",
"token",
"sequence",
"is",
"unified",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/patterns/Unifier.java#L403-L427
|
19,101
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/spelling/morfologik/MorfologikSpellerRule.java
|
MorfologikSpellerRule.isSurrogatePairCombination
|
protected boolean isSurrogatePairCombination (String word) {
if (word.length() > 1 && word.length() % 2 == 0 && word.codePointCount(0, word.length()) != word.length()) {
// some symbols such as emojis (๐) have a string length that equals 2
boolean isSurrogatePairCombination = true;
for (int i = 0; i < word.length() && isSurrogatePairCombination; i += 2) {
isSurrogatePairCombination &= Character.isSurrogatePair(word.charAt(i), word.charAt(i + 1));
}
return isSurrogatePairCombination;
}
return false;
}
|
java
|
protected boolean isSurrogatePairCombination (String word) {
if (word.length() > 1 && word.length() % 2 == 0 && word.codePointCount(0, word.length()) != word.length()) {
// some symbols such as emojis (๐) have a string length that equals 2
boolean isSurrogatePairCombination = true;
for (int i = 0; i < word.length() && isSurrogatePairCombination; i += 2) {
isSurrogatePairCombination &= Character.isSurrogatePair(word.charAt(i), word.charAt(i + 1));
}
return isSurrogatePairCombination;
}
return false;
}
|
[
"protected",
"boolean",
"isSurrogatePairCombination",
"(",
"String",
"word",
")",
"{",
"if",
"(",
"word",
".",
"length",
"(",
")",
">",
"1",
"&&",
"word",
".",
"length",
"(",
")",
"%",
"2",
"==",
"0",
"&&",
"word",
".",
"codePointCount",
"(",
"0",
",",
"word",
".",
"length",
"(",
")",
")",
"!=",
"word",
".",
"length",
"(",
")",
")",
"{",
"// some symbols such as emojis (๐) have a string length that equals 2",
"boolean",
"isSurrogatePairCombination",
"=",
"true",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"word",
".",
"length",
"(",
")",
"&&",
"isSurrogatePairCombination",
";",
"i",
"+=",
"2",
")",
"{",
"isSurrogatePairCombination",
"&=",
"Character",
".",
"isSurrogatePair",
"(",
"word",
".",
"charAt",
"(",
"i",
")",
",",
"word",
".",
"charAt",
"(",
"i",
"+",
"1",
")",
")",
";",
"}",
"return",
"isSurrogatePairCombination",
";",
"}",
"return",
"false",
";",
"}"
] |
Checks whether a given String consists only of surrogate pairs.
@param word to be checked
@since 4.2
|
[
"Checks",
"whether",
"a",
"given",
"String",
"consists",
"only",
"of",
"surrogate",
"pairs",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/spelling/morfologik/MorfologikSpellerRule.java#L346-L356
|
19,102
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternRule.java
|
PatternRule.canBeIgnoredFor
|
public boolean canBeIgnoredFor(AnalyzedSentence sentence) {
return (!simpleRuleTokens.isEmpty() && !sentence.getTokenSet().containsAll(simpleRuleTokens))
|| (!inflectedRuleTokens.isEmpty() && !sentence.getLemmaSet().containsAll(inflectedRuleTokens));
}
|
java
|
public boolean canBeIgnoredFor(AnalyzedSentence sentence) {
return (!simpleRuleTokens.isEmpty() && !sentence.getTokenSet().containsAll(simpleRuleTokens))
|| (!inflectedRuleTokens.isEmpty() && !sentence.getLemmaSet().containsAll(inflectedRuleTokens));
}
|
[
"public",
"boolean",
"canBeIgnoredFor",
"(",
"AnalyzedSentence",
"sentence",
")",
"{",
"return",
"(",
"!",
"simpleRuleTokens",
".",
"isEmpty",
"(",
")",
"&&",
"!",
"sentence",
".",
"getTokenSet",
"(",
")",
".",
"containsAll",
"(",
"simpleRuleTokens",
")",
")",
"||",
"(",
"!",
"inflectedRuleTokens",
".",
"isEmpty",
"(",
")",
"&&",
"!",
"sentence",
".",
"getLemmaSet",
"(",
")",
".",
"containsAll",
"(",
"inflectedRuleTokens",
")",
")",
";",
"}"
] |
A fast check whether this rule can be ignored for the given sentence
because it can never match. Used internally for performance optimization.
@since 2.4
|
[
"A",
"fast",
"check",
"whether",
"this",
"rule",
"can",
"be",
"ignored",
"for",
"the",
"given",
"sentence",
"because",
"it",
"can",
"never",
"match",
".",
"Used",
"internally",
"for",
"performance",
"optimization",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternRule.java#L248-L251
|
19,103
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternRule.java
|
PatternRule.getSet
|
private Set<String> getSet(boolean isInflected) {
Set<String> set = new HashSet<>();
for (PatternToken patternToken : patternTokens) {
boolean acceptInflectionValue = isInflected ? patternToken.isInflected() : !patternToken.isInflected();
if (acceptInflectionValue && !patternToken.getNegation() && !patternToken.isRegularExpression()
&& !patternToken.isReferenceElement() && patternToken.getMinOccurrence() > 0) {
String str = patternToken.getString();
if (!StringTools.isEmpty(str)) {
set.add(str.toLowerCase());
}
}
}
return Collections.unmodifiableSet(set);
}
|
java
|
private Set<String> getSet(boolean isInflected) {
Set<String> set = new HashSet<>();
for (PatternToken patternToken : patternTokens) {
boolean acceptInflectionValue = isInflected ? patternToken.isInflected() : !patternToken.isInflected();
if (acceptInflectionValue && !patternToken.getNegation() && !patternToken.isRegularExpression()
&& !patternToken.isReferenceElement() && patternToken.getMinOccurrence() > 0) {
String str = patternToken.getString();
if (!StringTools.isEmpty(str)) {
set.add(str.toLowerCase());
}
}
}
return Collections.unmodifiableSet(set);
}
|
[
"private",
"Set",
"<",
"String",
">",
"getSet",
"(",
"boolean",
"isInflected",
")",
"{",
"Set",
"<",
"String",
">",
"set",
"=",
"new",
"HashSet",
"<>",
"(",
")",
";",
"for",
"(",
"PatternToken",
"patternToken",
":",
"patternTokens",
")",
"{",
"boolean",
"acceptInflectionValue",
"=",
"isInflected",
"?",
"patternToken",
".",
"isInflected",
"(",
")",
":",
"!",
"patternToken",
".",
"isInflected",
"(",
")",
";",
"if",
"(",
"acceptInflectionValue",
"&&",
"!",
"patternToken",
".",
"getNegation",
"(",
")",
"&&",
"!",
"patternToken",
".",
"isRegularExpression",
"(",
")",
"&&",
"!",
"patternToken",
".",
"isReferenceElement",
"(",
")",
"&&",
"patternToken",
".",
"getMinOccurrence",
"(",
")",
">",
"0",
")",
"{",
"String",
"str",
"=",
"patternToken",
".",
"getString",
"(",
")",
";",
"if",
"(",
"!",
"StringTools",
".",
"isEmpty",
"(",
"str",
")",
")",
"{",
"set",
".",
"add",
"(",
"str",
".",
"toLowerCase",
"(",
")",
")",
";",
"}",
"}",
"}",
"return",
"Collections",
".",
"unmodifiableSet",
"(",
"set",
")",
";",
"}"
] |
tokens that just refer to a word - no regex and optionally no inflection etc.
|
[
"tokens",
"that",
"just",
"refer",
"to",
"a",
"word",
"-",
"no",
"regex",
"and",
"optionally",
"no",
"inflection",
"etc",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternRule.java#L254-L267
|
19,104
|
languagetool-org/languagetool
|
languagetool-wikipedia/src/main/java/org/languagetool/dev/index/PatternRuleQueryBuilder.java
|
PatternRuleQueryBuilder.buildRelaxedQuery
|
public Query buildRelaxedQuery(AbstractPatternRule rule) throws UnsupportedPatternRuleException {
BooleanQuery.Builder builder = new BooleanQuery.Builder();
for (PatternToken patternToken : rule.getPatternTokens()) {
try {
BooleanClause clause = makeQuery(patternToken);
builder.add(clause);
} catch (UnsupportedPatternRuleException e) {
//System.out.println("Ignoring because it's not supported: " + element + ": " + e);
// cannot handle - okay to ignore, as we may return too broad matches
} catch (Exception e) {
throw new RuntimeException("Could not create query for rule " + rule.getId(), e);
}
}
BooleanQuery query = builder.build();
if (query.clauses().isEmpty()) {
throw new UnsupportedPatternRuleException("No items found in rule that can be used to build a search query: " + rule);
}
return query;
}
|
java
|
public Query buildRelaxedQuery(AbstractPatternRule rule) throws UnsupportedPatternRuleException {
BooleanQuery.Builder builder = new BooleanQuery.Builder();
for (PatternToken patternToken : rule.getPatternTokens()) {
try {
BooleanClause clause = makeQuery(patternToken);
builder.add(clause);
} catch (UnsupportedPatternRuleException e) {
//System.out.println("Ignoring because it's not supported: " + element + ": " + e);
// cannot handle - okay to ignore, as we may return too broad matches
} catch (Exception e) {
throw new RuntimeException("Could not create query for rule " + rule.getId(), e);
}
}
BooleanQuery query = builder.build();
if (query.clauses().isEmpty()) {
throw new UnsupportedPatternRuleException("No items found in rule that can be used to build a search query: " + rule);
}
return query;
}
|
[
"public",
"Query",
"buildRelaxedQuery",
"(",
"AbstractPatternRule",
"rule",
")",
"throws",
"UnsupportedPatternRuleException",
"{",
"BooleanQuery",
".",
"Builder",
"builder",
"=",
"new",
"BooleanQuery",
".",
"Builder",
"(",
")",
";",
"for",
"(",
"PatternToken",
"patternToken",
":",
"rule",
".",
"getPatternTokens",
"(",
")",
")",
"{",
"try",
"{",
"BooleanClause",
"clause",
"=",
"makeQuery",
"(",
"patternToken",
")",
";",
"builder",
".",
"add",
"(",
"clause",
")",
";",
"}",
"catch",
"(",
"UnsupportedPatternRuleException",
"e",
")",
"{",
"//System.out.println(\"Ignoring because it's not supported: \" + element + \": \" + e);\r",
"// cannot handle - okay to ignore, as we may return too broad matches\r",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Could not create query for rule \"",
"+",
"rule",
".",
"getId",
"(",
")",
",",
"e",
")",
";",
"}",
"}",
"BooleanQuery",
"query",
"=",
"builder",
".",
"build",
"(",
")",
";",
"if",
"(",
"query",
".",
"clauses",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"UnsupportedPatternRuleException",
"(",
"\"No items found in rule that can be used to build a search query: \"",
"+",
"rule",
")",
";",
"}",
"return",
"query",
";",
"}"
] |
Iterate over all elements, ignore those not supported, add the other ones to a BooleanQuery.
@throws UnsupportedPatternRuleException if no query could be created for the rule
|
[
"Iterate",
"over",
"all",
"elements",
"ignore",
"those",
"not",
"supported",
"add",
"the",
"other",
"ones",
"to",
"a",
"BooleanQuery",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-wikipedia/src/main/java/org/languagetool/dev/index/PatternRuleQueryBuilder.java#L69-L87
|
19,105
|
languagetool-org/languagetool
|
languagetool-standalone/src/main/java/org/languagetool/gui/LanguageManagerDialog.java
|
LanguageManagerDialog.getLanguages
|
List<Language> getLanguages() throws IllegalAccessException, InstantiationException {
List<Language> languages = new ArrayList<>();
for (File ruleFile : ruleFiles) {
if (ruleFile != null) {
Language newLanguage = LanguageBuilder.makeAdditionalLanguage(ruleFile);
languages.add(newLanguage);
}
}
return languages;
}
|
java
|
List<Language> getLanguages() throws IllegalAccessException, InstantiationException {
List<Language> languages = new ArrayList<>();
for (File ruleFile : ruleFiles) {
if (ruleFile != null) {
Language newLanguage = LanguageBuilder.makeAdditionalLanguage(ruleFile);
languages.add(newLanguage);
}
}
return languages;
}
|
[
"List",
"<",
"Language",
">",
"getLanguages",
"(",
")",
"throws",
"IllegalAccessException",
",",
"InstantiationException",
"{",
"List",
"<",
"Language",
">",
"languages",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"File",
"ruleFile",
":",
"ruleFiles",
")",
"{",
"if",
"(",
"ruleFile",
"!=",
"null",
")",
"{",
"Language",
"newLanguage",
"=",
"LanguageBuilder",
".",
"makeAdditionalLanguage",
"(",
"ruleFile",
")",
";",
"languages",
".",
"add",
"(",
"newLanguage",
")",
";",
"}",
"}",
"return",
"languages",
";",
"}"
] |
Return all external Languages.
|
[
"Return",
"all",
"external",
"Languages",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-standalone/src/main/java/org/languagetool/gui/LanguageManagerDialog.java#L196-L205
|
19,106
|
languagetool-org/languagetool
|
languagetool-wikipedia/src/main/java/org/languagetool/dev/wikipedia/SuggestionReplacer.java
|
SuggestionReplacer.applySuggestionsToOriginalText
|
public List<RuleMatchApplication> applySuggestionsToOriginalText(RuleMatch match) {
List<String> replacements = new ArrayList<>(match.getSuggestedReplacements());
boolean hasRealReplacements = replacements.size() > 0;
if (!hasRealReplacements) {
// create a pseudo replacement with the error text itself
String plainText = textMapping.getPlainText();
replacements.add(plainText.substring(match.getFromPos(), match.getToPos()));
}
List<RuleMatchApplication> ruleMatchApplications = new ArrayList<>();
Location fromPosLocation = textMapping.getOriginalTextPositionFor(match.getFromPos() + 1); // not zero-based!
Location toPosLocation = textMapping.getOriginalTextPositionFor(match.getToPos() + 1);
/*System.out.println("=========");
System.out.println(textMapping.getMapping());
System.out.println("=========");
System.out.println(textMapping.getPlainText());
System.out.println("=========");
System.out.println(originalText);
System.out.println("=========");*/
int fromPos = LocationHelper.absolutePositionFor(fromPosLocation, originalText);
int toPos = LocationHelper.absolutePositionFor(toPosLocation, originalText);
for (String replacement : replacements) {
String errorText = textMapping.getPlainText().substring(match.getFromPos(), match.getToPos());
// the algorithm is off a bit sometimes due to the complex syntax, so consider the next whitespace:
int contextFrom = findNextWhitespaceToTheLeft(originalText, fromPos);
int contextTo = findNextWhitespaceToTheRight(originalText, toPos);
/*System.out.println(match + ":");
System.out.println("match.getFrom/ToPos(): " + match.getFromPos() + "/" + match.getToPos());
System.out.println("from/toPosLocation: " + fromPosLocation + "/" + toPosLocation);
System.out.println("from/toPos: " + fromPos + "/" + toPos);
System.out.println("contextFrom/To: " + contextFrom + "/" + contextTo);*/
String context = originalText.substring(contextFrom, contextTo);
String text = originalText.substring(0, contextFrom)
+ errorMarker.getStartMarker()
+ context
+ errorMarker.getEndMarker()
+ originalText.substring(contextTo);
String newContext;
if (StringUtils.countMatches(context, errorText) == 1) {
newContext = context.replace(errorText, replacement);
} else {
// This may happen especially for very short strings. As this is an
// error, we don't claim to have real replacements:
newContext = context;
hasRealReplacements = false;
}
String newText = originalText.substring(0, contextFrom)
// we do a simple string replacement as that works even if our mapping is off a bit:
+ errorMarker.getStartMarker()
+ newContext
+ errorMarker.getEndMarker()
+ originalText.substring(contextTo);
RuleMatchApplication application;
if (hasRealReplacements) {
application = RuleMatchApplication.forMatchWithReplacement(match, text, newText, errorMarker);
} else {
application = RuleMatchApplication.forMatchWithoutReplacement(match, text, newText, errorMarker);
}
ruleMatchApplications.add(application);
}
return ruleMatchApplications;
}
|
java
|
public List<RuleMatchApplication> applySuggestionsToOriginalText(RuleMatch match) {
List<String> replacements = new ArrayList<>(match.getSuggestedReplacements());
boolean hasRealReplacements = replacements.size() > 0;
if (!hasRealReplacements) {
// create a pseudo replacement with the error text itself
String plainText = textMapping.getPlainText();
replacements.add(plainText.substring(match.getFromPos(), match.getToPos()));
}
List<RuleMatchApplication> ruleMatchApplications = new ArrayList<>();
Location fromPosLocation = textMapping.getOriginalTextPositionFor(match.getFromPos() + 1); // not zero-based!
Location toPosLocation = textMapping.getOriginalTextPositionFor(match.getToPos() + 1);
/*System.out.println("=========");
System.out.println(textMapping.getMapping());
System.out.println("=========");
System.out.println(textMapping.getPlainText());
System.out.println("=========");
System.out.println(originalText);
System.out.println("=========");*/
int fromPos = LocationHelper.absolutePositionFor(fromPosLocation, originalText);
int toPos = LocationHelper.absolutePositionFor(toPosLocation, originalText);
for (String replacement : replacements) {
String errorText = textMapping.getPlainText().substring(match.getFromPos(), match.getToPos());
// the algorithm is off a bit sometimes due to the complex syntax, so consider the next whitespace:
int contextFrom = findNextWhitespaceToTheLeft(originalText, fromPos);
int contextTo = findNextWhitespaceToTheRight(originalText, toPos);
/*System.out.println(match + ":");
System.out.println("match.getFrom/ToPos(): " + match.getFromPos() + "/" + match.getToPos());
System.out.println("from/toPosLocation: " + fromPosLocation + "/" + toPosLocation);
System.out.println("from/toPos: " + fromPos + "/" + toPos);
System.out.println("contextFrom/To: " + contextFrom + "/" + contextTo);*/
String context = originalText.substring(contextFrom, contextTo);
String text = originalText.substring(0, contextFrom)
+ errorMarker.getStartMarker()
+ context
+ errorMarker.getEndMarker()
+ originalText.substring(contextTo);
String newContext;
if (StringUtils.countMatches(context, errorText) == 1) {
newContext = context.replace(errorText, replacement);
} else {
// This may happen especially for very short strings. As this is an
// error, we don't claim to have real replacements:
newContext = context;
hasRealReplacements = false;
}
String newText = originalText.substring(0, contextFrom)
// we do a simple string replacement as that works even if our mapping is off a bit:
+ errorMarker.getStartMarker()
+ newContext
+ errorMarker.getEndMarker()
+ originalText.substring(contextTo);
RuleMatchApplication application;
if (hasRealReplacements) {
application = RuleMatchApplication.forMatchWithReplacement(match, text, newText, errorMarker);
} else {
application = RuleMatchApplication.forMatchWithoutReplacement(match, text, newText, errorMarker);
}
ruleMatchApplications.add(application);
}
return ruleMatchApplications;
}
|
[
"public",
"List",
"<",
"RuleMatchApplication",
">",
"applySuggestionsToOriginalText",
"(",
"RuleMatch",
"match",
")",
"{",
"List",
"<",
"String",
">",
"replacements",
"=",
"new",
"ArrayList",
"<>",
"(",
"match",
".",
"getSuggestedReplacements",
"(",
")",
")",
";",
"boolean",
"hasRealReplacements",
"=",
"replacements",
".",
"size",
"(",
")",
">",
"0",
";",
"if",
"(",
"!",
"hasRealReplacements",
")",
"{",
"// create a pseudo replacement with the error text itself",
"String",
"plainText",
"=",
"textMapping",
".",
"getPlainText",
"(",
")",
";",
"replacements",
".",
"add",
"(",
"plainText",
".",
"substring",
"(",
"match",
".",
"getFromPos",
"(",
")",
",",
"match",
".",
"getToPos",
"(",
")",
")",
")",
";",
"}",
"List",
"<",
"RuleMatchApplication",
">",
"ruleMatchApplications",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"Location",
"fromPosLocation",
"=",
"textMapping",
".",
"getOriginalTextPositionFor",
"(",
"match",
".",
"getFromPos",
"(",
")",
"+",
"1",
")",
";",
"// not zero-based!",
"Location",
"toPosLocation",
"=",
"textMapping",
".",
"getOriginalTextPositionFor",
"(",
"match",
".",
"getToPos",
"(",
")",
"+",
"1",
")",
";",
"/*System.out.println(\"=========\");\n System.out.println(textMapping.getMapping());\n System.out.println(\"=========\");\n System.out.println(textMapping.getPlainText());\n System.out.println(\"=========\");\n System.out.println(originalText);\n System.out.println(\"=========\");*/",
"int",
"fromPos",
"=",
"LocationHelper",
".",
"absolutePositionFor",
"(",
"fromPosLocation",
",",
"originalText",
")",
";",
"int",
"toPos",
"=",
"LocationHelper",
".",
"absolutePositionFor",
"(",
"toPosLocation",
",",
"originalText",
")",
";",
"for",
"(",
"String",
"replacement",
":",
"replacements",
")",
"{",
"String",
"errorText",
"=",
"textMapping",
".",
"getPlainText",
"(",
")",
".",
"substring",
"(",
"match",
".",
"getFromPos",
"(",
")",
",",
"match",
".",
"getToPos",
"(",
")",
")",
";",
"// the algorithm is off a bit sometimes due to the complex syntax, so consider the next whitespace:",
"int",
"contextFrom",
"=",
"findNextWhitespaceToTheLeft",
"(",
"originalText",
",",
"fromPos",
")",
";",
"int",
"contextTo",
"=",
"findNextWhitespaceToTheRight",
"(",
"originalText",
",",
"toPos",
")",
";",
"/*System.out.println(match + \":\");\n System.out.println(\"match.getFrom/ToPos(): \" + match.getFromPos() + \"/\" + match.getToPos());\n System.out.println(\"from/toPosLocation: \" + fromPosLocation + \"/\" + toPosLocation);\n System.out.println(\"from/toPos: \" + fromPos + \"/\" + toPos);\n System.out.println(\"contextFrom/To: \" + contextFrom + \"/\" + contextTo);*/",
"String",
"context",
"=",
"originalText",
".",
"substring",
"(",
"contextFrom",
",",
"contextTo",
")",
";",
"String",
"text",
"=",
"originalText",
".",
"substring",
"(",
"0",
",",
"contextFrom",
")",
"+",
"errorMarker",
".",
"getStartMarker",
"(",
")",
"+",
"context",
"+",
"errorMarker",
".",
"getEndMarker",
"(",
")",
"+",
"originalText",
".",
"substring",
"(",
"contextTo",
")",
";",
"String",
"newContext",
";",
"if",
"(",
"StringUtils",
".",
"countMatches",
"(",
"context",
",",
"errorText",
")",
"==",
"1",
")",
"{",
"newContext",
"=",
"context",
".",
"replace",
"(",
"errorText",
",",
"replacement",
")",
";",
"}",
"else",
"{",
"// This may happen especially for very short strings. As this is an",
"// error, we don't claim to have real replacements:",
"newContext",
"=",
"context",
";",
"hasRealReplacements",
"=",
"false",
";",
"}",
"String",
"newText",
"=",
"originalText",
".",
"substring",
"(",
"0",
",",
"contextFrom",
")",
"// we do a simple string replacement as that works even if our mapping is off a bit:",
"+",
"errorMarker",
".",
"getStartMarker",
"(",
")",
"+",
"newContext",
"+",
"errorMarker",
".",
"getEndMarker",
"(",
")",
"+",
"originalText",
".",
"substring",
"(",
"contextTo",
")",
";",
"RuleMatchApplication",
"application",
";",
"if",
"(",
"hasRealReplacements",
")",
"{",
"application",
"=",
"RuleMatchApplication",
".",
"forMatchWithReplacement",
"(",
"match",
",",
"text",
",",
"newText",
",",
"errorMarker",
")",
";",
"}",
"else",
"{",
"application",
"=",
"RuleMatchApplication",
".",
"forMatchWithoutReplacement",
"(",
"match",
",",
"text",
",",
"newText",
",",
"errorMarker",
")",
";",
"}",
"ruleMatchApplications",
".",
"add",
"(",
"application",
")",
";",
"}",
"return",
"ruleMatchApplications",
";",
"}"
] |
Applies the suggestions from the rule to the original text. For rules that
have no suggestion, a pseudo-correction is generated that contains the same
text as before.
|
[
"Applies",
"the",
"suggestions",
"from",
"the",
"rule",
"to",
"the",
"original",
"text",
".",
"For",
"rules",
"that",
"have",
"no",
"suggestion",
"a",
"pseudo",
"-",
"correction",
"is",
"generated",
"that",
"contains",
"the",
"same",
"text",
"as",
"before",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-wikipedia/src/main/java/org/languagetool/dev/wikipedia/SuggestionReplacer.java#L60-L125
|
19,107
|
languagetool-org/languagetool
|
languagetool-language-modules/en/src/main/java/org/languagetool/chunking/EnglishChunker.java
|
EnglishChunker.tokenize
|
String[] tokenize(String sentence) {
TokenizerME tokenizer = new TokenizerME(tokenModel);
String cleanString = sentence.replace('โ', '\''); // this is the type of apostrophe that OpenNLP expects
return tokenizer.tokenize(cleanString);
}
|
java
|
String[] tokenize(String sentence) {
TokenizerME tokenizer = new TokenizerME(tokenModel);
String cleanString = sentence.replace('โ', '\''); // this is the type of apostrophe that OpenNLP expects
return tokenizer.tokenize(cleanString);
}
|
[
"String",
"[",
"]",
"tokenize",
"(",
"String",
"sentence",
")",
"{",
"TokenizerME",
"tokenizer",
"=",
"new",
"TokenizerME",
"(",
"tokenModel",
")",
";",
"String",
"cleanString",
"=",
"sentence",
".",
"replace",
"(",
"'",
" ",
"'",
"'",
";",
" ",
" ",
" this is the type of apostrophe that OpenNLP expects",
"return",
"tokenizer",
".",
"tokenize",
"(",
"cleanString",
")",
";",
"}"
] |
non-private for test cases
|
[
"non",
"-",
"private",
"for",
"test",
"cases"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-language-modules/en/src/main/java/org/languagetool/chunking/EnglishChunker.java#L95-L99
|
19,108
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/XMLValidator.java
|
XMLValidator.checkSimpleXMLString
|
public void checkSimpleXMLString(String xml) throws IOException {
Pattern pattern = Pattern.compile("(<error.*?/>)", Pattern.DOTALL|Pattern.MULTILINE);
Matcher matcher = pattern.matcher(xml);
int pos = 0;
while (matcher.find(pos)) {
String errorElement = matcher.group();
pos = matcher.end();
if (errorElement.contains("\n") || errorElement.contains("\r")) {
throw new IOException("<error ...> may not contain line breaks");
}
char beforeError = xml.charAt(matcher.start()-1);
if (beforeError != '\n' && beforeError != '\r') {
throw new IOException("Each <error ...> must start on a new line");
}
}
}
|
java
|
public void checkSimpleXMLString(String xml) throws IOException {
Pattern pattern = Pattern.compile("(<error.*?/>)", Pattern.DOTALL|Pattern.MULTILINE);
Matcher matcher = pattern.matcher(xml);
int pos = 0;
while (matcher.find(pos)) {
String errorElement = matcher.group();
pos = matcher.end();
if (errorElement.contains("\n") || errorElement.contains("\r")) {
throw new IOException("<error ...> may not contain line breaks");
}
char beforeError = xml.charAt(matcher.start()-1);
if (beforeError != '\n' && beforeError != '\r') {
throw new IOException("Each <error ...> must start on a new line");
}
}
}
|
[
"public",
"void",
"checkSimpleXMLString",
"(",
"String",
"xml",
")",
"throws",
"IOException",
"{",
"Pattern",
"pattern",
"=",
"Pattern",
".",
"compile",
"(",
"\"(<error.*?/>)\"",
",",
"Pattern",
".",
"DOTALL",
"|",
"Pattern",
".",
"MULTILINE",
")",
";",
"Matcher",
"matcher",
"=",
"pattern",
".",
"matcher",
"(",
"xml",
")",
";",
"int",
"pos",
"=",
"0",
";",
"while",
"(",
"matcher",
".",
"find",
"(",
"pos",
")",
")",
"{",
"String",
"errorElement",
"=",
"matcher",
".",
"group",
"(",
")",
";",
"pos",
"=",
"matcher",
".",
"end",
"(",
")",
";",
"if",
"(",
"errorElement",
".",
"contains",
"(",
"\"\\n\"",
")",
"||",
"errorElement",
".",
"contains",
"(",
"\"\\r\"",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"<error ...> may not contain line breaks\"",
")",
";",
"}",
"char",
"beforeError",
"=",
"xml",
".",
"charAt",
"(",
"matcher",
".",
"start",
"(",
")",
"-",
"1",
")",
";",
"if",
"(",
"beforeError",
"!=",
"'",
"'",
"&&",
"beforeError",
"!=",
"'",
"'",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Each <error ...> must start on a new line\"",
")",
";",
"}",
"}",
"}"
] |
Check some limits of our simplified XML output.
|
[
"Check",
"some",
"limits",
"of",
"our",
"simplified",
"XML",
"output",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/XMLValidator.java#L66-L81
|
19,109
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/XMLValidator.java
|
XMLValidator.validateXMLString
|
public void validateXMLString(String xml, String dtdFile, String docType) throws SAXException, IOException, ParserConfigurationException {
validateInternal(xml, dtdFile, docType);
}
|
java
|
public void validateXMLString(String xml, String dtdFile, String docType) throws SAXException, IOException, ParserConfigurationException {
validateInternal(xml, dtdFile, docType);
}
|
[
"public",
"void",
"validateXMLString",
"(",
"String",
"xml",
",",
"String",
"dtdFile",
",",
"String",
"docType",
")",
"throws",
"SAXException",
",",
"IOException",
",",
"ParserConfigurationException",
"{",
"validateInternal",
"(",
"xml",
",",
"dtdFile",
",",
"docType",
")",
";",
"}"
] |
Validate XML with the given DTD. Throws exception on error.
|
[
"Validate",
"XML",
"with",
"the",
"given",
"DTD",
".",
"Throws",
"exception",
"on",
"error",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/XMLValidator.java#L86-L88
|
19,110
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/XMLValidator.java
|
XMLValidator.validateWithDtd
|
public void validateWithDtd(String filename, String dtdPath, String docType) throws IOException {
try (InputStream xmlStream = this.getClass().getResourceAsStream(filename)) {
if (xmlStream == null) {
throw new IOException("Not found in classpath: " + filename);
}
try {
String xml = StringTools.readStream(xmlStream, "utf-8");
validateInternal(xml, dtdPath, docType);
} catch (Exception e) {
throw new IOException("Cannot load or parse '" + filename + "'", e);
}
}
}
|
java
|
public void validateWithDtd(String filename, String dtdPath, String docType) throws IOException {
try (InputStream xmlStream = this.getClass().getResourceAsStream(filename)) {
if (xmlStream == null) {
throw new IOException("Not found in classpath: " + filename);
}
try {
String xml = StringTools.readStream(xmlStream, "utf-8");
validateInternal(xml, dtdPath, docType);
} catch (Exception e) {
throw new IOException("Cannot load or parse '" + filename + "'", e);
}
}
}
|
[
"public",
"void",
"validateWithDtd",
"(",
"String",
"filename",
",",
"String",
"dtdPath",
",",
"String",
"docType",
")",
"throws",
"IOException",
"{",
"try",
"(",
"InputStream",
"xmlStream",
"=",
"this",
".",
"getClass",
"(",
")",
".",
"getResourceAsStream",
"(",
"filename",
")",
")",
"{",
"if",
"(",
"xmlStream",
"==",
"null",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Not found in classpath: \"",
"+",
"filename",
")",
";",
"}",
"try",
"{",
"String",
"xml",
"=",
"StringTools",
".",
"readStream",
"(",
"xmlStream",
",",
"\"utf-8\"",
")",
";",
"validateInternal",
"(",
"xml",
",",
"dtdPath",
",",
"docType",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Cannot load or parse '\"",
"+",
"filename",
"+",
"\"'\"",
",",
"e",
")",
";",
"}",
"}",
"}"
] |
Validate XML file in classpath with the given DTD. Throws exception on error.
|
[
"Validate",
"XML",
"file",
"in",
"classpath",
"with",
"the",
"given",
"DTD",
".",
"Throws",
"exception",
"on",
"error",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/XMLValidator.java#L93-L105
|
19,111
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/JLanguageTool.java
|
JLanguageTool.activateNeuralNetworkRules
|
public void activateNeuralNetworkRules(File modelDir) throws IOException {
ResourceBundle messages = getMessageBundle(language);
List<Rule> rules = language.getRelevantNeuralNetworkModels(messages, modelDir);
userRules.addAll(rules);
}
|
java
|
public void activateNeuralNetworkRules(File modelDir) throws IOException {
ResourceBundle messages = getMessageBundle(language);
List<Rule> rules = language.getRelevantNeuralNetworkModels(messages, modelDir);
userRules.addAll(rules);
}
|
[
"public",
"void",
"activateNeuralNetworkRules",
"(",
"File",
"modelDir",
")",
"throws",
"IOException",
"{",
"ResourceBundle",
"messages",
"=",
"getMessageBundle",
"(",
"language",
")",
";",
"List",
"<",
"Rule",
">",
"rules",
"=",
"language",
".",
"getRelevantNeuralNetworkModels",
"(",
"messages",
",",
"modelDir",
")",
";",
"userRules",
".",
"addAll",
"(",
"rules",
")",
";",
"}"
] |
Activate rules that depend on pretrained neural network models.
@param modelDir root dir of exported models
@since 4.4
|
[
"Activate",
"rules",
"that",
"depend",
"on",
"pretrained",
"neural",
"network",
"models",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/JLanguageTool.java#L471-L475
|
19,112
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/JLanguageTool.java
|
JLanguageTool.activateLanguageModelRules
|
public void activateLanguageModelRules(File indexDir) throws IOException {
LanguageModel languageModel = language.getLanguageModel(indexDir);
if (languageModel != null) {
ResourceBundle messages = getMessageBundle(language);
List<Rule> rules = language.getRelevantLanguageModelRules(messages, languageModel);
userRules.addAll(rules);
updateOptionalLanguageModelRules(languageModel);
}
}
|
java
|
public void activateLanguageModelRules(File indexDir) throws IOException {
LanguageModel languageModel = language.getLanguageModel(indexDir);
if (languageModel != null) {
ResourceBundle messages = getMessageBundle(language);
List<Rule> rules = language.getRelevantLanguageModelRules(messages, languageModel);
userRules.addAll(rules);
updateOptionalLanguageModelRules(languageModel);
}
}
|
[
"public",
"void",
"activateLanguageModelRules",
"(",
"File",
"indexDir",
")",
"throws",
"IOException",
"{",
"LanguageModel",
"languageModel",
"=",
"language",
".",
"getLanguageModel",
"(",
"indexDir",
")",
";",
"if",
"(",
"languageModel",
"!=",
"null",
")",
"{",
"ResourceBundle",
"messages",
"=",
"getMessageBundle",
"(",
"language",
")",
";",
"List",
"<",
"Rule",
">",
"rules",
"=",
"language",
".",
"getRelevantLanguageModelRules",
"(",
"messages",
",",
"languageModel",
")",
";",
"userRules",
".",
"addAll",
"(",
"rules",
")",
";",
"updateOptionalLanguageModelRules",
"(",
"languageModel",
")",
";",
"}",
"}"
] |
Activate rules that depend on a language model. The language model currently
consists of Lucene indexes with ngram occurrence counts.
@param indexDir directory with a '3grams' sub directory which contains a Lucene index with 3gram occurrence counts
@since 2.7
|
[
"Activate",
"rules",
"that",
"depend",
"on",
"a",
"language",
"model",
".",
"The",
"language",
"model",
"currently",
"consists",
"of",
"Lucene",
"indexes",
"with",
"ngram",
"occurrence",
"counts",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/JLanguageTool.java#L483-L491
|
19,113
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/JLanguageTool.java
|
JLanguageTool.activateWord2VecModelRules
|
public void activateWord2VecModelRules(File indexDir) throws IOException {
Word2VecModel word2vecModel = language.getWord2VecModel(indexDir);
if (word2vecModel != null) {
ResourceBundle messages = getMessageBundle(language);
List<Rule> rules = language.getRelevantWord2VecModelRules(messages, word2vecModel);
userRules.addAll(rules);
}
}
|
java
|
public void activateWord2VecModelRules(File indexDir) throws IOException {
Word2VecModel word2vecModel = language.getWord2VecModel(indexDir);
if (word2vecModel != null) {
ResourceBundle messages = getMessageBundle(language);
List<Rule> rules = language.getRelevantWord2VecModelRules(messages, word2vecModel);
userRules.addAll(rules);
}
}
|
[
"public",
"void",
"activateWord2VecModelRules",
"(",
"File",
"indexDir",
")",
"throws",
"IOException",
"{",
"Word2VecModel",
"word2vecModel",
"=",
"language",
".",
"getWord2VecModel",
"(",
"indexDir",
")",
";",
"if",
"(",
"word2vecModel",
"!=",
"null",
")",
"{",
"ResourceBundle",
"messages",
"=",
"getMessageBundle",
"(",
"language",
")",
";",
"List",
"<",
"Rule",
">",
"rules",
"=",
"language",
".",
"getRelevantWord2VecModelRules",
"(",
"messages",
",",
"word2vecModel",
")",
";",
"userRules",
".",
"addAll",
"(",
"rules",
")",
";",
"}",
"}"
] |
Activate rules that depend on a word2vec language model.
@param indexDir directory with a subdirectories like 'en', each containing dictionary.txt and final_embeddings.txt
@since 4.0
|
[
"Activate",
"rules",
"that",
"depend",
"on",
"a",
"word2vec",
"language",
"model",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/JLanguageTool.java#L498-L505
|
19,114
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/JLanguageTool.java
|
JLanguageTool.adjustRuleMatchPos
|
public RuleMatch adjustRuleMatchPos(RuleMatch match, int charCount,
int columnCount, int lineCount, String sentence, AnnotatedText annotatedText) {
int fromPos = match.getFromPos() + charCount;
int toPos = match.getToPos() + charCount;
if (annotatedText != null) {
fromPos = annotatedText.getOriginalTextPositionFor(fromPos);
toPos = annotatedText.getOriginalTextPositionFor(toPos - 1) + 1;
}
RuleMatch thisMatch = new RuleMatch(match);
thisMatch.setOffsetPosition(fromPos, toPos);
List<SuggestedReplacement> replacements = match.getSuggestedReplacementObjects();
thisMatch.setSuggestedReplacementObjects(extendSuggestions(replacements));
String sentencePartToError = sentence.substring(0, match.getFromPos());
String sentencePartToEndOfError = sentence.substring(0, match.getToPos());
int lastLineBreakPos = sentencePartToError.lastIndexOf('\n');
int column;
int endColumn;
if (lastLineBreakPos == -1) {
column = sentencePartToError.length() + columnCount;
} else {
column = sentencePartToError.length() - lastLineBreakPos;
}
int lastLineBreakPosInError = sentencePartToEndOfError.lastIndexOf('\n');
if (lastLineBreakPosInError == -1) {
endColumn = sentencePartToEndOfError.length() + columnCount;
} else {
endColumn = sentencePartToEndOfError.length() - lastLineBreakPosInError;
}
int lineBreaksToError = countLineBreaks(sentencePartToError);
int lineBreaksToEndOfError = countLineBreaks(sentencePartToEndOfError);
thisMatch.setLine(lineCount + lineBreaksToError);
thisMatch.setEndLine(lineCount + lineBreaksToEndOfError);
thisMatch.setColumn(column);
thisMatch.setEndColumn(endColumn);
return thisMatch;
}
|
java
|
public RuleMatch adjustRuleMatchPos(RuleMatch match, int charCount,
int columnCount, int lineCount, String sentence, AnnotatedText annotatedText) {
int fromPos = match.getFromPos() + charCount;
int toPos = match.getToPos() + charCount;
if (annotatedText != null) {
fromPos = annotatedText.getOriginalTextPositionFor(fromPos);
toPos = annotatedText.getOriginalTextPositionFor(toPos - 1) + 1;
}
RuleMatch thisMatch = new RuleMatch(match);
thisMatch.setOffsetPosition(fromPos, toPos);
List<SuggestedReplacement> replacements = match.getSuggestedReplacementObjects();
thisMatch.setSuggestedReplacementObjects(extendSuggestions(replacements));
String sentencePartToError = sentence.substring(0, match.getFromPos());
String sentencePartToEndOfError = sentence.substring(0, match.getToPos());
int lastLineBreakPos = sentencePartToError.lastIndexOf('\n');
int column;
int endColumn;
if (lastLineBreakPos == -1) {
column = sentencePartToError.length() + columnCount;
} else {
column = sentencePartToError.length() - lastLineBreakPos;
}
int lastLineBreakPosInError = sentencePartToEndOfError.lastIndexOf('\n');
if (lastLineBreakPosInError == -1) {
endColumn = sentencePartToEndOfError.length() + columnCount;
} else {
endColumn = sentencePartToEndOfError.length() - lastLineBreakPosInError;
}
int lineBreaksToError = countLineBreaks(sentencePartToError);
int lineBreaksToEndOfError = countLineBreaks(sentencePartToEndOfError);
thisMatch.setLine(lineCount + lineBreaksToError);
thisMatch.setEndLine(lineCount + lineBreaksToEndOfError);
thisMatch.setColumn(column);
thisMatch.setEndColumn(endColumn);
return thisMatch;
}
|
[
"public",
"RuleMatch",
"adjustRuleMatchPos",
"(",
"RuleMatch",
"match",
",",
"int",
"charCount",
",",
"int",
"columnCount",
",",
"int",
"lineCount",
",",
"String",
"sentence",
",",
"AnnotatedText",
"annotatedText",
")",
"{",
"int",
"fromPos",
"=",
"match",
".",
"getFromPos",
"(",
")",
"+",
"charCount",
";",
"int",
"toPos",
"=",
"match",
".",
"getToPos",
"(",
")",
"+",
"charCount",
";",
"if",
"(",
"annotatedText",
"!=",
"null",
")",
"{",
"fromPos",
"=",
"annotatedText",
".",
"getOriginalTextPositionFor",
"(",
"fromPos",
")",
";",
"toPos",
"=",
"annotatedText",
".",
"getOriginalTextPositionFor",
"(",
"toPos",
"-",
"1",
")",
"+",
"1",
";",
"}",
"RuleMatch",
"thisMatch",
"=",
"new",
"RuleMatch",
"(",
"match",
")",
";",
"thisMatch",
".",
"setOffsetPosition",
"(",
"fromPos",
",",
"toPos",
")",
";",
"List",
"<",
"SuggestedReplacement",
">",
"replacements",
"=",
"match",
".",
"getSuggestedReplacementObjects",
"(",
")",
";",
"thisMatch",
".",
"setSuggestedReplacementObjects",
"(",
"extendSuggestions",
"(",
"replacements",
")",
")",
";",
"String",
"sentencePartToError",
"=",
"sentence",
".",
"substring",
"(",
"0",
",",
"match",
".",
"getFromPos",
"(",
")",
")",
";",
"String",
"sentencePartToEndOfError",
"=",
"sentence",
".",
"substring",
"(",
"0",
",",
"match",
".",
"getToPos",
"(",
")",
")",
";",
"int",
"lastLineBreakPos",
"=",
"sentencePartToError",
".",
"lastIndexOf",
"(",
"'",
"'",
")",
";",
"int",
"column",
";",
"int",
"endColumn",
";",
"if",
"(",
"lastLineBreakPos",
"==",
"-",
"1",
")",
"{",
"column",
"=",
"sentencePartToError",
".",
"length",
"(",
")",
"+",
"columnCount",
";",
"}",
"else",
"{",
"column",
"=",
"sentencePartToError",
".",
"length",
"(",
")",
"-",
"lastLineBreakPos",
";",
"}",
"int",
"lastLineBreakPosInError",
"=",
"sentencePartToEndOfError",
".",
"lastIndexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"lastLineBreakPosInError",
"==",
"-",
"1",
")",
"{",
"endColumn",
"=",
"sentencePartToEndOfError",
".",
"length",
"(",
")",
"+",
"columnCount",
";",
"}",
"else",
"{",
"endColumn",
"=",
"sentencePartToEndOfError",
".",
"length",
"(",
")",
"-",
"lastLineBreakPosInError",
";",
"}",
"int",
"lineBreaksToError",
"=",
"countLineBreaks",
"(",
"sentencePartToError",
")",
";",
"int",
"lineBreaksToEndOfError",
"=",
"countLineBreaks",
"(",
"sentencePartToEndOfError",
")",
";",
"thisMatch",
".",
"setLine",
"(",
"lineCount",
"+",
"lineBreaksToError",
")",
";",
"thisMatch",
".",
"setEndLine",
"(",
"lineCount",
"+",
"lineBreaksToEndOfError",
")",
";",
"thisMatch",
".",
"setColumn",
"(",
"column",
")",
";",
"thisMatch",
".",
"setEndColumn",
"(",
"endColumn",
")",
";",
"return",
"thisMatch",
";",
"}"
] |
Change RuleMatch positions so they are relative to the complete text,
not just to the sentence.
@param charCount Count of characters in the sentences before
@param columnCount Current column number
@param lineCount Current line number
@param sentence The text being checked
@return The RuleMatch object with adjustments
|
[
"Change",
"RuleMatch",
"positions",
"so",
"they",
"are",
"relative",
"to",
"the",
"complete",
"text",
"not",
"just",
"to",
"the",
"sentence",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/JLanguageTool.java#L851-L888
|
19,115
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/JLanguageTool.java
|
JLanguageTool.countLineBreaks
|
static int countLineBreaks(String s) {
int pos = -1;
int count = 0;
while (true) {
int nextPos = s.indexOf('\n', pos + 1);
if (nextPos == -1) {
break;
}
pos = nextPos;
count++;
}
return count;
}
|
java
|
static int countLineBreaks(String s) {
int pos = -1;
int count = 0;
while (true) {
int nextPos = s.indexOf('\n', pos + 1);
if (nextPos == -1) {
break;
}
pos = nextPos;
count++;
}
return count;
}
|
[
"static",
"int",
"countLineBreaks",
"(",
"String",
"s",
")",
"{",
"int",
"pos",
"=",
"-",
"1",
";",
"int",
"count",
"=",
"0",
";",
"while",
"(",
"true",
")",
"{",
"int",
"nextPos",
"=",
"s",
".",
"indexOf",
"(",
"'",
"'",
",",
"pos",
"+",
"1",
")",
";",
"if",
"(",
"nextPos",
"==",
"-",
"1",
")",
"{",
"break",
";",
"}",
"pos",
"=",
"nextPos",
";",
"count",
"++",
";",
"}",
"return",
"count",
";",
"}"
] |
non-private only for test case
|
[
"non",
"-",
"private",
"only",
"for",
"test",
"case"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/JLanguageTool.java#L928-L940
|
19,116
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/JLanguageTool.java
|
JLanguageTool.getCategories
|
public Map<CategoryId, Category> getCategories() {
Map<CategoryId, Category> map = new HashMap<>();
for (Rule rule : getAllRules()) {
map.put(rule.getCategory().getId(), rule.getCategory());
}
return map;
}
|
java
|
public Map<CategoryId, Category> getCategories() {
Map<CategoryId, Category> map = new HashMap<>();
for (Rule rule : getAllRules()) {
map.put(rule.getCategory().getId(), rule.getCategory());
}
return map;
}
|
[
"public",
"Map",
"<",
"CategoryId",
",",
"Category",
">",
"getCategories",
"(",
")",
"{",
"Map",
"<",
"CategoryId",
",",
"Category",
">",
"map",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"for",
"(",
"Rule",
"rule",
":",
"getAllRules",
"(",
")",
")",
"{",
"map",
".",
"put",
"(",
"rule",
".",
"getCategory",
"(",
")",
".",
"getId",
"(",
")",
",",
"rule",
".",
"getCategory",
"(",
")",
")",
";",
"}",
"return",
"map",
";",
"}"
] |
Get all rule categories for the current language.
@return a map of {@link Category Categories}, keyed by their {@link CategoryId id}.
@since 3.5
|
[
"Get",
"all",
"rule",
"categories",
"for",
"the",
"current",
"language",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/JLanguageTool.java#L1044-L1050
|
19,117
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/JLanguageTool.java
|
JLanguageTool.getAllActiveOfficeRules
|
public List<Rule> getAllActiveOfficeRules() {
List<Rule> rules = new ArrayList<>();
List<Rule> rulesActive = new ArrayList<>();
rules.addAll(builtinRules);
rules.addAll(userRules);
for (Rule rule : rules) {
if (!ignoreRule(rule) && !rule.isOfficeDefaultOff()) {
rulesActive.add(rule);
} else if (rule.isOfficeDefaultOn()) {
rulesActive.add(rule);
enableRule(rule.getId());
} else if (!ignoreRule(rule) && rule.isOfficeDefaultOff()) {
disableRule(rule.getId());
}
}
return rulesActive;
}
|
java
|
public List<Rule> getAllActiveOfficeRules() {
List<Rule> rules = new ArrayList<>();
List<Rule> rulesActive = new ArrayList<>();
rules.addAll(builtinRules);
rules.addAll(userRules);
for (Rule rule : rules) {
if (!ignoreRule(rule) && !rule.isOfficeDefaultOff()) {
rulesActive.add(rule);
} else if (rule.isOfficeDefaultOn()) {
rulesActive.add(rule);
enableRule(rule.getId());
} else if (!ignoreRule(rule) && rule.isOfficeDefaultOff()) {
disableRule(rule.getId());
}
}
return rulesActive;
}
|
[
"public",
"List",
"<",
"Rule",
">",
"getAllActiveOfficeRules",
"(",
")",
"{",
"List",
"<",
"Rule",
">",
"rules",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"List",
"<",
"Rule",
">",
"rulesActive",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"rules",
".",
"addAll",
"(",
"builtinRules",
")",
";",
"rules",
".",
"addAll",
"(",
"userRules",
")",
";",
"for",
"(",
"Rule",
"rule",
":",
"rules",
")",
"{",
"if",
"(",
"!",
"ignoreRule",
"(",
"rule",
")",
"&&",
"!",
"rule",
".",
"isOfficeDefaultOff",
"(",
")",
")",
"{",
"rulesActive",
".",
"add",
"(",
"rule",
")",
";",
"}",
"else",
"if",
"(",
"rule",
".",
"isOfficeDefaultOn",
"(",
")",
")",
"{",
"rulesActive",
".",
"add",
"(",
"rule",
")",
";",
"enableRule",
"(",
"rule",
".",
"getId",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"!",
"ignoreRule",
"(",
"rule",
")",
"&&",
"rule",
".",
"isOfficeDefaultOff",
"(",
")",
")",
"{",
"disableRule",
"(",
"rule",
".",
"getId",
"(",
")",
")",
";",
"}",
"}",
"return",
"rulesActive",
";",
"}"
] |
Works like getAllActiveRules but overrides defaults by officeefaults
@return a List of {@link Rule} objects
@since 4.0
|
[
"Works",
"like",
"getAllActiveRules",
"but",
"overrides",
"defaults",
"by",
"officeefaults"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/JLanguageTool.java#L1095-L1111
|
19,118
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternRuleMatcher.java
|
PatternRuleMatcher.matchPreservesCase
|
private boolean matchPreservesCase(List<Match> suggestionMatches, String msg) {
if (suggestionMatches != null && !suggestionMatches.isEmpty()) {
//PatternRule rule = (PatternRule) this.rule;
int sugStart = msg.indexOf(SUGGESTION_START_TAG) + SUGGESTION_START_TAG.length();
for (Match sMatch : suggestionMatches) {
if (!sMatch.isInMessageOnly() && sMatch.convertsCase()
&& msg.charAt(sugStart) == '\\') {
return false;
}
}
}
return true;
}
|
java
|
private boolean matchPreservesCase(List<Match> suggestionMatches, String msg) {
if (suggestionMatches != null && !suggestionMatches.isEmpty()) {
//PatternRule rule = (PatternRule) this.rule;
int sugStart = msg.indexOf(SUGGESTION_START_TAG) + SUGGESTION_START_TAG.length();
for (Match sMatch : suggestionMatches) {
if (!sMatch.isInMessageOnly() && sMatch.convertsCase()
&& msg.charAt(sugStart) == '\\') {
return false;
}
}
}
return true;
}
|
[
"private",
"boolean",
"matchPreservesCase",
"(",
"List",
"<",
"Match",
">",
"suggestionMatches",
",",
"String",
"msg",
")",
"{",
"if",
"(",
"suggestionMatches",
"!=",
"null",
"&&",
"!",
"suggestionMatches",
".",
"isEmpty",
"(",
")",
")",
"{",
"//PatternRule rule = (PatternRule) this.rule;",
"int",
"sugStart",
"=",
"msg",
".",
"indexOf",
"(",
"SUGGESTION_START_TAG",
")",
"+",
"SUGGESTION_START_TAG",
".",
"length",
"(",
")",
";",
"for",
"(",
"Match",
"sMatch",
":",
"suggestionMatches",
")",
"{",
"if",
"(",
"!",
"sMatch",
".",
"isInMessageOnly",
"(",
")",
"&&",
"sMatch",
".",
"convertsCase",
"(",
")",
"&&",
"msg",
".",
"charAt",
"(",
"sugStart",
")",
"==",
"'",
"'",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] |
Checks if the suggestion starts with a match that is supposed to preserve
case. If it does not, perform the default conversion to uppercase.
@return true, if the match preserves the case of the token.
|
[
"Checks",
"if",
"the",
"suggestion",
"starts",
"with",
"a",
"match",
"that",
"is",
"supposed",
"to",
"preserve",
"case",
".",
"If",
"it",
"does",
"not",
"perform",
"the",
"default",
"conversion",
"to",
"uppercase",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternRuleMatcher.java#L261-L273
|
19,119
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternRuleMatcher.java
|
PatternRuleMatcher.translateElementNo
|
private int translateElementNo(int i) {
if (!useList || i < 0) {
return i;
}
int j = 0;
PatternRule rule = (PatternRule) this.rule;
for (int k = 0; k < i; k++) {
j += rule.getElementNo().get(k);
}
return j;
}
|
java
|
private int translateElementNo(int i) {
if (!useList || i < 0) {
return i;
}
int j = 0;
PatternRule rule = (PatternRule) this.rule;
for (int k = 0; k < i; k++) {
j += rule.getElementNo().get(k);
}
return j;
}
|
[
"private",
"int",
"translateElementNo",
"(",
"int",
"i",
")",
"{",
"if",
"(",
"!",
"useList",
"||",
"i",
"<",
"0",
")",
"{",
"return",
"i",
";",
"}",
"int",
"j",
"=",
"0",
";",
"PatternRule",
"rule",
"=",
"(",
"PatternRule",
")",
"this",
".",
"rule",
";",
"for",
"(",
"int",
"k",
"=",
"0",
";",
"k",
"<",
"i",
";",
"k",
"++",
")",
"{",
"j",
"+=",
"rule",
".",
"getElementNo",
"(",
")",
".",
"get",
"(",
"k",
")",
";",
"}",
"return",
"j",
";",
"}"
] |
Gets the index of the element indexed by i, adding any offsets because of
the phrases in the rule.
@param i Current element index.
@return int Index translated into XML element no.
|
[
"Gets",
"the",
"index",
"of",
"the",
"element",
"indexed",
"by",
"i",
"adding",
"any",
"offsets",
"because",
"of",
"the",
"phrases",
"in",
"the",
"rule",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternRuleMatcher.java#L281-L291
|
19,120
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternRuleMatcher.java
|
PatternRuleMatcher.combineLists
|
private static String[] combineLists(String[][] input,
String[] output, int r, Language lang) {
List<String> outputList = new ArrayList<>();
if (r == input.length) {
StringBuilder sb = new StringBuilder();
for (int k = 0; k < output.length; k++) {
sb.append(output[k]);
if (k < output.length - 1) {
sb.append(StringTools.addSpace(output[k + 1], lang));
}
}
outputList.add(sb.toString());
} else {
for (int c = 0; c < input[r].length; c++) {
output[r] = input[r][c];
String[] sList = combineLists(input, output, r + 1, lang);
outputList.addAll(Arrays.asList(sList));
}
}
return outputList.toArray(new String[0]);
}
|
java
|
private static String[] combineLists(String[][] input,
String[] output, int r, Language lang) {
List<String> outputList = new ArrayList<>();
if (r == input.length) {
StringBuilder sb = new StringBuilder();
for (int k = 0; k < output.length; k++) {
sb.append(output[k]);
if (k < output.length - 1) {
sb.append(StringTools.addSpace(output[k + 1], lang));
}
}
outputList.add(sb.toString());
} else {
for (int c = 0; c < input[r].length; c++) {
output[r] = input[r][c];
String[] sList = combineLists(input, output, r + 1, lang);
outputList.addAll(Arrays.asList(sList));
}
}
return outputList.toArray(new String[0]);
}
|
[
"private",
"static",
"String",
"[",
"]",
"combineLists",
"(",
"String",
"[",
"]",
"[",
"]",
"input",
",",
"String",
"[",
"]",
"output",
",",
"int",
"r",
",",
"Language",
"lang",
")",
"{",
"List",
"<",
"String",
">",
"outputList",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"if",
"(",
"r",
"==",
"input",
".",
"length",
")",
"{",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"int",
"k",
"=",
"0",
";",
"k",
"<",
"output",
".",
"length",
";",
"k",
"++",
")",
"{",
"sb",
".",
"append",
"(",
"output",
"[",
"k",
"]",
")",
";",
"if",
"(",
"k",
"<",
"output",
".",
"length",
"-",
"1",
")",
"{",
"sb",
".",
"append",
"(",
"StringTools",
".",
"addSpace",
"(",
"output",
"[",
"k",
"+",
"1",
"]",
",",
"lang",
")",
")",
";",
"}",
"}",
"outputList",
".",
"add",
"(",
"sb",
".",
"toString",
"(",
")",
")",
";",
"}",
"else",
"{",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"input",
"[",
"r",
"]",
".",
"length",
";",
"c",
"++",
")",
"{",
"output",
"[",
"r",
"]",
"=",
"input",
"[",
"r",
"]",
"[",
"c",
"]",
";",
"String",
"[",
"]",
"sList",
"=",
"combineLists",
"(",
"input",
",",
"output",
",",
"r",
"+",
"1",
",",
"lang",
")",
";",
"outputList",
".",
"addAll",
"(",
"Arrays",
".",
"asList",
"(",
"sList",
")",
")",
";",
"}",
"}",
"return",
"outputList",
".",
"toArray",
"(",
"new",
"String",
"[",
"0",
"]",
")",
";",
"}"
] |
Creates a Cartesian product of the arrays stored in the input array.
@param input Array of string arrays to combine.
@param output Work array of strings.
@param r Starting parameter (use 0 to get all combinations).
@param lang Text language for adding spaces in some languages.
@return Combined array of String.
|
[
"Creates",
"a",
"Cartesian",
"product",
"of",
"the",
"arrays",
"stored",
"in",
"the",
"input",
"array",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternRuleMatcher.java#L502-L522
|
19,121
|
languagetool-org/languagetool
|
languagetool-gui-commons/src/main/java/org/languagetool/gui/ConfigurationDialog.java
|
ConfigurationDialog.getLanguageForLocalizedName
|
@Nullable
private Language getLanguageForLocalizedName(String languageName) {
for (Language element : Languages.get()) {
if (languageName.equals(element.getTranslatedName(messages))) {
return element;
}
}
return null;
}
|
java
|
@Nullable
private Language getLanguageForLocalizedName(String languageName) {
for (Language element : Languages.get()) {
if (languageName.equals(element.getTranslatedName(messages))) {
return element;
}
}
return null;
}
|
[
"@",
"Nullable",
"private",
"Language",
"getLanguageForLocalizedName",
"(",
"String",
"languageName",
")",
"{",
"for",
"(",
"Language",
"element",
":",
"Languages",
".",
"get",
"(",
")",
")",
"{",
"if",
"(",
"languageName",
".",
"equals",
"(",
"element",
".",
"getTranslatedName",
"(",
"messages",
")",
")",
")",
"{",
"return",
"element",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Get the Language object for the given localized language name.
@param languageName e.g. <code>English</code> or <code>German</code> (case is significant)
@return a Language object or <code>null</code> if the language could not be found
|
[
"Get",
"the",
"Language",
"object",
"for",
"the",
"given",
"localized",
"language",
"name",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-gui-commons/src/main/java/org/languagetool/gui/ConfigurationDialog.java#L984-L992
|
19,122
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/LinguisticServices.java
|
LinguisticServices.GetLinguSvcMgr
|
private XLinguServiceManager GetLinguSvcMgr(XComponentContext xContext) {
try {
XMultiComponentFactory xMCF = UnoRuntime.queryInterface(XMultiComponentFactory.class,
xContext.getServiceManager());
if (xMCF == null) {
printText("XMultiComponentFactory == null");
return null;
}
// retrieve Office's remote component context as a property
XPropertySet props = UnoRuntime.queryInterface(XPropertySet.class, xMCF);
if (props == null) {
printText("XPropertySet == null");
return null;
}
// initObject);
Object defaultContext = props.getPropertyValue("DefaultContext");
// get the remote interface XComponentContext
XComponentContext xComponentContext = UnoRuntime.queryInterface(XComponentContext.class, defaultContext);
if (xComponentContext == null) {
printText("XComponentContext == null");
return null;
}
Object o = xMCF.createInstanceWithContext("com.sun.star.linguistic2.LinguServiceManager", xComponentContext);
// create service component using the specified component context
XLinguServiceManager mxLinguSvcMgr = UnoRuntime.queryInterface(XLinguServiceManager.class, o);
if (mxLinguSvcMgr == null) {
printText("XLinguServiceManager2 == null");
return null;
}
return mxLinguSvcMgr;
} catch (Throwable t) {
// If anything goes wrong, give the user a stack trace
printMessage(t);
}
return null;
}
|
java
|
private XLinguServiceManager GetLinguSvcMgr(XComponentContext xContext) {
try {
XMultiComponentFactory xMCF = UnoRuntime.queryInterface(XMultiComponentFactory.class,
xContext.getServiceManager());
if (xMCF == null) {
printText("XMultiComponentFactory == null");
return null;
}
// retrieve Office's remote component context as a property
XPropertySet props = UnoRuntime.queryInterface(XPropertySet.class, xMCF);
if (props == null) {
printText("XPropertySet == null");
return null;
}
// initObject);
Object defaultContext = props.getPropertyValue("DefaultContext");
// get the remote interface XComponentContext
XComponentContext xComponentContext = UnoRuntime.queryInterface(XComponentContext.class, defaultContext);
if (xComponentContext == null) {
printText("XComponentContext == null");
return null;
}
Object o = xMCF.createInstanceWithContext("com.sun.star.linguistic2.LinguServiceManager", xComponentContext);
// create service component using the specified component context
XLinguServiceManager mxLinguSvcMgr = UnoRuntime.queryInterface(XLinguServiceManager.class, o);
if (mxLinguSvcMgr == null) {
printText("XLinguServiceManager2 == null");
return null;
}
return mxLinguSvcMgr;
} catch (Throwable t) {
// If anything goes wrong, give the user a stack trace
printMessage(t);
}
return null;
}
|
[
"private",
"XLinguServiceManager",
"GetLinguSvcMgr",
"(",
"XComponentContext",
"xContext",
")",
"{",
"try",
"{",
"XMultiComponentFactory",
"xMCF",
"=",
"UnoRuntime",
".",
"queryInterface",
"(",
"XMultiComponentFactory",
".",
"class",
",",
"xContext",
".",
"getServiceManager",
"(",
")",
")",
";",
"if",
"(",
"xMCF",
"==",
"null",
")",
"{",
"printText",
"(",
"\"XMultiComponentFactory == null\"",
")",
";",
"return",
"null",
";",
"}",
"// retrieve Office's remote component context as a property",
"XPropertySet",
"props",
"=",
"UnoRuntime",
".",
"queryInterface",
"(",
"XPropertySet",
".",
"class",
",",
"xMCF",
")",
";",
"if",
"(",
"props",
"==",
"null",
")",
"{",
"printText",
"(",
"\"XPropertySet == null\"",
")",
";",
"return",
"null",
";",
"}",
"// initObject);",
"Object",
"defaultContext",
"=",
"props",
".",
"getPropertyValue",
"(",
"\"DefaultContext\"",
")",
";",
"// get the remote interface XComponentContext",
"XComponentContext",
"xComponentContext",
"=",
"UnoRuntime",
".",
"queryInterface",
"(",
"XComponentContext",
".",
"class",
",",
"defaultContext",
")",
";",
"if",
"(",
"xComponentContext",
"==",
"null",
")",
"{",
"printText",
"(",
"\"XComponentContext == null\"",
")",
";",
"return",
"null",
";",
"}",
"Object",
"o",
"=",
"xMCF",
".",
"createInstanceWithContext",
"(",
"\"com.sun.star.linguistic2.LinguServiceManager\"",
",",
"xComponentContext",
")",
";",
"// create service component using the specified component context",
"XLinguServiceManager",
"mxLinguSvcMgr",
"=",
"UnoRuntime",
".",
"queryInterface",
"(",
"XLinguServiceManager",
".",
"class",
",",
"o",
")",
";",
"if",
"(",
"mxLinguSvcMgr",
"==",
"null",
")",
"{",
"printText",
"(",
"\"XLinguServiceManager2 == null\"",
")",
";",
"return",
"null",
";",
"}",
"return",
"mxLinguSvcMgr",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"// If anything goes wrong, give the user a stack trace",
"printMessage",
"(",
"t",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Get the LinguServiceManager to be used for example
to access spell checker, thesaurus and hyphenator
|
[
"Get",
"the",
"LinguServiceManager",
"to",
"be",
"used",
"for",
"example",
"to",
"access",
"spell",
"checker",
"thesaurus",
"and",
"hyphenator"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/LinguisticServices.java#L62-L97
|
19,123
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/LinguisticServices.java
|
LinguisticServices.GetThesaurus
|
private XThesaurus GetThesaurus(XLinguServiceManager mxLinguSvcMgr) {
try {
if (mxLinguSvcMgr != null) {
return mxLinguSvcMgr.getThesaurus();
}
} catch (Throwable t) {
// If anything goes wrong, give the user a stack trace
printMessage(t);
}
return null;
}
|
java
|
private XThesaurus GetThesaurus(XLinguServiceManager mxLinguSvcMgr) {
try {
if (mxLinguSvcMgr != null) {
return mxLinguSvcMgr.getThesaurus();
}
} catch (Throwable t) {
// If anything goes wrong, give the user a stack trace
printMessage(t);
}
return null;
}
|
[
"private",
"XThesaurus",
"GetThesaurus",
"(",
"XLinguServiceManager",
"mxLinguSvcMgr",
")",
"{",
"try",
"{",
"if",
"(",
"mxLinguSvcMgr",
"!=",
"null",
")",
"{",
"return",
"mxLinguSvcMgr",
".",
"getThesaurus",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"// If anything goes wrong, give the user a stack trace",
"printMessage",
"(",
"t",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Get the Thesaurus to be used.
|
[
"Get",
"the",
"Thesaurus",
"to",
"be",
"used",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/LinguisticServices.java#L102-L112
|
19,124
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/LinguisticServices.java
|
LinguisticServices.GetHyphenator
|
private XHyphenator GetHyphenator(XLinguServiceManager mxLinguSvcMgr) {
try {
if (mxLinguSvcMgr != null) {
return mxLinguSvcMgr.getHyphenator();
}
} catch (Throwable t) {
// If anything goes wrong, give the user a stack trace
printMessage(t);
}
return null;
}
|
java
|
private XHyphenator GetHyphenator(XLinguServiceManager mxLinguSvcMgr) {
try {
if (mxLinguSvcMgr != null) {
return mxLinguSvcMgr.getHyphenator();
}
} catch (Throwable t) {
// If anything goes wrong, give the user a stack trace
printMessage(t);
}
return null;
}
|
[
"private",
"XHyphenator",
"GetHyphenator",
"(",
"XLinguServiceManager",
"mxLinguSvcMgr",
")",
"{",
"try",
"{",
"if",
"(",
"mxLinguSvcMgr",
"!=",
"null",
")",
"{",
"return",
"mxLinguSvcMgr",
".",
"getHyphenator",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"// If anything goes wrong, give the user a stack trace",
"printMessage",
"(",
"t",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Get the Hyphenator to be used.
|
[
"Get",
"the",
"Hyphenator",
"to",
"be",
"used",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/LinguisticServices.java#L117-L127
|
19,125
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/LinguisticServices.java
|
LinguisticServices.GetSpellChecker
|
private XSpellChecker GetSpellChecker(XLinguServiceManager mxLinguSvcMgr) {
try {
if (mxLinguSvcMgr != null) {
return mxLinguSvcMgr.getSpellChecker();
}
} catch (Throwable t) {
// If anything goes wrong, give the user a stack trace
printMessage(t);
}
return null;
}
|
java
|
private XSpellChecker GetSpellChecker(XLinguServiceManager mxLinguSvcMgr) {
try {
if (mxLinguSvcMgr != null) {
return mxLinguSvcMgr.getSpellChecker();
}
} catch (Throwable t) {
// If anything goes wrong, give the user a stack trace
printMessage(t);
}
return null;
}
|
[
"private",
"XSpellChecker",
"GetSpellChecker",
"(",
"XLinguServiceManager",
"mxLinguSvcMgr",
")",
"{",
"try",
"{",
"if",
"(",
"mxLinguSvcMgr",
"!=",
"null",
")",
"{",
"return",
"mxLinguSvcMgr",
".",
"getSpellChecker",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"// If anything goes wrong, give the user a stack trace",
"printMessage",
"(",
"t",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Get the SpellChecker to be used.
|
[
"Get",
"the",
"SpellChecker",
"to",
"be",
"used",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/LinguisticServices.java#L132-L142
|
19,126
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/LinguisticServices.java
|
LinguisticServices.getSynonyms
|
@Override
public List<String> getSynonyms(String word, Language lang) {
return getSynonyms(word, getLocale(lang));
}
|
java
|
@Override
public List<String> getSynonyms(String word, Language lang) {
return getSynonyms(word, getLocale(lang));
}
|
[
"@",
"Override",
"public",
"List",
"<",
"String",
">",
"getSynonyms",
"(",
"String",
"word",
",",
"Language",
"lang",
")",
"{",
"return",
"getSynonyms",
"(",
"word",
",",
"getLocale",
"(",
"lang",
")",
")",
";",
"}"
] |
Get all synonyms of a word as list of strings.
|
[
"Get",
"all",
"synonyms",
"of",
"a",
"word",
"as",
"list",
"of",
"strings",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/LinguisticServices.java#L167-L170
|
19,127
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/LinguisticServices.java
|
LinguisticServices.isCorrectSpell
|
@Override
public boolean isCorrectSpell(String word, Language lang) {
return isCorrectSpell(word, getLocale(lang));
}
|
java
|
@Override
public boolean isCorrectSpell(String word, Language lang) {
return isCorrectSpell(word, getLocale(lang));
}
|
[
"@",
"Override",
"public",
"boolean",
"isCorrectSpell",
"(",
"String",
"word",
",",
"Language",
"lang",
")",
"{",
"return",
"isCorrectSpell",
"(",
"word",
",",
"getLocale",
"(",
"lang",
")",
")",
";",
"}"
] |
Returns true if the spell check is positive
|
[
"Returns",
"true",
"if",
"the",
"spell",
"check",
"is",
"positive"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/LinguisticServices.java#L202-L205
|
19,128
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/LinguisticServices.java
|
LinguisticServices.getNumberOfSyllables
|
@Override
public int getNumberOfSyllables(String word, Language lang) {
return getNumberOfSyllables(word, getLocale(lang));
}
|
java
|
@Override
public int getNumberOfSyllables(String word, Language lang) {
return getNumberOfSyllables(word, getLocale(lang));
}
|
[
"@",
"Override",
"public",
"int",
"getNumberOfSyllables",
"(",
"String",
"word",
",",
"Language",
"lang",
")",
"{",
"return",
"getNumberOfSyllables",
"(",
"word",
",",
"getLocale",
"(",
"lang",
")",
")",
";",
"}"
] |
Returns the number of syllable of a word
Returns -1 if the word was not found or anything goes wrong
|
[
"Returns",
"the",
"number",
"of",
"syllable",
"of",
"a",
"word",
"Returns",
"-",
"1",
"if",
"the",
"word",
"was",
"not",
"found",
"or",
"anything",
"goes",
"wrong"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/LinguisticServices.java#L222-L225
|
19,129
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/spelling/morfologik/MorfologikMultiSpeller.java
|
MorfologikMultiSpeller.isMisspelled
|
public boolean isMisspelled(String word) {
for (MorfologikSpeller speller : spellers) {
if (!speller.isMisspelled(word)) {
return false;
}
}
return true;
}
|
java
|
public boolean isMisspelled(String word) {
for (MorfologikSpeller speller : spellers) {
if (!speller.isMisspelled(word)) {
return false;
}
}
return true;
}
|
[
"public",
"boolean",
"isMisspelled",
"(",
"String",
"word",
")",
"{",
"for",
"(",
"MorfologikSpeller",
"speller",
":",
"spellers",
")",
"{",
"if",
"(",
"!",
"speller",
".",
"isMisspelled",
"(",
"word",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Accept the word if at least one of the dictionaries accepts it as not misspelled.
|
[
"Accept",
"the",
"word",
"if",
"at",
"least",
"one",
"of",
"the",
"dictionaries",
"accepts",
"it",
"as",
"not",
"misspelled",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/spelling/morfologik/MorfologikMultiSpeller.java#L199-L206
|
19,130
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/patterns/MatchState.java
|
MatchState.setToken
|
public final void setToken(AnalyzedTokenReadings[] tokens, int index, int next) {
int idx = index;
if (index >= tokens.length) {
// TODO: hacky workaround, find a proper solution. See EnglishPatternRuleTest.testBug()
idx = tokens.length - 1;
}
setToken(tokens[idx]);
IncludeRange includeSkipped = match.getIncludeSkipped();
if (next > 1 && includeSkipped != IncludeRange.NONE) {
StringBuilder sb = new StringBuilder();
if (includeSkipped == IncludeRange.FOLLOWING) {
formattedToken = null;
}
for (int k = index + 1; k < index + next; k++) {
if (tokens[k].isWhitespaceBefore()
&& !(k == index + 1 && includeSkipped == IncludeRange.FOLLOWING)) {
sb.append(' ');
}
sb.append(tokens[k].getToken());
}
skippedTokens = sb.toString();
} else {
skippedTokens = "";
}
}
|
java
|
public final void setToken(AnalyzedTokenReadings[] tokens, int index, int next) {
int idx = index;
if (index >= tokens.length) {
// TODO: hacky workaround, find a proper solution. See EnglishPatternRuleTest.testBug()
idx = tokens.length - 1;
}
setToken(tokens[idx]);
IncludeRange includeSkipped = match.getIncludeSkipped();
if (next > 1 && includeSkipped != IncludeRange.NONE) {
StringBuilder sb = new StringBuilder();
if (includeSkipped == IncludeRange.FOLLOWING) {
formattedToken = null;
}
for (int k = index + 1; k < index + next; k++) {
if (tokens[k].isWhitespaceBefore()
&& !(k == index + 1 && includeSkipped == IncludeRange.FOLLOWING)) {
sb.append(' ');
}
sb.append(tokens[k].getToken());
}
skippedTokens = sb.toString();
} else {
skippedTokens = "";
}
}
|
[
"public",
"final",
"void",
"setToken",
"(",
"AnalyzedTokenReadings",
"[",
"]",
"tokens",
",",
"int",
"index",
",",
"int",
"next",
")",
"{",
"int",
"idx",
"=",
"index",
";",
"if",
"(",
"index",
">=",
"tokens",
".",
"length",
")",
"{",
"// TODO: hacky workaround, find a proper solution. See EnglishPatternRuleTest.testBug()",
"idx",
"=",
"tokens",
".",
"length",
"-",
"1",
";",
"}",
"setToken",
"(",
"tokens",
"[",
"idx",
"]",
")",
";",
"IncludeRange",
"includeSkipped",
"=",
"match",
".",
"getIncludeSkipped",
"(",
")",
";",
"if",
"(",
"next",
">",
"1",
"&&",
"includeSkipped",
"!=",
"IncludeRange",
".",
"NONE",
")",
"{",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"if",
"(",
"includeSkipped",
"==",
"IncludeRange",
".",
"FOLLOWING",
")",
"{",
"formattedToken",
"=",
"null",
";",
"}",
"for",
"(",
"int",
"k",
"=",
"index",
"+",
"1",
";",
"k",
"<",
"index",
"+",
"next",
";",
"k",
"++",
")",
"{",
"if",
"(",
"tokens",
"[",
"k",
"]",
".",
"isWhitespaceBefore",
"(",
")",
"&&",
"!",
"(",
"k",
"==",
"index",
"+",
"1",
"&&",
"includeSkipped",
"==",
"IncludeRange",
".",
"FOLLOWING",
")",
")",
"{",
"sb",
".",
"append",
"(",
"'",
"'",
")",
";",
"}",
"sb",
".",
"append",
"(",
"tokens",
"[",
"k",
"]",
".",
"getToken",
"(",
")",
")",
";",
"}",
"skippedTokens",
"=",
"sb",
".",
"toString",
"(",
")",
";",
"}",
"else",
"{",
"skippedTokens",
"=",
"\"\"",
";",
"}",
"}"
] |
Sets the token to be formatted etc. and includes the support for
including the skipped tokens.
@param tokens Array of tokens
@param index Index of the token to be formatted
@param next Position of the next token (the skipped tokens are the ones between the tokens[index] and tokens[next]
|
[
"Sets",
"the",
"token",
"to",
"be",
"formatted",
"etc",
".",
"and",
"includes",
"the",
"support",
"for",
"including",
"the",
"skipped",
"tokens",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/patterns/MatchState.java#L81-L105
|
19,131
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/patterns/MatchState.java
|
MatchState.getTargetPosTag
|
public final String getTargetPosTag() {
String targetPosTag = match.getPosTag();
List<String> posTags = new ArrayList<>();
Pattern pPosRegexMatch = match.getPosRegexMatch();
String posTagReplace = match.getPosTagReplace();
if (match.isStaticLemma()) {
for (AnalyzedToken analyzedToken : matchedToken) {
String tst = analyzedToken.getPOSTag();
if (tst != null && pPosRegexMatch.matcher(tst).matches()) {
targetPosTag = analyzedToken.getPOSTag();
posTags.add(targetPosTag);
}
}
if (pPosRegexMatch != null && posTagReplace != null && !posTags.isEmpty()) {
targetPosTag = pPosRegexMatch.matcher(targetPosTag).replaceAll(
posTagReplace);
}
} else {
for (AnalyzedToken analyzedToken : formattedToken) {
String tst = analyzedToken.getPOSTag();
if (tst != null && pPosRegexMatch.matcher(tst).matches()) {
targetPosTag = analyzedToken.getPOSTag();
posTags.add(targetPosTag);
}
}
if (pPosRegexMatch != null && posTagReplace != null) {
if (posTags.isEmpty()) {
posTags.add(targetPosTag);
}
StringBuilder sb = new StringBuilder();
int posTagLen = posTags.size();
int l = 0;
for (String lPosTag : posTags) {
l++;
lPosTag = pPosRegexMatch.matcher(lPosTag).replaceAll(posTagReplace);
if (match.setsPos()) {
lPosTag = synthesizer.getPosTagCorrection(lPosTag);
}
sb.append(lPosTag);
if (l < posTagLen) {
sb.append('|');
}
}
targetPosTag = sb.toString();
}
}
return targetPosTag;
}
|
java
|
public final String getTargetPosTag() {
String targetPosTag = match.getPosTag();
List<String> posTags = new ArrayList<>();
Pattern pPosRegexMatch = match.getPosRegexMatch();
String posTagReplace = match.getPosTagReplace();
if (match.isStaticLemma()) {
for (AnalyzedToken analyzedToken : matchedToken) {
String tst = analyzedToken.getPOSTag();
if (tst != null && pPosRegexMatch.matcher(tst).matches()) {
targetPosTag = analyzedToken.getPOSTag();
posTags.add(targetPosTag);
}
}
if (pPosRegexMatch != null && posTagReplace != null && !posTags.isEmpty()) {
targetPosTag = pPosRegexMatch.matcher(targetPosTag).replaceAll(
posTagReplace);
}
} else {
for (AnalyzedToken analyzedToken : formattedToken) {
String tst = analyzedToken.getPOSTag();
if (tst != null && pPosRegexMatch.matcher(tst).matches()) {
targetPosTag = analyzedToken.getPOSTag();
posTags.add(targetPosTag);
}
}
if (pPosRegexMatch != null && posTagReplace != null) {
if (posTags.isEmpty()) {
posTags.add(targetPosTag);
}
StringBuilder sb = new StringBuilder();
int posTagLen = posTags.size();
int l = 0;
for (String lPosTag : posTags) {
l++;
lPosTag = pPosRegexMatch.matcher(lPosTag).replaceAll(posTagReplace);
if (match.setsPos()) {
lPosTag = synthesizer.getPosTagCorrection(lPosTag);
}
sb.append(lPosTag);
if (l < posTagLen) {
sb.append('|');
}
}
targetPosTag = sb.toString();
}
}
return targetPosTag;
}
|
[
"public",
"final",
"String",
"getTargetPosTag",
"(",
")",
"{",
"String",
"targetPosTag",
"=",
"match",
".",
"getPosTag",
"(",
")",
";",
"List",
"<",
"String",
">",
"posTags",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"Pattern",
"pPosRegexMatch",
"=",
"match",
".",
"getPosRegexMatch",
"(",
")",
";",
"String",
"posTagReplace",
"=",
"match",
".",
"getPosTagReplace",
"(",
")",
";",
"if",
"(",
"match",
".",
"isStaticLemma",
"(",
")",
")",
"{",
"for",
"(",
"AnalyzedToken",
"analyzedToken",
":",
"matchedToken",
")",
"{",
"String",
"tst",
"=",
"analyzedToken",
".",
"getPOSTag",
"(",
")",
";",
"if",
"(",
"tst",
"!=",
"null",
"&&",
"pPosRegexMatch",
".",
"matcher",
"(",
"tst",
")",
".",
"matches",
"(",
")",
")",
"{",
"targetPosTag",
"=",
"analyzedToken",
".",
"getPOSTag",
"(",
")",
";",
"posTags",
".",
"add",
"(",
"targetPosTag",
")",
";",
"}",
"}",
"if",
"(",
"pPosRegexMatch",
"!=",
"null",
"&&",
"posTagReplace",
"!=",
"null",
"&&",
"!",
"posTags",
".",
"isEmpty",
"(",
")",
")",
"{",
"targetPosTag",
"=",
"pPosRegexMatch",
".",
"matcher",
"(",
"targetPosTag",
")",
".",
"replaceAll",
"(",
"posTagReplace",
")",
";",
"}",
"}",
"else",
"{",
"for",
"(",
"AnalyzedToken",
"analyzedToken",
":",
"formattedToken",
")",
"{",
"String",
"tst",
"=",
"analyzedToken",
".",
"getPOSTag",
"(",
")",
";",
"if",
"(",
"tst",
"!=",
"null",
"&&",
"pPosRegexMatch",
".",
"matcher",
"(",
"tst",
")",
".",
"matches",
"(",
")",
")",
"{",
"targetPosTag",
"=",
"analyzedToken",
".",
"getPOSTag",
"(",
")",
";",
"posTags",
".",
"add",
"(",
"targetPosTag",
")",
";",
"}",
"}",
"if",
"(",
"pPosRegexMatch",
"!=",
"null",
"&&",
"posTagReplace",
"!=",
"null",
")",
"{",
"if",
"(",
"posTags",
".",
"isEmpty",
"(",
")",
")",
"{",
"posTags",
".",
"add",
"(",
"targetPosTag",
")",
";",
"}",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"int",
"posTagLen",
"=",
"posTags",
".",
"size",
"(",
")",
";",
"int",
"l",
"=",
"0",
";",
"for",
"(",
"String",
"lPosTag",
":",
"posTags",
")",
"{",
"l",
"++",
";",
"lPosTag",
"=",
"pPosRegexMatch",
".",
"matcher",
"(",
"lPosTag",
")",
".",
"replaceAll",
"(",
"posTagReplace",
")",
";",
"if",
"(",
"match",
".",
"setsPos",
"(",
")",
")",
"{",
"lPosTag",
"=",
"synthesizer",
".",
"getPosTagCorrection",
"(",
"lPosTag",
")",
";",
"}",
"sb",
".",
"append",
"(",
"lPosTag",
")",
";",
"if",
"(",
"l",
"<",
"posTagLen",
")",
"{",
"sb",
".",
"append",
"(",
"'",
"'",
")",
";",
"}",
"}",
"targetPosTag",
"=",
"sb",
".",
"toString",
"(",
")",
";",
"}",
"}",
"return",
"targetPosTag",
";",
"}"
] |
on the other hand, many POS tags = too many suggestions?
|
[
"on",
"the",
"other",
"hand",
"many",
"POS",
"tags",
"=",
"too",
"many",
"suggestions?"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/patterns/MatchState.java#L323-L372
|
19,132
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/patterns/MatchState.java
|
MatchState.toTokenString
|
final String toTokenString() throws IOException {
String[] stringToFormat = toFinalString(null);
return String.join("|", Arrays.asList(stringToFormat));
}
|
java
|
final String toTokenString() throws IOException {
String[] stringToFormat = toFinalString(null);
return String.join("|", Arrays.asList(stringToFormat));
}
|
[
"final",
"String",
"toTokenString",
"(",
")",
"throws",
"IOException",
"{",
"String",
"[",
"]",
"stringToFormat",
"=",
"toFinalString",
"(",
"null",
")",
";",
"return",
"String",
".",
"join",
"(",
"\"|\"",
",",
"Arrays",
".",
"asList",
"(",
"stringToFormat",
")",
")",
";",
"}"
] |
Method for getting the formatted match as a single string. In case of
multiple matches, it joins them using a regular expression operator "|".
@return Formatted string of the matched token.
|
[
"Method",
"for",
"getting",
"the",
"formatted",
"match",
"as",
"a",
"single",
"string",
".",
"In",
"case",
"of",
"multiple",
"matches",
"it",
"joins",
"them",
"using",
"a",
"regular",
"expression",
"operator",
"|",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/patterns/MatchState.java#L379-L382
|
19,133
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/SingleDocument.java
|
SingleDocument.getCheckResults
|
ProofreadingResult getCheckResults(String paraText, Locale locale, ProofreadingResult paRes,
int[] footnotePositions, boolean isParallelThread, JLanguageTool langTool) {
try {
SingleProofreadingError[] sErrors = null;
paraNum = getParaPos(paraText, isParallelThread);
// Don't use Cache for check in single paragraph mode
if(numParasToCheck != 0 && paraNum >= 0 && doResetCheck) {
sErrors = sentencesCache.getMatches(paraNum, paRes.nStartOfSentencePosition);
// return Cache result if available
if(sErrors != null) {
paRes.nStartOfNextSentencePosition = sentencesCache.getNextSentencePosition(paraNum, paRes.nStartOfSentencePosition);
paRes.nBehindEndOfSentencePosition = paRes.nStartOfNextSentencePosition;
}
}
if (debugMode > 1) {
MessageHandler.printToLogFile("... Check Sentence: numCurPara: " + paraNum
+ "; startPos: " + paRes.nStartOfSentencePosition + "; Paragraph: " + paraText
+ ", sErrors: " + (sErrors == null ? 0 : sErrors.length) + logLineBreak);
}
if(sErrors == null) {
SentenceFromPara sfp = new SentenceFromPara(paraText, paRes.nStartOfSentencePosition, langTool);
String sentence = sfp.getSentence();
paRes.nStartOfSentencePosition = sfp.getPosition();
paRes.nStartOfNextSentencePosition = sfp.getPosition() + sentence.length();
paRes.nBehindEndOfSentencePosition = paRes.nStartOfNextSentencePosition;
sErrors = checkSentence(sentence, paRes.nStartOfSentencePosition, paRes.nStartOfNextSentencePosition,
paraNum, footnotePositions, isParallelThread, langTool);
}
SingleProofreadingError[] pErrors = checkParaRules(paraText, paraNum, paRes.nStartOfSentencePosition,
paRes.nStartOfNextSentencePosition, isParallelThread, langTool);
paRes.aErrors = mergeErrors(sErrors, pErrors);
if (debugMode > 1) {
MessageHandler.printToLogFile("paRes.aErrors.length: " + paRes.aErrors.length + "; docID: " + docID + logLineBreak);
}
textIsChanged = false;
} catch (Throwable t) {
MessageHandler.showError(t);
}
return paRes;
}
|
java
|
ProofreadingResult getCheckResults(String paraText, Locale locale, ProofreadingResult paRes,
int[] footnotePositions, boolean isParallelThread, JLanguageTool langTool) {
try {
SingleProofreadingError[] sErrors = null;
paraNum = getParaPos(paraText, isParallelThread);
// Don't use Cache for check in single paragraph mode
if(numParasToCheck != 0 && paraNum >= 0 && doResetCheck) {
sErrors = sentencesCache.getMatches(paraNum, paRes.nStartOfSentencePosition);
// return Cache result if available
if(sErrors != null) {
paRes.nStartOfNextSentencePosition = sentencesCache.getNextSentencePosition(paraNum, paRes.nStartOfSentencePosition);
paRes.nBehindEndOfSentencePosition = paRes.nStartOfNextSentencePosition;
}
}
if (debugMode > 1) {
MessageHandler.printToLogFile("... Check Sentence: numCurPara: " + paraNum
+ "; startPos: " + paRes.nStartOfSentencePosition + "; Paragraph: " + paraText
+ ", sErrors: " + (sErrors == null ? 0 : sErrors.length) + logLineBreak);
}
if(sErrors == null) {
SentenceFromPara sfp = new SentenceFromPara(paraText, paRes.nStartOfSentencePosition, langTool);
String sentence = sfp.getSentence();
paRes.nStartOfSentencePosition = sfp.getPosition();
paRes.nStartOfNextSentencePosition = sfp.getPosition() + sentence.length();
paRes.nBehindEndOfSentencePosition = paRes.nStartOfNextSentencePosition;
sErrors = checkSentence(sentence, paRes.nStartOfSentencePosition, paRes.nStartOfNextSentencePosition,
paraNum, footnotePositions, isParallelThread, langTool);
}
SingleProofreadingError[] pErrors = checkParaRules(paraText, paraNum, paRes.nStartOfSentencePosition,
paRes.nStartOfNextSentencePosition, isParallelThread, langTool);
paRes.aErrors = mergeErrors(sErrors, pErrors);
if (debugMode > 1) {
MessageHandler.printToLogFile("paRes.aErrors.length: " + paRes.aErrors.length + "; docID: " + docID + logLineBreak);
}
textIsChanged = false;
} catch (Throwable t) {
MessageHandler.showError(t);
}
return paRes;
}
|
[
"ProofreadingResult",
"getCheckResults",
"(",
"String",
"paraText",
",",
"Locale",
"locale",
",",
"ProofreadingResult",
"paRes",
",",
"int",
"[",
"]",
"footnotePositions",
",",
"boolean",
"isParallelThread",
",",
"JLanguageTool",
"langTool",
")",
"{",
"try",
"{",
"SingleProofreadingError",
"[",
"]",
"sErrors",
"=",
"null",
";",
"paraNum",
"=",
"getParaPos",
"(",
"paraText",
",",
"isParallelThread",
")",
";",
"// Don't use Cache for check in single paragraph mode",
"if",
"(",
"numParasToCheck",
"!=",
"0",
"&&",
"paraNum",
">=",
"0",
"&&",
"doResetCheck",
")",
"{",
"sErrors",
"=",
"sentencesCache",
".",
"getMatches",
"(",
"paraNum",
",",
"paRes",
".",
"nStartOfSentencePosition",
")",
";",
"// return Cache result if available",
"if",
"(",
"sErrors",
"!=",
"null",
")",
"{",
"paRes",
".",
"nStartOfNextSentencePosition",
"=",
"sentencesCache",
".",
"getNextSentencePosition",
"(",
"paraNum",
",",
"paRes",
".",
"nStartOfSentencePosition",
")",
";",
"paRes",
".",
"nBehindEndOfSentencePosition",
"=",
"paRes",
".",
"nStartOfNextSentencePosition",
";",
"}",
"}",
"if",
"(",
"debugMode",
">",
"1",
")",
"{",
"MessageHandler",
".",
"printToLogFile",
"(",
"\"... Check Sentence: numCurPara: \"",
"+",
"paraNum",
"+",
"\"; startPos: \"",
"+",
"paRes",
".",
"nStartOfSentencePosition",
"+",
"\"; Paragraph: \"",
"+",
"paraText",
"+",
"\", sErrors: \"",
"+",
"(",
"sErrors",
"==",
"null",
"?",
"0",
":",
"sErrors",
".",
"length",
")",
"+",
"logLineBreak",
")",
";",
"}",
"if",
"(",
"sErrors",
"==",
"null",
")",
"{",
"SentenceFromPara",
"sfp",
"=",
"new",
"SentenceFromPara",
"(",
"paraText",
",",
"paRes",
".",
"nStartOfSentencePosition",
",",
"langTool",
")",
";",
"String",
"sentence",
"=",
"sfp",
".",
"getSentence",
"(",
")",
";",
"paRes",
".",
"nStartOfSentencePosition",
"=",
"sfp",
".",
"getPosition",
"(",
")",
";",
"paRes",
".",
"nStartOfNextSentencePosition",
"=",
"sfp",
".",
"getPosition",
"(",
")",
"+",
"sentence",
".",
"length",
"(",
")",
";",
"paRes",
".",
"nBehindEndOfSentencePosition",
"=",
"paRes",
".",
"nStartOfNextSentencePosition",
";",
"sErrors",
"=",
"checkSentence",
"(",
"sentence",
",",
"paRes",
".",
"nStartOfSentencePosition",
",",
"paRes",
".",
"nStartOfNextSentencePosition",
",",
"paraNum",
",",
"footnotePositions",
",",
"isParallelThread",
",",
"langTool",
")",
";",
"}",
"SingleProofreadingError",
"[",
"]",
"pErrors",
"=",
"checkParaRules",
"(",
"paraText",
",",
"paraNum",
",",
"paRes",
".",
"nStartOfSentencePosition",
",",
"paRes",
".",
"nStartOfNextSentencePosition",
",",
"isParallelThread",
",",
"langTool",
")",
";",
"paRes",
".",
"aErrors",
"=",
"mergeErrors",
"(",
"sErrors",
",",
"pErrors",
")",
";",
"if",
"(",
"debugMode",
">",
"1",
")",
"{",
"MessageHandler",
".",
"printToLogFile",
"(",
"\"paRes.aErrors.length: \"",
"+",
"paRes",
".",
"aErrors",
".",
"length",
"+",
"\"; docID: \"",
"+",
"docID",
"+",
"logLineBreak",
")",
";",
"}",
"textIsChanged",
"=",
"false",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"MessageHandler",
".",
"showError",
"(",
"t",
")",
";",
"}",
"return",
"paRes",
";",
"}"
] |
get the result for a check of a single document
@param paraText paragraph text
@param paRes proof reading result
@param footnotePositions position of footnotes
@param isParallelThread true: check runs as parallel thread
@return proof reading result
|
[
"get",
"the",
"result",
"for",
"a",
"check",
"of",
"a",
"single",
"document"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/SingleDocument.java#L120-L159
|
19,134
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/SingleDocument.java
|
SingleDocument.setConfigValues
|
void setConfigValues(Configuration config) {
this.config = config;
numParasToCheck = config.getNumParasToCheck();
defaultParaCheck = numParasToCheck * PARA_CHECK_FACTOR;
doResetCheck = config.isResetCheck();
}
|
java
|
void setConfigValues(Configuration config) {
this.config = config;
numParasToCheck = config.getNumParasToCheck();
defaultParaCheck = numParasToCheck * PARA_CHECK_FACTOR;
doResetCheck = config.isResetCheck();
}
|
[
"void",
"setConfigValues",
"(",
"Configuration",
"config",
")",
"{",
"this",
".",
"config",
"=",
"config",
";",
"numParasToCheck",
"=",
"config",
".",
"getNumParasToCheck",
"(",
")",
";",
"defaultParaCheck",
"=",
"numParasToCheck",
"*",
"PARA_CHECK_FACTOR",
";",
"doResetCheck",
"=",
"config",
".",
"isResetCheck",
"(",
")",
";",
"}"
] |
set values set by configuration dialog
|
[
"set",
"values",
"set",
"by",
"configuration",
"dialog"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/SingleDocument.java#L164-L169
|
19,135
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/SingleDocument.java
|
SingleDocument.optimizeReset
|
void optimizeReset() {
FlatParagraphTools flatPara = new FlatParagraphTools(xContext);
flatPara.markFlatParasAsChecked(resetFrom + divNum, resetTo + divNum, isChecked);
resetCheck = false;
}
|
java
|
void optimizeReset() {
FlatParagraphTools flatPara = new FlatParagraphTools(xContext);
flatPara.markFlatParasAsChecked(resetFrom + divNum, resetTo + divNum, isChecked);
resetCheck = false;
}
|
[
"void",
"optimizeReset",
"(",
")",
"{",
"FlatParagraphTools",
"flatPara",
"=",
"new",
"FlatParagraphTools",
"(",
"xContext",
")",
";",
"flatPara",
".",
"markFlatParasAsChecked",
"(",
"resetFrom",
"+",
"divNum",
",",
"resetTo",
"+",
"divNum",
",",
"isChecked",
")",
";",
"resetCheck",
"=",
"false",
";",
"}"
] |
Reset only changed paragraphs
|
[
"Reset",
"only",
"changed",
"paragraphs"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/SingleDocument.java#L220-L224
|
19,136
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/SingleDocument.java
|
SingleDocument.loadIsChecked
|
public void loadIsChecked () {
FlatParagraphTools flatPara = new FlatParagraphTools(xContext);
isChecked = flatPara.isChecked();
if (debugMode > 0) {
int nChecked = 0;
for (boolean bChecked : isChecked) {
if(bChecked) {
nChecked++;
}
}
MessageHandler.printToLogFile("Checked parapraphs: docID: " + docID + ", Number of Paragraphs: " + isChecked.size()
+ ", Checked: " + nChecked + logLineBreak);
}
}
|
java
|
public void loadIsChecked () {
FlatParagraphTools flatPara = new FlatParagraphTools(xContext);
isChecked = flatPara.isChecked();
if (debugMode > 0) {
int nChecked = 0;
for (boolean bChecked : isChecked) {
if(bChecked) {
nChecked++;
}
}
MessageHandler.printToLogFile("Checked parapraphs: docID: " + docID + ", Number of Paragraphs: " + isChecked.size()
+ ", Checked: " + nChecked + logLineBreak);
}
}
|
[
"public",
"void",
"loadIsChecked",
"(",
")",
"{",
"FlatParagraphTools",
"flatPara",
"=",
"new",
"FlatParagraphTools",
"(",
"xContext",
")",
";",
"isChecked",
"=",
"flatPara",
".",
"isChecked",
"(",
")",
";",
"if",
"(",
"debugMode",
">",
"0",
")",
"{",
"int",
"nChecked",
"=",
"0",
";",
"for",
"(",
"boolean",
"bChecked",
":",
"isChecked",
")",
"{",
"if",
"(",
"bChecked",
")",
"{",
"nChecked",
"++",
";",
"}",
"}",
"MessageHandler",
".",
"printToLogFile",
"(",
"\"Checked parapraphs: docID: \"",
"+",
"docID",
"+",
"\", Number of Paragraphs: \"",
"+",
"isChecked",
".",
"size",
"(",
")",
"+",
"\", Checked: \"",
"+",
"nChecked",
"+",
"logLineBreak",
")",
";",
"}",
"}"
] |
load checked status of all paragraphs
|
[
"load",
"checked",
"status",
"of",
"all",
"paragraphs"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/SingleDocument.java#L229-L242
|
19,137
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/SingleDocument.java
|
SingleDocument.getDocAsString
|
private String getDocAsString(int numCurPara) {
if (numCurPara < 0 || allParas == null || allParas.size() < numCurPara - 1) {
return "";
}
int startPos;
int endPos;
if (numParasToCheck < 1) {
startPos = 0;
endPos = allParas.size();
} else {
startPos = numCurPara - numParasToCheck;
if(textIsChanged && doResetCheck) {
startPos -= numParasToCheck;
}
if (startPos < 0) {
startPos = 0;
}
endPos = numCurPara + 1 + numParasToCheck;
if(!textIsChanged) {
endPos += defaultParaCheck;
} else if(doResetCheck) {
endPos += numParasToCheck;
}
if (endPos > allParas.size()) {
endPos = allParas.size();
}
}
StringBuilder docText = new StringBuilder(fixLinebreak(allParas.get(startPos)));
for (int i = startPos + 1; i < endPos; i++) {
docText.append(END_OF_PARAGRAPH).append(fixLinebreak(allParas.get(i)));
}
return docText.toString();
}
|
java
|
private String getDocAsString(int numCurPara) {
if (numCurPara < 0 || allParas == null || allParas.size() < numCurPara - 1) {
return "";
}
int startPos;
int endPos;
if (numParasToCheck < 1) {
startPos = 0;
endPos = allParas.size();
} else {
startPos = numCurPara - numParasToCheck;
if(textIsChanged && doResetCheck) {
startPos -= numParasToCheck;
}
if (startPos < 0) {
startPos = 0;
}
endPos = numCurPara + 1 + numParasToCheck;
if(!textIsChanged) {
endPos += defaultParaCheck;
} else if(doResetCheck) {
endPos += numParasToCheck;
}
if (endPos > allParas.size()) {
endPos = allParas.size();
}
}
StringBuilder docText = new StringBuilder(fixLinebreak(allParas.get(startPos)));
for (int i = startPos + 1; i < endPos; i++) {
docText.append(END_OF_PARAGRAPH).append(fixLinebreak(allParas.get(i)));
}
return docText.toString();
}
|
[
"private",
"String",
"getDocAsString",
"(",
"int",
"numCurPara",
")",
"{",
"if",
"(",
"numCurPara",
"<",
"0",
"||",
"allParas",
"==",
"null",
"||",
"allParas",
".",
"size",
"(",
")",
"<",
"numCurPara",
"-",
"1",
")",
"{",
"return",
"\"\"",
";",
"}",
"int",
"startPos",
";",
"int",
"endPos",
";",
"if",
"(",
"numParasToCheck",
"<",
"1",
")",
"{",
"startPos",
"=",
"0",
";",
"endPos",
"=",
"allParas",
".",
"size",
"(",
")",
";",
"}",
"else",
"{",
"startPos",
"=",
"numCurPara",
"-",
"numParasToCheck",
";",
"if",
"(",
"textIsChanged",
"&&",
"doResetCheck",
")",
"{",
"startPos",
"-=",
"numParasToCheck",
";",
"}",
"if",
"(",
"startPos",
"<",
"0",
")",
"{",
"startPos",
"=",
"0",
";",
"}",
"endPos",
"=",
"numCurPara",
"+",
"1",
"+",
"numParasToCheck",
";",
"if",
"(",
"!",
"textIsChanged",
")",
"{",
"endPos",
"+=",
"defaultParaCheck",
";",
"}",
"else",
"if",
"(",
"doResetCheck",
")",
"{",
"endPos",
"+=",
"numParasToCheck",
";",
"}",
"if",
"(",
"endPos",
">",
"allParas",
".",
"size",
"(",
")",
")",
"{",
"endPos",
"=",
"allParas",
".",
"size",
"(",
")",
";",
"}",
"}",
"StringBuilder",
"docText",
"=",
"new",
"StringBuilder",
"(",
"fixLinebreak",
"(",
"allParas",
".",
"get",
"(",
"startPos",
")",
")",
")",
";",
"for",
"(",
"int",
"i",
"=",
"startPos",
"+",
"1",
";",
"i",
"<",
"endPos",
";",
"i",
"++",
")",
"{",
"docText",
".",
"append",
"(",
"END_OF_PARAGRAPH",
")",
".",
"append",
"(",
"fixLinebreak",
"(",
"allParas",
".",
"get",
"(",
"i",
")",
")",
")",
";",
"}",
"return",
"docText",
".",
"toString",
"(",
")",
";",
"}"
] |
Gives Back the full Text as String
|
[
"Gives",
"Back",
"the",
"full",
"Text",
"as",
"String"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/SingleDocument.java#L468-L500
|
19,138
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/SingleDocument.java
|
SingleDocument.getStartOfParagraph
|
private int getStartOfParagraph(int nPara, int checkedPara) {
if (allParas != null && nPara >= 0 && nPara < allParas.size()) {
int startPos;
if (numParasToCheck < 1) {
startPos = 0;
} else {
startPos = checkedPara - numParasToCheck;
if(textIsChanged && doResetCheck) {
startPos -= numParasToCheck;
}
if (startPos < 0) startPos = 0;
}
int pos = 0;
for (int i = startPos; i < nPara; i++) {
pos += allParas.get(i).length() + 1;
}
return pos;
}
return -1;
}
|
java
|
private int getStartOfParagraph(int nPara, int checkedPara) {
if (allParas != null && nPara >= 0 && nPara < allParas.size()) {
int startPos;
if (numParasToCheck < 1) {
startPos = 0;
} else {
startPos = checkedPara - numParasToCheck;
if(textIsChanged && doResetCheck) {
startPos -= numParasToCheck;
}
if (startPos < 0) startPos = 0;
}
int pos = 0;
for (int i = startPos; i < nPara; i++) {
pos += allParas.get(i).length() + 1;
}
return pos;
}
return -1;
}
|
[
"private",
"int",
"getStartOfParagraph",
"(",
"int",
"nPara",
",",
"int",
"checkedPara",
")",
"{",
"if",
"(",
"allParas",
"!=",
"null",
"&&",
"nPara",
">=",
"0",
"&&",
"nPara",
"<",
"allParas",
".",
"size",
"(",
")",
")",
"{",
"int",
"startPos",
";",
"if",
"(",
"numParasToCheck",
"<",
"1",
")",
"{",
"startPos",
"=",
"0",
";",
"}",
"else",
"{",
"startPos",
"=",
"checkedPara",
"-",
"numParasToCheck",
";",
"if",
"(",
"textIsChanged",
"&&",
"doResetCheck",
")",
"{",
"startPos",
"-=",
"numParasToCheck",
";",
"}",
"if",
"(",
"startPos",
"<",
"0",
")",
"startPos",
"=",
"0",
";",
"}",
"int",
"pos",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"startPos",
";",
"i",
"<",
"nPara",
";",
"i",
"++",
")",
"{",
"pos",
"+=",
"allParas",
".",
"get",
"(",
"i",
")",
".",
"length",
"(",
")",
"+",
"1",
";",
"}",
"return",
"pos",
";",
"}",
"return",
"-",
"1",
";",
"}"
] |
Gives Back the StartPosition of Paragraph
|
[
"Gives",
"Back",
"the",
"StartPosition",
"of",
"Paragraph"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/SingleDocument.java#L505-L524
|
19,139
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/SimpleReplaceDataLoader.java
|
SimpleReplaceDataLoader.loadWords
|
public Map<String, List<String>> loadWords(String path) {
InputStream stream = JLanguageTool.getDataBroker().getFromRulesDirAsStream(path);
Map<String, List<String>> map = new HashMap<>();
try (Scanner scanner = new Scanner(stream, "utf-8")) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.isEmpty() || line.charAt(0) == '#') { // # = comment
continue;
}
String[] parts = line.split("=");
if (parts.length != 2) {
throw new RuntimeException("Could not load simple replacement data from: " + path + ". " +
"Error in line '" + line + "', expected format 'word=replacement'");
}
String[] wrongForms = parts[0].split("\\|");
List<String> replacements = Arrays.asList(parts[1].split("\\|"));
for (String wrongForm : wrongForms) {
map.put(wrongForm, replacements);
}
}
}
return Collections.unmodifiableMap(map);
}
|
java
|
public Map<String, List<String>> loadWords(String path) {
InputStream stream = JLanguageTool.getDataBroker().getFromRulesDirAsStream(path);
Map<String, List<String>> map = new HashMap<>();
try (Scanner scanner = new Scanner(stream, "utf-8")) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.isEmpty() || line.charAt(0) == '#') { // # = comment
continue;
}
String[] parts = line.split("=");
if (parts.length != 2) {
throw new RuntimeException("Could not load simple replacement data from: " + path + ". " +
"Error in line '" + line + "', expected format 'word=replacement'");
}
String[] wrongForms = parts[0].split("\\|");
List<String> replacements = Arrays.asList(parts[1].split("\\|"));
for (String wrongForm : wrongForms) {
map.put(wrongForm, replacements);
}
}
}
return Collections.unmodifiableMap(map);
}
|
[
"public",
"Map",
"<",
"String",
",",
"List",
"<",
"String",
">",
">",
"loadWords",
"(",
"String",
"path",
")",
"{",
"InputStream",
"stream",
"=",
"JLanguageTool",
".",
"getDataBroker",
"(",
")",
".",
"getFromRulesDirAsStream",
"(",
"path",
")",
";",
"Map",
"<",
"String",
",",
"List",
"<",
"String",
">",
">",
"map",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"try",
"(",
"Scanner",
"scanner",
"=",
"new",
"Scanner",
"(",
"stream",
",",
"\"utf-8\"",
")",
")",
"{",
"while",
"(",
"scanner",
".",
"hasNextLine",
"(",
")",
")",
"{",
"String",
"line",
"=",
"scanner",
".",
"nextLine",
"(",
")",
";",
"if",
"(",
"line",
".",
"isEmpty",
"(",
")",
"||",
"line",
".",
"charAt",
"(",
"0",
")",
"==",
"'",
"'",
")",
"{",
"// # = comment",
"continue",
";",
"}",
"String",
"[",
"]",
"parts",
"=",
"line",
".",
"split",
"(",
"\"=\"",
")",
";",
"if",
"(",
"parts",
".",
"length",
"!=",
"2",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Could not load simple replacement data from: \"",
"+",
"path",
"+",
"\". \"",
"+",
"\"Error in line '\"",
"+",
"line",
"+",
"\"', expected format 'word=replacement'\"",
")",
";",
"}",
"String",
"[",
"]",
"wrongForms",
"=",
"parts",
"[",
"0",
"]",
".",
"split",
"(",
"\"\\\\|\"",
")",
";",
"List",
"<",
"String",
">",
"replacements",
"=",
"Arrays",
".",
"asList",
"(",
"parts",
"[",
"1",
"]",
".",
"split",
"(",
"\"\\\\|\"",
")",
")",
";",
"for",
"(",
"String",
"wrongForm",
":",
"wrongForms",
")",
"{",
"map",
".",
"put",
"(",
"wrongForm",
",",
"replacements",
")",
";",
"}",
"}",
"}",
"return",
"Collections",
".",
"unmodifiableMap",
"(",
"map",
")",
";",
"}"
] |
Load replacement rules from a utf-8 file in the classpath.
|
[
"Load",
"replacement",
"rules",
"from",
"a",
"utf",
"-",
"8",
"file",
"in",
"the",
"classpath",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/SimpleReplaceDataLoader.java#L38-L60
|
19,140
|
languagetool-org/languagetool
|
languagetool-language-modules/ca/src/main/java/org/languagetool/rules/ca/ReflexiveVerbsRule.java
|
ReflexiveVerbsRule.matchLemmaRegexp
|
private boolean matchLemmaRegexp(AnalyzedTokenReadings aToken,
Pattern pattern) {
boolean matches = false;
for (AnalyzedToken analyzedToken : aToken) {
final String posTag = analyzedToken.getLemma();
if (posTag != null) {
final Matcher m = pattern.matcher(posTag);
if (m.matches()) {
matches = true;
break;
}
}
}
return matches;
}
|
java
|
private boolean matchLemmaRegexp(AnalyzedTokenReadings aToken,
Pattern pattern) {
boolean matches = false;
for (AnalyzedToken analyzedToken : aToken) {
final String posTag = analyzedToken.getLemma();
if (posTag != null) {
final Matcher m = pattern.matcher(posTag);
if (m.matches()) {
matches = true;
break;
}
}
}
return matches;
}
|
[
"private",
"boolean",
"matchLemmaRegexp",
"(",
"AnalyzedTokenReadings",
"aToken",
",",
"Pattern",
"pattern",
")",
"{",
"boolean",
"matches",
"=",
"false",
";",
"for",
"(",
"AnalyzedToken",
"analyzedToken",
":",
"aToken",
")",
"{",
"final",
"String",
"posTag",
"=",
"analyzedToken",
".",
"getLemma",
"(",
")",
";",
"if",
"(",
"posTag",
"!=",
"null",
")",
"{",
"final",
"Matcher",
"m",
"=",
"pattern",
".",
"matcher",
"(",
"posTag",
")",
";",
"if",
"(",
"m",
".",
"matches",
"(",
")",
")",
"{",
"matches",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"return",
"matches",
";",
"}"
] |
Match lemma with regular expression
|
[
"Match",
"lemma",
"with",
"regular",
"expression"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-language-modules/ca/src/main/java/org/languagetool/rules/ca/ReflexiveVerbsRule.java#L476-L490
|
19,141
|
languagetool-org/languagetool
|
languagetool-language-modules/ca/src/main/java/org/languagetool/rules/ca/ReflexiveVerbsRule.java
|
ReflexiveVerbsRule.matchLemmaList
|
private boolean matchLemmaList(AnalyzedTokenReadings aToken,
List<String> list) {
boolean matches = false;
for (AnalyzedToken analyzedToken : aToken) {
if (list.contains(analyzedToken.getLemma())) {
matches = true;
break;
}
}
return matches;
}
|
java
|
private boolean matchLemmaList(AnalyzedTokenReadings aToken,
List<String> list) {
boolean matches = false;
for (AnalyzedToken analyzedToken : aToken) {
if (list.contains(analyzedToken.getLemma())) {
matches = true;
break;
}
}
return matches;
}
|
[
"private",
"boolean",
"matchLemmaList",
"(",
"AnalyzedTokenReadings",
"aToken",
",",
"List",
"<",
"String",
">",
"list",
")",
"{",
"boolean",
"matches",
"=",
"false",
";",
"for",
"(",
"AnalyzedToken",
"analyzedToken",
":",
"aToken",
")",
"{",
"if",
"(",
"list",
".",
"contains",
"(",
"analyzedToken",
".",
"getLemma",
"(",
")",
")",
")",
"{",
"matches",
"=",
"true",
";",
"break",
";",
"}",
"}",
"return",
"matches",
";",
"}"
] |
Match lemma with String list
|
[
"Match",
"lemma",
"with",
"String",
"list"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-language-modules/ca/src/main/java/org/languagetool/rules/ca/ReflexiveVerbsRule.java#L495-L505
|
19,142
|
languagetool-org/languagetool
|
languagetool-language-modules/ca/src/main/java/org/languagetool/rules/ca/ReflexiveVerbsRule.java
|
ReflexiveVerbsRule.matchRegexp
|
private boolean matchRegexp(String s, Pattern pattern) {
final Matcher m = pattern.matcher(s);
return m.matches();
}
|
java
|
private boolean matchRegexp(String s, Pattern pattern) {
final Matcher m = pattern.matcher(s);
return m.matches();
}
|
[
"private",
"boolean",
"matchRegexp",
"(",
"String",
"s",
",",
"Pattern",
"pattern",
")",
"{",
"final",
"Matcher",
"m",
"=",
"pattern",
".",
"matcher",
"(",
"s",
")",
";",
"return",
"m",
".",
"matches",
"(",
")",
";",
"}"
] |
Match String with regular expression
|
[
"Match",
"String",
"with",
"regular",
"expression"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-language-modules/ca/src/main/java/org/languagetool/rules/ca/ReflexiveVerbsRule.java#L510-L513
|
19,143
|
languagetool-org/languagetool
|
languagetool-language-modules/ca/src/main/java/org/languagetool/rules/ca/ReflexiveVerbsRule.java
|
ReflexiveVerbsRule.isTherePronoun
|
private boolean isTherePronoun(final AnalyzedTokenReadings[] tokens, int i,
Pattern lemma, Pattern postag) {
int j = 1;
boolean keepCounting = true;
while (i - j > 0 && keepCounting) {
if (matchPostagRegexp(tokens[i - j], postag)
&& matchLemmaRegexp(tokens[i - j], lemma))
return true;
keepCounting = matchPostagRegexp(tokens[i - j], PREP_VERB_PRONOM);
j++;
}
j = 1;
keepCounting = true;
while (i + j < tokens.length && keepCounting) {
if (matchPostagRegexp(tokens[i + j], postag)
&& matchLemmaRegexp(tokens[i + j], lemma))
return true;
keepCounting = matchPostagRegexp(tokens[i + j], PREP_VERB_PRONOM);
j++;
}
return false;
}
|
java
|
private boolean isTherePronoun(final AnalyzedTokenReadings[] tokens, int i,
Pattern lemma, Pattern postag) {
int j = 1;
boolean keepCounting = true;
while (i - j > 0 && keepCounting) {
if (matchPostagRegexp(tokens[i - j], postag)
&& matchLemmaRegexp(tokens[i - j], lemma))
return true;
keepCounting = matchPostagRegexp(tokens[i - j], PREP_VERB_PRONOM);
j++;
}
j = 1;
keepCounting = true;
while (i + j < tokens.length && keepCounting) {
if (matchPostagRegexp(tokens[i + j], postag)
&& matchLemmaRegexp(tokens[i + j], lemma))
return true;
keepCounting = matchPostagRegexp(tokens[i + j], PREP_VERB_PRONOM);
j++;
}
return false;
}
|
[
"private",
"boolean",
"isTherePronoun",
"(",
"final",
"AnalyzedTokenReadings",
"[",
"]",
"tokens",
",",
"int",
"i",
",",
"Pattern",
"lemma",
",",
"Pattern",
"postag",
")",
"{",
"int",
"j",
"=",
"1",
";",
"boolean",
"keepCounting",
"=",
"true",
";",
"while",
"(",
"i",
"-",
"j",
">",
"0",
"&&",
"keepCounting",
")",
"{",
"if",
"(",
"matchPostagRegexp",
"(",
"tokens",
"[",
"i",
"-",
"j",
"]",
",",
"postag",
")",
"&&",
"matchLemmaRegexp",
"(",
"tokens",
"[",
"i",
"-",
"j",
"]",
",",
"lemma",
")",
")",
"return",
"true",
";",
"keepCounting",
"=",
"matchPostagRegexp",
"(",
"tokens",
"[",
"i",
"-",
"j",
"]",
",",
"PREP_VERB_PRONOM",
")",
";",
"j",
"++",
";",
"}",
"j",
"=",
"1",
";",
"keepCounting",
"=",
"true",
";",
"while",
"(",
"i",
"+",
"j",
"<",
"tokens",
".",
"length",
"&&",
"keepCounting",
")",
"{",
"if",
"(",
"matchPostagRegexp",
"(",
"tokens",
"[",
"i",
"+",
"j",
"]",
",",
"postag",
")",
"&&",
"matchLemmaRegexp",
"(",
"tokens",
"[",
"i",
"+",
"j",
"]",
",",
"lemma",
")",
")",
"return",
"true",
";",
"keepCounting",
"=",
"matchPostagRegexp",
"(",
"tokens",
"[",
"i",
"+",
"j",
"]",
",",
"PREP_VERB_PRONOM",
")",
";",
"j",
"++",
";",
"}",
"return",
"false",
";",
"}"
] |
Checks if there is a desired pronoun near the verb
|
[
"Checks",
"if",
"there",
"is",
"a",
"desired",
"pronoun",
"near",
"the",
"verb"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-language-modules/ca/src/main/java/org/languagetool/rules/ca/ReflexiveVerbsRule.java#L678-L699
|
19,144
|
languagetool-org/languagetool
|
languagetool-server/src/main/java/org/languagetool/server/Server.java
|
Server.stop
|
public void stop() {
if (httpHandler != null) {
httpHandler.shutdown();
}
if (server != null) {
ServerTools.print("Stopping server...");
server.stop(5);
isRunning = false;
ServerTools.print("Server stopped");
}
}
|
java
|
public void stop() {
if (httpHandler != null) {
httpHandler.shutdown();
}
if (server != null) {
ServerTools.print("Stopping server...");
server.stop(5);
isRunning = false;
ServerTools.print("Server stopped");
}
}
|
[
"public",
"void",
"stop",
"(",
")",
"{",
"if",
"(",
"httpHandler",
"!=",
"null",
")",
"{",
"httpHandler",
".",
"shutdown",
"(",
")",
";",
"}",
"if",
"(",
"server",
"!=",
"null",
")",
"{",
"ServerTools",
".",
"print",
"(",
"\"Stopping server...\"",
")",
";",
"server",
".",
"stop",
"(",
"5",
")",
";",
"isRunning",
"=",
"false",
";",
"ServerTools",
".",
"print",
"(",
"\"Server stopped\"",
")",
";",
"}",
"}"
] |
Stop the server. Once stopped, a server cannot be used again.
|
[
"Stop",
"the",
"server",
".",
"Once",
"stopped",
"a",
"server",
"cannot",
"be",
"used",
"again",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-server/src/main/java/org/languagetool/server/Server.java#L73-L83
|
19,145
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/WrongWordInContextRule.java
|
WrongWordInContextRule.loadContextWords
|
private static List<ContextWords> loadContextWords(String path) {
List<ContextWords> set = new ArrayList<>();
InputStream stream = JLanguageTool.getDataBroker().getFromRulesDirAsStream(path);
try (Scanner scanner = new Scanner(stream, "utf-8")) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.trim().isEmpty() || line.charAt(0) == '#') {
continue;
}
String[] column = line.split("\t");
if (column.length >= 6) {
ContextWords contextWords = new ContextWords();
contextWords.setWord(0, column[0]);
contextWords.setWord(1, column[1]);
contextWords.matches[0] = column[2];
contextWords.matches[1] = column[3];
contextWords.setContext(0, column[4]);
contextWords.setContext(1, column[5]);
if (column.length > 6) {
contextWords.explanations[0] = column[6];
if (column.length > 7) {
contextWords.explanations[1] = column[7];
}
}
set.add(contextWords);
} // if (column.length >= 6)
}
}
return Collections.unmodifiableList(set);
}
|
java
|
private static List<ContextWords> loadContextWords(String path) {
List<ContextWords> set = new ArrayList<>();
InputStream stream = JLanguageTool.getDataBroker().getFromRulesDirAsStream(path);
try (Scanner scanner = new Scanner(stream, "utf-8")) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.trim().isEmpty() || line.charAt(0) == '#') {
continue;
}
String[] column = line.split("\t");
if (column.length >= 6) {
ContextWords contextWords = new ContextWords();
contextWords.setWord(0, column[0]);
contextWords.setWord(1, column[1]);
contextWords.matches[0] = column[2];
contextWords.matches[1] = column[3];
contextWords.setContext(0, column[4]);
contextWords.setContext(1, column[5]);
if (column.length > 6) {
contextWords.explanations[0] = column[6];
if (column.length > 7) {
contextWords.explanations[1] = column[7];
}
}
set.add(contextWords);
} // if (column.length >= 6)
}
}
return Collections.unmodifiableList(set);
}
|
[
"private",
"static",
"List",
"<",
"ContextWords",
">",
"loadContextWords",
"(",
"String",
"path",
")",
"{",
"List",
"<",
"ContextWords",
">",
"set",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"InputStream",
"stream",
"=",
"JLanguageTool",
".",
"getDataBroker",
"(",
")",
".",
"getFromRulesDirAsStream",
"(",
"path",
")",
";",
"try",
"(",
"Scanner",
"scanner",
"=",
"new",
"Scanner",
"(",
"stream",
",",
"\"utf-8\"",
")",
")",
"{",
"while",
"(",
"scanner",
".",
"hasNextLine",
"(",
")",
")",
"{",
"String",
"line",
"=",
"scanner",
".",
"nextLine",
"(",
")",
";",
"if",
"(",
"line",
".",
"trim",
"(",
")",
".",
"isEmpty",
"(",
")",
"||",
"line",
".",
"charAt",
"(",
"0",
")",
"==",
"'",
"'",
")",
"{",
"continue",
";",
"}",
"String",
"[",
"]",
"column",
"=",
"line",
".",
"split",
"(",
"\"\\t\"",
")",
";",
"if",
"(",
"column",
".",
"length",
">=",
"6",
")",
"{",
"ContextWords",
"contextWords",
"=",
"new",
"ContextWords",
"(",
")",
";",
"contextWords",
".",
"setWord",
"(",
"0",
",",
"column",
"[",
"0",
"]",
")",
";",
"contextWords",
".",
"setWord",
"(",
"1",
",",
"column",
"[",
"1",
"]",
")",
";",
"contextWords",
".",
"matches",
"[",
"0",
"]",
"=",
"column",
"[",
"2",
"]",
";",
"contextWords",
".",
"matches",
"[",
"1",
"]",
"=",
"column",
"[",
"3",
"]",
";",
"contextWords",
".",
"setContext",
"(",
"0",
",",
"column",
"[",
"4",
"]",
")",
";",
"contextWords",
".",
"setContext",
"(",
"1",
",",
"column",
"[",
"5",
"]",
")",
";",
"if",
"(",
"column",
".",
"length",
">",
"6",
")",
"{",
"contextWords",
".",
"explanations",
"[",
"0",
"]",
"=",
"column",
"[",
"6",
"]",
";",
"if",
"(",
"column",
".",
"length",
">",
"7",
")",
"{",
"contextWords",
".",
"explanations",
"[",
"1",
"]",
"=",
"column",
"[",
"7",
"]",
";",
"}",
"}",
"set",
".",
"add",
"(",
"contextWords",
")",
";",
"}",
"// if (column.length >= 6)",
"}",
"}",
"return",
"Collections",
".",
"unmodifiableList",
"(",
"set",
")",
";",
"}"
] |
Load words, contexts, and explanations.
|
[
"Load",
"words",
"contexts",
"and",
"explanations",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/WrongWordInContextRule.java#L224-L253
|
19,146
|
languagetool-org/languagetool
|
languagetool-commandline/src/main/java/org/languagetool/commandline/Main.java
|
Main.getFilteredText
|
private String getFilteredText(String filename, String encoding, boolean xmlFiltering) throws IOException {
if (options.isVerbose()) {
lt.setOutput(System.err);
}
// don't use StringTools.readStream() as that might add newlines which aren't there:
try (InputStreamReader reader = getInputStreamReader(filename, encoding)) {
String fileContents = readerToString(reader);
if (xmlFiltering) {
return filterXML(fileContents);
} else {
return fileContents;
}
}
}
|
java
|
private String getFilteredText(String filename, String encoding, boolean xmlFiltering) throws IOException {
if (options.isVerbose()) {
lt.setOutput(System.err);
}
// don't use StringTools.readStream() as that might add newlines which aren't there:
try (InputStreamReader reader = getInputStreamReader(filename, encoding)) {
String fileContents = readerToString(reader);
if (xmlFiltering) {
return filterXML(fileContents);
} else {
return fileContents;
}
}
}
|
[
"private",
"String",
"getFilteredText",
"(",
"String",
"filename",
",",
"String",
"encoding",
",",
"boolean",
"xmlFiltering",
")",
"throws",
"IOException",
"{",
"if",
"(",
"options",
".",
"isVerbose",
"(",
")",
")",
"{",
"lt",
".",
"setOutput",
"(",
"System",
".",
"err",
")",
";",
"}",
"// don't use StringTools.readStream() as that might add newlines which aren't there:",
"try",
"(",
"InputStreamReader",
"reader",
"=",
"getInputStreamReader",
"(",
"filename",
",",
"encoding",
")",
")",
"{",
"String",
"fileContents",
"=",
"readerToString",
"(",
"reader",
")",
";",
"if",
"(",
"xmlFiltering",
")",
"{",
"return",
"filterXML",
"(",
"fileContents",
")",
";",
"}",
"else",
"{",
"return",
"fileContents",
";",
"}",
"}",
"}"
] |
Loads filename and filters out XML. Note that the XML
filtering can lead to incorrect positions in the list of matching rules.
|
[
"Loads",
"filename",
"and",
"filters",
"out",
"XML",
".",
"Note",
"that",
"the",
"XML",
"filtering",
"can",
"lead",
"to",
"incorrect",
"positions",
"in",
"the",
"list",
"of",
"matching",
"rules",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-commandline/src/main/java/org/languagetool/commandline/Main.java#L342-L355
|
19,147
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/Main.java
|
Main.doProofreading
|
@Override
public final ProofreadingResult doProofreading(String docID,
String paraText, Locale locale, int startOfSentencePos,
int nSuggestedBehindEndOfSentencePosition,
PropertyValue[] propertyValues) {
ProofreadingResult paRes = new ProofreadingResult();
paRes.nStartOfSentencePosition = startOfSentencePos;
paRes.nStartOfNextSentencePosition = nSuggestedBehindEndOfSentencePosition;
paRes.nBehindEndOfSentencePosition = paRes.nStartOfNextSentencePosition;
paRes.xProofreader = this;
paRes.aLocale = locale;
paRes.aDocumentIdentifier = docID;
paRes.aText = paraText;
paRes.aProperties = propertyValues;
try {
int[] footnotePositions = getPropertyValues("FootnotePositions", propertyValues); // since LO 4.3
paRes = documents.getCheckResults(paraText, locale, paRes, footnotePositions);
if (disabledRules == null) {
prepareConfig();
}
if(documents.doResetCheck()) {
resetCheck();
documents.optimizeReset();
}
} catch (Throwable t) {
MessageHandler.showError(t);
}
return paRes;
}
|
java
|
@Override
public final ProofreadingResult doProofreading(String docID,
String paraText, Locale locale, int startOfSentencePos,
int nSuggestedBehindEndOfSentencePosition,
PropertyValue[] propertyValues) {
ProofreadingResult paRes = new ProofreadingResult();
paRes.nStartOfSentencePosition = startOfSentencePos;
paRes.nStartOfNextSentencePosition = nSuggestedBehindEndOfSentencePosition;
paRes.nBehindEndOfSentencePosition = paRes.nStartOfNextSentencePosition;
paRes.xProofreader = this;
paRes.aLocale = locale;
paRes.aDocumentIdentifier = docID;
paRes.aText = paraText;
paRes.aProperties = propertyValues;
try {
int[] footnotePositions = getPropertyValues("FootnotePositions", propertyValues); // since LO 4.3
paRes = documents.getCheckResults(paraText, locale, paRes, footnotePositions);
if (disabledRules == null) {
prepareConfig();
}
if(documents.doResetCheck()) {
resetCheck();
documents.optimizeReset();
}
} catch (Throwable t) {
MessageHandler.showError(t);
}
return paRes;
}
|
[
"@",
"Override",
"public",
"final",
"ProofreadingResult",
"doProofreading",
"(",
"String",
"docID",
",",
"String",
"paraText",
",",
"Locale",
"locale",
",",
"int",
"startOfSentencePos",
",",
"int",
"nSuggestedBehindEndOfSentencePosition",
",",
"PropertyValue",
"[",
"]",
"propertyValues",
")",
"{",
"ProofreadingResult",
"paRes",
"=",
"new",
"ProofreadingResult",
"(",
")",
";",
"paRes",
".",
"nStartOfSentencePosition",
"=",
"startOfSentencePos",
";",
"paRes",
".",
"nStartOfNextSentencePosition",
"=",
"nSuggestedBehindEndOfSentencePosition",
";",
"paRes",
".",
"nBehindEndOfSentencePosition",
"=",
"paRes",
".",
"nStartOfNextSentencePosition",
";",
"paRes",
".",
"xProofreader",
"=",
"this",
";",
"paRes",
".",
"aLocale",
"=",
"locale",
";",
"paRes",
".",
"aDocumentIdentifier",
"=",
"docID",
";",
"paRes",
".",
"aText",
"=",
"paraText",
";",
"paRes",
".",
"aProperties",
"=",
"propertyValues",
";",
"try",
"{",
"int",
"[",
"]",
"footnotePositions",
"=",
"getPropertyValues",
"(",
"\"FootnotePositions\"",
",",
"propertyValues",
")",
";",
"// since LO 4.3",
"paRes",
"=",
"documents",
".",
"getCheckResults",
"(",
"paraText",
",",
"locale",
",",
"paRes",
",",
"footnotePositions",
")",
";",
"if",
"(",
"disabledRules",
"==",
"null",
")",
"{",
"prepareConfig",
"(",
")",
";",
"}",
"if",
"(",
"documents",
".",
"doResetCheck",
"(",
")",
")",
"{",
"resetCheck",
"(",
")",
";",
"documents",
".",
"optimizeReset",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"MessageHandler",
".",
"showError",
"(",
"t",
")",
";",
"}",
"return",
"paRes",
";",
"}"
] |
Runs the grammar checker on paragraph text.
@param docID document ID
@param paraText paragraph text
@param locale Locale the text Locale
@param startOfSentencePos start of sentence position
@param nSuggestedBehindEndOfSentencePosition end of sentence position
@return ProofreadingResult containing the results of the check.
|
[
"Runs",
"the",
"grammar",
"checker",
"on",
"paragraph",
"text",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/Main.java#L134-L162
|
19,148
|
languagetool-org/languagetool
|
languagetool-standalone/src/main/java/org/languagetool/gui/UndoRedoSupport.java
|
UndoRedoSupport.endCompoundEdit
|
void endCompoundEdit()
{
if(!compoundMode) {
throw new RuntimeException("not in compound mode");
}
ce.end();
undoManager.addEdit(ce);
ce = null;
compoundMode = false;
}
|
java
|
void endCompoundEdit()
{
if(!compoundMode) {
throw new RuntimeException("not in compound mode");
}
ce.end();
undoManager.addEdit(ce);
ce = null;
compoundMode = false;
}
|
[
"void",
"endCompoundEdit",
"(",
")",
"{",
"if",
"(",
"!",
"compoundMode",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"not in compound mode\"",
")",
";",
"}",
"ce",
".",
"end",
"(",
")",
";",
"undoManager",
".",
"addEdit",
"(",
"ce",
")",
";",
"ce",
"=",
"null",
";",
"compoundMode",
"=",
"false",
";",
"}"
] |
Notify manager to stop merging undoable edits.
Calling endCompoundEdit when not in compound mode is an error
and will throw a RuntimeException.
@since 2.7
|
[
"Notify",
"manager",
"to",
"stop",
"merging",
"undoable",
"edits",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-standalone/src/main/java/org/languagetool/gui/UndoRedoSupport.java#L109-L118
|
19,149
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/spelling/hunspell/Hunspell.java
|
Hunspell.getInstance
|
public static synchronized Hunspell getInstance(String libDir) throws UnsatisfiedLinkError, UnsupportedOperationException {
if (hunspell != null) {
return hunspell;
}
hunspell = new Hunspell(libDir);
return hunspell;
}
|
java
|
public static synchronized Hunspell getInstance(String libDir) throws UnsatisfiedLinkError, UnsupportedOperationException {
if (hunspell != null) {
return hunspell;
}
hunspell = new Hunspell(libDir);
return hunspell;
}
|
[
"public",
"static",
"synchronized",
"Hunspell",
"getInstance",
"(",
"String",
"libDir",
")",
"throws",
"UnsatisfiedLinkError",
",",
"UnsupportedOperationException",
"{",
"if",
"(",
"hunspell",
"!=",
"null",
")",
"{",
"return",
"hunspell",
";",
"}",
"hunspell",
"=",
"new",
"Hunspell",
"(",
"libDir",
")",
";",
"return",
"hunspell",
";",
"}"
] |
The instance of the HunspellManager, looks for the native lib in
the directory specified.
@param libDir Optional absolute directory where the native lib can be found.
|
[
"The",
"instance",
"of",
"the",
"HunspellManager",
"looks",
"for",
"the",
"native",
"lib",
"in",
"the",
"directory",
"specified",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/spelling/hunspell/Hunspell.java#L63-L70
|
19,150
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/spelling/hunspell/Hunspell.java
|
Hunspell.libName
|
public static String libName() throws UnsupportedOperationException {
String os = System.getProperty("os.name").toLowerCase();
if (os.startsWith("windows")) {
return libNameBare()+".dll";
} else if (os.startsWith("mac os x")) {
// return libNameBare()+".dylib";
return libNameBare()+".jnilib";
} else {
return "lib"+libNameBare()+".so";
}
}
|
java
|
public static String libName() throws UnsupportedOperationException {
String os = System.getProperty("os.name").toLowerCase();
if (os.startsWith("windows")) {
return libNameBare()+".dll";
} else if (os.startsWith("mac os x")) {
// return libNameBare()+".dylib";
return libNameBare()+".jnilib";
} else {
return "lib"+libNameBare()+".so";
}
}
|
[
"public",
"static",
"String",
"libName",
"(",
")",
"throws",
"UnsupportedOperationException",
"{",
"String",
"os",
"=",
"System",
".",
"getProperty",
"(",
"\"os.name\"",
")",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"os",
".",
"startsWith",
"(",
"\"windows\"",
")",
")",
"{",
"return",
"libNameBare",
"(",
")",
"+",
"\".dll\"",
";",
"}",
"else",
"if",
"(",
"os",
".",
"startsWith",
"(",
"\"mac os x\"",
")",
")",
"{",
"//\t return libNameBare()+\".dylib\";",
"return",
"libNameBare",
"(",
")",
"+",
"\".jnilib\"",
";",
"}",
"else",
"{",
"return",
"\"lib\"",
"+",
"libNameBare",
"(",
")",
"+",
"\".so\"",
";",
"}",
"}"
] |
Calculate the filename of the native hunspell lib.
The files have completely different names to allow them to live
in the same directory and avoid confusion.
|
[
"Calculate",
"the",
"filename",
"of",
"the",
"native",
"hunspell",
"lib",
".",
"The",
"files",
"have",
"completely",
"different",
"names",
"to",
"allow",
"them",
"to",
"live",
"in",
"the",
"same",
"directory",
"and",
"avoid",
"confusion",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/spelling/hunspell/Hunspell.java#L140-L152
|
19,151
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/spelling/hunspell/Hunspell.java
|
Hunspell.getDictionary
|
public Dictionary getDictionary(String baseFileName)
throws IOException {
if (map.containsKey(baseFileName)) {
return map.get(baseFileName);
} else {
Dictionary d = new Dictionary(baseFileName);
map.put(baseFileName, d);
return d;
}
}
|
java
|
public Dictionary getDictionary(String baseFileName)
throws IOException {
if (map.containsKey(baseFileName)) {
return map.get(baseFileName);
} else {
Dictionary d = new Dictionary(baseFileName);
map.put(baseFileName, d);
return d;
}
}
|
[
"public",
"Dictionary",
"getDictionary",
"(",
"String",
"baseFileName",
")",
"throws",
"IOException",
"{",
"if",
"(",
"map",
".",
"containsKey",
"(",
"baseFileName",
")",
")",
"{",
"return",
"map",
".",
"get",
"(",
"baseFileName",
")",
";",
"}",
"else",
"{",
"Dictionary",
"d",
"=",
"new",
"Dictionary",
"(",
"baseFileName",
")",
";",
"map",
".",
"put",
"(",
"baseFileName",
",",
"d",
")",
";",
"return",
"d",
";",
"}",
"}"
] |
Gets an instance of the dictionary.
@param baseFileName the base name of the dictionary,
passing /dict/da_DK means that the files /dict/da_DK.dic
and /dict/da_DK.aff get loaded
|
[
"Gets",
"an",
"instance",
"of",
"the",
"dictionary",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/spelling/hunspell/Hunspell.java#L233-L244
|
19,152
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/tagging/disambiguation/MultiWordChunker2.java
|
MultiWordChunker2.formatPosTag
|
protected String formatPosTag(String posTag, int position, int multiwordLength) {
return tagFormat != null ? String.format(tagFormat, posTag) : posTag;
}
|
java
|
protected String formatPosTag(String posTag, int position, int multiwordLength) {
return tagFormat != null ? String.format(tagFormat, posTag) : posTag;
}
|
[
"protected",
"String",
"formatPosTag",
"(",
"String",
"posTag",
",",
"int",
"position",
",",
"int",
"multiwordLength",
")",
"{",
"return",
"tagFormat",
"!=",
"null",
"?",
"String",
".",
"format",
"(",
"tagFormat",
",",
"posTag",
")",
":",
"posTag",
";",
"}"
] |
Override this method if you want format POS tag differently
@param posTag POS tag for the multiword
@param position Position of the token in the multiword
@return Returns formatted POS tag for the multiword
|
[
"Override",
"this",
"method",
"if",
"you",
"want",
"format",
"POS",
"tag",
"differently"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/tagging/disambiguation/MultiWordChunker2.java#L89-L91
|
19,153
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/tagging/BaseTagger.java
|
BaseTagger.addTokens
|
private void addTokens(List<AnalyzedToken> taggedTokens, List<AnalyzedToken> l) {
if (taggedTokens != null) {
for (AnalyzedToken at : taggedTokens) {
l.add(at);
}
}
}
|
java
|
private void addTokens(List<AnalyzedToken> taggedTokens, List<AnalyzedToken> l) {
if (taggedTokens != null) {
for (AnalyzedToken at : taggedTokens) {
l.add(at);
}
}
}
|
[
"private",
"void",
"addTokens",
"(",
"List",
"<",
"AnalyzedToken",
">",
"taggedTokens",
",",
"List",
"<",
"AnalyzedToken",
">",
"l",
")",
"{",
"if",
"(",
"taggedTokens",
"!=",
"null",
")",
"{",
"for",
"(",
"AnalyzedToken",
"at",
":",
"taggedTokens",
")",
"{",
"l",
".",
"add",
"(",
"at",
")",
";",
"}",
"}",
"}"
] |
please do not make protected, this breaks other languages
|
[
"please",
"do",
"not",
"make",
"protected",
"this",
"breaks",
"other",
"languages"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/tagging/BaseTagger.java#L222-L228
|
19,154
|
languagetool-org/languagetool
|
languagetool-gui-commons/src/main/java/org/languagetool/gui/Tools.java
|
Tools.openFileDialog
|
static File openFileDialog(Frame frame, FileFilter fileFilter, File initialDir) {
return openFileDialog(frame, fileFilter, initialDir, JFileChooser.FILES_ONLY);
}
|
java
|
static File openFileDialog(Frame frame, FileFilter fileFilter, File initialDir) {
return openFileDialog(frame, fileFilter, initialDir, JFileChooser.FILES_ONLY);
}
|
[
"static",
"File",
"openFileDialog",
"(",
"Frame",
"frame",
",",
"FileFilter",
"fileFilter",
",",
"File",
"initialDir",
")",
"{",
"return",
"openFileDialog",
"(",
"frame",
",",
"fileFilter",
",",
"initialDir",
",",
"JFileChooser",
".",
"FILES_ONLY",
")",
";",
"}"
] |
Show a file chooser dialog in a specified directory
@param frame Owner frame
@param fileFilter The pattern of files to choose from
@param initialDir The initial directory
@return the selected file
@since 2.6
|
[
"Show",
"a",
"file",
"chooser",
"dialog",
"in",
"a",
"specified",
"directory"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-gui-commons/src/main/java/org/languagetool/gui/Tools.java#L69-L71
|
19,155
|
languagetool-org/languagetool
|
languagetool-gui-commons/src/main/java/org/languagetool/gui/Tools.java
|
Tools.openDirectoryDialog
|
static File openDirectoryDialog(Frame frame, File initialDir) {
return openFileDialog(frame, null, initialDir, JFileChooser.DIRECTORIES_ONLY);
}
|
java
|
static File openDirectoryDialog(Frame frame, File initialDir) {
return openFileDialog(frame, null, initialDir, JFileChooser.DIRECTORIES_ONLY);
}
|
[
"static",
"File",
"openDirectoryDialog",
"(",
"Frame",
"frame",
",",
"File",
"initialDir",
")",
"{",
"return",
"openFileDialog",
"(",
"frame",
",",
"null",
",",
"initialDir",
",",
"JFileChooser",
".",
"DIRECTORIES_ONLY",
")",
";",
"}"
] |
Show a directory chooser dialog, starting with a specified directory
@param frame Owner frame
@param initialDir The initial directory
@return the selected file
@since 3.0
|
[
"Show",
"a",
"directory",
"chooser",
"dialog",
"starting",
"with",
"a",
"specified",
"directory"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-gui-commons/src/main/java/org/languagetool/gui/Tools.java#L80-L82
|
19,156
|
languagetool-org/languagetool
|
languagetool-gui-commons/src/main/java/org/languagetool/gui/Tools.java
|
Tools.getMnemonic
|
public static char getMnemonic(String label) {
int mnemonicPos = label.indexOf('&');
while (mnemonicPos != -1 && mnemonicPos == label.indexOf("&&")
&& mnemonicPos < label.length()) {
mnemonicPos = label.indexOf('&', mnemonicPos + 2);
}
if (mnemonicPos == -1 || mnemonicPos == label.length()) {
return '\u0000';
}
return label.charAt(mnemonicPos + 1);
}
|
java
|
public static char getMnemonic(String label) {
int mnemonicPos = label.indexOf('&');
while (mnemonicPos != -1 && mnemonicPos == label.indexOf("&&")
&& mnemonicPos < label.length()) {
mnemonicPos = label.indexOf('&', mnemonicPos + 2);
}
if (mnemonicPos == -1 || mnemonicPos == label.length()) {
return '\u0000';
}
return label.charAt(mnemonicPos + 1);
}
|
[
"public",
"static",
"char",
"getMnemonic",
"(",
"String",
"label",
")",
"{",
"int",
"mnemonicPos",
"=",
"label",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"while",
"(",
"mnemonicPos",
"!=",
"-",
"1",
"&&",
"mnemonicPos",
"==",
"label",
".",
"indexOf",
"(",
"\"&&\"",
")",
"&&",
"mnemonicPos",
"<",
"label",
".",
"length",
"(",
")",
")",
"{",
"mnemonicPos",
"=",
"label",
".",
"indexOf",
"(",
"'",
"'",
",",
"mnemonicPos",
"+",
"2",
")",
";",
"}",
"if",
"(",
"mnemonicPos",
"==",
"-",
"1",
"||",
"mnemonicPos",
"==",
"label",
".",
"length",
"(",
")",
")",
"{",
"return",
"'",
"'",
";",
"}",
"return",
"label",
".",
"charAt",
"(",
"mnemonicPos",
"+",
"1",
")",
";",
"}"
] |
Returns mnemonic of a UI element.
@param label String Label of the UI element
@return Mnemonic of the UI element, or {@code \u0000} in case of no mnemonic set.
|
[
"Returns",
"mnemonic",
"of",
"a",
"UI",
"element",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-gui-commons/src/main/java/org/languagetool/gui/Tools.java#L165-L175
|
19,157
|
languagetool-org/languagetool
|
languagetool-gui-commons/src/main/java/org/languagetool/gui/Tools.java
|
Tools.centerDialog
|
public static void centerDialog(JDialog dialog) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = dialog.getSize();
dialog.setLocation(screenSize.width / 2 - frameSize.width / 2,
screenSize.height / 2 - frameSize.height / 2);
dialog.setLocationByPlatform(true);
}
|
java
|
public static void centerDialog(JDialog dialog) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = dialog.getSize();
dialog.setLocation(screenSize.width / 2 - frameSize.width / 2,
screenSize.height / 2 - frameSize.height / 2);
dialog.setLocationByPlatform(true);
}
|
[
"public",
"static",
"void",
"centerDialog",
"(",
"JDialog",
"dialog",
")",
"{",
"Dimension",
"screenSize",
"=",
"Toolkit",
".",
"getDefaultToolkit",
"(",
")",
".",
"getScreenSize",
"(",
")",
";",
"Dimension",
"frameSize",
"=",
"dialog",
".",
"getSize",
"(",
")",
";",
"dialog",
".",
"setLocation",
"(",
"screenSize",
".",
"width",
"/",
"2",
"-",
"frameSize",
".",
"width",
"/",
"2",
",",
"screenSize",
".",
"height",
"/",
"2",
"-",
"frameSize",
".",
"height",
"/",
"2",
")",
";",
"dialog",
".",
"setLocationByPlatform",
"(",
"true",
")",
";",
"}"
] |
Set dialog location to the center of the screen
@param dialog the dialog which will be centered
@since 2.6
|
[
"Set",
"dialog",
"location",
"to",
"the",
"center",
"of",
"the",
"screen"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-gui-commons/src/main/java/org/languagetool/gui/Tools.java#L183-L189
|
19,158
|
languagetool-org/languagetool
|
languagetool-server/src/main/java/org/languagetool/server/DatabaseAccess.java
|
DatabaseAccess.executeStatement
|
static ResultSet executeStatement(SQL sql) throws SQLException {
try (SqlSession session = sqlSessionFactory.openSession(true)) {
try (Connection conn = session.getConnection()) {
try (Statement stmt = conn.createStatement()) {
return stmt.executeQuery(sql.toString());
}
}
}
}
|
java
|
static ResultSet executeStatement(SQL sql) throws SQLException {
try (SqlSession session = sqlSessionFactory.openSession(true)) {
try (Connection conn = session.getConnection()) {
try (Statement stmt = conn.createStatement()) {
return stmt.executeQuery(sql.toString());
}
}
}
}
|
[
"static",
"ResultSet",
"executeStatement",
"(",
"SQL",
"sql",
")",
"throws",
"SQLException",
"{",
"try",
"(",
"SqlSession",
"session",
"=",
"sqlSessionFactory",
".",
"openSession",
"(",
"true",
")",
")",
"{",
"try",
"(",
"Connection",
"conn",
"=",
"session",
".",
"getConnection",
"(",
")",
")",
"{",
"try",
"(",
"Statement",
"stmt",
"=",
"conn",
".",
"createStatement",
"(",
")",
")",
"{",
"return",
"stmt",
".",
"executeQuery",
"(",
"sql",
".",
"toString",
"(",
")",
")",
";",
"}",
"}",
"}",
"}"
] |
For unit tests only
|
[
"For",
"unit",
"tests",
"only"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-server/src/main/java/org/languagetool/server/DatabaseAccess.java#L356-L364
|
19,159
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternToken.java
|
PatternToken.isExceptionMatched
|
public boolean isExceptionMatched(AnalyzedToken token) {
if (exceptionSet) {
for (PatternToken testException : exceptionList) {
if (!testException.exceptionValidNext) {
if (testException.isMatched(token)) {
return true;
}
}
}
}
return false;
}
|
java
|
public boolean isExceptionMatched(AnalyzedToken token) {
if (exceptionSet) {
for (PatternToken testException : exceptionList) {
if (!testException.exceptionValidNext) {
if (testException.isMatched(token)) {
return true;
}
}
}
}
return false;
}
|
[
"public",
"boolean",
"isExceptionMatched",
"(",
"AnalyzedToken",
"token",
")",
"{",
"if",
"(",
"exceptionSet",
")",
"{",
"for",
"(",
"PatternToken",
"testException",
":",
"exceptionList",
")",
"{",
"if",
"(",
"!",
"testException",
".",
"exceptionValidNext",
")",
"{",
"if",
"(",
"testException",
".",
"isMatched",
"(",
"token",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Checks whether an exception matches.
@param token AnalyzedToken to check matching against
@return True if any of the exceptions matches (logical disjunction).
|
[
"Checks",
"whether",
"an",
"exception",
"matches",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternToken.java#L146-L157
|
19,160
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternToken.java
|
PatternToken.isAndExceptionGroupMatched
|
public boolean isAndExceptionGroupMatched(AnalyzedToken token) {
for (PatternToken testAndGroup : andGroupList) {
if (testAndGroup.isExceptionMatched(token)) {
return true;
}
}
return false;
}
|
java
|
public boolean isAndExceptionGroupMatched(AnalyzedToken token) {
for (PatternToken testAndGroup : andGroupList) {
if (testAndGroup.isExceptionMatched(token)) {
return true;
}
}
return false;
}
|
[
"public",
"boolean",
"isAndExceptionGroupMatched",
"(",
"AnalyzedToken",
"token",
")",
"{",
"for",
"(",
"PatternToken",
"testAndGroup",
":",
"andGroupList",
")",
"{",
"if",
"(",
"testAndGroup",
".",
"isExceptionMatched",
"(",
"token",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Enables testing multiple conditions specified by multiple element exceptions.
Works as logical AND operator.
@param token the token checked for exceptions.
@return true if all conditions are met, false otherwise.
|
[
"Enables",
"testing",
"multiple",
"conditions",
"specified",
"by",
"multiple",
"element",
"exceptions",
".",
"Works",
"as",
"logical",
"AND",
"operator",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternToken.java#L165-L172
|
19,161
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternToken.java
|
PatternToken.isSentenceStart
|
public boolean isSentenceStart() {
return posToken != null && JLanguageTool.SENTENCE_START_TAGNAME.equals(posToken.posTag) && !posToken.negation;
}
|
java
|
public boolean isSentenceStart() {
return posToken != null && JLanguageTool.SENTENCE_START_TAGNAME.equals(posToken.posTag) && !posToken.negation;
}
|
[
"public",
"boolean",
"isSentenceStart",
"(",
")",
"{",
"return",
"posToken",
"!=",
"null",
"&&",
"JLanguageTool",
".",
"SENTENCE_START_TAGNAME",
".",
"equals",
"(",
"posToken",
".",
"posTag",
")",
"&&",
"!",
"posToken",
".",
"negation",
";",
"}"
] |
Checks if the token is a sentence start.
@return True if the element starts the sentence and the element hasn't been set to have negated POS token.
|
[
"Checks",
"if",
"the",
"token",
"is",
"a",
"sentence",
"start",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternToken.java#L281-L283
|
19,162
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternToken.java
|
PatternToken.isPosTokenMatched
|
private boolean isPosTokenMatched(AnalyzedToken token) {
if (posToken == null || posToken.posTag == null) {
// if no POS set defaulting to true
return true;
}
if (token.getPOSTag() == null) {
return posToken.posUnknown && token.hasNoTag();
}
boolean match;
if (posToken.regExp) {
Matcher mPos = posToken.posPattern.matcher(token.getPOSTag());
match = mPos.matches();
} else {
match = posToken.posTag.equals(token.getPOSTag());
}
if (!match && posToken.posUnknown) { // ignore helper tags
match = token.hasNoTag();
}
return match;
}
|
java
|
private boolean isPosTokenMatched(AnalyzedToken token) {
if (posToken == null || posToken.posTag == null) {
// if no POS set defaulting to true
return true;
}
if (token.getPOSTag() == null) {
return posToken.posUnknown && token.hasNoTag();
}
boolean match;
if (posToken.regExp) {
Matcher mPos = posToken.posPattern.matcher(token.getPOSTag());
match = mPos.matches();
} else {
match = posToken.posTag.equals(token.getPOSTag());
}
if (!match && posToken.posUnknown) { // ignore helper tags
match = token.hasNoTag();
}
return match;
}
|
[
"private",
"boolean",
"isPosTokenMatched",
"(",
"AnalyzedToken",
"token",
")",
"{",
"if",
"(",
"posToken",
"==",
"null",
"||",
"posToken",
".",
"posTag",
"==",
"null",
")",
"{",
"// if no POS set defaulting to true",
"return",
"true",
";",
"}",
"if",
"(",
"token",
".",
"getPOSTag",
"(",
")",
"==",
"null",
")",
"{",
"return",
"posToken",
".",
"posUnknown",
"&&",
"token",
".",
"hasNoTag",
"(",
")",
";",
"}",
"boolean",
"match",
";",
"if",
"(",
"posToken",
".",
"regExp",
")",
"{",
"Matcher",
"mPos",
"=",
"posToken",
".",
"posPattern",
".",
"matcher",
"(",
"token",
".",
"getPOSTag",
"(",
")",
")",
";",
"match",
"=",
"mPos",
".",
"matches",
"(",
")",
";",
"}",
"else",
"{",
"match",
"=",
"posToken",
".",
"posTag",
".",
"equals",
"(",
"token",
".",
"getPOSTag",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"match",
"&&",
"posToken",
".",
"posUnknown",
")",
"{",
"// ignore helper tags",
"match",
"=",
"token",
".",
"hasNoTag",
"(",
")",
";",
"}",
"return",
"match",
";",
"}"
] |
Tests if part of speech matches a given string.
Special value UNKNOWN_TAG matches null POS tags.
@param token Token to test.
@return true if matches
|
[
"Tests",
"if",
"part",
"of",
"speech",
"matches",
"a",
"given",
"string",
".",
"Special",
"value",
"UNKNOWN_TAG",
"matches",
"null",
"POS",
"tags",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternToken.java#L367-L386
|
19,163
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternToken.java
|
PatternToken.isStringTokenMatched
|
private boolean isStringTokenMatched(AnalyzedToken token) {
String testToken = getTestToken(token);
if (stringRegExp) {
Matcher m = pattern.matcher(new InterruptibleCharSequence(testToken));
return m.matches();
}
if (caseSensitive) {
return stringToken.equals(testToken);
}
return stringToken.equalsIgnoreCase(testToken);
}
|
java
|
private boolean isStringTokenMatched(AnalyzedToken token) {
String testToken = getTestToken(token);
if (stringRegExp) {
Matcher m = pattern.matcher(new InterruptibleCharSequence(testToken));
return m.matches();
}
if (caseSensitive) {
return stringToken.equals(testToken);
}
return stringToken.equalsIgnoreCase(testToken);
}
|
[
"private",
"boolean",
"isStringTokenMatched",
"(",
"AnalyzedToken",
"token",
")",
"{",
"String",
"testToken",
"=",
"getTestToken",
"(",
"token",
")",
";",
"if",
"(",
"stringRegExp",
")",
"{",
"Matcher",
"m",
"=",
"pattern",
".",
"matcher",
"(",
"new",
"InterruptibleCharSequence",
"(",
"testToken",
")",
")",
";",
"return",
"m",
".",
"matches",
"(",
")",
";",
"}",
"if",
"(",
"caseSensitive",
")",
"{",
"return",
"stringToken",
".",
"equals",
"(",
"testToken",
")",
";",
"}",
"return",
"stringToken",
".",
"equalsIgnoreCase",
"(",
"testToken",
")",
";",
"}"
] |
Tests whether the string token element matches a given token.
@param token {@link AnalyzedToken} to match against.
@return True if matches.
|
[
"Tests",
"whether",
"the",
"string",
"token",
"element",
"matches",
"a",
"given",
"token",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternToken.java#L393-L403
|
19,164
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternToken.java
|
PatternToken.setExceptionSpaceBefore
|
public void setExceptionSpaceBefore(boolean isWhite) {
if (previousExceptionList != null && exceptionValidPrevious) {
previousExceptionList.get(previousExceptionList.size() - 1).setWhitespaceBefore(isWhite);
} else {
if (exceptionList != null) {
exceptionList.get(exceptionList.size() - 1).setWhitespaceBefore(isWhite);
}
}
}
|
java
|
public void setExceptionSpaceBefore(boolean isWhite) {
if (previousExceptionList != null && exceptionValidPrevious) {
previousExceptionList.get(previousExceptionList.size() - 1).setWhitespaceBefore(isWhite);
} else {
if (exceptionList != null) {
exceptionList.get(exceptionList.size() - 1).setWhitespaceBefore(isWhite);
}
}
}
|
[
"public",
"void",
"setExceptionSpaceBefore",
"(",
"boolean",
"isWhite",
")",
"{",
"if",
"(",
"previousExceptionList",
"!=",
"null",
"&&",
"exceptionValidPrevious",
")",
"{",
"previousExceptionList",
".",
"get",
"(",
"previousExceptionList",
".",
"size",
"(",
")",
"-",
"1",
")",
".",
"setWhitespaceBefore",
"(",
"isWhite",
")",
";",
"}",
"else",
"{",
"if",
"(",
"exceptionList",
"!=",
"null",
")",
"{",
"exceptionList",
".",
"get",
"(",
"exceptionList",
".",
"size",
"(",
")",
"-",
"1",
")",
".",
"setWhitespaceBefore",
"(",
"isWhite",
")",
";",
"}",
"}",
"}"
] |
Sets the attribute on the exception that determines matching of patterns
that depends on whether there was a space before the token matching the exception
or not.
The same procedure is used for tokens that are valid for previous or current tokens.
@param isWhite If true, the space before exception is required.
|
[
"Sets",
"the",
"attribute",
"on",
"the",
"exception",
"that",
"determines",
"matching",
"of",
"patterns",
"that",
"depends",
"on",
"whether",
"there",
"was",
"a",
"space",
"before",
"the",
"token",
"matching",
"the",
"exception",
"or",
"not",
".",
"The",
"same",
"procedure",
"is",
"used",
"for",
"tokens",
"that",
"are",
"valid",
"for",
"previous",
"or",
"current",
"tokens",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternToken.java#L709-L717
|
19,165
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/tagging/disambiguation/rules/DisambiguationPatternRule.java
|
DisambiguationPatternRule.replace
|
public final AnalyzedSentence replace(AnalyzedSentence sentence) throws IOException {
DisambiguationPatternRuleReplacer replacer = new DisambiguationPatternRuleReplacer(this);
return replacer.replace(sentence);
}
|
java
|
public final AnalyzedSentence replace(AnalyzedSentence sentence) throws IOException {
DisambiguationPatternRuleReplacer replacer = new DisambiguationPatternRuleReplacer(this);
return replacer.replace(sentence);
}
|
[
"public",
"final",
"AnalyzedSentence",
"replace",
"(",
"AnalyzedSentence",
"sentence",
")",
"throws",
"IOException",
"{",
"DisambiguationPatternRuleReplacer",
"replacer",
"=",
"new",
"DisambiguationPatternRuleReplacer",
"(",
"this",
")",
";",
"return",
"replacer",
".",
"replace",
"(",
"sentence",
")",
";",
"}"
] |
Performs disambiguation on the source sentence.
@param sentence {@link AnalyzedSentence} Sentence to be disambiguated.
@return {@link AnalyzedSentence} Disambiguated sentence (might be unchanged).
|
[
"Performs",
"disambiguation",
"on",
"the",
"source",
"sentence",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/tagging/disambiguation/rules/DisambiguationPatternRule.java#L99-L102
|
19,166
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/MultipleWhitespaceRule.java
|
MultipleWhitespaceRule.isRemovableWhite
|
private static boolean isRemovableWhite(AnalyzedTokenReadings token) {
return (token.isWhitespace() || StringTools.isNonBreakingWhitespace(token.getToken()))
&& !token.isLinebreak() && !token.getToken().equals("\t") && !token.getToken().equals("\u200B");
}
|
java
|
private static boolean isRemovableWhite(AnalyzedTokenReadings token) {
return (token.isWhitespace() || StringTools.isNonBreakingWhitespace(token.getToken()))
&& !token.isLinebreak() && !token.getToken().equals("\t") && !token.getToken().equals("\u200B");
}
|
[
"private",
"static",
"boolean",
"isRemovableWhite",
"(",
"AnalyzedTokenReadings",
"token",
")",
"{",
"return",
"(",
"token",
".",
"isWhitespace",
"(",
")",
"||",
"StringTools",
".",
"isNonBreakingWhitespace",
"(",
"token",
".",
"getToken",
"(",
")",
")",
")",
"&&",
"!",
"token",
".",
"isLinebreak",
"(",
")",
"&&",
"!",
"token",
".",
"getToken",
"(",
")",
".",
"equals",
"(",
"\"\\t\"",
")",
"&&",
"!",
"token",
".",
"getToken",
"(",
")",
".",
"equals",
"(",
"\"\\u200B\"",
")",
";",
"}"
] |
Removable white space are not linebreaks, tabs, functions or footnotes
|
[
"Removable",
"white",
"space",
"are",
"not",
"linebreaks",
"tabs",
"functions",
"or",
"footnotes"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/MultipleWhitespaceRule.java#L62-L65
|
19,167
|
languagetool-org/languagetool
|
languagetool-language-modules/pl/src/main/java/org/languagetool/rules/pl/DecadeSpellingFilter.java
|
DecadeSpellingFilter.getRomanNumber
|
private String getRomanNumber(int num) {
String roman = ""; // The roman numeral.
int N = num; // N represents the part of num that still has
// to be converted to Roman numeral representation.
for (int i = 0; i < numbers.length; i++) {
while (N >= numbers[i]) {
roman += letters[i];
N -= numbers[i];
}
}
return roman;
}
|
java
|
private String getRomanNumber(int num) {
String roman = ""; // The roman numeral.
int N = num; // N represents the part of num that still has
// to be converted to Roman numeral representation.
for (int i = 0; i < numbers.length; i++) {
while (N >= numbers[i]) {
roman += letters[i];
N -= numbers[i];
}
}
return roman;
}
|
[
"private",
"String",
"getRomanNumber",
"(",
"int",
"num",
")",
"{",
"String",
"roman",
"=",
"\"\"",
";",
"// The roman numeral.",
"int",
"N",
"=",
"num",
";",
"// N represents the part of num that still has",
"// to be converted to Roman numeral representation.",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"numbers",
".",
"length",
";",
"i",
"++",
")",
"{",
"while",
"(",
"N",
">=",
"numbers",
"[",
"i",
"]",
")",
"{",
"roman",
"+=",
"letters",
"[",
"i",
"]",
";",
"N",
"-=",
"numbers",
"[",
"i",
"]",
";",
"}",
"}",
"return",
"roman",
";",
"}"
] |
Gets the Roman notation for numbers.
@param num the integer to convert
@return the String using the number.
|
[
"Gets",
"the",
"Roman",
"notation",
"for",
"numbers",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-language-modules/pl/src/main/java/org/languagetool/rules/pl/DecadeSpellingFilter.java#L46-L57
|
19,168
|
languagetool-org/languagetool
|
languagetool-standalone/src/main/java/org/languagetool/gui/FontChooser.java
|
FontChooser.setSelectedFont
|
void setSelectedFont(Font font) {
this.selectedFont = font;
fontNameList.setSelectedValue(font.getFamily(), true);
fontStyleList.setSelectedValue(getStyle(font), true);
fontSizeList.setSelectedValue(font.getSize(), true);
}
|
java
|
void setSelectedFont(Font font) {
this.selectedFont = font;
fontNameList.setSelectedValue(font.getFamily(), true);
fontStyleList.setSelectedValue(getStyle(font), true);
fontSizeList.setSelectedValue(font.getSize(), true);
}
|
[
"void",
"setSelectedFont",
"(",
"Font",
"font",
")",
"{",
"this",
".",
"selectedFont",
"=",
"font",
";",
"fontNameList",
".",
"setSelectedValue",
"(",
"font",
".",
"getFamily",
"(",
")",
",",
"true",
")",
";",
"fontStyleList",
".",
"setSelectedValue",
"(",
"getStyle",
"(",
"font",
")",
",",
"true",
")",
";",
"fontSizeList",
".",
"setSelectedValue",
"(",
"font",
".",
"getSize",
"(",
")",
",",
"true",
")",
";",
"}"
] |
Sets the current font of the font chooser to the specified font.
@param font the font to be set in the font chooser
|
[
"Sets",
"the",
"current",
"font",
"of",
"the",
"font",
"chooser",
"to",
"the",
"specified",
"font",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-standalone/src/main/java/org/languagetool/gui/FontChooser.java#L113-L118
|
19,169
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/AbstractStyleRepeatedWordRule.java
|
AbstractStyleRepeatedWordRule.getSynonyms
|
public List<String> getSynonyms(AnalyzedTokenReadings token) {
List<String> synonyms = new ArrayList<String>();
if(linguServices == null || token == null) {
return synonyms;
}
List<AnalyzedToken> readings = token.getReadings();
for (AnalyzedToken reading : readings) {
String lemma = reading.getLemma();
if (lemma != null) {
List<String> rawSynonyms = linguServices.getSynonyms(lemma, lang);
for (String synonym : rawSynonyms) {
synonym = synonym.replaceAll("\\(.*\\)", "").trim();
if (!synonym.isEmpty() && !synonyms.contains(synonym)) {
synonyms.add(synonym);
}
}
}
}
if(synonyms.isEmpty()) {
List<String> rawSynonyms = linguServices.getSynonyms(token.getToken(), lang);
for (String synonym : rawSynonyms) {
synonym = synonym.replaceAll("\\(.*\\)", "").trim();
if (!synonym.isEmpty() && !synonyms.contains(synonym)) {
synonyms.add(synonym);
}
}
}
return synonyms;
}
|
java
|
public List<String> getSynonyms(AnalyzedTokenReadings token) {
List<String> synonyms = new ArrayList<String>();
if(linguServices == null || token == null) {
return synonyms;
}
List<AnalyzedToken> readings = token.getReadings();
for (AnalyzedToken reading : readings) {
String lemma = reading.getLemma();
if (lemma != null) {
List<String> rawSynonyms = linguServices.getSynonyms(lemma, lang);
for (String synonym : rawSynonyms) {
synonym = synonym.replaceAll("\\(.*\\)", "").trim();
if (!synonym.isEmpty() && !synonyms.contains(synonym)) {
synonyms.add(synonym);
}
}
}
}
if(synonyms.isEmpty()) {
List<String> rawSynonyms = linguServices.getSynonyms(token.getToken(), lang);
for (String synonym : rawSynonyms) {
synonym = synonym.replaceAll("\\(.*\\)", "").trim();
if (!synonym.isEmpty() && !synonyms.contains(synonym)) {
synonyms.add(synonym);
}
}
}
return synonyms;
}
|
[
"public",
"List",
"<",
"String",
">",
"getSynonyms",
"(",
"AnalyzedTokenReadings",
"token",
")",
"{",
"List",
"<",
"String",
">",
"synonyms",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
")",
";",
"if",
"(",
"linguServices",
"==",
"null",
"||",
"token",
"==",
"null",
")",
"{",
"return",
"synonyms",
";",
"}",
"List",
"<",
"AnalyzedToken",
">",
"readings",
"=",
"token",
".",
"getReadings",
"(",
")",
";",
"for",
"(",
"AnalyzedToken",
"reading",
":",
"readings",
")",
"{",
"String",
"lemma",
"=",
"reading",
".",
"getLemma",
"(",
")",
";",
"if",
"(",
"lemma",
"!=",
"null",
")",
"{",
"List",
"<",
"String",
">",
"rawSynonyms",
"=",
"linguServices",
".",
"getSynonyms",
"(",
"lemma",
",",
"lang",
")",
";",
"for",
"(",
"String",
"synonym",
":",
"rawSynonyms",
")",
"{",
"synonym",
"=",
"synonym",
".",
"replaceAll",
"(",
"\"\\\\(.*\\\\)\"",
",",
"\"\"",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"!",
"synonym",
".",
"isEmpty",
"(",
")",
"&&",
"!",
"synonyms",
".",
"contains",
"(",
"synonym",
")",
")",
"{",
"synonyms",
".",
"add",
"(",
"synonym",
")",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"synonyms",
".",
"isEmpty",
"(",
")",
")",
"{",
"List",
"<",
"String",
">",
"rawSynonyms",
"=",
"linguServices",
".",
"getSynonyms",
"(",
"token",
".",
"getToken",
"(",
")",
",",
"lang",
")",
";",
"for",
"(",
"String",
"synonym",
":",
"rawSynonyms",
")",
"{",
"synonym",
"=",
"synonym",
".",
"replaceAll",
"(",
"\"\\\\(.*\\\\)\"",
",",
"\"\"",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"!",
"synonym",
".",
"isEmpty",
"(",
")",
"&&",
"!",
"synonyms",
".",
"contains",
"(",
"synonym",
")",
")",
"{",
"synonyms",
".",
"add",
"(",
"synonym",
")",
";",
"}",
"}",
"}",
"return",
"synonyms",
";",
"}"
] |
get synonyms for a repeated word
|
[
"get",
"synonyms",
"for",
"a",
"repeated",
"word"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/AbstractStyleRepeatedWordRule.java#L188-L216
|
19,170
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/synthesis/BaseSynthesizer.java
|
BaseSynthesizer.lookup
|
protected void lookup(String lemma, String posTag, List<String> results) {
synchronized (this) { // the stemmer is not thread-safe
List<WordData> wordForms = stemmer.lookup(lemma + "|" + posTag);
for (WordData wd : wordForms) {
results.add(wd.getStem().toString());
}
}
}
|
java
|
protected void lookup(String lemma, String posTag, List<String> results) {
synchronized (this) { // the stemmer is not thread-safe
List<WordData> wordForms = stemmer.lookup(lemma + "|" + posTag);
for (WordData wd : wordForms) {
results.add(wd.getStem().toString());
}
}
}
|
[
"protected",
"void",
"lookup",
"(",
"String",
"lemma",
",",
"String",
"posTag",
",",
"List",
"<",
"String",
">",
"results",
")",
"{",
"synchronized",
"(",
"this",
")",
"{",
"// the stemmer is not thread-safe",
"List",
"<",
"WordData",
">",
"wordForms",
"=",
"stemmer",
".",
"lookup",
"(",
"lemma",
"+",
"\"|\"",
"+",
"posTag",
")",
";",
"for",
"(",
"WordData",
"wd",
":",
"wordForms",
")",
"{",
"results",
".",
"add",
"(",
"wd",
".",
"getStem",
"(",
")",
".",
"toString",
"(",
")",
")",
";",
"}",
"}",
"}"
] |
Lookup the inflected forms of a lemma defined by a part-of-speech tag.
@param lemma the lemma to be inflected.
@param posTag the desired part-of-speech tag.
@param results the list to collect the inflected forms.
|
[
"Lookup",
"the",
"inflected",
"forms",
"of",
"a",
"lemma",
"defined",
"by",
"a",
"part",
"-",
"of",
"-",
"speech",
"tag",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/synthesis/BaseSynthesizer.java#L95-L102
|
19,171
|
languagetool-org/languagetool
|
languagetool-gui-commons/src/main/java/org/languagetool/gui/Configuration.java
|
Configuration.copy
|
Configuration copy(Configuration configuration) {
Configuration copy = new Configuration();
copy.restoreState(configuration);
return copy;
}
|
java
|
Configuration copy(Configuration configuration) {
Configuration copy = new Configuration();
copy.restoreState(configuration);
return copy;
}
|
[
"Configuration",
"copy",
"(",
"Configuration",
"configuration",
")",
"{",
"Configuration",
"copy",
"=",
"new",
"Configuration",
"(",
")",
";",
"copy",
".",
"restoreState",
"(",
"configuration",
")",
";",
"return",
"copy",
";",
"}"
] |
Returns a copy of the given configuration.
@param configuration the object to copy.
@since 2.6
|
[
"Returns",
"a",
"copy",
"of",
"the",
"given",
"configuration",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-gui-commons/src/main/java/org/languagetool/gui/Configuration.java#L169-L173
|
19,172
|
languagetool-org/languagetool
|
languagetool-gui-commons/src/main/java/org/languagetool/gui/Configuration.java
|
Configuration.restoreState
|
void restoreState(Configuration configuration) {
this.configFile = configuration.configFile;
this.language = configuration.language;
this.motherTongue = configuration.motherTongue;
this.ngramDirectory = configuration.ngramDirectory;
this.word2vecDirectory = configuration.word2vecDirectory;
this.runServer = configuration.runServer;
this.autoDetect = configuration.autoDetect;
this.taggerShowsDisambigLog = configuration.taggerShowsDisambigLog;
this.guiConfig = configuration.guiConfig;
this.fontName = configuration.fontName;
this.fontStyle = configuration.fontStyle;
this.fontSize = configuration.fontSize;
this.serverPort = configuration.serverPort;
this.numParasToCheck = configuration.numParasToCheck;
this.doResetCheck = configuration.doResetCheck;
this.noMultiReset = configuration.noMultiReset;
this.useDocLanguage = configuration.useDocLanguage;
this.lookAndFeelName = configuration.lookAndFeelName;
this.externalRuleDirectory = configuration.externalRuleDirectory;
this.disabledRuleIds.clear();
this.disabledRuleIds.addAll(configuration.disabledRuleIds);
this.enabledRuleIds.clear();
this.enabledRuleIds.addAll(configuration.enabledRuleIds);
this.disabledCategoryNames.clear();
this.disabledCategoryNames.addAll(configuration.disabledCategoryNames);
this.enabledCategoryNames.clear();
this.enabledCategoryNames.addAll(configuration.enabledCategoryNames);
this.configForOtherLanguages.clear();
for (String key : configuration.configForOtherLanguages.keySet()) {
this.configForOtherLanguages.put(key, configuration.configForOtherLanguages.get(key));
}
this.underlineColors.clear();
for (Map.Entry<String, Color> entry : configuration.underlineColors.entrySet()) {
this.underlineColors.put(entry.getKey(), entry.getValue());
}
this.configurableRuleValues.clear();
for (Map.Entry<String, Integer> entry : configuration.configurableRuleValues.entrySet()) {
this.configurableRuleValues.put(entry.getKey(), entry.getValue());
}
this.styleLikeCategories.clear();
this.styleLikeCategories.addAll(configuration.styleLikeCategories);
this.specialTabCategories.clear();
for (Map.Entry<String, String> entry : configuration.specialTabCategories.entrySet()) {
this.specialTabCategories.put(entry.getKey(), entry.getValue());
}
}
|
java
|
void restoreState(Configuration configuration) {
this.configFile = configuration.configFile;
this.language = configuration.language;
this.motherTongue = configuration.motherTongue;
this.ngramDirectory = configuration.ngramDirectory;
this.word2vecDirectory = configuration.word2vecDirectory;
this.runServer = configuration.runServer;
this.autoDetect = configuration.autoDetect;
this.taggerShowsDisambigLog = configuration.taggerShowsDisambigLog;
this.guiConfig = configuration.guiConfig;
this.fontName = configuration.fontName;
this.fontStyle = configuration.fontStyle;
this.fontSize = configuration.fontSize;
this.serverPort = configuration.serverPort;
this.numParasToCheck = configuration.numParasToCheck;
this.doResetCheck = configuration.doResetCheck;
this.noMultiReset = configuration.noMultiReset;
this.useDocLanguage = configuration.useDocLanguage;
this.lookAndFeelName = configuration.lookAndFeelName;
this.externalRuleDirectory = configuration.externalRuleDirectory;
this.disabledRuleIds.clear();
this.disabledRuleIds.addAll(configuration.disabledRuleIds);
this.enabledRuleIds.clear();
this.enabledRuleIds.addAll(configuration.enabledRuleIds);
this.disabledCategoryNames.clear();
this.disabledCategoryNames.addAll(configuration.disabledCategoryNames);
this.enabledCategoryNames.clear();
this.enabledCategoryNames.addAll(configuration.enabledCategoryNames);
this.configForOtherLanguages.clear();
for (String key : configuration.configForOtherLanguages.keySet()) {
this.configForOtherLanguages.put(key, configuration.configForOtherLanguages.get(key));
}
this.underlineColors.clear();
for (Map.Entry<String, Color> entry : configuration.underlineColors.entrySet()) {
this.underlineColors.put(entry.getKey(), entry.getValue());
}
this.configurableRuleValues.clear();
for (Map.Entry<String, Integer> entry : configuration.configurableRuleValues.entrySet()) {
this.configurableRuleValues.put(entry.getKey(), entry.getValue());
}
this.styleLikeCategories.clear();
this.styleLikeCategories.addAll(configuration.styleLikeCategories);
this.specialTabCategories.clear();
for (Map.Entry<String, String> entry : configuration.specialTabCategories.entrySet()) {
this.specialTabCategories.put(entry.getKey(), entry.getValue());
}
}
|
[
"void",
"restoreState",
"(",
"Configuration",
"configuration",
")",
"{",
"this",
".",
"configFile",
"=",
"configuration",
".",
"configFile",
";",
"this",
".",
"language",
"=",
"configuration",
".",
"language",
";",
"this",
".",
"motherTongue",
"=",
"configuration",
".",
"motherTongue",
";",
"this",
".",
"ngramDirectory",
"=",
"configuration",
".",
"ngramDirectory",
";",
"this",
".",
"word2vecDirectory",
"=",
"configuration",
".",
"word2vecDirectory",
";",
"this",
".",
"runServer",
"=",
"configuration",
".",
"runServer",
";",
"this",
".",
"autoDetect",
"=",
"configuration",
".",
"autoDetect",
";",
"this",
".",
"taggerShowsDisambigLog",
"=",
"configuration",
".",
"taggerShowsDisambigLog",
";",
"this",
".",
"guiConfig",
"=",
"configuration",
".",
"guiConfig",
";",
"this",
".",
"fontName",
"=",
"configuration",
".",
"fontName",
";",
"this",
".",
"fontStyle",
"=",
"configuration",
".",
"fontStyle",
";",
"this",
".",
"fontSize",
"=",
"configuration",
".",
"fontSize",
";",
"this",
".",
"serverPort",
"=",
"configuration",
".",
"serverPort",
";",
"this",
".",
"numParasToCheck",
"=",
"configuration",
".",
"numParasToCheck",
";",
"this",
".",
"doResetCheck",
"=",
"configuration",
".",
"doResetCheck",
";",
"this",
".",
"noMultiReset",
"=",
"configuration",
".",
"noMultiReset",
";",
"this",
".",
"useDocLanguage",
"=",
"configuration",
".",
"useDocLanguage",
";",
"this",
".",
"lookAndFeelName",
"=",
"configuration",
".",
"lookAndFeelName",
";",
"this",
".",
"externalRuleDirectory",
"=",
"configuration",
".",
"externalRuleDirectory",
";",
"this",
".",
"disabledRuleIds",
".",
"clear",
"(",
")",
";",
"this",
".",
"disabledRuleIds",
".",
"addAll",
"(",
"configuration",
".",
"disabledRuleIds",
")",
";",
"this",
".",
"enabledRuleIds",
".",
"clear",
"(",
")",
";",
"this",
".",
"enabledRuleIds",
".",
"addAll",
"(",
"configuration",
".",
"enabledRuleIds",
")",
";",
"this",
".",
"disabledCategoryNames",
".",
"clear",
"(",
")",
";",
"this",
".",
"disabledCategoryNames",
".",
"addAll",
"(",
"configuration",
".",
"disabledCategoryNames",
")",
";",
"this",
".",
"enabledCategoryNames",
".",
"clear",
"(",
")",
";",
"this",
".",
"enabledCategoryNames",
".",
"addAll",
"(",
"configuration",
".",
"enabledCategoryNames",
")",
";",
"this",
".",
"configForOtherLanguages",
".",
"clear",
"(",
")",
";",
"for",
"(",
"String",
"key",
":",
"configuration",
".",
"configForOtherLanguages",
".",
"keySet",
"(",
")",
")",
"{",
"this",
".",
"configForOtherLanguages",
".",
"put",
"(",
"key",
",",
"configuration",
".",
"configForOtherLanguages",
".",
"get",
"(",
"key",
")",
")",
";",
"}",
"this",
".",
"underlineColors",
".",
"clear",
"(",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"Color",
">",
"entry",
":",
"configuration",
".",
"underlineColors",
".",
"entrySet",
"(",
")",
")",
"{",
"this",
".",
"underlineColors",
".",
"put",
"(",
"entry",
".",
"getKey",
"(",
")",
",",
"entry",
".",
"getValue",
"(",
")",
")",
";",
"}",
"this",
".",
"configurableRuleValues",
".",
"clear",
"(",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"Integer",
">",
"entry",
":",
"configuration",
".",
"configurableRuleValues",
".",
"entrySet",
"(",
")",
")",
"{",
"this",
".",
"configurableRuleValues",
".",
"put",
"(",
"entry",
".",
"getKey",
"(",
")",
",",
"entry",
".",
"getValue",
"(",
")",
")",
";",
"}",
"this",
".",
"styleLikeCategories",
".",
"clear",
"(",
")",
";",
"this",
".",
"styleLikeCategories",
".",
"addAll",
"(",
"configuration",
".",
"styleLikeCategories",
")",
";",
"this",
".",
"specialTabCategories",
".",
"clear",
"(",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"String",
">",
"entry",
":",
"configuration",
".",
"specialTabCategories",
".",
"entrySet",
"(",
")",
")",
"{",
"this",
".",
"specialTabCategories",
".",
"put",
"(",
"entry",
".",
"getKey",
"(",
")",
",",
"entry",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}"
] |
Restore the state of this object from configuration.
@param configuration the object from which we will read the state
@since 2.6
|
[
"Restore",
"the",
"state",
"of",
"this",
"object",
"from",
"configuration",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-gui-commons/src/main/java/org/languagetool/gui/Configuration.java#L180-L226
|
19,173
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java
|
AnalyzedTokenReadings.hasPosTag
|
public boolean hasPosTag(String posTag) {
boolean found = false;
for (AnalyzedToken reading : anTokReadings) {
if (reading.getPOSTag() != null) {
found = posTag.equals(reading.getPOSTag());
if (found) {
break;
}
}
}
return found;
}
|
java
|
public boolean hasPosTag(String posTag) {
boolean found = false;
for (AnalyzedToken reading : anTokReadings) {
if (reading.getPOSTag() != null) {
found = posTag.equals(reading.getPOSTag());
if (found) {
break;
}
}
}
return found;
}
|
[
"public",
"boolean",
"hasPosTag",
"(",
"String",
"posTag",
")",
"{",
"boolean",
"found",
"=",
"false",
";",
"for",
"(",
"AnalyzedToken",
"reading",
":",
"anTokReadings",
")",
"{",
"if",
"(",
"reading",
".",
"getPOSTag",
"(",
")",
"!=",
"null",
")",
"{",
"found",
"=",
"posTag",
".",
"equals",
"(",
"reading",
".",
"getPOSTag",
"(",
")",
")",
";",
"if",
"(",
"found",
")",
"{",
"break",
";",
"}",
"}",
"}",
"return",
"found",
";",
"}"
] |
Checks if the token has a particular POS tag.
@param posTag POS tag to look for
|
[
"Checks",
"if",
"the",
"token",
"has",
"a",
"particular",
"POS",
"tag",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java#L116-L127
|
19,174
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java
|
AnalyzedTokenReadings.hasLemma
|
public boolean hasLemma(String lemma) {
boolean found = false;
for (AnalyzedToken reading : anTokReadings) {
if (reading.getLemma() != null) {
found = lemma.equals(reading.getLemma());
if (found) {
break;
}
}
}
return found;
}
|
java
|
public boolean hasLemma(String lemma) {
boolean found = false;
for (AnalyzedToken reading : anTokReadings) {
if (reading.getLemma() != null) {
found = lemma.equals(reading.getLemma());
if (found) {
break;
}
}
}
return found;
}
|
[
"public",
"boolean",
"hasLemma",
"(",
"String",
"lemma",
")",
"{",
"boolean",
"found",
"=",
"false",
";",
"for",
"(",
"AnalyzedToken",
"reading",
":",
"anTokReadings",
")",
"{",
"if",
"(",
"reading",
".",
"getLemma",
"(",
")",
"!=",
"null",
")",
"{",
"found",
"=",
"lemma",
".",
"equals",
"(",
"reading",
".",
"getLemma",
"(",
")",
")",
";",
"if",
"(",
"found",
")",
"{",
"break",
";",
"}",
"}",
"}",
"return",
"found",
";",
"}"
] |
Checks if one of the token's readings has a particular lemma.
@param lemma lemma POS tag to look for
|
[
"Checks",
"if",
"one",
"of",
"the",
"token",
"s",
"readings",
"has",
"a",
"particular",
"lemma",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java#L134-L145
|
19,175
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java
|
AnalyzedTokenReadings.hasAnyLemma
|
public boolean hasAnyLemma(String... lemmas) {
boolean found = false;
for(String lemma : lemmas) {
for (AnalyzedToken reading : anTokReadings) {
if (reading.getLemma() != null) {
found = lemma.equals(reading.getLemma());
if (found) {
return found;
}
}
}
}
return found;
}
|
java
|
public boolean hasAnyLemma(String... lemmas) {
boolean found = false;
for(String lemma : lemmas) {
for (AnalyzedToken reading : anTokReadings) {
if (reading.getLemma() != null) {
found = lemma.equals(reading.getLemma());
if (found) {
return found;
}
}
}
}
return found;
}
|
[
"public",
"boolean",
"hasAnyLemma",
"(",
"String",
"...",
"lemmas",
")",
"{",
"boolean",
"found",
"=",
"false",
";",
"for",
"(",
"String",
"lemma",
":",
"lemmas",
")",
"{",
"for",
"(",
"AnalyzedToken",
"reading",
":",
"anTokReadings",
")",
"{",
"if",
"(",
"reading",
".",
"getLemma",
"(",
")",
"!=",
"null",
")",
"{",
"found",
"=",
"lemma",
".",
"equals",
"(",
"reading",
".",
"getLemma",
"(",
")",
")",
";",
"if",
"(",
"found",
")",
"{",
"return",
"found",
";",
"}",
"}",
"}",
"}",
"return",
"found",
";",
"}"
] |
Checks if one of the token's readings has one of the given lemmas
@param lemmas to look for
|
[
"Checks",
"if",
"one",
"of",
"the",
"token",
"s",
"readings",
"has",
"one",
"of",
"the",
"given",
"lemmas"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java#L152-L165
|
19,176
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java
|
AnalyzedTokenReadings.hasPartialPosTag
|
public boolean hasPartialPosTag(String posTag) {
boolean found = false;
for (AnalyzedToken reading : anTokReadings) {
if (reading.getPOSTag() != null) {
found = reading.getPOSTag().contains(posTag);
if (found) {
break;
}
}
}
return found;
}
|
java
|
public boolean hasPartialPosTag(String posTag) {
boolean found = false;
for (AnalyzedToken reading : anTokReadings) {
if (reading.getPOSTag() != null) {
found = reading.getPOSTag().contains(posTag);
if (found) {
break;
}
}
}
return found;
}
|
[
"public",
"boolean",
"hasPartialPosTag",
"(",
"String",
"posTag",
")",
"{",
"boolean",
"found",
"=",
"false",
";",
"for",
"(",
"AnalyzedToken",
"reading",
":",
"anTokReadings",
")",
"{",
"if",
"(",
"reading",
".",
"getPOSTag",
"(",
")",
"!=",
"null",
")",
"{",
"found",
"=",
"reading",
".",
"getPOSTag",
"(",
")",
".",
"contains",
"(",
"posTag",
")",
";",
"if",
"(",
"found",
")",
"{",
"break",
";",
"}",
"}",
"}",
"return",
"found",
";",
"}"
] |
Checks if the token has a particular POS tag, where only a part of the given POS tag needs to match.
@param posTag POS tag substring to look for
@since 1.8
|
[
"Checks",
"if",
"the",
"token",
"has",
"a",
"particular",
"POS",
"tag",
"where",
"only",
"a",
"part",
"of",
"the",
"given",
"POS",
"tag",
"needs",
"to",
"match",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java#L173-L184
|
19,177
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java
|
AnalyzedTokenReadings.hasPosTagStartingWith
|
public boolean hasPosTagStartingWith(String posTag) {
boolean found = false;
for (AnalyzedToken reading : anTokReadings) {
if (reading.getPOSTag() != null) {
found = reading.getPOSTag().startsWith(posTag);
if (found) {
break;
}
}
}
return found;
}
|
java
|
public boolean hasPosTagStartingWith(String posTag) {
boolean found = false;
for (AnalyzedToken reading : anTokReadings) {
if (reading.getPOSTag() != null) {
found = reading.getPOSTag().startsWith(posTag);
if (found) {
break;
}
}
}
return found;
}
|
[
"public",
"boolean",
"hasPosTagStartingWith",
"(",
"String",
"posTag",
")",
"{",
"boolean",
"found",
"=",
"false",
";",
"for",
"(",
"AnalyzedToken",
"reading",
":",
"anTokReadings",
")",
"{",
"if",
"(",
"reading",
".",
"getPOSTag",
"(",
")",
"!=",
"null",
")",
"{",
"found",
"=",
"reading",
".",
"getPOSTag",
"(",
")",
".",
"startsWith",
"(",
"posTag",
")",
";",
"if",
"(",
"found",
")",
"{",
"break",
";",
"}",
"}",
"}",
"return",
"found",
";",
"}"
] |
Checks if the token has a POS tag starting with the given string.
@param posTag POS tag substring to look for
@since 4.0
|
[
"Checks",
"if",
"the",
"token",
"has",
"a",
"POS",
"tag",
"starting",
"with",
"the",
"given",
"string",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java#L207-L218
|
19,178
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java
|
AnalyzedTokenReadings.matchesPosTagRegex
|
public boolean matchesPosTagRegex(String posTagRegex) {
Pattern pattern = Pattern.compile(posTagRegex);
boolean found = false;
for (AnalyzedToken reading : anTokReadings) {
if (reading.getPOSTag() != null) {
found = pattern.matcher(reading.getPOSTag()).matches();
if (found) {
break;
}
}
}
return found;
}
|
java
|
public boolean matchesPosTagRegex(String posTagRegex) {
Pattern pattern = Pattern.compile(posTagRegex);
boolean found = false;
for (AnalyzedToken reading : anTokReadings) {
if (reading.getPOSTag() != null) {
found = pattern.matcher(reading.getPOSTag()).matches();
if (found) {
break;
}
}
}
return found;
}
|
[
"public",
"boolean",
"matchesPosTagRegex",
"(",
"String",
"posTagRegex",
")",
"{",
"Pattern",
"pattern",
"=",
"Pattern",
".",
"compile",
"(",
"posTagRegex",
")",
";",
"boolean",
"found",
"=",
"false",
";",
"for",
"(",
"AnalyzedToken",
"reading",
":",
"anTokReadings",
")",
"{",
"if",
"(",
"reading",
".",
"getPOSTag",
"(",
")",
"!=",
"null",
")",
"{",
"found",
"=",
"pattern",
".",
"matcher",
"(",
"reading",
".",
"getPOSTag",
"(",
")",
")",
".",
"matches",
"(",
")",
";",
"if",
"(",
"found",
")",
"{",
"break",
";",
"}",
"}",
"}",
"return",
"found",
";",
"}"
] |
Checks if at least one of the readings matches a given POS tag regex.
@param posTagRegex POS tag regular expression to look for
@since 2.9
|
[
"Checks",
"if",
"at",
"least",
"one",
"of",
"the",
"readings",
"matches",
"a",
"given",
"POS",
"tag",
"regex",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java#L226-L238
|
19,179
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java
|
AnalyzedTokenReadings.addReading
|
public void addReading(AnalyzedToken token) {
List<AnalyzedToken> l = new ArrayList<>(Arrays.asList(anTokReadings).subList(0, anTokReadings.length - 1));
if (anTokReadings[anTokReadings.length - 1].getPOSTag() != null) {
l.add(anTokReadings[anTokReadings.length - 1]);
}
token.setWhitespaceBefore(isWhitespaceBefore);
l.add(token);
anTokReadings = l.toArray(new AnalyzedToken[0]);
if (token.getToken().length() > this.token.length()) { //in case a longer token is added
this.token = token.getToken();
}
anTokReadings[anTokReadings.length - 1].setWhitespaceBefore(isWhitespaceBefore);
isParaEnd = hasPosTag(PARAGRAPH_END_TAGNAME);
isSentEnd = hasPosTag(SENTENCE_END_TAGNAME);
setNoRealPOStag();
hasSameLemmas = areLemmasSame();
}
|
java
|
public void addReading(AnalyzedToken token) {
List<AnalyzedToken> l = new ArrayList<>(Arrays.asList(anTokReadings).subList(0, anTokReadings.length - 1));
if (anTokReadings[anTokReadings.length - 1].getPOSTag() != null) {
l.add(anTokReadings[anTokReadings.length - 1]);
}
token.setWhitespaceBefore(isWhitespaceBefore);
l.add(token);
anTokReadings = l.toArray(new AnalyzedToken[0]);
if (token.getToken().length() > this.token.length()) { //in case a longer token is added
this.token = token.getToken();
}
anTokReadings[anTokReadings.length - 1].setWhitespaceBefore(isWhitespaceBefore);
isParaEnd = hasPosTag(PARAGRAPH_END_TAGNAME);
isSentEnd = hasPosTag(SENTENCE_END_TAGNAME);
setNoRealPOStag();
hasSameLemmas = areLemmasSame();
}
|
[
"public",
"void",
"addReading",
"(",
"AnalyzedToken",
"token",
")",
"{",
"List",
"<",
"AnalyzedToken",
">",
"l",
"=",
"new",
"ArrayList",
"<>",
"(",
"Arrays",
".",
"asList",
"(",
"anTokReadings",
")",
".",
"subList",
"(",
"0",
",",
"anTokReadings",
".",
"length",
"-",
"1",
")",
")",
";",
"if",
"(",
"anTokReadings",
"[",
"anTokReadings",
".",
"length",
"-",
"1",
"]",
".",
"getPOSTag",
"(",
")",
"!=",
"null",
")",
"{",
"l",
".",
"add",
"(",
"anTokReadings",
"[",
"anTokReadings",
".",
"length",
"-",
"1",
"]",
")",
";",
"}",
"token",
".",
"setWhitespaceBefore",
"(",
"isWhitespaceBefore",
")",
";",
"l",
".",
"add",
"(",
"token",
")",
";",
"anTokReadings",
"=",
"l",
".",
"toArray",
"(",
"new",
"AnalyzedToken",
"[",
"0",
"]",
")",
";",
"if",
"(",
"token",
".",
"getToken",
"(",
")",
".",
"length",
"(",
")",
">",
"this",
".",
"token",
".",
"length",
"(",
")",
")",
"{",
"//in case a longer token is added",
"this",
".",
"token",
"=",
"token",
".",
"getToken",
"(",
")",
";",
"}",
"anTokReadings",
"[",
"anTokReadings",
".",
"length",
"-",
"1",
"]",
".",
"setWhitespaceBefore",
"(",
"isWhitespaceBefore",
")",
";",
"isParaEnd",
"=",
"hasPosTag",
"(",
"PARAGRAPH_END_TAGNAME",
")",
";",
"isSentEnd",
"=",
"hasPosTag",
"(",
"SENTENCE_END_TAGNAME",
")",
";",
"setNoRealPOStag",
"(",
")",
";",
"hasSameLemmas",
"=",
"areLemmasSame",
"(",
")",
";",
"}"
] |
Add a new reading.
@param token new reading, given as {@link AnalyzedToken}
|
[
"Add",
"a",
"new",
"reading",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java#L244-L260
|
19,180
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java
|
AnalyzedTokenReadings.leaveReading
|
public void leaveReading(AnalyzedToken token) {
List<AnalyzedToken> l = new ArrayList<>();
AnalyzedToken tmpTok = new AnalyzedToken(token.getToken(), token.getPOSTag(), token.getLemma());
tmpTok.setWhitespaceBefore(isWhitespaceBefore);
for (AnalyzedToken anTokReading : anTokReadings) {
if (anTokReading.matches(tmpTok)) {
l.add(anTokReading);
}
}
if (l.isEmpty()) {
l.add(new AnalyzedToken(this.token, null, null));
l.get(0).setWhitespaceBefore(isWhitespaceBefore);
}
anTokReadings = l.toArray(new AnalyzedToken[0]);
setNoRealPOStag();
hasSameLemmas = areLemmasSame();
}
|
java
|
public void leaveReading(AnalyzedToken token) {
List<AnalyzedToken> l = new ArrayList<>();
AnalyzedToken tmpTok = new AnalyzedToken(token.getToken(), token.getPOSTag(), token.getLemma());
tmpTok.setWhitespaceBefore(isWhitespaceBefore);
for (AnalyzedToken anTokReading : anTokReadings) {
if (anTokReading.matches(tmpTok)) {
l.add(anTokReading);
}
}
if (l.isEmpty()) {
l.add(new AnalyzedToken(this.token, null, null));
l.get(0).setWhitespaceBefore(isWhitespaceBefore);
}
anTokReadings = l.toArray(new AnalyzedToken[0]);
setNoRealPOStag();
hasSameLemmas = areLemmasSame();
}
|
[
"public",
"void",
"leaveReading",
"(",
"AnalyzedToken",
"token",
")",
"{",
"List",
"<",
"AnalyzedToken",
">",
"l",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"AnalyzedToken",
"tmpTok",
"=",
"new",
"AnalyzedToken",
"(",
"token",
".",
"getToken",
"(",
")",
",",
"token",
".",
"getPOSTag",
"(",
")",
",",
"token",
".",
"getLemma",
"(",
")",
")",
";",
"tmpTok",
".",
"setWhitespaceBefore",
"(",
"isWhitespaceBefore",
")",
";",
"for",
"(",
"AnalyzedToken",
"anTokReading",
":",
"anTokReadings",
")",
"{",
"if",
"(",
"anTokReading",
".",
"matches",
"(",
"tmpTok",
")",
")",
"{",
"l",
".",
"add",
"(",
"anTokReading",
")",
";",
"}",
"}",
"if",
"(",
"l",
".",
"isEmpty",
"(",
")",
")",
"{",
"l",
".",
"add",
"(",
"new",
"AnalyzedToken",
"(",
"this",
".",
"token",
",",
"null",
",",
"null",
")",
")",
";",
"l",
".",
"get",
"(",
"0",
")",
".",
"setWhitespaceBefore",
"(",
"isWhitespaceBefore",
")",
";",
"}",
"anTokReadings",
"=",
"l",
".",
"toArray",
"(",
"new",
"AnalyzedToken",
"[",
"0",
"]",
")",
";",
"setNoRealPOStag",
"(",
")",
";",
"hasSameLemmas",
"=",
"areLemmasSame",
"(",
")",
";",
"}"
] |
Removes all readings but the one that matches the token given.
@param token Token to be matched
@since 1.5
|
[
"Removes",
"all",
"readings",
"but",
"the",
"one",
"that",
"matches",
"the",
"token",
"given",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java#L305-L321
|
19,181
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java
|
AnalyzedTokenReadings.setParagraphEnd
|
public void setParagraphEnd() {
if (!isParagraphEnd()) {
AnalyzedToken paragraphEnd = new AnalyzedToken(getToken(),
PARAGRAPH_END_TAGNAME, getAnalyzedToken(0).getLemma());
addReading(paragraphEnd);
}
}
|
java
|
public void setParagraphEnd() {
if (!isParagraphEnd()) {
AnalyzedToken paragraphEnd = new AnalyzedToken(getToken(),
PARAGRAPH_END_TAGNAME, getAnalyzedToken(0).getLemma());
addReading(paragraphEnd);
}
}
|
[
"public",
"void",
"setParagraphEnd",
"(",
")",
"{",
"if",
"(",
"!",
"isParagraphEnd",
"(",
")",
")",
"{",
"AnalyzedToken",
"paragraphEnd",
"=",
"new",
"AnalyzedToken",
"(",
"getToken",
"(",
")",
",",
"PARAGRAPH_END_TAGNAME",
",",
"getAnalyzedToken",
"(",
"0",
")",
".",
"getLemma",
"(",
")",
")",
";",
"addReading",
"(",
"paragraphEnd",
")",
";",
"}",
"}"
] |
Add a reading with a paragraph end token unless this is already a paragraph end.
@since 2.3
|
[
"Add",
"a",
"reading",
"with",
"a",
"paragraph",
"end",
"token",
"unless",
"this",
"is",
"already",
"a",
"paragraph",
"end",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java#L360-L366
|
19,182
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java
|
AnalyzedTokenReadings.setSentEnd
|
public void setSentEnd() {
if (!isSentenceEnd()) {
AnalyzedToken sentenceEnd = new AnalyzedToken(getToken(),
SENTENCE_END_TAGNAME, getAnalyzedToken(0).getLemma());
addReading(sentenceEnd);
}
}
|
java
|
public void setSentEnd() {
if (!isSentenceEnd()) {
AnalyzedToken sentenceEnd = new AnalyzedToken(getToken(),
SENTENCE_END_TAGNAME, getAnalyzedToken(0).getLemma());
addReading(sentenceEnd);
}
}
|
[
"public",
"void",
"setSentEnd",
"(",
")",
"{",
"if",
"(",
"!",
"isSentenceEnd",
"(",
")",
")",
"{",
"AnalyzedToken",
"sentenceEnd",
"=",
"new",
"AnalyzedToken",
"(",
"getToken",
"(",
")",
",",
"SENTENCE_END_TAGNAME",
",",
"getAnalyzedToken",
"(",
"0",
")",
".",
"getLemma",
"(",
")",
")",
";",
"addReading",
"(",
"sentenceEnd",
")",
";",
"}",
"}"
] |
Add a SENT_END tag.
|
[
"Add",
"a",
"SENT_END",
"tag",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java#L387-L393
|
19,183
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java
|
AnalyzedTokenReadings.areLemmasSame
|
private boolean areLemmasSame() {
String previousLemma = anTokReadings[0].getLemma();
if (previousLemma == null) {
for (AnalyzedToken element : anTokReadings) {
if (element.getLemma() != null) {
return false;
}
}
return true;
}
for (AnalyzedToken element : anTokReadings) {
if (!previousLemma.equals(element.getLemma())) {
return false;
}
}
return true;
}
|
java
|
private boolean areLemmasSame() {
String previousLemma = anTokReadings[0].getLemma();
if (previousLemma == null) {
for (AnalyzedToken element : anTokReadings) {
if (element.getLemma() != null) {
return false;
}
}
return true;
}
for (AnalyzedToken element : anTokReadings) {
if (!previousLemma.equals(element.getLemma())) {
return false;
}
}
return true;
}
|
[
"private",
"boolean",
"areLemmasSame",
"(",
")",
"{",
"String",
"previousLemma",
"=",
"anTokReadings",
"[",
"0",
"]",
".",
"getLemma",
"(",
")",
";",
"if",
"(",
"previousLemma",
"==",
"null",
")",
"{",
"for",
"(",
"AnalyzedToken",
"element",
":",
"anTokReadings",
")",
"{",
"if",
"(",
"element",
".",
"getLemma",
"(",
")",
"!=",
"null",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"for",
"(",
"AnalyzedToken",
"element",
":",
"anTokReadings",
")",
"{",
"if",
"(",
"!",
"previousLemma",
".",
"equals",
"(",
"element",
".",
"getLemma",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Used to configure the internal variable for lemma equality.
@return true if all {@link AnalyzedToken} lemmas are the same.
@since 2.5
|
[
"Used",
"to",
"configure",
"the",
"internal",
"variable",
"for",
"lemma",
"equality",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/AnalyzedTokenReadings.java#L550-L566
|
19,184
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/AbstractUnitConversionRule.java
|
AbstractUnitConversionRule.addUnit
|
protected void addUnit(String pattern, Unit base, String symbol, double factor, boolean metric) {
Unit unit = base.multiply(factor);
unitPatterns.put(Pattern.compile("\\b" + NUMBER_REGEX + "\\s{0," + WHITESPACE_LIMIT + "}" + pattern + "\\b"), unit);
unitSymbols.putIfAbsent(unit, new ArrayList<>());
unitSymbols.get(unit).add(symbol);
if (metric && !metricUnits.contains(unit)) {
metricUnits.add(unit);
}
}
|
java
|
protected void addUnit(String pattern, Unit base, String symbol, double factor, boolean metric) {
Unit unit = base.multiply(factor);
unitPatterns.put(Pattern.compile("\\b" + NUMBER_REGEX + "\\s{0," + WHITESPACE_LIMIT + "}" + pattern + "\\b"), unit);
unitSymbols.putIfAbsent(unit, new ArrayList<>());
unitSymbols.get(unit).add(symbol);
if (metric && !metricUnits.contains(unit)) {
metricUnits.add(unit);
}
}
|
[
"protected",
"void",
"addUnit",
"(",
"String",
"pattern",
",",
"Unit",
"base",
",",
"String",
"symbol",
",",
"double",
"factor",
",",
"boolean",
"metric",
")",
"{",
"Unit",
"unit",
"=",
"base",
".",
"multiply",
"(",
"factor",
")",
";",
"unitPatterns",
".",
"put",
"(",
"Pattern",
".",
"compile",
"(",
"\"\\\\b\"",
"+",
"NUMBER_REGEX",
"+",
"\"\\\\s{0,\"",
"+",
"WHITESPACE_LIMIT",
"+",
"\"}\"",
"+",
"pattern",
"+",
"\"\\\\b\"",
")",
",",
"unit",
")",
";",
"unitSymbols",
".",
"putIfAbsent",
"(",
"unit",
",",
"new",
"ArrayList",
"<>",
"(",
")",
")",
";",
"unitSymbols",
".",
"get",
"(",
"unit",
")",
".",
"add",
"(",
"symbol",
")",
";",
"if",
"(",
"metric",
"&&",
"!",
"metricUnits",
".",
"contains",
"(",
"unit",
")",
")",
"{",
"metricUnits",
".",
"add",
"(",
"unit",
")",
";",
"}",
"}"
] |
Associate a notation with a given unit.
@param pattern Regex for recognizing the unit. Word boundaries and numbers are added to this pattern by addUnit itself.
@param base Unit to associate with the pattern
@param symbol Suffix used for suggestion.
@param factor Convenience parameter for prefixes for metric units, unit is multiplied with this. Defaults to 1 if not used.
@param metric Register this notation for suggestion.
|
[
"Associate",
"a",
"notation",
"with",
"a",
"given",
"unit",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/AbstractUnitConversionRule.java#L183-L191
|
19,185
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/AbstractUnitConversionRule.java
|
AbstractUnitConversionRule.getFormattedConversions
|
@NotNull
private List<String> getFormattedConversions(List<Map.Entry<Unit, Double>> conversions) {
List<String> formatted = new ArrayList<>();
for (Map.Entry<Unit, Double> equivalent : conversions) {
Unit metric = equivalent.getKey();
double converted = equivalent.getValue();
long rounded = Math.round(converted);
for (String symbol : unitSymbols.getOrDefault(metric, new ArrayList<>())) {
if (formatted.size() > MAX_SUGGESTIONS) {
break;
}
if (Math.abs(converted - rounded) / Math.abs(converted) < ROUNDING_DELTA && rounded != 0) {
String formattedStr = formatRounded(getNumberFormat().format(rounded) + " " + symbol);
if (!formatted.contains(formattedStr)) {
formatted.add(formattedStr);
}
}
String formattedNumber = getNumberFormat().format(converted);
String formattedStr = formattedNumber + " " + symbol;
// TODO: be cleverer than !equals("0"), can prevent valid conversions
if (!formatted.contains(formattedStr) && !formattedNumber.equals("0")) {
formatted.add(formattedStr);
}
}
}
return formatted;
}
|
java
|
@NotNull
private List<String> getFormattedConversions(List<Map.Entry<Unit, Double>> conversions) {
List<String> formatted = new ArrayList<>();
for (Map.Entry<Unit, Double> equivalent : conversions) {
Unit metric = equivalent.getKey();
double converted = equivalent.getValue();
long rounded = Math.round(converted);
for (String symbol : unitSymbols.getOrDefault(metric, new ArrayList<>())) {
if (formatted.size() > MAX_SUGGESTIONS) {
break;
}
if (Math.abs(converted - rounded) / Math.abs(converted) < ROUNDING_DELTA && rounded != 0) {
String formattedStr = formatRounded(getNumberFormat().format(rounded) + " " + symbol);
if (!formatted.contains(formattedStr)) {
formatted.add(formattedStr);
}
}
String formattedNumber = getNumberFormat().format(converted);
String formattedStr = formattedNumber + " " + symbol;
// TODO: be cleverer than !equals("0"), can prevent valid conversions
if (!formatted.contains(formattedStr) && !formattedNumber.equals("0")) {
formatted.add(formattedStr);
}
}
}
return formatted;
}
|
[
"@",
"NotNull",
"private",
"List",
"<",
"String",
">",
"getFormattedConversions",
"(",
"List",
"<",
"Map",
".",
"Entry",
"<",
"Unit",
",",
"Double",
">",
">",
"conversions",
")",
"{",
"List",
"<",
"String",
">",
"formatted",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"Unit",
",",
"Double",
">",
"equivalent",
":",
"conversions",
")",
"{",
"Unit",
"metric",
"=",
"equivalent",
".",
"getKey",
"(",
")",
";",
"double",
"converted",
"=",
"equivalent",
".",
"getValue",
"(",
")",
";",
"long",
"rounded",
"=",
"Math",
".",
"round",
"(",
"converted",
")",
";",
"for",
"(",
"String",
"symbol",
":",
"unitSymbols",
".",
"getOrDefault",
"(",
"metric",
",",
"new",
"ArrayList",
"<>",
"(",
")",
")",
")",
"{",
"if",
"(",
"formatted",
".",
"size",
"(",
")",
">",
"MAX_SUGGESTIONS",
")",
"{",
"break",
";",
"}",
"if",
"(",
"Math",
".",
"abs",
"(",
"converted",
"-",
"rounded",
")",
"/",
"Math",
".",
"abs",
"(",
"converted",
")",
"<",
"ROUNDING_DELTA",
"&&",
"rounded",
"!=",
"0",
")",
"{",
"String",
"formattedStr",
"=",
"formatRounded",
"(",
"getNumberFormat",
"(",
")",
".",
"format",
"(",
"rounded",
")",
"+",
"\" \"",
"+",
"symbol",
")",
";",
"if",
"(",
"!",
"formatted",
".",
"contains",
"(",
"formattedStr",
")",
")",
"{",
"formatted",
".",
"add",
"(",
"formattedStr",
")",
";",
"}",
"}",
"String",
"formattedNumber",
"=",
"getNumberFormat",
"(",
")",
".",
"format",
"(",
"converted",
")",
";",
"String",
"formattedStr",
"=",
"formattedNumber",
"+",
"\" \"",
"+",
"symbol",
";",
"// TODO: be cleverer than !equals(\"0\"), can prevent valid conversions",
"if",
"(",
"!",
"formatted",
".",
"contains",
"(",
"formattedStr",
")",
"&&",
"!",
"formattedNumber",
".",
"equals",
"(",
"\"0\"",
")",
")",
"{",
"formatted",
".",
"add",
"(",
"formattedStr",
")",
";",
"}",
"}",
"}",
"return",
"formatted",
";",
"}"
] |
Adds different formatted variants of the given conversions up to MAX_SUGGESTIONS.
@param conversions as computed by getMetricEquivalent
@return formatted numbers, with various units and unit symbols, rounded to integers or according to getNumberFormat
|
[
"Adds",
"different",
"formatted",
"variants",
"of",
"the",
"given",
"conversions",
"up",
"to",
"MAX_SUGGESTIONS",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/AbstractUnitConversionRule.java#L330-L356
|
19,186
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/OfficeTools.java
|
OfficeTools.getCurrentDesktop
|
@Nullable
public static XDesktop getCurrentDesktop(XComponentContext xContext) {
try {
if (xContext == null) {
return null;
}
XMultiComponentFactory xMCF = UnoRuntime.queryInterface(XMultiComponentFactory.class,
xContext.getServiceManager());
if (xMCF == null) {
return null;
}
Object desktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
if (desktop == null) {
return null;
}
return UnoRuntime.queryInterface(XDesktop.class, desktop);
} catch (Throwable t) {
MessageHandler.printException(t); // all Exceptions thrown by UnoRuntime.queryInterface are caught
return null; // Return null as method failed
}
}
|
java
|
@Nullable
public static XDesktop getCurrentDesktop(XComponentContext xContext) {
try {
if (xContext == null) {
return null;
}
XMultiComponentFactory xMCF = UnoRuntime.queryInterface(XMultiComponentFactory.class,
xContext.getServiceManager());
if (xMCF == null) {
return null;
}
Object desktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
if (desktop == null) {
return null;
}
return UnoRuntime.queryInterface(XDesktop.class, desktop);
} catch (Throwable t) {
MessageHandler.printException(t); // all Exceptions thrown by UnoRuntime.queryInterface are caught
return null; // Return null as method failed
}
}
|
[
"@",
"Nullable",
"public",
"static",
"XDesktop",
"getCurrentDesktop",
"(",
"XComponentContext",
"xContext",
")",
"{",
"try",
"{",
"if",
"(",
"xContext",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"XMultiComponentFactory",
"xMCF",
"=",
"UnoRuntime",
".",
"queryInterface",
"(",
"XMultiComponentFactory",
".",
"class",
",",
"xContext",
".",
"getServiceManager",
"(",
")",
")",
";",
"if",
"(",
"xMCF",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"Object",
"desktop",
"=",
"xMCF",
".",
"createInstanceWithContext",
"(",
"\"com.sun.star.frame.Desktop\"",
",",
"xContext",
")",
";",
"if",
"(",
"desktop",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"UnoRuntime",
".",
"queryInterface",
"(",
"XDesktop",
".",
"class",
",",
"desktop",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"MessageHandler",
".",
"printException",
"(",
"t",
")",
";",
"// all Exceptions thrown by UnoRuntime.queryInterface are caught",
"return",
"null",
";",
"// Return null as method failed",
"}",
"}"
] |
Returns the current XDesktop
Returns null if it fails
|
[
"Returns",
"the",
"current",
"XDesktop",
"Returns",
"null",
"if",
"it",
"fails"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/OfficeTools.java#L47-L67
|
19,187
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/OfficeTools.java
|
OfficeTools.getCurrentComponent
|
@Nullable
public static XComponent getCurrentComponent(XComponentContext xContext) {
try {
XDesktop xdesktop = getCurrentDesktop(xContext);
if(xdesktop == null) {
return null;
}
else return xdesktop.getCurrentComponent();
} catch (Throwable t) {
MessageHandler.printException(t); // all Exceptions thrown by UnoRuntime.queryInterface are caught
return null; // Return null as method failed
}
}
|
java
|
@Nullable
public static XComponent getCurrentComponent(XComponentContext xContext) {
try {
XDesktop xdesktop = getCurrentDesktop(xContext);
if(xdesktop == null) {
return null;
}
else return xdesktop.getCurrentComponent();
} catch (Throwable t) {
MessageHandler.printException(t); // all Exceptions thrown by UnoRuntime.queryInterface are caught
return null; // Return null as method failed
}
}
|
[
"@",
"Nullable",
"public",
"static",
"XComponent",
"getCurrentComponent",
"(",
"XComponentContext",
"xContext",
")",
"{",
"try",
"{",
"XDesktop",
"xdesktop",
"=",
"getCurrentDesktop",
"(",
"xContext",
")",
";",
"if",
"(",
"xdesktop",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"else",
"return",
"xdesktop",
".",
"getCurrentComponent",
"(",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"MessageHandler",
".",
"printException",
"(",
"t",
")",
";",
"// all Exceptions thrown by UnoRuntime.queryInterface are caught",
"return",
"null",
";",
"// Return null as method failed",
"}",
"}"
] |
Returns the current XComponent
Returns null if it fails
|
[
"Returns",
"the",
"current",
"XComponent",
"Returns",
"null",
"if",
"it",
"fails"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/OfficeTools.java#L73-L85
|
19,188
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/spelling/suggestions/SuggestionsOrdererFeatureExtractor.java
|
SuggestionsOrdererFeatureExtractor.computeFeatures
|
public Pair<List<SuggestedReplacement>, SortedMap<String, Float>> computeFeatures(List<String> suggestions, String word, AnalyzedSentence sentence, int startPos) {
if (suggestions.isEmpty()) {
return Pair.of(Collections.emptyList(), Collections.emptySortedMap());
}
if (topN <= 0) {
topN = suggestions.size();
}
List<String> topSuggestions = suggestions.subList(0, Math.min(suggestions.size(), topN));
//EditDistance<Integer> levenshteinDistance = new LevenshteinDistance(4);
EditDistance levenstheinDistance = new EditDistance(word, EditDistance.DistanceAlgorithm.Damerau);
SimilarityScore<Double> jaroWrinklerDistance = new JaroWinklerDistance();
List<Feature> features = new ArrayList<>(topSuggestions.size());
for (String candidate : topSuggestions) {
double prob1 = languageModel.getPseudoProbability(Collections.singletonList(candidate)).getProb();
double prob3 = LanguageModelUtils.get3gramProbabilityFor(language, languageModel, startPos, sentence, candidate);
//double prob4 = LanguageModelUtils.get4gramProbabilityFor(language, languageModel, startPos, sentence, candidate);
long wordCount = ((BaseLanguageModel) languageModel).getCount(candidate);
int levenstheinDist = levenstheinDistance.compare(candidate, 3);
double jaroWrinklerDist = jaroWrinklerDistance.apply(word, candidate);
DetailedDamerauLevenstheinDistance.Distance detailedDistance = DetailedDamerauLevenstheinDistance.compare(word, candidate);
features.add(new Feature(prob1, prob3, wordCount, levenstheinDist, detailedDistance, jaroWrinklerDist, candidate));
}
if (!"noop".equals(score)) {
features.sort(Feature::compareTo);
}
//logger.trace("Features for '%s' in '%s': %n", word, sentence.getText());
//features.stream().map(Feature::toString).forEach(logger::trace);
List<String> words = features.stream().map(Feature::getWord).collect(Collectors.toList());
// compute general features, not tied to candidates
SortedMap<String, Float> matchData = new TreeMap<>();
matchData.put("candidateCount", (float) words.size());
List<SuggestedReplacement> suggestionsData = features.stream().map(f -> {
SuggestedReplacement s = new SuggestedReplacement(f.getWord());
s.setFeatures(f.getData());
return s;
}).collect(Collectors.toList());
return Pair.of(suggestionsData, matchData);
}
|
java
|
public Pair<List<SuggestedReplacement>, SortedMap<String, Float>> computeFeatures(List<String> suggestions, String word, AnalyzedSentence sentence, int startPos) {
if (suggestions.isEmpty()) {
return Pair.of(Collections.emptyList(), Collections.emptySortedMap());
}
if (topN <= 0) {
topN = suggestions.size();
}
List<String> topSuggestions = suggestions.subList(0, Math.min(suggestions.size(), topN));
//EditDistance<Integer> levenshteinDistance = new LevenshteinDistance(4);
EditDistance levenstheinDistance = new EditDistance(word, EditDistance.DistanceAlgorithm.Damerau);
SimilarityScore<Double> jaroWrinklerDistance = new JaroWinklerDistance();
List<Feature> features = new ArrayList<>(topSuggestions.size());
for (String candidate : topSuggestions) {
double prob1 = languageModel.getPseudoProbability(Collections.singletonList(candidate)).getProb();
double prob3 = LanguageModelUtils.get3gramProbabilityFor(language, languageModel, startPos, sentence, candidate);
//double prob4 = LanguageModelUtils.get4gramProbabilityFor(language, languageModel, startPos, sentence, candidate);
long wordCount = ((BaseLanguageModel) languageModel).getCount(candidate);
int levenstheinDist = levenstheinDistance.compare(candidate, 3);
double jaroWrinklerDist = jaroWrinklerDistance.apply(word, candidate);
DetailedDamerauLevenstheinDistance.Distance detailedDistance = DetailedDamerauLevenstheinDistance.compare(word, candidate);
features.add(new Feature(prob1, prob3, wordCount, levenstheinDist, detailedDistance, jaroWrinklerDist, candidate));
}
if (!"noop".equals(score)) {
features.sort(Feature::compareTo);
}
//logger.trace("Features for '%s' in '%s': %n", word, sentence.getText());
//features.stream().map(Feature::toString).forEach(logger::trace);
List<String> words = features.stream().map(Feature::getWord).collect(Collectors.toList());
// compute general features, not tied to candidates
SortedMap<String, Float> matchData = new TreeMap<>();
matchData.put("candidateCount", (float) words.size());
List<SuggestedReplacement> suggestionsData = features.stream().map(f -> {
SuggestedReplacement s = new SuggestedReplacement(f.getWord());
s.setFeatures(f.getData());
return s;
}).collect(Collectors.toList());
return Pair.of(suggestionsData, matchData);
}
|
[
"public",
"Pair",
"<",
"List",
"<",
"SuggestedReplacement",
">",
",",
"SortedMap",
"<",
"String",
",",
"Float",
">",
">",
"computeFeatures",
"(",
"List",
"<",
"String",
">",
"suggestions",
",",
"String",
"word",
",",
"AnalyzedSentence",
"sentence",
",",
"int",
"startPos",
")",
"{",
"if",
"(",
"suggestions",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"Pair",
".",
"of",
"(",
"Collections",
".",
"emptyList",
"(",
")",
",",
"Collections",
".",
"emptySortedMap",
"(",
")",
")",
";",
"}",
"if",
"(",
"topN",
"<=",
"0",
")",
"{",
"topN",
"=",
"suggestions",
".",
"size",
"(",
")",
";",
"}",
"List",
"<",
"String",
">",
"topSuggestions",
"=",
"suggestions",
".",
"subList",
"(",
"0",
",",
"Math",
".",
"min",
"(",
"suggestions",
".",
"size",
"(",
")",
",",
"topN",
")",
")",
";",
"//EditDistance<Integer> levenshteinDistance = new LevenshteinDistance(4);",
"EditDistance",
"levenstheinDistance",
"=",
"new",
"EditDistance",
"(",
"word",
",",
"EditDistance",
".",
"DistanceAlgorithm",
".",
"Damerau",
")",
";",
"SimilarityScore",
"<",
"Double",
">",
"jaroWrinklerDistance",
"=",
"new",
"JaroWinklerDistance",
"(",
")",
";",
"List",
"<",
"Feature",
">",
"features",
"=",
"new",
"ArrayList",
"<>",
"(",
"topSuggestions",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"String",
"candidate",
":",
"topSuggestions",
")",
"{",
"double",
"prob1",
"=",
"languageModel",
".",
"getPseudoProbability",
"(",
"Collections",
".",
"singletonList",
"(",
"candidate",
")",
")",
".",
"getProb",
"(",
")",
";",
"double",
"prob3",
"=",
"LanguageModelUtils",
".",
"get3gramProbabilityFor",
"(",
"language",
",",
"languageModel",
",",
"startPos",
",",
"sentence",
",",
"candidate",
")",
";",
"//double prob4 = LanguageModelUtils.get4gramProbabilityFor(language, languageModel, startPos, sentence, candidate);",
"long",
"wordCount",
"=",
"(",
"(",
"BaseLanguageModel",
")",
"languageModel",
")",
".",
"getCount",
"(",
"candidate",
")",
";",
"int",
"levenstheinDist",
"=",
"levenstheinDistance",
".",
"compare",
"(",
"candidate",
",",
"3",
")",
";",
"double",
"jaroWrinklerDist",
"=",
"jaroWrinklerDistance",
".",
"apply",
"(",
"word",
",",
"candidate",
")",
";",
"DetailedDamerauLevenstheinDistance",
".",
"Distance",
"detailedDistance",
"=",
"DetailedDamerauLevenstheinDistance",
".",
"compare",
"(",
"word",
",",
"candidate",
")",
";",
"features",
".",
"add",
"(",
"new",
"Feature",
"(",
"prob1",
",",
"prob3",
",",
"wordCount",
",",
"levenstheinDist",
",",
"detailedDistance",
",",
"jaroWrinklerDist",
",",
"candidate",
")",
")",
";",
"}",
"if",
"(",
"!",
"\"noop\"",
".",
"equals",
"(",
"score",
")",
")",
"{",
"features",
".",
"sort",
"(",
"Feature",
"::",
"compareTo",
")",
";",
"}",
"//logger.trace(\"Features for '%s' in '%s': %n\", word, sentence.getText());",
"//features.stream().map(Feature::toString).forEach(logger::trace);",
"List",
"<",
"String",
">",
"words",
"=",
"features",
".",
"stream",
"(",
")",
".",
"map",
"(",
"Feature",
"::",
"getWord",
")",
".",
"collect",
"(",
"Collectors",
".",
"toList",
"(",
")",
")",
";",
"// compute general features, not tied to candidates",
"SortedMap",
"<",
"String",
",",
"Float",
">",
"matchData",
"=",
"new",
"TreeMap",
"<>",
"(",
")",
";",
"matchData",
".",
"put",
"(",
"\"candidateCount\"",
",",
"(",
"float",
")",
"words",
".",
"size",
"(",
")",
")",
";",
"List",
"<",
"SuggestedReplacement",
">",
"suggestionsData",
"=",
"features",
".",
"stream",
"(",
")",
".",
"map",
"(",
"f",
"->",
"{",
"SuggestedReplacement",
"s",
"=",
"new",
"SuggestedReplacement",
"(",
"f",
".",
"getWord",
"(",
")",
")",
";",
"s",
".",
"setFeatures",
"(",
"f",
".",
"getData",
"(",
")",
")",
";",
"return",
"s",
";",
"}",
")",
".",
"collect",
"(",
"Collectors",
".",
"toList",
"(",
")",
")",
";",
"return",
"Pair",
".",
"of",
"(",
"suggestionsData",
",",
"matchData",
")",
";",
"}"
] |
compute features for training or prediction of a ranking model for suggestions
@param suggestions
@param word
@param sentence
@param startPos
@return correction candidates, features for the match in general, features specific to candidates
|
[
"compute",
"features",
"for",
"training",
"or",
"prediction",
"of",
"a",
"ranking",
"model",
"for",
"suggestions"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/spelling/suggestions/SuggestionsOrdererFeatureExtractor.java#L92-L133
|
19,189
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/RuleInformation.java
|
RuleInformation.ignoreForIncompleteSentences
|
public static boolean ignoreForIncompleteSentences(String ruleId, Language lang) {
return rules.contains(new Key(lang.getShortCode(), ruleId));
}
|
java
|
public static boolean ignoreForIncompleteSentences(String ruleId, Language lang) {
return rules.contains(new Key(lang.getShortCode(), ruleId));
}
|
[
"public",
"static",
"boolean",
"ignoreForIncompleteSentences",
"(",
"String",
"ruleId",
",",
"Language",
"lang",
")",
"{",
"return",
"rules",
".",
"contains",
"(",
"new",
"Key",
"(",
"lang",
".",
"getShortCode",
"(",
")",
",",
"ruleId",
")",
")",
";",
"}"
] |
Whether this rule should be ignored when the sentence isn't finished yet.
@since 4.4
|
[
"Whether",
"this",
"rule",
"should",
"be",
"ignored",
"when",
"the",
"sentence",
"isn",
"t",
"finished",
"yet",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/RuleInformation.java#L65-L67
|
19,190
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/tools/Tools.java
|
Tools.i18n
|
public static String i18n(ResourceBundle messages, String key, Object... messageArguments) {
MessageFormat formatter = new MessageFormat("");
formatter.applyPattern(messages.getString(key).replaceAll("'", "''"));
return formatter.format(messageArguments);
}
|
java
|
public static String i18n(ResourceBundle messages, String key, Object... messageArguments) {
MessageFormat formatter = new MessageFormat("");
formatter.applyPattern(messages.getString(key).replaceAll("'", "''"));
return formatter.format(messageArguments);
}
|
[
"public",
"static",
"String",
"i18n",
"(",
"ResourceBundle",
"messages",
",",
"String",
"key",
",",
"Object",
"...",
"messageArguments",
")",
"{",
"MessageFormat",
"formatter",
"=",
"new",
"MessageFormat",
"(",
"\"\"",
")",
";",
"formatter",
".",
"applyPattern",
"(",
"messages",
".",
"getString",
"(",
"key",
")",
".",
"replaceAll",
"(",
"\"'\"",
",",
"\"''\"",
")",
")",
";",
"return",
"formatter",
".",
"format",
"(",
"messageArguments",
")",
";",
"}"
] |
Translate a text string based on our i18n files.
@since 3.1
|
[
"Translate",
"a",
"text",
"string",
"based",
"on",
"our",
"i18n",
"files",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/tools/Tools.java#L55-L59
|
19,191
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/tools/Tools.java
|
Tools.getAllBuiltinBitextRules
|
private static List<BitextRule> getAllBuiltinBitextRules(Language language,
ResourceBundle messages) {
List<BitextRule> rules = new ArrayList<>();
try {
List<Class<? extends BitextRule>> classes = BitextRule.getRelevantRules();
for (Class class1 : classes) {
Constructor[] constructors = class1.getConstructors();
boolean foundConstructor = false;
for (Constructor constructor : constructors) {
Class[] paramTypes = constructor.getParameterTypes();
if (paramTypes.length == 0) {
rules.add((BitextRule) constructor.newInstance());
foundConstructor = true;
break;
}
if (paramTypes.length == 1
&& paramTypes[0].equals(ResourceBundle.class)) {
rules.add((BitextRule) constructor.newInstance(messages));
foundConstructor = true;
break;
}
if (paramTypes.length == 2
&& paramTypes[0].equals(ResourceBundle.class)
&& paramTypes[1].equals(Language.class)) {
rules.add((BitextRule) constructor.newInstance(messages, language));
foundConstructor = true;
break;
}
}
if (!foundConstructor) {
throw new RuntimeException("Unknown constructor type for rule class " + class1.getName()
+ ", it supports only these constructors: " + Arrays.toString(constructors));
}
}
} catch (Exception e) {
throw new RuntimeException("Failed to load bitext rules", e);
}
return rules;
}
|
java
|
private static List<BitextRule> getAllBuiltinBitextRules(Language language,
ResourceBundle messages) {
List<BitextRule> rules = new ArrayList<>();
try {
List<Class<? extends BitextRule>> classes = BitextRule.getRelevantRules();
for (Class class1 : classes) {
Constructor[] constructors = class1.getConstructors();
boolean foundConstructor = false;
for (Constructor constructor : constructors) {
Class[] paramTypes = constructor.getParameterTypes();
if (paramTypes.length == 0) {
rules.add((BitextRule) constructor.newInstance());
foundConstructor = true;
break;
}
if (paramTypes.length == 1
&& paramTypes[0].equals(ResourceBundle.class)) {
rules.add((BitextRule) constructor.newInstance(messages));
foundConstructor = true;
break;
}
if (paramTypes.length == 2
&& paramTypes[0].equals(ResourceBundle.class)
&& paramTypes[1].equals(Language.class)) {
rules.add((BitextRule) constructor.newInstance(messages, language));
foundConstructor = true;
break;
}
}
if (!foundConstructor) {
throw new RuntimeException("Unknown constructor type for rule class " + class1.getName()
+ ", it supports only these constructors: " + Arrays.toString(constructors));
}
}
} catch (Exception e) {
throw new RuntimeException("Failed to load bitext rules", e);
}
return rules;
}
|
[
"private",
"static",
"List",
"<",
"BitextRule",
">",
"getAllBuiltinBitextRules",
"(",
"Language",
"language",
",",
"ResourceBundle",
"messages",
")",
"{",
"List",
"<",
"BitextRule",
">",
"rules",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"try",
"{",
"List",
"<",
"Class",
"<",
"?",
"extends",
"BitextRule",
">",
">",
"classes",
"=",
"BitextRule",
".",
"getRelevantRules",
"(",
")",
";",
"for",
"(",
"Class",
"class1",
":",
"classes",
")",
"{",
"Constructor",
"[",
"]",
"constructors",
"=",
"class1",
".",
"getConstructors",
"(",
")",
";",
"boolean",
"foundConstructor",
"=",
"false",
";",
"for",
"(",
"Constructor",
"constructor",
":",
"constructors",
")",
"{",
"Class",
"[",
"]",
"paramTypes",
"=",
"constructor",
".",
"getParameterTypes",
"(",
")",
";",
"if",
"(",
"paramTypes",
".",
"length",
"==",
"0",
")",
"{",
"rules",
".",
"add",
"(",
"(",
"BitextRule",
")",
"constructor",
".",
"newInstance",
"(",
")",
")",
";",
"foundConstructor",
"=",
"true",
";",
"break",
";",
"}",
"if",
"(",
"paramTypes",
".",
"length",
"==",
"1",
"&&",
"paramTypes",
"[",
"0",
"]",
".",
"equals",
"(",
"ResourceBundle",
".",
"class",
")",
")",
"{",
"rules",
".",
"add",
"(",
"(",
"BitextRule",
")",
"constructor",
".",
"newInstance",
"(",
"messages",
")",
")",
";",
"foundConstructor",
"=",
"true",
";",
"break",
";",
"}",
"if",
"(",
"paramTypes",
".",
"length",
"==",
"2",
"&&",
"paramTypes",
"[",
"0",
"]",
".",
"equals",
"(",
"ResourceBundle",
".",
"class",
")",
"&&",
"paramTypes",
"[",
"1",
"]",
".",
"equals",
"(",
"Language",
".",
"class",
")",
")",
"{",
"rules",
".",
"add",
"(",
"(",
"BitextRule",
")",
"constructor",
".",
"newInstance",
"(",
"messages",
",",
"language",
")",
")",
";",
"foundConstructor",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"foundConstructor",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Unknown constructor type for rule class \"",
"+",
"class1",
".",
"getName",
"(",
")",
"+",
"\", it supports only these constructors: \"",
"+",
"Arrays",
".",
"toString",
"(",
"constructors",
")",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Failed to load bitext rules\"",
",",
"e",
")",
";",
"}",
"return",
"rules",
";",
"}"
] |
Use reflection to add bitext rules.
|
[
"Use",
"reflection",
"to",
"add",
"bitext",
"rules",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/tools/Tools.java#L152-L190
|
19,192
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/tools/Tools.java
|
Tools.selectRules
|
public static void selectRules(JLanguageTool lt, List<String> disabledRuleIds, List<String> enabledRuleIds, boolean useEnabledOnly) {
Set<String> disabledRuleIdsSet = new HashSet<>();
disabledRuleIdsSet.addAll(disabledRuleIds);
Set<String> enabledRuleIdsSet = new HashSet<>();
enabledRuleIdsSet.addAll(enabledRuleIds);
selectRules(lt, Collections.emptySet(), Collections.emptySet(), disabledRuleIdsSet, enabledRuleIdsSet, useEnabledOnly);
}
|
java
|
public static void selectRules(JLanguageTool lt, List<String> disabledRuleIds, List<String> enabledRuleIds, boolean useEnabledOnly) {
Set<String> disabledRuleIdsSet = new HashSet<>();
disabledRuleIdsSet.addAll(disabledRuleIds);
Set<String> enabledRuleIdsSet = new HashSet<>();
enabledRuleIdsSet.addAll(enabledRuleIds);
selectRules(lt, Collections.emptySet(), Collections.emptySet(), disabledRuleIdsSet, enabledRuleIdsSet, useEnabledOnly);
}
|
[
"public",
"static",
"void",
"selectRules",
"(",
"JLanguageTool",
"lt",
",",
"List",
"<",
"String",
">",
"disabledRuleIds",
",",
"List",
"<",
"String",
">",
"enabledRuleIds",
",",
"boolean",
"useEnabledOnly",
")",
"{",
"Set",
"<",
"String",
">",
"disabledRuleIdsSet",
"=",
"new",
"HashSet",
"<>",
"(",
")",
";",
"disabledRuleIdsSet",
".",
"addAll",
"(",
"disabledRuleIds",
")",
";",
"Set",
"<",
"String",
">",
"enabledRuleIdsSet",
"=",
"new",
"HashSet",
"<>",
"(",
")",
";",
"enabledRuleIdsSet",
".",
"addAll",
"(",
"enabledRuleIds",
")",
";",
"selectRules",
"(",
"lt",
",",
"Collections",
".",
"emptySet",
"(",
")",
",",
"Collections",
".",
"emptySet",
"(",
")",
",",
"disabledRuleIdsSet",
",",
"enabledRuleIdsSet",
",",
"useEnabledOnly",
")",
";",
"}"
] |
Enable and disable rules of the given LanguageTool instance.
@param lt LanguageTool object
@param disabledRuleIds ids of the rules to be disabled
@param enabledRuleIds ids of the rules to be enabled
@param useEnabledOnly if set to {@code true}, disable all rules except those enabled explicitly
|
[
"Enable",
"and",
"disable",
"rules",
"of",
"the",
"given",
"LanguageTool",
"instance",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/tools/Tools.java#L286-L292
|
19,193
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/tools/Tools.java
|
Tools.selectBitextRules
|
public static List<BitextRule> selectBitextRules(List<BitextRule> bRules, List<String> disabledRules, List<String> enabledRules, boolean useEnabledOnly) {
List<BitextRule> newBRules = new ArrayList<>(bRules.size());
newBRules.addAll(bRules);
List<BitextRule> rulesToDisable = new ArrayList<>();
if (useEnabledOnly) {
for (String enabledRule : enabledRules) {
for (BitextRule b : bRules) {
if (!b.getId().equals(enabledRule)) {
rulesToDisable.add(b);
}
}
}
} else {
for (String disabledRule : disabledRules) {
for (BitextRule b : newBRules) {
if (b.getId().equals(disabledRule)) {
rulesToDisable.add(b);
}
}
}
}
newBRules.removeAll(rulesToDisable);
return newBRules;
}
|
java
|
public static List<BitextRule> selectBitextRules(List<BitextRule> bRules, List<String> disabledRules, List<String> enabledRules, boolean useEnabledOnly) {
List<BitextRule> newBRules = new ArrayList<>(bRules.size());
newBRules.addAll(bRules);
List<BitextRule> rulesToDisable = new ArrayList<>();
if (useEnabledOnly) {
for (String enabledRule : enabledRules) {
for (BitextRule b : bRules) {
if (!b.getId().equals(enabledRule)) {
rulesToDisable.add(b);
}
}
}
} else {
for (String disabledRule : disabledRules) {
for (BitextRule b : newBRules) {
if (b.getId().equals(disabledRule)) {
rulesToDisable.add(b);
}
}
}
}
newBRules.removeAll(rulesToDisable);
return newBRules;
}
|
[
"public",
"static",
"List",
"<",
"BitextRule",
">",
"selectBitextRules",
"(",
"List",
"<",
"BitextRule",
">",
"bRules",
",",
"List",
"<",
"String",
">",
"disabledRules",
",",
"List",
"<",
"String",
">",
"enabledRules",
",",
"boolean",
"useEnabledOnly",
")",
"{",
"List",
"<",
"BitextRule",
">",
"newBRules",
"=",
"new",
"ArrayList",
"<>",
"(",
"bRules",
".",
"size",
"(",
")",
")",
";",
"newBRules",
".",
"addAll",
"(",
"bRules",
")",
";",
"List",
"<",
"BitextRule",
">",
"rulesToDisable",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"if",
"(",
"useEnabledOnly",
")",
"{",
"for",
"(",
"String",
"enabledRule",
":",
"enabledRules",
")",
"{",
"for",
"(",
"BitextRule",
"b",
":",
"bRules",
")",
"{",
"if",
"(",
"!",
"b",
".",
"getId",
"(",
")",
".",
"equals",
"(",
"enabledRule",
")",
")",
"{",
"rulesToDisable",
".",
"add",
"(",
"b",
")",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"for",
"(",
"String",
"disabledRule",
":",
"disabledRules",
")",
"{",
"for",
"(",
"BitextRule",
"b",
":",
"newBRules",
")",
"{",
"if",
"(",
"b",
".",
"getId",
"(",
")",
".",
"equals",
"(",
"disabledRule",
")",
")",
"{",
"rulesToDisable",
".",
"add",
"(",
"b",
")",
";",
"}",
"}",
"}",
"}",
"newBRules",
".",
"removeAll",
"(",
"rulesToDisable",
")",
";",
"return",
"newBRules",
";",
"}"
] |
Enable and disable bitext rules.
@param bRules List of all bitext rules
@param disabledRules ids of rules to be disabled
@param enabledRules ids of rules to be enabled (by default all are enabled)
@param useEnabledOnly if set to {@code true}, if set to {@code true}, disable all rules except those enabled explicitly.
@return the list of rules to be used.
@since 2.8
|
[
"Enable",
"and",
"disable",
"bitext",
"rules",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/tools/Tools.java#L345-L368
|
19,194
|
languagetool-org/languagetool
|
languagetool-language-modules/uk/src/main/java/org/languagetool/tagging/uk/CompoundTagger.java
|
CompoundTagger.getNumAgreedPosTag
|
@Nullable
private String getNumAgreedPosTag(String leftPosTag, String rightPosTag, boolean leftNv) {
String agreedPosTag = null;
if( leftPosTag.contains(":p:") && SING_REGEX_F.matcher(rightPosTag).find()
|| SING_REGEX_F.matcher(leftPosTag).find() && rightPosTag.contains(":p:")) {
String leftConj = PosTagHelper.getConj(leftPosTag);
if( leftConj != null && leftConj.equals(PosTagHelper.getConj(rightPosTag)) ) {
agreedPosTag = leftPosTag;
}
}
return agreedPosTag;
}
|
java
|
@Nullable
private String getNumAgreedPosTag(String leftPosTag, String rightPosTag, boolean leftNv) {
String agreedPosTag = null;
if( leftPosTag.contains(":p:") && SING_REGEX_F.matcher(rightPosTag).find()
|| SING_REGEX_F.matcher(leftPosTag).find() && rightPosTag.contains(":p:")) {
String leftConj = PosTagHelper.getConj(leftPosTag);
if( leftConj != null && leftConj.equals(PosTagHelper.getConj(rightPosTag)) ) {
agreedPosTag = leftPosTag;
}
}
return agreedPosTag;
}
|
[
"@",
"Nullable",
"private",
"String",
"getNumAgreedPosTag",
"(",
"String",
"leftPosTag",
",",
"String",
"rightPosTag",
",",
"boolean",
"leftNv",
")",
"{",
"String",
"agreedPosTag",
"=",
"null",
";",
"if",
"(",
"leftPosTag",
".",
"contains",
"(",
"\":p:\"",
")",
"&&",
"SING_REGEX_F",
".",
"matcher",
"(",
"rightPosTag",
")",
".",
"find",
"(",
")",
"||",
"SING_REGEX_F",
".",
"matcher",
"(",
"leftPosTag",
")",
".",
"find",
"(",
")",
"&&",
"rightPosTag",
".",
"contains",
"(",
"\":p:\"",
")",
")",
"{",
"String",
"leftConj",
"=",
"PosTagHelper",
".",
"getConj",
"(",
"leftPosTag",
")",
";",
"if",
"(",
"leftConj",
"!=",
"null",
"&&",
"leftConj",
".",
"equals",
"(",
"PosTagHelper",
".",
"getConj",
"(",
"rightPosTag",
")",
")",
")",
"{",
"agreedPosTag",
"=",
"leftPosTag",
";",
"}",
"}",
"return",
"agreedPosTag",
";",
"}"
] |
right part is numr
|
[
"right",
"part",
"is",
"numr"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-language-modules/uk/src/main/java/org/languagetool/tagging/uk/CompoundTagger.java#L924-L936
|
19,195
|
languagetool-org/languagetool
|
languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternTokenBuilder.java
|
PatternTokenBuilder.csToken
|
public PatternTokenBuilder csToken(String token) {
this.token = Objects.requireNonNull(token);
caseSensitive = true;
return this;
}
|
java
|
public PatternTokenBuilder csToken(String token) {
this.token = Objects.requireNonNull(token);
caseSensitive = true;
return this;
}
|
[
"public",
"PatternTokenBuilder",
"csToken",
"(",
"String",
"token",
")",
"{",
"this",
".",
"token",
"=",
"Objects",
".",
"requireNonNull",
"(",
"token",
")",
";",
"caseSensitive",
"=",
"true",
";",
"return",
"this",
";",
"}"
] |
Add a case-sensitive token.
@since 3.3
|
[
"Add",
"a",
"case",
"-",
"sensitive",
"token",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternTokenBuilder.java#L52-L56
|
19,196
|
languagetool-org/languagetool
|
languagetool-server/src/main/java/org/languagetool/server/UserLimits.java
|
UserLimits.getLimitsFromToken
|
static UserLimits getLimitsFromToken(HTTPServerConfig config, String jwtToken) {
Objects.requireNonNull(jwtToken);
try {
String secretKey = config.getSecretTokenKey();
if (secretKey == null) {
throw new RuntimeException("You specified a 'token' parameter but this server doesn't accept tokens");
}
Algorithm algorithm = Algorithm.HMAC256(secretKey);
DecodedJWT decodedToken;
try {
JWT.require(algorithm).build().verify(jwtToken);
decodedToken = JWT.decode(jwtToken);
} catch (JWTDecodeException e) {
throw new AuthException("Could not decode token '" + jwtToken + "'", e);
}
Claim maxTextLengthClaim = decodedToken.getClaim("maxTextLength");
Claim premiumClaim = decodedToken.getClaim("premium");
boolean hasPremium = !premiumClaim.isNull() && premiumClaim.asBoolean();
Claim uidClaim = decodedToken.getClaim("uid");
long uid = uidClaim.isNull() ? -1 : uidClaim.asLong();
return new UserLimits(
maxTextLengthClaim.isNull() ? config.maxTextLength : maxTextLengthClaim.asInt(),
config.maxCheckTimeMillis,
hasPremium ? uid : null);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
|
java
|
static UserLimits getLimitsFromToken(HTTPServerConfig config, String jwtToken) {
Objects.requireNonNull(jwtToken);
try {
String secretKey = config.getSecretTokenKey();
if (secretKey == null) {
throw new RuntimeException("You specified a 'token' parameter but this server doesn't accept tokens");
}
Algorithm algorithm = Algorithm.HMAC256(secretKey);
DecodedJWT decodedToken;
try {
JWT.require(algorithm).build().verify(jwtToken);
decodedToken = JWT.decode(jwtToken);
} catch (JWTDecodeException e) {
throw new AuthException("Could not decode token '" + jwtToken + "'", e);
}
Claim maxTextLengthClaim = decodedToken.getClaim("maxTextLength");
Claim premiumClaim = decodedToken.getClaim("premium");
boolean hasPremium = !premiumClaim.isNull() && premiumClaim.asBoolean();
Claim uidClaim = decodedToken.getClaim("uid");
long uid = uidClaim.isNull() ? -1 : uidClaim.asLong();
return new UserLimits(
maxTextLengthClaim.isNull() ? config.maxTextLength : maxTextLengthClaim.asInt(),
config.maxCheckTimeMillis,
hasPremium ? uid : null);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
|
[
"static",
"UserLimits",
"getLimitsFromToken",
"(",
"HTTPServerConfig",
"config",
",",
"String",
"jwtToken",
")",
"{",
"Objects",
".",
"requireNonNull",
"(",
"jwtToken",
")",
";",
"try",
"{",
"String",
"secretKey",
"=",
"config",
".",
"getSecretTokenKey",
"(",
")",
";",
"if",
"(",
"secretKey",
"==",
"null",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"You specified a 'token' parameter but this server doesn't accept tokens\"",
")",
";",
"}",
"Algorithm",
"algorithm",
"=",
"Algorithm",
".",
"HMAC256",
"(",
"secretKey",
")",
";",
"DecodedJWT",
"decodedToken",
";",
"try",
"{",
"JWT",
".",
"require",
"(",
"algorithm",
")",
".",
"build",
"(",
")",
".",
"verify",
"(",
"jwtToken",
")",
";",
"decodedToken",
"=",
"JWT",
".",
"decode",
"(",
"jwtToken",
")",
";",
"}",
"catch",
"(",
"JWTDecodeException",
"e",
")",
"{",
"throw",
"new",
"AuthException",
"(",
"\"Could not decode token '\"",
"+",
"jwtToken",
"+",
"\"'\"",
",",
"e",
")",
";",
"}",
"Claim",
"maxTextLengthClaim",
"=",
"decodedToken",
".",
"getClaim",
"(",
"\"maxTextLength\"",
")",
";",
"Claim",
"premiumClaim",
"=",
"decodedToken",
".",
"getClaim",
"(",
"\"premium\"",
")",
";",
"boolean",
"hasPremium",
"=",
"!",
"premiumClaim",
".",
"isNull",
"(",
")",
"&&",
"premiumClaim",
".",
"asBoolean",
"(",
")",
";",
"Claim",
"uidClaim",
"=",
"decodedToken",
".",
"getClaim",
"(",
"\"uid\"",
")",
";",
"long",
"uid",
"=",
"uidClaim",
".",
"isNull",
"(",
")",
"?",
"-",
"1",
":",
"uidClaim",
".",
"asLong",
"(",
")",
";",
"return",
"new",
"UserLimits",
"(",
"maxTextLengthClaim",
".",
"isNull",
"(",
")",
"?",
"config",
".",
"maxTextLength",
":",
"maxTextLengthClaim",
".",
"asInt",
"(",
")",
",",
"config",
".",
"maxCheckTimeMillis",
",",
"hasPremium",
"?",
"uid",
":",
"null",
")",
";",
"}",
"catch",
"(",
"UnsupportedEncodingException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Get limits from the JWT key itself, no database access needed.
|
[
"Get",
"limits",
"from",
"the",
"JWT",
"key",
"itself",
"no",
"database",
"access",
"needed",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-server/src/main/java/org/languagetool/server/UserLimits.java#L65-L92
|
19,197
|
languagetool-org/languagetool
|
languagetool-server/src/main/java/org/languagetool/server/UserLimits.java
|
UserLimits.getLimitsByApiKey
|
public static UserLimits getLimitsByApiKey(HTTPServerConfig config, String username, String apiKey) {
DatabaseAccess db = DatabaseAccess.getInstance();
Long id = db.getUserId(username, apiKey);
return new UserLimits(config.maxTextLengthWithApiKey, config.maxCheckTimeWithApiKeyMillis, id);
}
|
java
|
public static UserLimits getLimitsByApiKey(HTTPServerConfig config, String username, String apiKey) {
DatabaseAccess db = DatabaseAccess.getInstance();
Long id = db.getUserId(username, apiKey);
return new UserLimits(config.maxTextLengthWithApiKey, config.maxCheckTimeWithApiKeyMillis, id);
}
|
[
"public",
"static",
"UserLimits",
"getLimitsByApiKey",
"(",
"HTTPServerConfig",
"config",
",",
"String",
"username",
",",
"String",
"apiKey",
")",
"{",
"DatabaseAccess",
"db",
"=",
"DatabaseAccess",
".",
"getInstance",
"(",
")",
";",
"Long",
"id",
"=",
"db",
".",
"getUserId",
"(",
"username",
",",
"apiKey",
")",
";",
"return",
"new",
"UserLimits",
"(",
"config",
".",
"maxTextLengthWithApiKey",
",",
"config",
".",
"maxCheckTimeWithApiKeyMillis",
",",
"id",
")",
";",
"}"
] |
Get limits from the api key itself, database access is needed.
|
[
"Get",
"limits",
"from",
"the",
"api",
"key",
"itself",
"database",
"access",
"is",
"needed",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-server/src/main/java/org/languagetool/server/UserLimits.java#L97-L101
|
19,198
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/MultiDocumentsHandler.java
|
MultiDocumentsHandler.getLanguage
|
@Nullable
public Language getLanguage() {
XComponent xComponent = OfficeTools.getCurrentComponent(xContext);
Locale charLocale;
XPropertySet xCursorProps;
try {
XModel model = UnoRuntime.queryInterface(XModel.class, xComponent);
if(model == null) {
return Languages.getLanguageForShortCode("en-US");
}
XTextViewCursorSupplier xViewCursorSupplier =
UnoRuntime.queryInterface(XTextViewCursorSupplier.class, model.getCurrentController());
XTextViewCursor xCursor = xViewCursorSupplier.getViewCursor();
if (xCursor.isCollapsed()) { // no text selection
xCursorProps = UnoRuntime.queryInterface(XPropertySet.class, xCursor);
} else { // text is selected, need to create another cursor
// as multiple languages can occur here - we care only
// about character under the cursor, which might be wrong
// but it applies only to the checking dialog to be removed
xCursorProps = UnoRuntime.queryInterface(
XPropertySet.class,
xCursor.getText().createTextCursorByRange(xCursor.getStart()));
}
// The CharLocale and CharLocaleComplex properties may both be set, so we still cannot know
// whether the text is e.g. Khmer or Tamil (the only "complex text layout (CTL)" languages we support so far).
// Thus we check the text itself:
if (new KhmerDetector().isThisLanguage(xCursor.getText().getString())) {
return Languages.getLanguageForShortCode("km");
}
if (new TamilDetector().isThisLanguage(xCursor.getText().getString())) {
return Languages.getLanguageForShortCode("ta");
}
Object obj = xCursorProps.getPropertyValue("CharLocale");
if (obj == null) {
return Languages.getLanguageForShortCode("en-US");
}
charLocale = (Locale) obj;
boolean langIsSupported = false;
for (Language element : Languages.get()) {
if (charLocale.Language.equalsIgnoreCase(LIBREOFFICE_SPECIAL_LANGUAGE_TAG)
&& element.getShortCodeWithCountryAndVariant().equalsIgnoreCase(charLocale.Variant)) {
langIsSupported = true;
break;
}
if (element.getShortCode().equals(charLocale.Language)) {
langIsSupported = true;
break;
}
}
if (!langIsSupported) {
String message = Tools.i18n(messages, "language_not_supported", charLocale.Language);
JOptionPane.showMessageDialog(null, message);
return null;
}
} catch (Throwable t) {
MessageHandler.showError(t);
return null;
}
return getLanguage(charLocale);
}
|
java
|
@Nullable
public Language getLanguage() {
XComponent xComponent = OfficeTools.getCurrentComponent(xContext);
Locale charLocale;
XPropertySet xCursorProps;
try {
XModel model = UnoRuntime.queryInterface(XModel.class, xComponent);
if(model == null) {
return Languages.getLanguageForShortCode("en-US");
}
XTextViewCursorSupplier xViewCursorSupplier =
UnoRuntime.queryInterface(XTextViewCursorSupplier.class, model.getCurrentController());
XTextViewCursor xCursor = xViewCursorSupplier.getViewCursor();
if (xCursor.isCollapsed()) { // no text selection
xCursorProps = UnoRuntime.queryInterface(XPropertySet.class, xCursor);
} else { // text is selected, need to create another cursor
// as multiple languages can occur here - we care only
// about character under the cursor, which might be wrong
// but it applies only to the checking dialog to be removed
xCursorProps = UnoRuntime.queryInterface(
XPropertySet.class,
xCursor.getText().createTextCursorByRange(xCursor.getStart()));
}
// The CharLocale and CharLocaleComplex properties may both be set, so we still cannot know
// whether the text is e.g. Khmer or Tamil (the only "complex text layout (CTL)" languages we support so far).
// Thus we check the text itself:
if (new KhmerDetector().isThisLanguage(xCursor.getText().getString())) {
return Languages.getLanguageForShortCode("km");
}
if (new TamilDetector().isThisLanguage(xCursor.getText().getString())) {
return Languages.getLanguageForShortCode("ta");
}
Object obj = xCursorProps.getPropertyValue("CharLocale");
if (obj == null) {
return Languages.getLanguageForShortCode("en-US");
}
charLocale = (Locale) obj;
boolean langIsSupported = false;
for (Language element : Languages.get()) {
if (charLocale.Language.equalsIgnoreCase(LIBREOFFICE_SPECIAL_LANGUAGE_TAG)
&& element.getShortCodeWithCountryAndVariant().equalsIgnoreCase(charLocale.Variant)) {
langIsSupported = true;
break;
}
if (element.getShortCode().equals(charLocale.Language)) {
langIsSupported = true;
break;
}
}
if (!langIsSupported) {
String message = Tools.i18n(messages, "language_not_supported", charLocale.Language);
JOptionPane.showMessageDialog(null, message);
return null;
}
} catch (Throwable t) {
MessageHandler.showError(t);
return null;
}
return getLanguage(charLocale);
}
|
[
"@",
"Nullable",
"public",
"Language",
"getLanguage",
"(",
")",
"{",
"XComponent",
"xComponent",
"=",
"OfficeTools",
".",
"getCurrentComponent",
"(",
"xContext",
")",
";",
"Locale",
"charLocale",
";",
"XPropertySet",
"xCursorProps",
";",
"try",
"{",
"XModel",
"model",
"=",
"UnoRuntime",
".",
"queryInterface",
"(",
"XModel",
".",
"class",
",",
"xComponent",
")",
";",
"if",
"(",
"model",
"==",
"null",
")",
"{",
"return",
"Languages",
".",
"getLanguageForShortCode",
"(",
"\"en-US\"",
")",
";",
"}",
"XTextViewCursorSupplier",
"xViewCursorSupplier",
"=",
"UnoRuntime",
".",
"queryInterface",
"(",
"XTextViewCursorSupplier",
".",
"class",
",",
"model",
".",
"getCurrentController",
"(",
")",
")",
";",
"XTextViewCursor",
"xCursor",
"=",
"xViewCursorSupplier",
".",
"getViewCursor",
"(",
")",
";",
"if",
"(",
"xCursor",
".",
"isCollapsed",
"(",
")",
")",
"{",
"// no text selection",
"xCursorProps",
"=",
"UnoRuntime",
".",
"queryInterface",
"(",
"XPropertySet",
".",
"class",
",",
"xCursor",
")",
";",
"}",
"else",
"{",
"// text is selected, need to create another cursor",
"// as multiple languages can occur here - we care only",
"// about character under the cursor, which might be wrong",
"// but it applies only to the checking dialog to be removed",
"xCursorProps",
"=",
"UnoRuntime",
".",
"queryInterface",
"(",
"XPropertySet",
".",
"class",
",",
"xCursor",
".",
"getText",
"(",
")",
".",
"createTextCursorByRange",
"(",
"xCursor",
".",
"getStart",
"(",
")",
")",
")",
";",
"}",
"// The CharLocale and CharLocaleComplex properties may both be set, so we still cannot know",
"// whether the text is e.g. Khmer or Tamil (the only \"complex text layout (CTL)\" languages we support so far).",
"// Thus we check the text itself:",
"if",
"(",
"new",
"KhmerDetector",
"(",
")",
".",
"isThisLanguage",
"(",
"xCursor",
".",
"getText",
"(",
")",
".",
"getString",
"(",
")",
")",
")",
"{",
"return",
"Languages",
".",
"getLanguageForShortCode",
"(",
"\"km\"",
")",
";",
"}",
"if",
"(",
"new",
"TamilDetector",
"(",
")",
".",
"isThisLanguage",
"(",
"xCursor",
".",
"getText",
"(",
")",
".",
"getString",
"(",
")",
")",
")",
"{",
"return",
"Languages",
".",
"getLanguageForShortCode",
"(",
"\"ta\"",
")",
";",
"}",
"Object",
"obj",
"=",
"xCursorProps",
".",
"getPropertyValue",
"(",
"\"CharLocale\"",
")",
";",
"if",
"(",
"obj",
"==",
"null",
")",
"{",
"return",
"Languages",
".",
"getLanguageForShortCode",
"(",
"\"en-US\"",
")",
";",
"}",
"charLocale",
"=",
"(",
"Locale",
")",
"obj",
";",
"boolean",
"langIsSupported",
"=",
"false",
";",
"for",
"(",
"Language",
"element",
":",
"Languages",
".",
"get",
"(",
")",
")",
"{",
"if",
"(",
"charLocale",
".",
"Language",
".",
"equalsIgnoreCase",
"(",
"LIBREOFFICE_SPECIAL_LANGUAGE_TAG",
")",
"&&",
"element",
".",
"getShortCodeWithCountryAndVariant",
"(",
")",
".",
"equalsIgnoreCase",
"(",
"charLocale",
".",
"Variant",
")",
")",
"{",
"langIsSupported",
"=",
"true",
";",
"break",
";",
"}",
"if",
"(",
"element",
".",
"getShortCode",
"(",
")",
".",
"equals",
"(",
"charLocale",
".",
"Language",
")",
")",
"{",
"langIsSupported",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"langIsSupported",
")",
"{",
"String",
"message",
"=",
"Tools",
".",
"i18n",
"(",
"messages",
",",
"\"language_not_supported\"",
",",
"charLocale",
".",
"Language",
")",
";",
"JOptionPane",
".",
"showMessageDialog",
"(",
"null",
",",
"message",
")",
";",
"return",
"null",
";",
"}",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"MessageHandler",
".",
"showError",
"(",
"t",
")",
";",
"return",
"null",
";",
"}",
"return",
"getLanguage",
"(",
"charLocale",
")",
";",
"}"
] |
Checks the language under the cursor. Used for opening the configuration dialog.
@return the language under the visible cursor
|
[
"Checks",
"the",
"language",
"under",
"the",
"cursor",
".",
"Used",
"for",
"opening",
"the",
"configuration",
"dialog",
"."
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/MultiDocumentsHandler.java#L218-L279
|
19,199
|
languagetool-org/languagetool
|
languagetool-office-extension/src/main/java/org/languagetool/openoffice/MultiDocumentsHandler.java
|
MultiDocumentsHandler.setConfigValues
|
private void setConfigValues(Configuration config, JLanguageTool langTool) {
this.config = config;
this.langTool = langTool;
this.noMultiReset = config.isNoMultiReset();
for (SingleDocument document : documents) {
document.setConfigValues(config);
}
}
|
java
|
private void setConfigValues(Configuration config, JLanguageTool langTool) {
this.config = config;
this.langTool = langTool;
this.noMultiReset = config.isNoMultiReset();
for (SingleDocument document : documents) {
document.setConfigValues(config);
}
}
|
[
"private",
"void",
"setConfigValues",
"(",
"Configuration",
"config",
",",
"JLanguageTool",
"langTool",
")",
"{",
"this",
".",
"config",
"=",
"config",
";",
"this",
".",
"langTool",
"=",
"langTool",
";",
"this",
".",
"noMultiReset",
"=",
"config",
".",
"isNoMultiReset",
"(",
")",
";",
"for",
"(",
"SingleDocument",
"document",
":",
"documents",
")",
"{",
"document",
".",
"setConfigValues",
"(",
"config",
")",
";",
"}",
"}"
] |
Set config Values for all documents
|
[
"Set",
"config",
"Values",
"for",
"all",
"documents"
] |
b7a3d63883d242fb2525877c6382681c57a0a142
|
https://github.com/languagetool-org/languagetool/blob/b7a3d63883d242fb2525877c6382681c57a0a142/languagetool-office-extension/src/main/java/org/languagetool/openoffice/MultiDocumentsHandler.java#L305-L312
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.