【问题标题】:How to measure Syntactic Similarity between a query and a document?如何测量查询和文档之间的句法相似度?
【发布时间】:2013-03-03 15:38:01
【问题描述】:

有没有办法衡量查询(句子)和文档(一组句子)之间的句法相似度?

【问题讨论】:

  • 是的。但是如果你想要一个更具体的答案,你将不得不让你的问题更具体。 (您已经搜索过什么?您期望找到什么,您发现了什么,whathaveyoutried.com,表明您已尽一切努力自己找到答案,但找不到)跨度>
  • 实际上我已经阅读了一些树内核并比较了句法树的 2 个句子。但是我无法得出如何在查询文档相似度中使用这个基本思想。它真的会提供合乎逻辑的结果吗!
  • 测量查询与文档中每个单独句子之间的句法相似性是有意义的,即寻找与查询最相似的句子,而不是整个文档。有一个名为 Question Answering (en.wikipedia.org/wiki/Question_answering) 的字段旨在做到这一点,并且,AFAIK,句法相似性被用于 QA。

标签: text syntax nlp similarity


【解决方案1】:

您是否考虑过使用涉及深层语法的deep linguistic processing 工具,如HPSG 和LFG?如果您正在寻找基于特征的句法相似度,您可以查看Kenji Sagae and Andrew S. Gordon 的工作,该工作使用 PropBank 计算动词的句法相似度,然后对相似的动词进行聚类以改进 HPSG 语法。

为了有一个更简单的方法,我建议只查看依赖解析并使用相同的解析节点对句子进行分组。或者只是 POS 标记句子并比较具有相同 POS 标记的句子。

为了一个简单的例子,首先下载并安装 NLTK (http://nltk.org/) 和 hunpos 标记器 (http://code.google.com/p/hunpos/)。解压 en_wsj.model.gz 并将其保存在 Python 脚本所在的位置。

import nltk 
from nltk.tag.hunpos import HunposTagger
from nltk.tokenize import word_tokenize

s1 = "This is a short sentence"
s2 = "That is the same sentence"

ht = HunposTagger('en_wsj.model')
print ht.tag(word_tokenize(corpus))http://nltk.org/

# Tag the sentences with HunPos
t1 = ht.tag(word_tokenize(s1))
t2 = ht.tag(word_tokenize(s2))

#Extract only the POS tags
pos1 = [i[1] for i in t1]
pos2 = [j[1] for j in t2]

if pos1 == pos2:
    print "same sentence according to POS tags"
else:
    print "diff sentences according to POS tags"

上面的这个脚本输出:

>>> print pos1
['DT', 'VBZ', 'DT', 'JJ', 'NN']
>>> print pos2
['DT', 'VBZ', 'DT', 'JJ', 'NN']
>>> if pos1 == pos2:
...     print "same sentence according to POS tags"
... else:
...     print "diff sentences according to POS tags"
... 
same sentence according to POS tags

要修改上面的代码,试试:

  • 使用依赖解析而不是比较 POS
  • 与其进行严格的列表比较,不如提出一些统计方法来衡量差异程度

【讨论】:

    【解决方案2】:

    您在寻找类似Apache Lucene 的东西吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-12
      • 2011-11-05
      • 1970-01-01
      • 1970-01-01
      • 2019-09-04
      • 1970-01-01
      • 1970-01-01
      • 2021-10-28
      相关资源
      最近更新 更多