コード例 #1
0
    def get_event(event_entry):
        name = event_entry['Relation']
        concept = Concept(name, db_refs={'TEXT': name})
        grounding = event_entry['Event_Type']
        if grounding:
            concept.db_refs['SOFIA'] = grounding
        context = WorldContext()
        time = event_entry.get('Time')
        if time:
            context.time = TimeContext(text=time.strip())
        loc = event_entry.get('Location')
        if loc:
            context.geo_location = RefContext(name=loc)

        text = event_entry.get('Text')
        ref = event_entry.get('Source')
        agent = event_entry.get('Agent')
        patient = event_entry.get('Patient')
        anns = {}
        if agent:
            anns['agent'] = agent
        if patient:
            anns['patient'] = patient
        ev = Evidence(source_api='sofia', pmid=ref, text=text,
                      annotations=anns, source_id=event_entry['Event Index'])
        pol = event_entry.get('Polarity')
        event = Event(concept, context=context, evidence=[ev],
                      delta=QualitativeDelta(polarity=pol, adjectives=None))

        return event
コード例 #2
0
    def get_event_compositional(self, event_entry: Dict[str, str]) -> Event:
        """Get an Event with compositional grounding

        Parameters
        ----------
        event_entry :
            The event to process

        Returns
        -------
        event :
            An Event statement
        """
        # Get get compositional grounding
        comp_name, comp_grnd = self.get_compositional_grounding(event_entry)
        if comp_name is not None and \
                comp_grnd[0] is not None and \
                comp_grnd[0][0] is not None:
            concept = Concept(comp_name,
                              db_refs={
                                  'TEXT': comp_name,
                                  'WM': [comp_grnd]
                              })
        # If not try to get old style Sofia grounding
        else:
            name = event_entry['Relation']
            concept = Concept(name, db_refs={'TEXT': name})
            if event_entry['Event_Type']:
                concept.db_refs['SOFIA'] = event_entry['Event_Type']

        context = WorldContext()
        time = event_entry.get('Time')
        if time:
            context.time = TimeContext(text=time.strip())
        loc = event_entry.get('Location')
        if loc:
            context.geo_location = RefContext(name=loc)

        text = event_entry.get('Text')
        ref = event_entry.get('Source')
        agent = event_entry.get('Agent')
        patient = event_entry.get('Patient')
        anns = {}
        if agent:
            anns['agent'] = agent
        if patient:
            anns['patient'] = patient
        text_refs = {'DART': ref}
        ev = Evidence(source_api='sofia',
                      text_refs=text_refs,
                      text=text,
                      annotations=anns,
                      source_id=event_entry['Event Index'])
        pol = event_entry.get('Polarity')
        event = Event(concept,
                      context=context,
                      evidence=[ev],
                      delta=QualitativeDelta(polarity=pol, adjectives=None))

        return event
コード例 #3
0
    def get_event(event_entry):
        name = event_entry['Relation']
        concept = Concept(name, db_refs={'TEXT': name})
        grounding = event_entry['Event_Type']
        if grounding:
            concept.db_refs['SOFIA'] = grounding
        context = WorldContext()
        time = event_entry.get('Time')
        if time:
            context.time = TimeContext(text=time.strip())
        loc = event_entry.get('Location')
        if loc:
            context.geo_location = RefContext(name=loc)

        text = event_entry.get('Text')
        ref = event_entry.get('Source')
        ev = Evidence(source_api='sofia', pmid=ref, text=text)
        pol = event_entry.get('Polarity')
        event = Event(concept,
                      context=context,
                      evidence=[ev],
                      delta={
                          'polarity': pol,
                          'adjectives': []
                      })

        return event
