def hypernyms_of_class(w_class): """ Given a wikipedia class, return a list of hypernyms (as a list of strings) from DBpedia's Ontology Classes. """ result = get_hypernyms(w_class) return [from_dbpedia_class(x) for x in result]
def hypernyms_of_article_from_db(article, limit=sys.maxint): """ Given a case-sensitive article title, return all hypernyms of that article (as a list of strings) from DBpedia's Ontology Classes. """ result = (DbpediaClass.select().join(Hypernym).join( ArticleClass, on=Hypernym.c_id).join(Article, on=ArticleClass.a_id).where( Article.title == article, ).limit(limit)) return [from_dbpedia_class(x.dbpedia_class) for x in result]
def hypernyms_of_class_from_db(w_class, limit=sys.maxint): """ Given a wikipedia class, return a list of hypernyms (as a list of strings) from DBpedia's Ontology Classes. Deprecated: uses the database, resulting in slow, unordered results. Use hypernyms_of_class() instead. """ w_class = to_wikipedia_class(w_class) result = (DbpediaClass.select().join(Hypernym).join(WikiClass).where( WikiClass.class_name == w_class).limit(limit)) return [from_dbpedia_class(x.dbpedia_class) for x in result]
def hypernyms_of_article_from_db(article, limit=sys.maxint): """ Given a case-sensitive article title, return all hypernyms of that article (as a list of strings) from DBpedia's Ontology Classes. """ result = (DbpediaClass .select() .join(Hypernym) .join(ArticleClass, on=Hypernym.c_id) .join(Article, on=ArticleClass.a_id) .where( Article.title == article, ) .limit(limit)) return [from_dbpedia_class(x.dbpedia_class) for x in result]
def hypernyms_of_class_from_db(w_class, limit=sys.maxint): """ Given a wikipedia class, return a list of hypernyms (as a list of strings) from DBpedia's Ontology Classes. Deprecated: uses the database, resulting in slow, unordered results. Use hypernyms_of_class() instead. """ w_class = to_wikipedia_class(w_class) result = (DbpediaClass .select() .join(Hypernym) .join(WikiClass) .where(WikiClass.class_name == w_class) .limit(limit)) return [from_dbpedia_class(x.dbpedia_class) for x in result]
def test_from_dbpedia_class(self): self.assertEqual(util.from_dbpedia_class("owl:Thing"), "thing")