本文整理汇总了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))