コード例 #4
0
    def get_event_flat(self, event_entry: Dict[str, str]) -> Event:
        """Get an Event with flattened grounding

        Parameters
        ----------
        event_entry :
            The event to process

        Returns
        -------
        event :
            An Event statement
        """
        name = event_entry['Relation']
        concept = Concept(name, db_refs={'TEXT': name})
        grounding = event_entry['Event_Type']
        if grounding:
            concept.db_refs['SOFIA'] = grounding
        context = WorldContext()
        time = event_entry.get('Time')
        if time:
            context.time = TimeContext(text=time.strip())
        loc = event_entry.get('Location')
        if loc:
            context.geo_location = RefContext(name=loc)

        text = event_entry.get('Text')
        ref = event_entry.get('Source')
        agent = event_entry.get('Agent')
        patient = event_entry.get('Patient')
        anns = {}
        if agent:
            anns['agent'] = agent
        if patient:
            anns['patient'] = patient
        text_refs = {'DART': ref}
        ev = Evidence(source_api='sofia',
                      text_refs=text_refs,
                      text=text,
                      annotations=anns,
                      source_id=event_entry['Event Index'])
        pol = event_entry.get('Polarity')
        event = Event(concept,
                      context=context,
                      evidence=[ev],
                      delta=QualitativeDelta(polarity=pol, adjectives=None))
        return event
コード例 #5
0
ファイル: processor.py プロジェクト: johnbachman/indra
    def get_event(event_entry):
        name = event_entry['Relation']
        concept = Concept(name, db_refs={'TEXT': name})
        grounding = event_entry['Event_Type']
        if grounding:
            concept.db_refs['SOFIA'] = grounding
        context = WorldContext()
        time = event_entry.get('Time')
        if time:
            context.time = TimeContext(text=time.strip())
        loc = event_entry.get('Location')
        if loc:
            context.geo_location = RefContext(name=loc)

        text = event_entry.get('Text')
        ref = event_entry.get('Source')
        ev = Evidence(source_api='sofia', pmid=ref, text=text)
        pol = event_entry.get('Polarity')
        event = Event(concept, context=context, evidence=[ev],
                      delta=QualitativeDelta(polarity=pol, adjectives=None))

        return event
コード例 #6
0
    def _build_stmts(self, rel_dict):
        stmt_list = []
        cause_entries = rel_dict.get('Cause Index')
        effect_entries = rel_dict.get('Effect Index')

        # FIXME: Handle cases in which there is a missing cause/effect
        if not cause_entries or not effect_entries:
            return []
        causes = [c.strip() for c in cause_entries.split(',')]
        effects = [e.strip() for e in effect_entries.split(',')]
        rel = rel_dict.get('Relation')
        if _in_rels(rel, pos_rels):
            pol = 1
        elif _in_rels(rel, neg_rels):
            pol = -1
        elif _in_rels(rel, neu_rels):
            pol = None
        # If we don't recognize this relation, we don't get any
        # statements
        else:
            return []

        text = rel_dict.get('Sentence')
        annot_keys = ['Relation']
        annots = {k: rel_dict.get(k) for k in annot_keys}
        ref = rel_dict.get('Source_File')

        for cause_idx, effect_idx in itertools.product(causes, effects):
            cause_name = self._events[cause_idx]['Relation']
            cause_grounding = self._events[cause_idx]['Event_Type']
            effect_name = self._events[effect_idx]['Relation']
            effect_grounding = self._events[effect_idx]['Event_Type']
            cause_concept = Concept(cause_name, db_refs={'TEXT': cause_name})
            if cause_grounding:
                cause_concept.db_refs['SOFIA'] = cause_grounding
            effect_concept = Concept(effect_name,
                                     db_refs={'TEXT': effect_name})
            if effect_grounding:
                effect_concept.db_refs['SOFIA'] = effect_grounding

            # NOTE: Extract context. The basic issue is that
            # time/location
            # here is given at the event level, not at the relation
            # level, and so we need to choose which event's context
            # we will associate with the relation
            def choose_context(context_type):
                locs = [
                    self._events[cause_idx].get(context_type),
                    self._events[effect_idx].get(context_type)
                ]
                if locs[0]:
                    return locs[0].strip()
                elif locs[1]:
                    return locs[1].strip()
                else:
                    return None

            context = WorldContext()
            location = choose_context('Location')
            if location:
                context.location = RefContext(name=location)
            time = choose_context('Time')
            if time:
                context.time = TimeContext(text=time)
            # Overwrite blank context
            if not context:
                context = None

            ev = Evidence(source_api='sofia',
                          pmid=ref,
                          annotations=annots,
                          text=text,
                          context=context)
            stmt = Influence(cause_concept, effect_concept, evidence=[ev])
            # Assume unknown polarity on the subject, put the overall
            # polarity in the sign of the object
            stmt.subj_delta['polarity'] = None
            stmt.obj_delta['polarity'] = pol

            stmt_list.append(stmt)
        return stmt_list