您所查詢的是好的,但斯坦福解析器不支持此尚未(版本3.6.0)。
以下代碼在使用法語模式時會打印「false」。您正在使用的命令會在內部檢查此內容,並在虛假時安靜地避免分析。
System.out.println(
LexicalizedParser
.loadModel("frenchFactored.ser.gz")
.treebankLanguagePack()
.supportsGrammaticalStructures()
);
這就是爲什麼我使用麥芽解析器(http://www.maltparser.org/)。
如果你喜歡的以下輸出:
1 Je Je C CLS null 2 suj _ _
2 mange mange V V null 0 root _ _
3 des des P P null 2 mod _ _
4 pommes pommes N N null 3 obj _ _
5 . . P PUNC null 2 mod _ _
然後使用以下代碼生成它(不能簡單地使用命令行)。我使用這兩個斯坦福大學和麥芽來實現:
LexicalizedParser lexParser = LexicalizedParser.loadModel("frenchFactored.ser.gz");
TokenizerFactory<CoreLabel> tokenizerFactory = PTBTokenizer.factory(new CoreLabelTokenFactory(), "");
ConcurrentMaltParserModel parserModel = ConcurrentMaltParserService.initializeParserModel(new File("fremalt-1.7.mco"));
Tokenizer<CoreLabel> tok = tokenizerFactory.getTokenizer(new StringReader("Je mange des pommes."));
List<CoreLabel> rawWords2 = tok.tokenize();
Tree parse = lexParser.apply(rawWords2);
// The malt parser requires token in the MaltTab format (Connll).
// Instead of using the Stanford tagger, we could have used Melt or another parser.
String[] tokens = parse.taggedLabeledYield().stream()
.map(word -> {
CoreLabel w = (CoreLabel)word;
String lemma = Morphology.lemmatizeStatic(new WordTag(w.word(), w.tag())).word();
String tag = w.value();
return String.join("\t", new String[]{
String.valueOf(w.index()+1),
w.word(),
lemma != null ? lemma : w.word(),
tag != null ? String.valueOf(tag.charAt(0)) : "_",
tag != null ? tag : "_"
});
})
.toArray(String[]::new);
ConcurrentDependencyGraph graph = parserModel.parse(tokens);
System.out.println(graph);
從那裏,你可以通過編程方式使用遍歷圖形:
graph.nTokenNodes()
如果你使用Maven,只需添加以下依賴你POM:
<dependency>
<groupId>org.maltparser</groupId>
<artifactId>maltparser</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.6.0</version>
</dependency>
獎勵:進口
import org.maltparser.concurrent.ConcurrentMaltParserModel;
import org.maltparser.concurrent.ConcurrentMaltParserService;
import org.maltparser.concurrent.graph.ConcurrentDependencyGraph;
import org.maltparser.concurrent.graph.ConcurrentDependencyNode;
import org.maltparser.core.exception.MaltChainedException;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.ling.WordTag;
import edu.stanford.nlp.parser.lexparser.LexicalizedParser;
import edu.stanford.nlp.process.CoreLabelTokenFactory;
import edu.stanford.nlp.process.Morphology;
import edu.stanford.nlp.process.PTBTokenizer;
import edu.stanford.nlp.process.Tokenizer;
import edu.stanford.nlp.process.TokenizerFactory;
import edu.stanford.nlp.trees.Tree;
超:fremalt-1.7.mco文件
http://www.maltparser.org/mco/french_parser/fremalt.html
感謝您的回覆! – starckman
我給這個命令:java -mx1g -cp stanford-corenlp-3.7.0.jar:stanford-french-corenlp-2016-10-31-models.jar edu.stanford.nlp.pipeline.StanfordCoreNLP -props StanfordCoreNLP-french .properties -annotators tokenize,ssplit,pos,depparse -file /Users/Rafael/Desktop/LANGAGES/CORPUS/Sentences_FR/3aube_schtrouFR30.txt -outputFormat sortie.txt但我得到這個錯誤信息無法打開「edu/stanford/nlp/models/pos-tagger/french/french.tagger「作爲類路徑,文件名或URL – starckman
這些jar文件是否存在於您運行此命令的目錄中。你得到這個錯誤是因爲某些原因,法語模型jar不在你的CLASSPATH中。如果你在法語模型jar上做了jar -tf,你會看到標記文件存在。 – StanfordNLPHelp