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

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

PARSER GUIDELINE

S 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:格式类似于penn

Words:只给出分词格式。如:

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

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

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

rootSymbolOnly:只给出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 -parserFile

englishPCFG.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)

相关文档
最新文档