Пример #1
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')
Пример #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_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')
Пример #4
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')
Пример #5
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')
Пример #6
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')
Пример #7
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')
Пример #8
0
def test_load_eidos_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')
Пример #9
0
def test_load_eidos_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('EIDOS', a, 'EIDOS', b)
    assert eidos_isa('events/human/conflict/war', 'events/human/conflict')
    assert not eidos_isa('events/human/conflict/war',
                         'events/human/human_migration/migration')
    assert eidos_isa('entities/measurement/distance/meter',
                     'entities/measurement')
    assert eidos_isa('events/natural/weather/storm/tornado', 'events')
    assert not eidos_isa('events', 'events/natural/weather/storm/tornado')
Пример #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')