Exemplo n.º 1
0
    def __init__(
            self,
            name,  # onttype name
            parent,  # parent's name
            children=None,  # childrens' names
            words=None,  # explicitly mapped words
            wordnet_types=None,  # Some wordnet keys that should map to this onttype
            ancestors=None,  # some ancestors' names
            offspring=None,  # some offspring
    ):

        self.name = name
        self.type = trips[name]
        self.parent = Normalize.ont_name(parent)
        if not children:
            self.children = set()
        else:
            self.children = set([Normalize.ont_name(c) for c in self.children])
        if not words:
            self.words = set()
        else:
            self.words = set([l.lower() for l in words])
        if not wordnet_types:
            self.wordnet_types = set()
        else:
            self.wordnet_types = set(wordnet_types)
        if not ancestors:
            self.ancestors = set()
        else:
            self.ancestors = set([Normalize.ont_name(a) for a in ancestors])
        if not offspring:
            self.offspring = set()
        else:
            self.offspring = set([Normalize.ont_name(o) for o in offspring])
Exemplo n.º 2
0
def tag_word_wn(token):
    pos = Normalize.spacy_pos(token.pos_)
    word = token.text.lower()
    lemma = token.lemma_

    if pos not in "nvar":
        return frozenset(), word

    return frozenset(wn.synsets(word, pos)), word
Exemplo n.º 3
0
def tag_word(token):
    pos = Normalize.spacy_pos(token.pos_)
    word = token.text.lower()
    lemma = token.lemma_

    if pos not in "nvar":  # if the pos is not in wordnet
        return set()

    query = (word, lemma, pos)
    return word_cache[(word, lemma, pos)]
Exemplo n.º 4
0
def tag_word(token):
    pos = Normalize.spacy_pos(token.pos_)
    word = token.text.lower()
    lemma = token.lemma_

    if pos not in "nvar":  # if the pos is not in wordnet
        return set(), word

    # word lookup:
    wlookup = ont[("q::" + word, pos)]
    llookup = ont[("q::" + lemma, pos)]

    res = wlookup["lex"]
    res += wlookup["wn"]
    res += llookup["lex"]
    res += llookup["wn"]

    return (frozenset(res), word)
Exemplo n.º 5
0
def test_nmlz_ont():
    assert Normalize.ont_name("test") == "ont::test"
    assert Normalize.ont_name("ont::test") == "ont::test"
Exemplo n.º 6
0
 def tokenform(token):
     pos = Normalize.spacy_pos(token.pos_)
     tag = token.tag_
     lemma = token.lemma_
     return "{}.{}.{}".format(lemma,tag,pos)
Exemplo n.º 7
0
def test_parent(TestType):
    assert str(TestType.type.parent) == Normalize.ont_name(TestType.parent)
Exemplo n.º 8
0
def test_name(TestType):
    assert str(TestType.type) == Normalize.ont_name(TestType.name)