def test_event_decrease(): test_file = os.path.join(path_here, 'sofia_event_decreased.json') sp = sofia.process_json_file(test_file) assert len(sp.statements) == 1, sp.statements stmt = sp.statements[0] assert isinstance(stmt, Event), stmt assert stmt.delta.polarity == -1, stmt.delta assert stmt.concept.name == 'rainfall', stmt.concept # Test extraction filter sp = sofia.process_json_file(test_file, extract_filter={'influence'}) assert len(sp.statements) == 0
def test_influence_event_polarity(): test_file = os.path.join(path_here, 'sofia_infl_polarities.json') sp = sofia.process_json_file(test_file) assert len(sp.statements) == 1, sp.statements stmt = sp.statements[0] assert isinstance(stmt, Influence) assert stmt.subj.delta['polarity'] == 1, stmt.subj.delta assert stmt.obj.delta['polarity'] == -1, stmt.obj.delta
def test_event_decrease(): test_file = os.path.join(path_here, 'sofia_event_decreased.json') sp = sofia.process_json_file(test_file) assert len(sp.statements) == 1, sp.statements stmt = sp.statements[0] assert isinstance(stmt, Event), stmt assert stmt.delta['polarity'] == -1, stmt.delta assert stmt.concept.name == 'rainfall', stmt.concept
def test_influence_event_polarity(): test_file = os.path.join(path_here, 'sofia_infl_polarities.json') sp = sofia.process_json_file(test_file) assert len(sp.statements) == 1, sp.statements stmt = sp.statements[0] assert isinstance(stmt, Influence) assert stmt.subj.delta.polarity == 1, stmt.subj.delta assert stmt.obj.delta.polarity == -1, stmt.obj.delta
def test_event_decrease(): test_file = os.path.join(path_here, 'sofia_event_decreased.json') sp = sofia.process_json_file(test_file) assert len(sp.statements) == 1, sp.statements stmt = sp.statements[0] assert isinstance(stmt, Event), stmt assert stmt.delta.polarity == -1, stmt.delta assert stmt.concept.name == 'rainfall', stmt.concept
def test_process_json(): test_file = os.path.join(path_here, 'sofia_test.json') sp = sofia.process_json_file(test_file) assert len(sp.statements) == 2 assert isinstance(sp.statements[0], Influence) assert sp.statements[0].subj.concept.name == 'rainfall' assert sp.statements[0].obj.concept.name == 'floods' assert len(sp.statements[0].evidence) == 1, len(sp.statements[0].evidence) assert isinstance(sp.statements[1], Event) assert sp.statements[1].concept.name == 'inflation' assert isinstance(sp.statements[1].context, WorldContext) assert sp.statements[1].context.time.text == '28, JULY, 2016' assert sp.statements[1].context.geo_location.name == 'South Sudan'
def test_compositional_grounding(): test_file = os.path.join(path_here, 'sofia_test_comp_no_causal.json') sp = sofia.process_json_file(test_file, grounding_mode='compositional') assert len(sp.statements) == 2 assert isinstance(sp.statements[0], Event) assert isinstance(sp.statements[1], Event) assert sp.statements[0].concept.db_refs['TEXT'] == 'wheat', \ sp.statements[0].concept.db_refs assert isinstance(sp.statements[0].concept.db_refs['WM'], list) assert isinstance(sp.statements[0].concept.db_refs['WM'][0], tuple), \ sp.statements[0].concept.db_refs['WM'] assert sp.statements[1].concept.db_refs['TEXT'] == 'cereal' assert isinstance(sp.statements[1].concept.db_refs['WM'], list) assert isinstance(sp.statements[1].concept.db_refs['WM'][0], tuple)
for reader in readers: version = reader_versions[grounding][reader] pattern = '*' if reader != 'sofia' \ else ('*_new' if grounding == 'compositional' else '*_old') fnames = glob.glob('/Users/ben/data/dart/%s/%s/%s' % (reader, version, pattern)) print('Found %d files for %s' % (len(fnames), reader)) for fname in tqdm.tqdm(fnames): if reader == 'eidos': pp = eidos.process_json_file(fname, grounding_mode=grounding) elif reader == 'hume': pp = hume.process_jsonld_file(fname, grounding_mode=grounding) elif reader == 'cwms': pp = cwms.process_ekb_file(fname, grounding_mode=grounding) elif reader == 'sofia': pp = sofia.process_json_file(fname, grounding_mode=grounding) doc_id = os.path.basename(fname)[:32] for stmt in pp.statements: for ev in stmt.evidence: if 'provenance' not in ev.annotations: ev.annotations['provenance'] = [{ 'document': { '@id': doc_id } }] else: prov = ev.annotations['provenance'][0]['document'] prov['@id'] = doc_id stmts += pp.statements if grounding == 'compositional': validate_grounding_format(stmts)