Example #1
0
def test_normalize_opposites():
    concept1 = 'wm/concept/causal_factor/food_security/food_stability'
    concept2 = 'wm/concept/causal_factor/food_insecurity/food_instability'
    concept3 = ('wm/concept/causal_factor/crisis_and_disaster/'
                'environmental_disasters/natural_disaster/flooding')

    # First test the inherently positive being the main grounding
    dbr = {'WM': [(concept1, 1.0), (concept2, 0.5), (concept3, 0.1)]}
    ev = Event(Concept('x', db_refs=dbr), delta=QualitativeDelta(polarity=1))
    pa = Preassembler(world_ontology, stmts=[ev])
    pa.normalize_opposites(ns='WM')
    # We are normalizing to food supply since that is the inherently
    # positive concept
    assert pa.stmts[0].concept.db_refs['WM'][0] == \
        (concept1, 1.0), pa.stmts[0].concept.db_refs['WM']
    assert pa.stmts[0].concept.db_refs['WM'][1] == \
        (concept1, 0.5), pa.stmts[0].concept.db_refs['WM']
    assert pa.stmts[0].concept.db_refs['WM'][2] == \
        (concept3, 0.1), pa.stmts[0].concept.db_refs['WM']
    assert pa.stmts[0].delta.polarity == 1

    # Next test the inherently negative being the main grounding
    dbr = {'WM': [(concept2, 1.0), (concept1, 0.5), (concept3, 0.1)]}
    ev = Event(Concept('x', db_refs=dbr), delta=QualitativeDelta(polarity=1))
    pa = Preassembler(world_ontology, stmts=[ev])
    pa.normalize_opposites(ns='WM')
    # We are normalizing to food supply since that is the inherently
    # positive concept
    assert pa.stmts[0].concept.db_refs['WM'][0] == \
           (concept1, 1.0), pa.stmts[0].concept.db_refs['WM']
    assert pa.stmts[0].concept.db_refs['WM'][1] == \
           (concept1, 0.5), pa.stmts[0].concept.db_refs['WM']
    assert pa.stmts[0].concept.db_refs['WM'][2] == \
           (concept3, 0.1), pa.stmts[0].concept.db_refs['WM']
    assert pa.stmts[0].delta.polarity == -1
Example #2
0
def test_normalize_opposites_influence():
    concept1 = 'wm/concept/causal_factor/food_security/food_stability'
    concept2 = 'wm/concept/causal_factor/food_insecurity/food_instability'
    dbr1 = {'WM': [(concept1, 1.0), (concept2, 0.5)]}
    dbr2 = {'WM': [(concept2, 1.0), (concept1, 0.5)]}
    stmt = Influence(
        Event(Concept('x', db_refs=dbr1), delta=QualitativeDelta(polarity=1)),
        Event(Concept('y', db_refs=dbr2), delta=QualitativeDelta(polarity=-1)))
    pa = Preassembler(world_ontology, stmts=[stmt])
    pa.normalize_opposites(ns='WM')
    assert pa.stmts[0].subj.delta.polarity == 1
    assert pa.stmts[0].obj.delta.polarity == 1