2013-03-03 89 views
0

有没有方法可以测量查询(句子)和文档(一组句子)之间的句法相似度?如何测量查询和文档之间的句法相似度?

+1

是的。但是如果你想要一个更具体的答案,你将不得不提出更具体的问题。 (你已经搜索了什么?你期望找到什么,你发现了什么,取而代之的是,whathaveyoutried.com,显示你做了一切你可以自己找到答案的东西,但找不到它) – 2013-03-03 15:43:38

+0

实际上我已经阅读了一些树内核,并比较了句子树的2个句子。但是我不能总结如何在查询文档相似性中使用这个基本思想。它会真的提供合乎逻辑的结果! – hatemfaheem 2013-03-03 15:47:55

+1

衡量查询与文档中每个单独句子之间的句法相似性是有意义的,即查找检索与查询最相似的句子而不是整个文档。有一个名为Question Answering的字段(http://en.wikipedia.org/wiki/Question_answering)旨在做到这一点,而且AFAIK语法相似性正用于QA。 – vpekar 2013-03-04 19:41:18

回答

3

您是否考虑过使用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使用依赖解析,而不是一个严格的名单
  • 比较,拿出一些统计方法来衡量差异水平
相关问题