Esempio n. 1
0
def postprocess(result, function):
    """
    Clean up types for caller
    """
    if function == 'classes_of_article':
        result = [util.from_wikipedia_class(c) for c in result]
    elif function == 'hypernyms_of_article':
        # flatten DBpedia hypernyms to a set
        types = []
        for dbpedia_classes in result.values():
            types += dbpedia_classes
        result = set(types)
        if 'thing' in result:
            # every entity has type owl:Thing
            # remove it form the output because it is not informative
            result.remove('thing')

    # replace dashes with spaces
    return [s.replace('-', ' ').lower().strip() for s in result]
Esempio n. 2
0
 def test_from_wikipedia_class(self):
     self.assertEqual('french-commune',
                      util.from_wikipedia_class('wikipedia-french-commune'))
Esempio n. 3
0
def get_hypernyms(wiki_class):
    wiki_class = from_wikipedia_class(wiki_class)
    return ontology.classes_above_infobox(wiki_class)
Esempio n. 4
0
 def test_from_wikipedia_class(self):
     self.assertEqual('french-commune',
                      util.from_wikipedia_class('wikipedia-french-commune'))