本文整理匯總了Python中term.Term.get_terms方法的典型用法代碼示例。如果您正苦於以下問題:Python Term.get_terms方法的具體用法?Python Term.get_terms怎麽用?Python Term.get_terms使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類term.Term
的用法示例。
在下文中一共展示了Term.get_terms方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: find_hearst_concepts
# 需要導入模塊: from term import Term [as 別名]
# 或者: from term.Term import get_terms [as 別名]
def find_hearst_concepts(self, triples):
s_concepts = []
m_concepts = []
for (t1, rel, t2) in triples:
term1 = Term(preprocessor.pos_tag(t1, True))
term2 = Term(preprocessor.pos_tag(t2, True))
synsets1 = wn.synsets(term1.get_head()[0], self.pos_tag(term1.get_head()[1]))
synsets2 = wn.synsets(term2.get_head()[0], self.pos_tag(term2.get_head()[1]))
if not synsets1:
raise Exception("'{}' not found in WordNet".format(term1.get_head()[0]))
if not synsets2:
raise Exception("'{}' not found in WordNet".format(term2.get_head()[0]))
(best1, best2) = self.comp(synsets1, synsets2)
con1 = self.get_concept(
concept.Concept(synset=best1, term=term1.get_head()[0])
)
con2 = self.get_concept(
concept.Concept(synset=best2, term=term2.get_head()[0])
)
conChild1 = None
conChild2 = None
if len(term1.get_terms()) > 1:
conChild1 = self.get_concept(
concept.Concept(name=term1.get_terms(), term=term1.get_head()[0])
)
con1.add_hyponym(conChild1)
conChild1.add_hypernym(con1)
#m_concepts.append(conChild1)
if len(term2.get_terms()) > 1:
conChild2 = self.get_concept(
concept.Concept(name=term2.get_terms(), term=term2.get_head()[0])
)
con2.add_hyponym(conChild2)
conChild2.add_hypernym(con2)
#m_concepts.append(conChild2)
if conChild1:
if conChild2:
conChild1.add_relation(conChild2, rel)
else:
conChild1.add_relation(con2, rel)
m_concepts.append(conChild1)
else:
if conChild2:
con1.add_relation(conChild2, rel)
m_concepts.append(conChild2)
else:
con1.add_relation(con2, rel)
s_concepts.append(con1)
s_concepts.append(con2)
self.single_concepts = self.single_concepts.union(set(s_concepts))
self.multi_concepts = self.multi_concepts.union(set(m_concepts))