输出格式由传递给Stanford Parser的TreePrint
构造函数的formatString
决定。
你得到一个是 “ONELINE” 选项:
(NP (DT the) (JJ dallas) (NN country) (NN club))
(NP (NP (CD 25) (NN cent)) (NP (NNP bingo)))
你想要的是 “字”:
the dallas country club
25 cent bingo
按照TreePrint javadoc,已知格式是:
oneline, penn, latexTree, xmlTree, words, wordsAndTags, rootSymbolOnly,
dependencies, typedDependencies, typedDependenciesCollapsed, collocations,
semanticGraph, conllStyleDependencies, conll2007
这个来自Stanford Parser homepage的例子展示了如何在co上设置它使用-outputFormat
标志mmand行:
java -mx200m edu.stanford.nlp.parser.lexparser.LexicalizedParser
-retainTMPSubcategories -outputFormat "wordsAndTags,penn,typedDependencies"
englishPCFG.ser.gz mumbai.txt
感谢@Diosjenin:这种反应是非常全面和伟大。它工作得很好。唯一需要的编辑是在解析器中我们有(NP(PRP $我们))(NN经济),所以这个解决方案将删除(PRP $我们),这是不正确的。通过删除所有$符号这种方法准确地工作 – user3147590
@ user3147590,因为情况是这样的:在执行之前,不要删除$ s,你可以添加一个转义的$'\\ $'并在大写字母匹配后标记为可选的'?'。新的正则表达式将读为'(?<= \\ [AZ] {2,3} \\ $?)[^ \\(\\)] +',它将与“(PRP $ our)”中的“我们”相匹配 – Diosjenin