コード例 #1
0
def test_load_sofia_hierarchy():
    sofia_ont = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             '../sources/sofia/sofia_ontology.rdf')
    hm = HierarchyManager(sofia_ont, True, True)
    assert hm.isa_closure
    sofia_isa = lambda a, b: hm.isa('SOFIA', a, 'SOFIA', b)
    assert sofia_isa('Accessibility/Accessibility', 'Accessibility')
    assert not sofia_isa('Movement/Transportation', 'Movement/Human_Migration')
    assert sofia_isa('Movement/Human_Migration', 'Movement')
コード例 #2
0
def test_load_hume_hierarchy():
    hume_ont = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            '../sources/hume/hume_ontology.rdf')
    hm = HierarchyManager(hume_ont, True, True)
    assert hm.isa_closure
    hume_isa = lambda a, b: hm.isa('HUME', a, 'HUME', b)
    assert hume_isa('entity/academic_discipline', 'entity')
    assert not hume_isa('entity', 'entity/academic_discipline')
    assert hume_isa('event/healthcare/human_disease',
                    'event/healthcare')
コード例 #3
0
def test_load_trips_hierarchy():
    trips_ont = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             '../sources/cwms/trips_ontology.rdf')
    hm = HierarchyManager(trips_ont, True, True)
    assert hm.isa_closure
    trips_isa = lambda a, b: hm.isa('CWMS', a, 'CWMS', b)
    assert trips_isa('ONT::TRUCK', 'ONT::VEHICLE')
    assert not trips_isa('ONT::VEHICLE', 'ONT::TRUCK')
    assert trips_isa('ONT::MONEY', 'ONT::PHYS-OBJECT')
    assert trips_isa('ONT::TABLE', 'ONT::MANUFACTURED-OBJECT')
コード例 #4
0
def test_influence_duplicate():
    gov = 'UN/entities/human/government/government_entity'
    agr = 'UN/entities/natural/crop_technology'
    cgov = Event(Concept('government', db_refs={'UN': [(gov, 1.0)]}))
    cagr = Event(Concept('agriculture', db_refs={'UN': [(agr, 1.0)]}))
    stmt1 = Influence(cgov, cagr, evidence=[Evidence(source_api='eidos1')])
    stmt2 = Influence(cagr, cgov, evidence=[Evidence(source_api='eidos2')])
    stmt3 = Influence(cgov, cagr, evidence=[Evidence(source_api='eidos3')])
    eidos_ont = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             '../sources/eidos/eidos_ontology.rdf')
    hm = HierarchyManager(eidos_ont, True, True)
    hierarchies = {'entity': hm}
    pa = Preassembler(hierarchies, [stmt1, stmt2, stmt3])
    unique_stmts = pa.combine_duplicates()
    assert len(unique_stmts) == 2
    assert len(unique_stmts[0].evidence) == 2
    assert len(unique_stmts[1].evidence) == 1
    sources = [e.source_api for e in unique_stmts[0].evidence]
    assert set(sources) == set(['eidos1', 'eidos3'])
コード例 #5
0
ファイル: test_preassembler.py プロジェクト: budakn/INDRA
def test_influence_refinement():
    tran = 'UN/entities/human/infrastructure/transportation'
    truck = 'UN/entities/human/infrastructure/transportation/' + \
        'transportation_methods'
    agr = 'UN/entities/human/livelihood'
    ctran = Concept('transportation', db_refs={'UN': [(tran, 1.0)]})
    ctruck = Concept('trucking', db_refs={'UN': [(truck, 1.0)]})
    cagr = Concept('agriculture', db_refs={'UN': [(agr, 1.0)]})
    stmt1 = Influence(ctran, cagr, evidence=[Evidence(source_api='eidos1')])
    stmt2 = Influence(ctruck, cagr, evidence=[Evidence(source_api='eidos2')])
    stmt3 = Influence(cagr, ctran, evidence=[Evidence(source_api='eidos3')])
    eidos_ont = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             '../sources/eidos/eidos_ontology.rdf')
    hm = HierarchyManager(eidos_ont, True, True)
    hierarchies = {'entity': hm}
    pa = Preassembler(hierarchies, [stmt1, stmt2, stmt3])
    rel_stmts = pa.combine_related()
    assert len(rel_stmts) == 2
    truck_stmt = [st for st in rel_stmts if st.subj.name == 'trucking'][0]
    assert len(truck_stmt.supported_by) == 1
    assert truck_stmt.supported_by[0].subj.name == 'transportation'
