Text 如何度量查询和文档之间的语法相似性?
有没有一种方法可以衡量查询(句子)和文档(一组句子)之间的语法相似性?你在寻找类似的东西吗?你在寻找类似的东西吗?你考虑过使用像和LFG这样涉及深层语法的工具吗?如果您正在研究基于特征的语法相似性,那么您可以看一看作者使用PropBank计算动词语法相似性的工作,然后对相似动词进行聚类以改进HPSG语法 为了有一个更简单的方法,我建议只看依赖项解析,并用相同的解析节点对句子进行分组。或者只使用词性标记句,并比较具有相同词性标记的句子 为了获得一个简单的示例,首先下载并安装NLTK()和hunpos标记器()。解压缩en_wsj.model.gz并将其保存在python脚本所在的位置Text 如何度量查询和文档之间的语法相似性?,text,syntax,nlp,similarity,Text,Syntax,Nlp,Similarity,有没有一种方法可以衡量查询(句子)和文档(一组句子)之间的语法相似性?你在寻找类似的东西吗?你在寻找类似的东西吗?你考虑过使用像和LFG这样涉及深层语法的工具吗?如果您正在研究基于特征的语法相似性,那么您可以看一看作者使用PropBank计算动词语法相似性的工作,然后对相似动词进行聚类以改进HPSG语法 为了有一个更简单的方法,我建议只看依赖项解析,并用相同的解析节点对句子进行分组。或者只使用词性标记句,并比较具有相同词性标记的句子 为了获得一个简单的示例,首先下载并安装NLTK()和hunpo
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
- 提出一些统计方法来衡量差异的程度,而不是严格的列表比较
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
- 提出一些统计方法来衡量差异的程度,而不是严格的列表比较