当前位置:文档之家› 句法分析工具指南(parser guideline)

句法分析工具指南(parser guideline)

PARSER GUIDELINES tanford parser一个简易的Stanford parser系统只需要包含四类文件,它们分别是:①java包(最新版本为stanford-parser-2011-04-20.jar)、②模板(英文:englishFactored.ser.gz/englishPCFG.ser.gz/wsjFactored.ser.gz/wsjPCFG.ser.gz。

中文:chinesePCFG.ser.gz /chineseFactored.ser.gz/xinhuaFactored.ser.gz/xinhuaPCFG.ser.gz)、③输入文件(一般为.txt后缀的分词文件(、④输出文件(一般为.parse后缀的成分句法树文件或是以.dep 后缀的依存句法树文件)1.英文句法分析举例:Java -mx1g -cp stanford-parser-2011-04-20.jar edu.stanford.nlp.parser.lexparser.LexicalizedParser -maxLength 100 –outputFormat oneline -sentences newline -outputFormatOptions removeTopBracket englishFactored.ser.gz input.txt > output.std_Factored_parse参数解释:①-mx1g:给java虚拟机分配的最大内存为1g(大小可自行设置)。

②-cp :为了加载java包stanford-parser-2011-04-20.jar。

LexicalizedParser:parser类.③-maxLength:指定句子单词长度最大为100。

④–outputFormat:指定输出句子的格式。

outputFormat具体选项值如下:Oneline:成分句法分析输出文件的格式为每行一句的广义表形式的树结构。

Penn:成分句法分析输出文件的格式为层次化树的形式。

默认选项为penn。

latexTree:格式类似于pennWords:只给出分词格式。

如:继续播报详细的新闻内容。

wordsAndTags:给出分词文本和标记。

如:继续/VV 播报/VV 详细/VA 的/DEC 新闻/NN 内容/NN 。

/PUrootSymbolOnly:只给出ROOT结点typedDependencies:给出依存句法分析结果。

mmod(播报-2, 继续-1)rcmod(内容-6, 详细-3)cpm(详细-3, 的-4)nn(内容-6, 新闻-5)dobj(播报-2, 内容-6)conllStyleDependencies、conll2008:conll格式(每行一词,每词十项)如下:1 继续_ VV _ _2 _ _ _2 播报_ VV _ _ 0 _ _ _3 详细_ VA _ _4 _ _ _4 的_ DEC _ _ 6 _ _ _5 新闻_ NN _ _6 _ _ _6 内容_ NN _ _ 2 _ _ _7 。

_ PU _ _ 2 _ _ _⑤-escaper:字符的标准化(例如将英文的”(”改成”-LRB-”,默认情况即这样转换)。

英文的escaper为edu.stanford.nlp.process.PTBEscapingProcessor。

中文为:edu.stanford.nlp.trees.international.pennchinese.ChineseEscaper。

举例:java -mx500m -cp stanford-parser.jar edu.stanford.nlp.parser.lexparser.LexicalizedParser -escaper edu.stanford.nlp.trees.international.pennchinese.ChineseEscaper -sentences newline chineseFactored.ser.gz chinese-onesent > chinese-onesent.stp⑥-sentences:指定句子之间的边界,一般为newline :输入文件的句子通过换行符分割。

Parser得到的文本是每行一句,一句一句的进行分析。

⑦-encoding:指定输入输出文件的字符集。

(中文默认为GB18030)⑧-outputFormatOptions:进一步控制各种–outputFormat选项的输出行为(可以说是–outputFormat的附加选项)。

当–outputFormat为typedDependencies时,-outputFormatOptions可有如下选项(默认选项为collapsed dependencyies):basicDependencies:基本格式treeDependencies:以树结构保存的压缩依存关系(去除依存图中一些边构成树)。

collapsedDependencies:压缩依存(不一定为树结构)cc(makes-11, and-12)conj(makes-11, distributes-13)转化为:Conj_and(makes-11, distributes-13)CCPropagatedDependencies:带有连词依存传播的压缩依存。

⑨-writeOutputFiles:产生对应于输入文件的输出文件,输出文件名同输入文件,只是增加了”.stp”的后缀。

-outputFilesExtension:指定输出文件扩展名,默认为”.stp”⑩-outputFilesDirectory :指定输出文件目录,默认为当前目录。

在这一小节中,我们用到的parser类为parser.lexparser.LexicalizedParser,这个类既能生成基于短语结构的成分句法树(指定输出格式为penn或oneline),又可以生成基于依存结构的依存句法树(指定输出格式为typedDependencies)。

接下来,我们用到的类名为:trees.EnglishGrammaticalStructure。

我们使用这个类将已经是成分句法树结构(penn Treebank-style trees)转化为依存句法树结构。

这里的成分句法树来源,既可以是stanford parser生成的,又可以是其他种类的parser(如:berkeley parser、charniak parser)生成的。

2.依存句法分析举例:java -mx1g -cp "stanford-parser.jar;" edu.stanford.nlp.trees.EnglishGrammaticalStructure-treeFile input.tree -basic -collapsed -extraSep -keepPunct -parserFileenglishPCFG.ser.gz >output.deptree选项解释(与LexicalizedParser相同的选项省略)输出文件的树结构可以通过以下参数直接指定:-basic:basic dependencies-conllx :basic dependencies printed out in CoNLL X (CoNLL 2006) format-collapsed:collapsed dependencies (not necessarily a tree structure)-CCprocessed:collapsed dependencies with propagation of conjunctdependencies (not necessarily a tree structure)-collapsedTree:collapsed dependencies that preserve a tree structure-nonCollapsed:non-collapsed dependencies: basic dependencies as well as the extra ones which do not preserve a tree structure其他参数:-treeFile:指定输入文件,即成分句法树结构文件。

-extraSep:如果存在多种类型的输出格式,使用分隔符(------)将basicdependencies和其他形式的分隔开。

-keepPunct:默认不输出符号依存关系,可以通过该选项保留。

3. trees.EnglishGrammaticalStructure其他功能①trees.EnglishGrammaticalStructure还可以将CoNLL格式的依存关系转化为其他类型的依存关系。

可以通过-conllxFile来指定输入文件。

②它还可以parse分词文档,不过对输入文件的要求更高。

必须是每行一句。

只能指定依存类型,不能指定其他选项。

用-sentFile替代-treeFile指定输入文件,需要用-parserFile 选项指定模板文件,使用-parseTree选项打印句法树。

举例:java -mx100m edu.stanford.nlp.trees.EnglishGrammaticalStructure -sentFile file.txt-collapsedTree -CCprocessed -parseTree –parserFile englishPCFG.ser.gz4.中英文模板说明Stanford parser不需要我们自己训练模板,它为我们提供了现成的模板。

英文模板:englishFactored.ser.gz/englishPCFG.ser.gz/wsjFactored.ser.gz/wsjPCFG.ser.gzenglishPCFG.ser.gz仅仅包含一个未词汇化的概率上下文无关文法。

englishFactored.ser.gz包含两种语法(a (simpler) PCFG parser and then an untyped dependency parser)。

对英文来说,虽然上述两种模板的语法和分析方法都不同,但是两者的平均性能相似。

所以,一般倾向于使用快一点的模板englishPCFG.ser.gz。

对于其他语言(如中文),由于factored模板包含词汇化信息,factored类型模板的性能也明显的好于PCFG模板的性能。

中文模板:Xinhua grammars只在中国大陆《新华日报》语料中训练,更适合解析来自中国大陆的文本。

相关主题