use of org.jetbrains.annotations.Nullable in project languagetool by languagetool-org.
the class LanguageIdentifier method detectLanguageCode.
/**
* @return language or {@code null} if language could not be identified
*/
@Nullable
private String detectLanguageCode(String text) {
TextObject textObject = textObjectFactory.forText(text);
Optional<LdLocale> lang = languageDetector.detect(textObject);
//System.out.println(languageDetector.getProbabilities(textObject));
if (lang.isPresent()) {
return lang.get().getLanguage();
} else {
return null;
}
}
use of org.jetbrains.annotations.Nullable in project languagetool by languagetool-org.
the class SubjectVerbAgreementRule method getPluralMatchOrNull.
@Nullable
private RuleMatch getPluralMatchOrNull(AnalyzedTokenReadings[] tokens, int i, AnalyzedTokenReadings token, String tokenStr) {
if (plural.contains(tokenStr)) {
AnalyzedTokenReadings prevToken = tokens[i - 1];
List<ChunkTag> prevChunkTags = prevToken.getChunkTags();
boolean match = prevChunkTags.contains(NPS) && !prevChunkTags.contains(NPP) && !prevChunkTags.contains(PP) && !isCurrency(prevToken) && prevChunkIsNominative(tokens, i - 1) && !hasUnknownTokenToTheLeft(tokens, i) && !hasUnknownTokenToTheRight(tokens, i + 1) && // z.B. "Die Zielgruppe sind Männer." - beides Nominativ, aber 'Männer' ist das Subjekt
!isFollowedByNominativePlural(tokens, i + 1);
if (match) {
String message = "Bitte prüfen, ob hier <suggestion>" + getSingularFor(tokenStr) + "</suggestion> stehen sollte.";
return new RuleMatch(this, token.getStartPos(), token.getEndPos(), message);
}
}
return null;
}
use of org.jetbrains.annotations.Nullable in project languagetool by languagetool-org.
the class UppercaseNounReadingFilter method acceptRuleMatch.
@Nullable
@Override
public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> arguments, AnalyzedTokenReadings[] patternTokens) {
String token = arguments.get("token");
if (token == null) {
throw new RuntimeException("Set 'token' for filter " + UppercaseNounReadingFilter.class.getName() + " in rule " + match.getRule().getId());
}
try {
String uppercase = StringTools.uppercaseFirstChar(token);
List<AnalyzedTokenReadings> tags = tagger.tag(Collections.singletonList(uppercase));
boolean hasNounReading = false;
for (AnalyzedTokenReadings tag : tags) {
if (tag.hasPartialPosTag("SUB:") && !tag.hasPartialPosTag("ADJ")) {
hasNounReading = true;
break;
}
}
if (hasNounReading) {
return match;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return null;
}
use of org.jetbrains.annotations.Nullable in project languagetool by languagetool-org.
the class CatalanTagger method additionalTags.
@Nullable
protected List<AnalyzedToken> additionalTags(String word, IStemmer stemmer) {
final IStemmer dictLookup = new DictionaryLookup(getDictionary());
List<AnalyzedToken> additionalTaggedTokens = new ArrayList<>();
//Adjectiu femení singular o participi femení singular + -ment
if (word.endsWith("ment")) {
final String lowerWord = word.toLowerCase(conversionLocale);
final String possibleAdj = lowerWord.replaceAll("^(.+)ment$", "$1");
List<AnalyzedToken> taggerTokens;
taggerTokens = asAnalyzedTokenList(possibleAdj, dictLookup.lookup(possibleAdj));
for (AnalyzedToken taggerToken : taggerTokens) {
final String posTag = taggerToken.getPOSTag();
if (posTag != null) {
final Matcher m = ADJ_PART_FS.matcher(posTag);
if (m.matches()) {
additionalTaggedTokens.add(new AnalyzedToken(word, "RG", lowerWord));
return additionalTaggedTokens;
}
}
}
}
//Any well-formed verb with prefixes is tagged as a verb copying the original tags
Matcher matcher = PREFIXES_FOR_VERBS.matcher(word);
if (matcher.matches()) {
final String possibleVerb = matcher.group(2).toLowerCase();
List<AnalyzedToken> taggerTokens;
taggerTokens = asAnalyzedTokenList(possibleVerb, dictLookup.lookup(possibleVerb));
for (AnalyzedToken taggerToken : taggerTokens) {
final String posTag = taggerToken.getPOSTag();
if (posTag != null) {
final Matcher m = VERB.matcher(posTag);
if (m.matches()) {
String lemma = matcher.group(1).toLowerCase().concat(taggerToken.getLemma());
additionalTaggedTokens.add(new AnalyzedToken(word, posTag, lemma));
}
}
}
return additionalTaggedTokens;
}
// U+0140 LATIN SMALL LETTER L WITH MIDDLE DOT
if (word.contains("ŀ") || word.contains("Ŀ")) {
final String lowerWord = word.toLowerCase(conversionLocale);
final String possibleWord = lowerWord.replaceAll("ŀ", "l·");
List<AnalyzedToken> taggerTokens = asAnalyzedTokenList(word, dictLookup.lookup(possibleWord));
return taggerTokens;
}
return null;
}
use of org.jetbrains.annotations.Nullable in project languagetool by languagetool-org.
the class SubjectVerbAgreementRule method getSingularMatchOrNull.
@Nullable
private RuleMatch getSingularMatchOrNull(AnalyzedTokenReadings[] tokens, int i, AnalyzedTokenReadings token, String tokenStr) throws IOException {
if (singular.contains(tokenStr)) {
AnalyzedTokenReadings prevToken = tokens[i - 1];
AnalyzedTokenReadings nextToken = i + 1 < tokens.length ? tokens[i + 1] : null;
List<ChunkTag> prevChunkTags = prevToken.getChunkTags();
boolean match = prevChunkTags.contains(NPP) && !prevChunkTags.contains(PP) && // 'um 18 Uhr ist Feierabend'
!prevToken.getToken().equals("Uhr") && !isCurrency(prevToken) && // 'zehn Jahre ist es her'
!(nextToken != null && nextToken.getToken().equals("es")) && prevChunkIsNominative(tokens, i - 1) && !hasUnknownTokenToTheLeft(tokens, i) && !hasQuestionPronounToTheLeft(tokens, i - 1) && !containsRegexToTheLeft("wer", tokens, i - 1) && !containsRegexToTheLeft("(?i)alle[nr]?", tokens, i - 1) && !containsRegexToTheLeft("(?i)jede[rs]?", tokens, i - 1) && !containsRegexToTheLeft("(?i)manche[nrs]?", tokens, i - 1) && !containsOnlyInfinitivesToTheLeft(tokens, i - 1);
if (match) {
String message = "Bitte prüfen, ob hier <suggestion>" + getPluralFor(tokenStr) + "</suggestion> stehen sollte.";
return new RuleMatch(this, token.getStartPos(), token.getEndPos(), message);
}
}
return null;
}
Aggregations