コード例 #6
0
def test_association_duplicate():
    ev1 = Event(Concept('a'))
    ev2 = Event(Concept('b'))
    ev3 = Event(Concept('c'))
    # Order of members does not matter
    st1 = Association([ev1, ev2], evidence=[Evidence(source_api='eidos1')])
    st2 = Association([ev1, ev3], evidence=[Evidence(source_api='eidos2')])
    st3 = Association([ev2, ev1], evidence=[Evidence(source_api='eidos3')])
    st4 = Association([ev2, ev3], evidence=[Evidence(source_api='eidos4')])
    st5 = Association([ev2, ev3], evidence=[Evidence(source_api='eidos5')])
    eidos_ont = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             '../sources/eidos/eidos_ontology.rdf')
    hm = HierarchyManager(eidos_ont, True, True)
    hierarchies = {'entity': hm}
    pa = Preassembler(hierarchies, [st1, st2, st3, st4, st5])
    unique_stmts = pa.combine_duplicates()
    assert len(unique_stmts) == 3
    assert len(unique_stmts[0].evidence) == 2
    assert len(unique_stmts[1].evidence) == 1
    assert len(unique_stmts[2].evidence) == 2
    sources = [e.source_api for e in unique_stmts[0].evidence]
    assert set(sources) == set(['eidos1', 'eidos3'])
コード例 #7
0
ファイル: expand_families.py プロジェクト: pupster90/indra
def _agent_from_uri(uri):
    ag_ns, ag_id = HierarchyManager.ns_id_from_uri(uri)
    agent = _agent_from_ns_id(ag_ns, ag_id)
    return agent
コード例 #8
0
def test_load_eid_hierarchy():
    eidos_ont = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             '../sources/eidos/eidos_ontology.rdf')
    eidos_ns = 'https://github.com/clulab/eidos/wiki/JSON-LD/Grounding#'
    hm = HierarchyManager(eidos_ont, True, True)
    assert hm.isa_closure
    eidos_isa = lambda a, b: hm.isa('UN', a, 'UN', b)
    assert eidos_isa('UN/events/human/conflict',
                     'UN/events/human')
    assert not eidos_isa('UN/events/human/conflict',
                         'UN/events/human/human_migration')
    assert eidos_isa('UN/entities/human/infrastructure',
                     'UN/entities')
    assert eidos_isa('UN/events/natural_disaster/storm',
                     'UN/events')
    assert not eidos_isa('UN/events',
                         'UN/events/natural/weather/storm')
    # Test case where graph is not given
    hm = HierarchyManager(None, True, True)
    hm.load_from_rdf_file(eidos_ont)
    assert eidos_isa('UN/events/natural_disaster/storm',
                     'UN/events')
    # Test loading from string
    with open(eidos_ont, 'r') as fh:
        hm = HierarchyManager(None, True, True)
        hm.load_from_rdf_string(fh.read())
    assert eidos_isa('UN/events/natural_disaster/storm',
                     'UN/events')
    # Test loading from Graph
    import rdflib
    g = rdflib.Graph()
    g.parse(eidos_ont, format='nt')
    hm = HierarchyManager(None, True, True)
    hm.load_from_rdf_graph(g)
    assert eidos_isa('UN/events/natural_disaster/storm',
                     'UN/events')
コード例 #9
0
import os
from indra.preassembler.hierarchy_manager import HierarchyManager

# Make a TRIPS ontology
_fname = os.path.join(os.path.dirname(__file__), 'trips_ontology.rdf')
trips_ontology = HierarchyManager(_fname,
                                  uri_as_name=False,
                                  build_closure=True)
trips_ontology.relations_prefix = 'http://trips.ihmc.us/relations/'
trips_ontology.initialize()


def trips_isa(concept1, concept2):
    # Preprocess to make this more general
    concept1 = concept1.lower().replace('ont::', '')
    concept2 = concept2.lower().replace('ont::', '')
    if concept1 == concept2:
        return True
    isa = trips_ontology.isa('http://trips.ihmc.us/concepts/', concept1,
                             'http://trips.ihmc.us/concepts/', concept2)
    return isa
コード例 #10
0
def test_load_eid_hierarchy():
    eidos_ont = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             '../sources/eidos/eidos_ontology.rdf')
    eidos_ns = 'https://github.com/clulab/eidos/wiki/JSON-LD/Grounding#'
    hm = HierarchyManager(eidos_ont, True, True)
    assert hm.isa_closure
    eidos_isa = lambda a, b: hm.isa('UN', a, 'UN', b)
    assert eidos_isa('UN/events/human/conflict', 'UN/events/human')
    assert not eidos_isa('UN/events/human/conflict',
                         'UN/events/human/human_migration')
    assert eidos_isa('UN/entities/human/infrastructure', 'UN/entities')
    assert eidos_isa('UN/events/natural_disaster/storm', 'UN/events')
    assert not eidos_isa('UN/events', 'UN/events/natural/weather/storm')
    # Test case where graph is not given
    hm = HierarchyManager(None, True, True)
    hm.load_from_rdf_file(eidos_ont)
    assert eidos_isa('UN/events/natural_disaster/storm', 'UN/events')
    # Test loading from string
    with open(eidos_ont, 'r') as fh:
        hm = HierarchyManager(None, True, True)
        hm.load_from_rdf_string(fh.read())
    assert eidos_isa('UN/events/natural_disaster/storm', 'UN/events')
    # Test loading from Graph
    import rdflib
    g = rdflib.Graph()
    g.parse(eidos_ont, format='nt')
    hm = HierarchyManager(None, True, True)
    hm.load_from_rdf_graph(g)
    assert eidos_isa('UN/events/natural_disaster/storm', 'UN/events')