将CoreNlp句子与多个SemgrexPatterns相匹配

时间:2019-01-19 08:27:11

标签: java nlp stanford-nlp

我想将我的句子与多个CoreNlp SemgrexPatterns相匹配。 我可能有30多个SemgrexPattern,我想看看哪种模式与句子匹配。

我尝试使用嵌套的if- else将句子与每个匹配项进行比较。

SemanticGraph dependencies = sentence.get(SemanticGraphCoreAnnotations.EnhancedPlusPlusDependenciesAnnotation.class);
SemgrexPattern pat = SemgrexPattern.compile("A <dobj B");
SemgrexMatcher mat = pat.matcher(dependencies, true);
        if(mat.find())
        {
                // some code
        }
        else
         {
            SemgrexPattern pat2 = SemgrexPattern.compile("A >nmod B");
            SemgrexMatcher mat2 = pat2.matcher(dependencies, true);
            if(mat2.find())
            {
                // some code
            }
            else
            {
                SemgrexPattern pat3 = SemgrexPattern.compile("A >someotherrelation B");
                SemgrexMatcher mat3 = pat3.matcher(dependencies, true);
                if(mat3.find())
                {
                // some code
                }
                  else
                     {
                       System.out.println("Sentence doesnt match against any pattern");
                     }

              }
         }

有一些简单的方法可以做到这一点。喜欢使用循环和列表? 还是一些预定义的方法来匹配corenlp库中多个模式的句子?

0 个答案:

没有答案
相关问题