Search in sources :

Example 16 with Nullable

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;
}
Also used : AnalyzedToken(org.languagetool.AnalyzedToken) Matcher(java.util.regex.Matcher) IStemmer(morfologik.stemming.IStemmer) ArrayList(java.util.ArrayList) DictionaryLookup(morfologik.stemming.DictionaryLookup) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with Nullable

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

Example 18 with Nullable

use of org.jetbrains.annotations.Nullable in project cassandra-mesos-deprecated by mesosphere.

the class SeedManagerTest method before.

@Before
public void before() {
    InMemoryState state = new InMemoryState();
    PersistedCassandraFrameworkConfiguration config = new PersistedCassandraFrameworkConfiguration(state, "name", 60, 30, "2.1", 0.5, 1024, 1024, 512, 1, 1, "role", "./backup", ".", false, true, "RACK1", "DC1", Arrays.asList(ExternalDc.newBuilder().setName("dc").setUrl("http://dc").build()), "name");
    seedManager = new SeedManager(config, new ObjectMapper(), new SystemClock()) {

        @Override
        @Nullable
        protected JsonNode fetchJson(@NotNull final String url) {
            try {
                return new ObjectMapper().readTree(jsonResponse);
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }
    };
}
Also used : SystemClock(io.mesosphere.mesos.util.SystemClock) InMemoryState(org.apache.mesos.state.InMemoryState) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Nullable(org.jetbrains.annotations.Nullable) Before(org.junit.Before)

Example 19 with Nullable

use of org.jetbrains.annotations.Nullable in project android-parcelable-intellij-plugin by mcharmas.

the class GenerateDialog method createSouthPanel.

@Nullable
@Override
protected JComponent createSouthPanel() {
    JComponent southPanel = super.createSouthPanel();
    if (showCheckbox && southPanel != null) {
        final VerticalBox combinedView = new VerticalBox();
        combinedView.add(includeSubclasses);
        combinedView.add(southPanel);
        return combinedView;
    } else {
        return southPanel;
    }
}
Also used : VerticalBox(com.intellij.ui.components.panels.VerticalBox) JComponent(javax.swing.JComponent) Nullable(org.jetbrains.annotations.Nullable)

Example 20 with Nullable

use of org.jetbrains.annotations.Nullable in project scss-lint-plugin by idok.

the class ActualFile method getOrCreateActualFile.

@Nullable
public static ActualFile getOrCreateActualFile(@NotNull Key<ThreadLocalActualFile> key, @NotNull VirtualFile virtualFile, @Nullable String content) {
    FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
    if (!fileDocumentManager.isFileModified(virtualFile)) {
        File file = new File(virtualFile.getPath());
        if (file.isFile()) {
            return new ActualFile(file);
        }
    }
    ThreadLocalActualFile threadLocal = key.get(virtualFile);
    if (threadLocal == null) {
        threadLocal = virtualFile.putUserDataIfAbsent(key, new ThreadLocalActualFile(virtualFile));
    }
    File file = threadLocal.getOrCreateFile();
    if (file == null) {
        return null;
    }
    if (content == null) {
        Document document = fileDocumentManager.getDocument(virtualFile);
        if (document != null) {
            content = document.getText();
        }
    }
    if (content == null) {
        return null;
    }
    try {
        FileUtil.writeToFile(file, content);
        return new ActualFile(new File(virtualFile.getPath()), file);
    } catch (IOException e) {
        LOG.warn("Can not write to " + file.getAbsolutePath(), e);
    }
    return null;
}
Also used : FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) Document(com.intellij.openapi.editor.Document) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) 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