Ejemplo n.º 1
0
def process_predicate(pred, batch):
    frametext = pred.frame.text
    matches = {1: pred.text1, 2: pred.text2}
    if pred.polarity < 0: matches['a'] = 'not'
    relation = pred.relation
    sentence = pred.sentence
    lang = pred.language

    surface_forms = [
        SurfaceForm.get(matches[i], lang, auto_create=True) for i in (1, 2)
    ]
    concepts = [s.concept for s in surface_forms]

    # FIXME: english only so far
    freq = map_adverb(matches.get('a', ''))
    relation = Relation.objects.get(id=relation.id)
    frame, _ = Frame.objects.get_or_create(relation=relation,
                                           language=lang,
                                           text=frametext,
                                           defaults=dict(frequency=freq,
                                                         goodness=1))
    frame.save()

    raw_assertion, _ = RawAssertion.objects.get_or_create(
        surface1=surface_forms[0],
        surface2=surface_forms[1],
        frame=frame,
        language=lang,
        creator=sentence.creator,
        defaults=dict(batch=batch))
    # still need to set assertion_id

    assertion, _ = Assertion.objects.get_or_create(relation=relation,
                                                   concept1=concepts[0],
                                                   concept2=concepts[1],
                                                   frequency=freq,
                                                   language=lang,
                                                   defaults=dict(score=0))
    #assertion.save()

    raw_assertion.assertion = assertion
    raw_assertion.sentence = sentence
    raw_assertion.save()

    sentence.set_rating(sentence.creator, 1, csamoa4_activity)
    raw_assertion.set_rating(sentence.creator, 1, csamoa4_activity)
    assertion.set_rating(sentence.creator, 1, csamoa4_activity)

    for rating in pred.rating_set.all():
        score = rating.rating_value.deltascore
        if score < -1: score = -1
        if score > 1: score = 1
        if rating.activity_id is None:
            rating_activity = Activity.objects.get(name='unknown')
        else:
            rating_activity = rating.activity
        sentence.set_rating(rating.user, score, rating_activity)
        raw_assertion.set_rating(rating.user, score, rating_activity)
        assertion.set_rating(rating.user, score, rating_activity)

    print '=>', unicode(assertion).encode('utf-8')
    return [assertion]
Ejemplo n.º 2
0
def process_predicate(pred, batch):
    frametext = pred.frame.text
    matches = {1: pred.text1, 2: pred.text2}
    if pred.polarity < 0: matches['a'] = 'not'
    relation = pred.relation
    sentence = pred.sentence
    lang = pred.language

    surface_forms = [SurfaceForm.get(matches[i], lang, auto_create=True)
                     for i in (1, 2)]
    concepts = [s.concept for s in surface_forms]
    
    # FIXME: english only so far
    freq = map_adverb(matches.get('a', ''))
    relation = Relation.objects.get(id=relation.id)
    frame, _ = Frame.objects.get_or_create(relation=relation, language=lang,
                                           text=frametext,
                                           defaults=dict(frequency=freq, 
                                                         goodness=1))
    frame.save()
    
    raw_assertion, _ = RawAssertion.objects.get_or_create(
        surface1=surface_forms[0],
        surface2=surface_forms[1],
        frame=frame,
        language=lang,
        creator=sentence.creator,
        defaults=dict(batch=batch))
    # still need to set assertion_id
    
    assertion, _ = Assertion.objects.get_or_create(
        relation=relation,
        concept1=concepts[0],
        concept2=concepts[1],
        frequency=freq,
        language=lang,
        defaults=dict(score=0)
    )
    #assertion.save()
    
    raw_assertion.assertion = assertion
    raw_assertion.sentence = sentence
    raw_assertion.save()

    sentence.set_rating(sentence.creator, 1, csamoa4_activity)
    raw_assertion.set_rating(sentence.creator, 1, csamoa4_activity)
    assertion.set_rating(sentence.creator, 1, csamoa4_activity)

    for rating in pred.rating_set.all():
        score = rating.rating_value.deltascore
        if score < -1: score = -1
        if score > 1: score = 1
        if rating.activity_id is None:
            rating_activity = Activity.objects.get(name='unknown')
        else:
            rating_activity = rating.activity
        sentence.set_rating(rating.user, score, rating_activity)
        raw_assertion.set_rating(rating.user, score, rating_activity)
        assertion.set_rating(rating.user, score, rating_activity)

    print '=>', unicode(assertion).encode('utf-8')
    return [assertion]
