HLR / DomiKnowS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Event-argument relation as a concept

guoquan opened this issue · comments

In ACE05, event-argument needs to be written as concept(s) so that it can be predicted.

Here is my sample implementation. Please see if this make sense.

Consider we already have these concepts:

phrase = Concept(name='phrase')
pair = Concept(name='pair')
pair.has_a(phrase, phrase)

trigger = phrase(name='trigger')
event = Concept(name='Event')
event.has_a(trigger)

We define concepts based on pairs for argument association:

event_argument = pair(name='EventArgument')
event_argument.has_a(event, phrase)
participant_argument = event_argument(name='Participant')
attribute_argument = event_argument(name='Attribute')

and a shortcut function

def involve(event_type, argument_type, **kwargs):
    for role, concepts in kwargs.items():
        if isinstance(concepts, Concept):
            concepts = (concepts,)
        role_argument = argument_type(name=f'{event_type.name}-{role}')
        ifL(role_argument, ('x', 'y'), andL(event_type, 'x', orL(*concepts, 'y')))

Then we can define concepts and arguments like this:

life = event(name='Life')
be_born = life(name='Be-Born')
involve(be_born, participant_argument, Person=PER)
involve(be_born, attribute_argument, Time=timex2, Place=(GPE, LOC, FAC))

The last two lines are expected to be equivalent to:

be_born_Person = participant_argument('Be-Born-Person')
ifL(be_born_Person, ('x', 'y'), andL(be_born, 'x', orL(PER, 'y')))

be_born_Time = attribute_argument('Be-Born-Time')
ifL(be_born_Time, ('x', 'y'), andL(be_born, 'x', orL(timex2, 'y')))
be_born_Place = attribute_argument('Be-Born-Place')
ifL(be_born_Place, ('x', 'y'), andL(be_born, 'x', orL(GPE, LOC, FAC, 'y')))

When modeling, we might have

pair[be_born_Person] = Some_Learner()
pair[be_born_Time] = Some_Learner2()
pair[be_born_Place] = Some_Learner3()

@auszok can you review this and see if this is good with the constraint language? Or do you need a running example (maybe with dummy sensor and learners) to test?

The method does not need orL if it only has single concept. Also single variable like 'x' names still need to be in tuples - ('x',).

Corrected below:

def involve(event_type, argument_type, **kwargs):
    for role, concepts in kwargs.items():
        role_argument = argument_type(name=f'{event_type.name}-{role}')
        ifL(role_argument, ('x', 'y'), andL(event_type , ('x',) , concepts, ('y',))))

Similar correction to constraints below:

ifL(be_born_Person, ('x', 'y'), andL(be_born, ('x',) , PER, ('y',) )))

ifL(be_born_Time, ('x', 'y'), andL(be_born, ('x',), timex2, ('y',))))

ifL(be_born_Place, ('x', 'y'), andL(be_born, ('x',), orL(GPE, LOC, FAC, ('y',))))
'''

It would be good to have a running example (maybe with dummy sensor and learners) to test.

Hi @auszok
Please check out on branch examples/ace-event, folder examples/ACE05, the main_prototype.py. It is a running example.

When I run it, there is some problem in inference with the orL statement in

ifL(be_born_Place, ('x', 'y'), andL(be_born, ('x',), orL(GPE, LOC, FAC, ('y',))))

This is mentioned in a new issue #186