あなたはそうです:ANTLRはこのようなものにはあまり適していません。
私はNLTKの経験はありませんが、あまりうまくいきませんでした。
Stanford Natural Language Processing Groupには、優れたNLパーサーがあります。つまり、私はそれについて良いことを聞いてきました、私は決してNLPの専門家ではありません!
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.objectbank.*;
import edu.stanford.nlp.parser.lexparser.*;
import edu.stanford.nlp.process.*;
import edu.stanford.nlp.trees.*;
import java.io.*;
import java.util.*;
public class StanfordParserDemo {
public static void main(String[] args) throws Exception {
// englishPCFG.ser.gz is in the download.
LexicalizedParser parser = new LexicalizedParser("/path/to/englishPCFG.ser.gz");
TokenizerFactory<Word> tokenFactory = PTBTokenizer.factory(false, new WordTokenFactory());
String sentence = "I am currently writing an NLP project in Java that tags and parses text.";
System.out.println("Sentence: " + sentence);
List<Word> words = tokenFactory.getTokenizer(new StringReader(sentence)).tokenize();
parser.parse(words);
Tree tree = parser.getBestParse();
TreePrint treePrinter = new TreePrint("penn,typedDependenciesCollapsed");
treePrinter.printTree(tree);
}
}
出力します:
Sentence: I am currently writing an NLP project in java that tags and parses text.
(ROOT
(S
(NP (PRP I))
(VP (VBP am)
(ADVP (RB currently))
(VP (VBG writing)
(NP (DT an) (NNP NLP) (NN project))
(PP (IN in)
(NP (NN java)))
(SBAR (IN that)
(S
(NP (NNS tags)
(CC and)
(NNS parses))
(VP (VBZ text))))))
(. .)))
をさまざまな言語のためのJARと文法がhereをダウンロードすることができます。ここ
あなたは"I am currently writing an NLP project in Java that tags and parses text."
のような簡単な英語の文章を解析できる方法です。
ANTLRなどの正式な言語用の解析ツールをNLPツールに強制することは、決して実際には機能しません。彼らは文法の頻繁な更新はもちろんのこと、自然言語で起こる曖昧さに対処するようには設計されていません。 –