Ejemplo n.º 3
0
def process_yaml(entry, lang, batch):
    if entry is None: return []
    frametext, id, matches, reltext = (entry['frametext'], entry['id'],
    entry['matches'], entry['reltext'])
    sentence = Sentence.objects.get(id=id)
    print sentence.text.encode('utf-8')
    if sentence.activity.id in good_acts:
        print "(we have a better parse)"
        return []
    if (sentence.text.startswith('Situation:')
        or sentence.text.startswith('The statement')
        or sentence.text.startswith('To understand')
        or sentence.text.startswith('In the event')):
            print "* skipped *"
            return []
    if matches.get(2).startswith('do the following'):
        print "** skipped **"
        return []
    
    if reltext is None or reltext == 'junk': return []

    # quick fixes
    if reltext == 'AtLocation' and matches.get('a') == 'of': return []
    if reltext == 'AtLocation' and matches.get('a') == 'near':
        reltext = 'LocatedNear'
    if reltext in ['IsA', 'CapableOf'] and matches.get('a') in ['in', 'on', 'at', 'by']:
        reltext = 'AtLocation'
        matches['a'] = ''
    for val in matches.values():
        if len(val.split()) > 6:
            # we'd rather wait to parse this better.
            return []

    relation = Relation.objects.get(name=reltext)
    
    surface_forms = [SurfaceForm.get(matches[i], lang, auto_create=True)
                     for i in (1, 2)]
    concepts = [s.concept for s in surface_forms]

    # FIXME: english only so far
    freq = map_adverb(matches.get('a', ''))
    
    frame, _ = Frame.objects.get_or_create(relation=relation, language=lang,
                                           text=frametext,
                                           defaults=dict(frequency=freq, 
                                                         goodness=1))
    frame.save()
    
    raw_assertion, _ = RawAssertion.objects.get_or_create(
        surface1=surface_forms[0],
        surface2=surface_forms[1],
        frame=frame,
        language=lang,
        creator=sentence.creator,
        defaults=dict(batch=batch))
    # still need to set assertion_id
    
    assertion, _ = Assertion.objects.get_or_create(
        relation=relation,
        concept1=concepts[0],
        concept2=concepts[1],
        frequency=freq,
        language=lang,
        defaults=dict(score=0)
    )
    assertion.score += 1
    #assertion.save()
    
    raw_assertion.assertion = assertion
    raw_assertion.sentence = sentence
    raw_assertion.save()

    sentence.set_rating(sentence.creator, 1, csamoa4_activity)
    raw_assertion.set_rating(sentence.creator, 1, csamoa4_activity)
    assertion.set_rating(sentence.creator, 1, csamoa4_activity)

    for old_raw in cn3.RawAssertion.objects.filter(sentence=sentence):
        pred = old_raw.predicate
        if not pred: continue
        for rating in pred.rating_set.all():
            score = rating.rating_value.deltascore
            if score > 0: score = 1
            if score < 0: score = -1
            if rating.activity_id is None:
                rating_activity = Activity.objects.get(name='unknown')
            else:
                rating_activity = rating.activity
            sentence.set_rating(rating.user, score, rating_activity)
            raw_assertion.set_rating(rating.user, score, rating_activity)
            assertion.set_rating(rating.user, score, rating_activity)
    
    print '=>', unicode(assertion).encode('utf-8')
    return [assertion]