def test_extract_relations_german3():
    utterance = u'''Sarah und Anna, von denen sie hofft, dass sie sicher sind'''

    re = RelationExtractor(lang=LANG.DE)
    result = re.extract_relations(utterance, plot_graph=False)

    assert result == [('sarah', 'KNOWS', 'anna')]
def test_extract_relations_8():
    utterance = u'''Well I'm thinking that Chandler's our friend and Janice makes him happy, 
                so I say we just all be adult about it and accept her.'''

    re = RelationExtractor(lang=LANG.EN)
    result = re.extract_relations(utterance, plot_graph=False)
    assert result == [('USER', 'friend-of', 'chandler'), ('USER', 'friend-of', 'janice'), ('chandler', 'friend-of', 'janice')]
Example #3
0
class AnalyticsEngine:
    def __init__(self, lang):
        self.ng = NetworkGraph()  # neo4j
        self.re = RelationExtractor(lang=lang)
        self.re_types = RelationTypes()

    def analyze_utterance(self,
                          utterance,
                          persist=False,
                          validate=False,
                          out_val_file=None):
        logger.debug(f"Start analyzing utterance {utterance}")

        # extract possible relations within utterance
        relations = self.re.extract_relations(text=utterance,
                                              plot_graph=False,
                                              validate=validate,
                                              out_val_file=out_val_file)
        logger.debug(f'relations: {relations}')
        response_message = None

        # add relations to graph database
        for relation in relations:
            if len(relation) == 3:
                ent1 = relation[0]
                rel = relation[1]
                ent2 = relation[2]
                logger.debug(f'Relation extracted: {ent1}, {ent2}, {rel}')
                response_message = f'{ent1} ist also {self.re_types.get_relation_from_relation_type_DE(rel)}?'

                # add entites to neo4j
                if persist:
                    self.ng.add_relationship(ent1, ent2, rel_type=rel)

            elif len(relation) == 2:
                ent1 = relation[0]
                rel = relation[1]
                logger.debug(f'Relation extracted: {ent1}, {rel}')
                response_message = f'Wie heißt {self.re_types.get_relation_from_relation_type_DE(rel)}?'

        return relations, response_message
def test_extract_relations_german2():
    utterance = u"Elfriede ist die Großmutter von Lisa."

    re = RelationExtractor(lang=LANG.DE)
    result = re.extract_relations(utterance, plot_graph=False)
    assert(result == [('elfriede', 'grandmother-of', 'lisa')])
def test_extract_relations_german1():
    utterance = u'Meine kleine Enkelin Lisa und mein Enkel Lukas fliegen morgen nach London.'

    re = RelationExtractor(lang=LANG.DE)
    result = re.extract_relations(utterance, plot_graph=False)
    assert(result == [('USER', 'granddaughter-of', 'lisa'), ('USER', 'grandson-of', 'lukas'), ('USER', 'friend-of', 'lukas')])
def test_extract_relation_11():
    utterance = u'''Well, if you want, you can stay with Rachel and me tonight.'''
    re = RelationExtractor(lang=LANG.EN)
    result = re.extract_relations(utterance)
    assert result == [('rachel', 'KNOWS', 'USER')]
def test_extract_relatiosn_10():
    utterance = u'''Tom Cruise and Nicole Kidman.'''
    re = RelationExtractor(lang=LANG.EN)
    result = re.extract_relations(utterance)
    assert result == [('tom_cruise', 'KNOWS', 'nicole_kidman')]
def test_extract_relations_german5():
    utterance = u'''Peter ist der Vater von Hans und Tom ist der Freund von Hubert'''

    re = RelationExtractor(lang=LANG.DE)
    result = re.extract_relations(utterance, plot_graph=True)
    assert result == [('peter', 'father-of', 'hans'), ('tom', 'friend-of', 'peter ')]
def test_extract_relations_7():
    utterance = u"Rose is the grandma of Monica."

    re = RelationExtractor(lang=LANG.EN)
    result = re.extract_relations(utterance, plot_graph=False)
    assert(result == [('rose', 'grandmother-of', 'monica')])
def test_extract_relations_1():
    utterance = u'''My daughter Lisa is moving to London next month.'''
    re = RelationExtractor(lang=LANG.EN)
    result = re.extract_relations(utterance, plot_graph=False)
    assert(result == [('lisa', 'daughter-of', 'USER')])
def test_extract_relations_6():
    utterance = u"Steve's girlfriend Monica is on the way back home."

    re = RelationExtractor(lang=LANG.EN)
    result = re.extract_relations(utterance, plot_graph=False)
    assert(result == [('steve', 'wife-of', 'monica')])
def test_extract_relations_4():
    utterance = u'''"So uh, Monica is Ross's sister."'''
    re = RelationExtractor(lang=LANG.EN)
    result = re.extract_relations(utterance, plot_graph=False)
    assert result == [('monica', 'sister-of', 'ross')]
def test_extract_relations_3():
    utterance = "I'll be playing Drake Remoray's twin brother, Stryker!"
    re = RelationExtractor(lang=LANG.EN)
    result = re.extract_relations(utterance, plot_graph=False)
    assert result == [('drake', 'brother-of', 'stryker')]
Example #14
0
 def __init__(self, lang):
     self.ng = NetworkGraph()  # neo4j
     self.re = RelationExtractor(lang=lang)
     self.re_types = RelationTypes()
def test_extract_relations_9():
    utterance = u''' my dad is our preacher '''
    re = RelationExtractor(lang=LANG.EN)
    result = re.extract_relations(utterance, plot_graph=False)
    assert result == [('father-of', 'USER')]
Example #16
0
 def __init__(self, component_config=None):
     super(SocialRelationExtractor, self).__init__(component_config)
     self.re = RelationExtractor(LANG.DE)
     self.ae = AnalyticsEngine(LANG.DE)
     self.rt = RelationTypes()
def test_extract_relations_german4():
    utterance = u'''Peter ist der Vater von Hans.'''

    re = RelationExtractor(lang=LANG.DE)
    result = re.extract_relations(utterance)
    assert result == [('peter', 'father-of', 'hans')]