Skip to content

matcher returns bad results #2

@phueb

Description

@phueb

When the text,

the dog and other animals are nice.

is fed to the knowledge graph pipeline, the relation animals-dog and animals-are are extracted. The latter is not a hyponym-hypernym pair, and this can be prevented with some modifcations to getRelations in and_other_pattern_matcher.py:

    def getRelations(self, doc: Doc) -> [Relation]:
        relations = []
        matches = self._matcher(doc)
        for match_id, start, end in matches:
            span = doc[start:end]
            hypernym = span.text.split()[-1]
            firstToken = span.root

            # get all hyponyms
            results = [firstToken]
            while firstToken and firstToken.head.pos_ == "NOUN":
                results.append(firstToken.head)
                firstToken = firstToken.head

            # make relations
            for result in results:
                relations.append(Relation(hypernym, result.text))
        return relations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions