Search in sources :

Example 11 with Nullable

use of org.jetbrains.annotations.Nullable in project languagetool by languagetool-org.

the class PatternRuleQueryBuilder method getPosQueryOrNull.

@Nullable
private BooleanClause getPosQueryOrNull(PatternToken patternToken, String pos) throws UnsupportedPatternRuleException {
    if (pos == null || pos.isEmpty()) {
        return null;
    }
    Query posQuery;
    Term posQueryTerm;
    if (patternToken.getPOSNegation() || patternToken.getMinOccurrence() == 0) {
        // we need to ignore this - negation, if any, must happen at the same position
        return null;
    } else if (patternToken.isPOStagRegularExpression()) {
        posQueryTerm = getQueryTerm(patternToken, POS_PREFIX + "(", pos, ")");
        posQuery = getRegexQuery(posQueryTerm, pos, patternToken);
    } else {
        posQueryTerm = getQueryTerm(patternToken, POS_PREFIX, pos, "");
        posQuery = new TermQuery(posQueryTerm);
    }
    return new BooleanClause(posQuery, BooleanClause.Occur.MUST);
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanNearQuery(org.apache.lucene.search.spans.SpanNearQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Term(org.apache.lucene.index.Term) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with Nullable

use of org.jetbrains.annotations.Nullable in project languagetool by languagetool-org.

the class JLanguageTool method getBuildDate.

/**
   * Returns the build date or {@code null} if not run from JAR.
   */
@Nullable
private static String getBuildDate() {
    try {
        URL res = JLanguageTool.class.getResource(JLanguageTool.class.getSimpleName() + ".class");
        if (res == null) {
            // this will happen on Android, see http://stackoverflow.com/questions/15371274/
            return null;
        }
        Object connObj = res.openConnection();
        if (connObj instanceof JarURLConnection) {
            JarURLConnection conn = (JarURLConnection) connObj;
            Manifest manifest = conn.getManifest();
            return manifest.getMainAttributes().getValue("Implementation-Date");
        } else {
            return null;
        }
    } catch (IOException e) {
        throw new RuntimeException("Could not get build date from JAR", e);
    }
}
Also used : JarURLConnection(java.net.JarURLConnection) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) URL(java.net.URL) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with Nullable

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;
    }
}
Also used : LdLocale(com.optimaize.langdetect.i18n.LdLocale) TextObject(com.optimaize.langdetect.text.TextObject) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with Nullable

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;
}
Also used : ChunkTag(org.languagetool.chunking.ChunkTag) AnalyzedTokenReadings(org.languagetool.AnalyzedTokenReadings) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with Nullable

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;
}
Also used : IOException(java.io.IOException) AnalyzedTokenReadings(org.languagetool.AnalyzedTokenReadings) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Nullable (org.jetbrains.annotations.Nullable)4642 VirtualFile (com.intellij.openapi.vfs.VirtualFile)810 PsiElement (com.intellij.psi.PsiElement)485 File (java.io.File)399 Project (com.intellij.openapi.project.Project)396 PsiFile (com.intellij.psi.PsiFile)319 NotNull (org.jetbrains.annotations.NotNull)257 IOException (java.io.IOException)243 Module (com.intellij.openapi.module.Module)227 ArrayList (java.util.ArrayList)169 TextRange (com.intellij.openapi.util.TextRange)156 Document (com.intellij.openapi.editor.Document)124 List (java.util.List)111 ASTNode (com.intellij.lang.ASTNode)105 IElementType (com.intellij.psi.tree.IElementType)103 XmlTag (com.intellij.psi.xml.XmlTag)96 Editor (com.intellij.openapi.editor.Editor)94 Element (org.jdom.Element)93 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)86 XmlFile (com.intellij.psi.xml.XmlFile)78