对英文单词的词性标注

QQ:66781877

1.前言

    最近的一个项目有个需求是这样的,需要从一篇英文文章或者一段英文文字中提取出其中的形容词(adjective),即对单词进行词性标注,我看到这个需求,第一反应是这肯定是个自然语言处理的问题。首先需要对句子进行分词,英文的分词是很容易的,但是分词之后,对于词性的判断,我最初的想法是,找一个英文字典,然后将单词输入,在字典中进行词性的查找。

    先不说这种方法词性判断的准确率,从效率上来说,这样去对单词按词性分类,速度是很慢的。于是我继续查找资料,发现,对中文的词性判断,是有开源的解决方案的,如一些中文分词器:jcseg等等。但是对英文单词的词性标注,这些中文分词器是没有做到的,至少我目前没有找到。

    既然中文分词器能对中文进行词性标注,那么英文分词器是否能对英文进行词性标注呢?很遗憾,我在lucene中,并没有找到相关的API,于是乎,我只能寻求其它解决办法。

    进过一番努力,我从Stanford University的自然语言处理小组网站上找到了一个开源的英文词性标注工具,大喜过望,看了相关的介绍文档之后,运行了例子程序,发现分词的准确率是很高的,而且速度很快。

2.程序及说明

    这个开源词性标注工具中有三种分类器,english-bidirectional-distsim.tagger   english-left3words-distsim.tagger   wsj-0-18-bidirectional-nodistsim.tagger,根据他的说明文档,标注的准确率大概在97.01%,另外,该工具还可以对中文、德文等语言进行词性标注。
    下面来看看标注程序及标注结果:

2.1.标注程序

public class Tagger {

  public static void main(String[] args) throws Exception {
	String str = "The list of prisoners who may be released in coming days includes militants" +
			" who threw firebombs, in one case at a bus carrying children; stabbed and shot" +
			" civilians, including women, elderly Jews and suspected Palestinian collaborators; " +
			"and ambushed and killed border guards, police officers, security agents and soldiers. " +
			"All of them have been in prison for at least two decades; some were serving life sentences.";
    MaxentTagger tagger = new MaxentTagger("c:/wsj-0-18-bidirectional-nodistsim.tagger");
    Long start = System.currentTimeMillis();
    List<List<HasWord>> sentences = MaxentTagger.tokenizeText(new StringReader(str));
    System.out.println("Tagging 用时"+(System.currentTimeMillis() - start)+"毫秒");
    for (List<HasWord> sentence : sentences) {
      ArrayList<TaggedWord> tSentence = tagger.tagSentence(sentence);
      System.out.println(Sentence.listToString(tSentence, false));
    }
  }

}

2.2.标注结果

Tagging 用时84毫秒
The/DT list/NN of/IN prisoners/NNS who/WP may/MD be/VB released/VBN in/IN coming/VBG days/NNS includes/VBZ militants/NNS who/WP threw/VBD firebombs/NNS ,/, 
in/IN one/CD case/NN at/IN a/DT bus/NN carrying/VBG children/NNS ;/: stabbed/VBN and/CC shot/VBN civilians/NNS ,/, including/VBG women/NNS ,/, elderly/JJ 
Jews/NNS and/CC suspected/JJ Palestinian/JJ collaborators/NNS ;/: and/CC ambushed/VBN and/CC killed/VBN border/NN guards/NNS ,/, police/NN officers/NNS ,/, 
security/NN agents/NNS and/CC soldiers/NNS ./.All/DT of/IN them/PRP have/VBP been/VBN in/IN prison/NN for/IN at/IN least/JJS two/CD decades/NNS ;/: some/DT 
were/VBD serving/VBG life/NN sentences/NNS ./.

下面这张表,是英文单词的词性表


从上面的表和程序的标注结果来看,分词是很准确的。
  • 4
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 14
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值