stanford parser 使用

Stanford Parser

1         处理一个中文的句子:

例如:一些盗版制品经营者为了应付和躲避打击,经营手法更为隐蔽。

首先, 使用Chinese segment  进行词语的切分。

调用的命令:

G:/chinesesegmenter>segment.bat pk input.txt gb18030 > out.txt

其中 pk 是词典 还有一个词典是ctb (没有比较过两个词典的优劣)

input.txt 是输入文件.里面包含该句子

gb18030 是文件编码 还支持GB utf-8

out.txt 是输出的文件

结果:一些 盗版 制品 经营者 为了 应付 躲避 打击 经营 手法 更为 隐蔽

2         词性标注 生成 依存关系

这里为方便生成一个批处理文件:lexparserCh.bat

文件内容:

@echo off

:: Runs the Chinese PCFG parser on one or more files, printing trees only

:: usage: lexparser fileToparse

java -server -mx800m -cp "stanford-parser.jar;" edu.stanford.nlp.parser.lexparser.LexicalizedParser -outputFormat "penn,typedDependenciesCollapsed" chineseFactored.ser.gz %1

---------------------------------------------------------------------------------------------------------------------------

调用的命令:

G:/stanfordparser>lexparserCh.bat input.txt>outputch.txt

Loading parser from serialized file chineseFactored.ser.gz ... done [30.2 sec].

Parsing file: input.txt with 1 sentences.

Parsing [sent. 1 len. 15]: 一些 盗版 制品 经营者 为了 应付 躲避 打击 经营

手法 更为 隐蔽

Parsed file: input.txt [1 sentences].

Parsed 15 words in 1 sentences (3.35 wds/sec; 0.22 sents/sec).

其中,chineseFactored.ser.gz 是用于中文的parser

 

结果:outputch.txt 文件

ROOT

  (IP

    (NP

      (NP

        (QP (CD 一些))

        (NP (NN 盗版) (NN 制品)))

      (NP (NN 经营者)))

    (PP (P 为了)

      (IP

        (VP

          (VP (VV 应付))

          (CC )

          (VP (VV 躲避)

            (NP (NN 打击))))))

    (PU )

    (NP (NN 经营) (NN 手法))

    (VP

      (ADVP (AD 更为))

      (VP (VV 隐蔽)))

    (PU )))

 

numod(制品-3, 一些-1)

nmod(制品-3, 盗版-2)

nmod(经营者-4, 制品-3)

nsubj(隐蔽-14, 经营者-4)

prep(隐蔽-14, 为了-5)

clmpd(为了-5, 应付-6)

cc(应付-6, -7)

ccomp(应付-6, 躲避-8)

dobj(躲避-8, 打击-9)

nmod(手法-12, 经营-11)

nsubj(隐蔽-14, 手法-12)

advmod(隐蔽-14, 更为-13)

3、图形工具界面

运行命令:lexparser-gui.bat

首先load parser

然后选择文件,必须是utf-8编码的,而且是分词过后的。

Language 选择中文。

最后 parser 得到结果的树形表示。

 

  parser
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
About A natural language parser is a program that works out the grammatical structure of sentences, for instance, which groups of words go together (as "phrases") and which words are the subject or object of a verb. Probabilistic parsers use knowledge of language gained from hand-parsed sentences to try to produce the most likely analysis of new sentences. These statistical parsers still make some mistakes, but commonly work rather well. Their development was one of the biggest breakthroughs in natural language processing in the 1990s. You can try out our parser online. This package is a Java implementation of probabilistic natural language parsers, both highly optimized PCFG and lexicalized dependency parsers, and a lexicalized PCFG parser. The original version of this parser was mainly written by Dan Klein, with support code and linguistic grammar development by Christopher Manning. Extensive additional work (internationalization and language-specific modeling, flexible input/output, grammar compaction, lattice parsing, k-best parsing, typed dependencies output, user support, etc.) has been done by Roger Levy, Christopher Manning, Teg Grenager, Galen Andrew, Marie-Catherine de Marneffe, Bill MacCartney, Anna Rafferty, Spence Green, Huihsin Tseng, Pi-Chuan Chang, Wolfgang Maier, and Jenny Finkel. The lexicalized probabilistic parser implements a factored product model, with separate PCFG phrase structure and lexical dependency experts, whose preferences are combined by efficient exact inference, using an A* algorithm. Or the software can be used simply as an accurate unlexicalized stochastic context-free grammar parser. Either of these yields a good performance statistical parsing system. A GUI is provided for viewing the phrase structure tree output of the parser. As well as providing an English parser, the parser can be and has been adapted to work with other languages. A Chinese parser based on the Chinese Treebank, a German parser based on the Negra corpus and Arabic parsers based on the Penn Arabic Treebank are also included. The parser has also been used for other languages, such as Italian, Bulgarian, and Portuguese. The parser provides Stanford Dependencies output as well as phrase structure trees. Typed dependencies are otherwise known grammatical relations. This style of output is available only for English and Chinese. For more details, please refer to the Stanford Dependencies webpage. The current version of the parser requires Java 6 (JDK1.6) or later. (You can also download an old version of the parser, version 1.4, which runs under JDK 1.4, or version 2.0 which runs under JDK 1.5, but those distributions are no longer supported.) The parser also requires a reasonable amount of memory (at least 100MB to run as a PCFG parser on sentences up to 40 words in length; typically around 500MB of memory to be able to parse similarly long typical-of-newswire sentences using the factored model). The parser is available for download, licensed under the GNU General Public License (v2 or later). Source is included. The package includes components for command-line invocation, a Java parsing GUI, and a Java API. The parser code is dual licensed (in a similar manner to MySQL, etc.). Open source licensing is under the full GPL, which allows many free uses. For distributors of proprietary software, commercial licensing with a ready-to-sign agreement is available. If you don't need a commercial license, but would like to support maintenance of these tools, we welcome gift funding. The download is a 54 MB zipped file (mainly consisting of included grammar data files). If you unpack the zip file, you should have everything needed. Simple scripts are included to invoke the parser on a Unix or Windows system. For another system, you merely need to similarly configure the classpath.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值