Scala中的词性标注
我尝试使用斯坦福语法分析器在Scala中对一个句子进行POS标记,如下所示Scala中的词性标注,scala,nlp,stanford-nlp,pos-tagger,Scala,Nlp,Stanford Nlp,Pos Tagger,我尝试使用斯坦福语法分析器在Scala中对一个句子进行POS标记,如下所示 val lp:LexicalizedParser = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz"); lp.setOptionFlags("-maxLength", "50", "-retainTmpSubcategories") val s = "I love to play" val parse
val lp:LexicalizedParser = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz");
lp.setOptionFlags("-maxLength", "50", "-retainTmpSubcategories")
val s = "I love to play"
val parse :Tree = lp.apply(s)
val taggedWords = parse.taggedYield()
println(taggedWords)
我得到一个错误类型不匹配;找到:java. Lang.Stand需要:java .U.L.List[[ P> > ],您可能会考虑FATTROION工具包()。它是一个通用的机器学习和图形模型库,它包含了一个广泛的自然语言处理组件套件。(标记化、标记规范化、形态分析、句子切分、词性标注、命名实体识别、依存分析、提及查找、共指代) 此外,它完全是用Scala编写的,并且是根据Apache许可证发布的 目前文档很少,但在未来几个月将有所改进 例如,基于Maven的安装完成后,可以在命令行中键入:
bin/fac nlp --pos1 --parser1 --ner1
要启动套接字侦听多线程NLP服务器,请执行以下操作。然后通过将纯文本传送到其套接字编号进行查询:
echo "Mr. Jones took a job at Google in New York. He and his Australian wife moved from New South Wales on 4/1/12." | nc localhost 3228
然后输出为
1 1 Mr. NNP 2 nn O
2 2 Jones NNP 3 nsubj U-PER
3 3 took VBD 0 root O
4 4 a DT 5 det O
5 5 job NN 3 dobj O
6 6 at IN 3 prep O
7 7 Google NNP 6 pobj U-ORG
8 8 in IN 7 prep O
9 9 New NNP 10 nn B-LOC
10 10 York NNP 8 pobj L-LOC
11 11 . . 3 punct O
12 1 He PRP 6 nsubj O
13 2 and CC 1 cc O
14 3 his PRP$ 5 poss O
15 4 Australian JJ 5 amod U-MISC
16 5 wife NN 6 nsubj O
17 6 moved VBD 0 root O
18 7 from IN 6 prep O
19 8 New NNP 9 nn B-LOC
20 9 South NNP 10 nn I-LOC
21 10 Wales NNP 7 pobj L-LOC
22 11 on IN 6 prep O
23 12 4/1/12 NNP 11 pobj O
24 13 . . 6 punct O
当然,所有这些功能都有一个编程API
import cc.factorie._
import cc.factorie.app.nlp._
val doc = new Document("Education is the most powerful weapon which you can use to change the world.")
DocumentAnnotatorPipeline(pos.POS1).process(doc)
for (token <- doc.tokens)
println("%-10s %-5s".format(token.string, token.posLabel.categoryValue))
我相信Stanford解析器的API已经发生了一些变化,有时也是如此。
apply
有签名,public Tree apply(java.util.List我发现了一种在Scala中进行词性标记的非常简单的方法
步骤1
从下面的链接下载stanford tagger 3.2.0版
步骤2
将文件夹中的stanford postaggerjar添加到项目中,并将english-left3words-distsim.tagger文件放置在项目的models文件夹中
然后,使用下面的代码,您可以在Scala中对句子进行pos标记
val tagger = new MaxentTagger(
"english-left3words-distsim.tagger")
val art_con = "My name is Rahul"
val tagged = tagger.tagString(art_con)
println(tagged)
输出:My_PRP$name_NN is_VBZ Rahul_NNP我刚刚在构建路径中添加了factorie-1.0.0-M6.jar,它在documentannotorpipeline.process(pos.POS1,doc)行上显示错误“not found:value documentannotorpipeline”。我需要添加更多的JAR来让它工作吗?你需要GitHub的最新版本。我们希望在几周内实现另一个里程碑。有scala绑定使它更容易!安装起来需要一些工作,但之后整个过程会压缩到一行。库是
val tagger = new MaxentTagger(
"english-left3words-distsim.tagger")
val art_con = "My name is Rahul"
val tagged = tagger.tagString(art_con)
println(tagged)