我有两个要比较的清单:
word1 = ['orange']
word2 = ['woman']
然后我有这个功能为列表中的每个单词找到一个同义词:
def getSynonyms(word):
synonymList1 = []
for data1 in word:
wordnetSynset1 = wn.synsets(data1)
tempList1=[]
for synset1 in wordnetSynset1:
synLemmas = synset1.lemma_names()
for i in xrange(len(synLemmas)):
word = synLemmas[i].replace('_',' ')
#tempList1.append(pos_tag(word.split()))
#if pos_tag(word.split()) not in tempList1:
#tempList1.append(pos_tag(word.split()))
if word not in tempList1:
tempList1.append(word)
synonymList1.append(tempList1)
return synonymList1
ds1 = getSynonyms([word1[0]])
ds2 = getSynonyms([word2[0]])
newds1 = ",".join(repr(e) for e in ds1)
newds2 = ",".join(repr(e) for e in ds2)
print newds1
print newds2
这是输出:
[u'orange', u'orangeness', u'orange tree', u'Orange', u'Orange River', u'orangish']
[u'woman', u'adult female', u'charwoman', u'char', u'cleaning woman', u'cleaning lady', u'womanhood', u'fair sex']
然后我有另一个功能。此函数检查word1
和word2
之间是否存在类似的同义词集。如果找到类似的单词,则该函数将返回1,这意味着它被找到。 :
def cekSynonyms(word1, word2):
tmp = 0
ds1 = getSynonyms([word1[0]])
ds2 = getSynonyms([word2[0]])
newds1 = ",".join(repr(e) for e in ds1)
newds2 = ",".join(repr(e) for e in ds2)
for i in newds1:
for j in newds2:
if i == j:
tmp = 1
else:
tmp = 0
return tmp
print cekSynonyms(word1, word2)
但输出为1
。
看起来word1
和word2
之间没有类似的同义词。但为什么它仍会导致1
而不是0
?
答案 0 :(得分:0)
您的循环始终会检查完整列表并在每次迭代中覆盖int output[CHAR_BIT];
char c;
int i;
for (i = 0; i < CHAR_BIT; ++i) {
output[i] = (c >> i) & 1;
}
。因此列表中的最后一个元素确定返回的值。也许你应该停止检查
tmp