def test_property_hierachy(self): rdf_content = rdf_prefix + ''' :code a owl:DatatypeProperty ; . :iso_code a owl:DatatypeProperty ; rdfs:subPropertyOf :code ; . :cameo_code a owl:DatatypeProperty ; rdfs:subPropertyOf :code ; . :iso_country_code a owl:DatatypeProperty ; rdfs:subPropertyOf :iso_code ; . :adm1_code a owl:DatatypeProperty ; rdfs:subPropertyOf :iso_code ; . ''' ontology = Ontology(rdf_content) self.assertEqual(len(ontology.all_classes()), 0) self.assertEqual(len(ontology.all_properties()), 5) code = ontology.get_entity(DIG.code.toPython()) self.assertIsNotNone(code) self.assertIsInstance(code, OntologyDatatypeProperty) iso_code = ontology.get_entity(DIG.iso_code.toPython()) self.assertIsNotNone(iso_code) iso_country_code = ontology.get_entity(DIG.iso_country_code.toPython()) self.assertIsNotNone(iso_country_code) self.assertSetEqual(iso_code.super_properties(), {code}) self.assertSetEqual(iso_country_code.super_properties_closure(), {code, iso_code})
def test_inverse_object_property(self): rdf_content = rdf_prefix + ''' :moved_to a owl:ObjectProperty ; :inverse :was_destination_of . ''' ontology = Ontology(rdf_content) self.assertEqual(len(ontology.all_properties()), 2) property_moved = ontology.get_entity(DIG.moved_to.toPython()) property_inverse = ontology.get_entity(DIG.was_destination_of.toPython()) self.assertIsNotNone(property_moved) self.assertIsNotNone(property_inverse) self.assertTrue(property_moved.is_primary()) self.assertFalse(property_inverse.is_primary()) self.assertEqual(property_moved.inverse(), property_inverse) self.assertEqual(property_inverse.inverse(), property_moved)
def test_property_domain(self): rdf_content = rdf_prefix + ''' :Entity a owl:Class . :Type a owl:Class . :Place a owl:Class . :Other a owl:Class ; :common_properties :code . :code a owl:DatatypeProperty ; rdfs:domain [ a owl:Class ; owl:unionOf ( :Type :Place ) ] ; schema:domainIncludes :Entity . ''' ontology = Ontology(rdf_content) property_code = ontology.get_entity(DIG.code.toPython()) self.assertIsInstance(property_code, OntologyDatatypeProperty) self.assertEqual(len(property_code.included_domains()), 4) self.assertSetEqual( property_code.included_domains(), set( map(ontology.get_entity, map(str, (DIG.Entity, DIG.Type, DIG.Other, DIG.Place)))))
def test_datatype_property_range(self): rdf_content = rdf_prefix + ''' :code a owl:DatatypeProperty ; schema:rangeIncludes xsd:string ; . :iso_code a owl:DatatypeProperty ; rdfs:subPropertyOf :code ; . ''' ontology = Ontology(rdf_content) property_code = ontology.get_entity(DIG.code.toPython()) property_iso_code = ontology.get_entity(DIG.code.toPython()) self.assertIsInstance(property_iso_code, OntologyDatatypeProperty) self.assertTrue(property_code.is_legal_object(XSD.string.toPython())) self.assertTrue(property_iso_code.is_legal_object(XSD.string.toPython())) self.assertFalse(property_code.is_legal_object(XSD.dateTime.toPython())) self.assertFalse(property_iso_code.is_legal_object(XSD.dateTime.toPython()))
def test_class_hierachy(self): rdf_content = rdf_prefix + ''' :Entity a owl:Class ; . :Group a owl:Class ; rdfs:subClassOf :Entity ; . :Actor a owl:Class ; owl:subClassOf :Group ; . ''' ontology = Ontology(rdf_content) self.assertEqual(len(ontology.all_classes()), 3) entity = ontology.get_entity(DIG.Entity.toPython()) self.assertIsNotNone(entity) self.assertSetEqual(ontology.root_classes(), {entity}) group = ontology.get_entity(DIG.Group.toPython()) self.assertIsNotNone(group) actor = ontology.get_entity(DIG.Actor.toPython()) self.assertIsNotNone(actor) self.assertSetEqual(group.super_classes(), {entity}) self.assertSetEqual(actor.super_classes(), {group}) self.assertSetEqual(actor.super_classes_closure(), {entity, group})