【问题标题】:Accessing Stanford Core NLP Coreference Chain output in Ruby在 Ruby 中访问 Stanford Core NLP Coreference Chain 输出
【发布时间】:2015-07-17 23:23:37
【问题描述】:

我正在尝试使用斯坦福核心 NLP :coref_chain 从某些文本中获取实体提及列表。当我运行这段代码时:

text = 'Angela Merkel met Nicolas Sarkozy on January 25th in ' +
   'Berlin to discuss a new austerity package. Sarkozy ' +
   'looked pleased, but Merkel was dismayed.'

pipeline =  StanfordCoreNLP.load(:tokenize, :ssplit, :pos, :lemma, :parse, :ner, :dcoref)
text = StanfordCoreNLP::Annotation.new(text)
pipeline.annotate(text)

  puts text.get(:coref_chain)

我得到这个输出:

{1=CHAIN1-["Angela Merkel" in sentence 1, "Merkel" in sentence 2], 3=CHAIN3-["January 25th" in sentence 1], 4=CHAIN4-["Berlin" in sentence 1], 5=CHAIN5-["Nicolas Sarkozy on January 25th" in sentence 1, "Sarkozy" in sentence 2], 6=CHAIN6-["a new austerity package" in sentence 1]}

这是一个哈希吗?根据斯坦福网站上的文档,我应该能够通过属性名称访问这些值,但没有任何组合对我有用。事实上,添加 to_s 以外的任何内容都会产生“找不到方法”错误。

有谁知道我如何从中得到名字?例如“安吉拉·默克尔”?在最好的情况下,我也会得到开头、结尾和正面。

【问题讨论】:

  • 请提供输出:puts text.get(:coref_chain).class.name,但我想它是文本...哈希需要采用 { key 的格式=> value },如果您仔细查看文档 - 句子在数组(令牌)中。
  • 但是您在文本上调用 coref_chain 而不是在令牌上,所以我不确定这是否有效?您的建议的输出是:Rjb::Rjb_JavaProxy
  • 经过进一步修改,coref 功能似乎无法在 Stanford Core NLP gem 中工作。哦,好吧,继续尝试治疗(到目前为止,对于遇到此问题的其他人来说都很好)

标签: ruby nlp stanford-nlp


【解决方案1】:

看看the example code for using the gem。你必须遍历text.get的返回值:

text.get(:sentences).each do |sentence|

您可以遍历返回的句子并提取更多信息。

你认为的哈希不是哈希。这是当您告诉puts 时创建的内部结构的字符串表示,类似于inspect 将返回的内容。

【讨论】:

  • 循环遍历句子适用于基本依赖项之类的事情,但不适用于文档级别的 coref 链。根据文档,应该有与链一起返回的属性,这些是我想要访问的;提及、头部、开始索引等。奇怪的是,在令牌级别,我可以看到每个输出被包装的标签。使用 coref_chain,我在输出中看不到这些标签。查看文档增益,如果您输出一个完整的 xml 文档,则这些标签是为了共同参考。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-12
  • 1970-01-01
  • 1970-01-01
  • 2015-05-16
  • 2012-09-03
  • 1970-01-01
相关资源
最近更新 更多