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_basic_entity_info(self): rdf_content = rdf_prefix + ''' :Entity a owl:Class ; rdfs:label "Entity" ; skos:definition """Everything that can be described, similar to owl:Thing.""" ; :common_properties :label, :title, :description ; . ''' ontology = Ontology(rdf_content) self.assertEqual(len(ontology.all_classes()), 1) for entity in ontology.all_classes(): self.assertIsInstance(entity, OntologyEntity) self.assertIsInstance(entity, OntologyClass) self.assertEqual(len(ontology.all_properties()), 0) for entity in ontology.all_properties(): self.assertIsInstance(entity, OntologyEntity) self.assertIsInstance(entity, OntologyProperty) self.assertEqual(len(ontology.root_classes()), 1) for entity in ontology.root_classes(): self.assertIsInstance(entity, OntologyClass) self.assertEqual(len(entity.super_classes()), 0)
def test_ontology_schema_org_datatype(self): import json rdf_content = rdf_prefix + ''' schema:Person a owl:Class ; . schema:Text a schema:DataType, rdfs:Class ; . schema:name a rdf:Property ; schema:domainIncludes schema:Person ; schema:rangeIncludes schema:Person . ''' kg = ''' { "@type": ["http://schema.org/Person"], "@id": "person1", "http://schema.org/name": "Person Name" } ''' ontology = Ontology(rdf_content) for entity in ontology.all_classes(): self.assertIsInstance(entity, OntologyEntity) self.assertIsInstance(entity, OntologyClass) self.assertEqual(len(ontology.all_properties()), 1) return_value = ontology.is_valid('schema:name', "person name1", json.loads(kg)) self.assertEqual(return_value, {'@id': 'person name1'}) rdf_content = rdf_prefix + ''' schema:Person a owl:Class ; . schema:DataType a owl:Class ; . schema:Text a schema:DataType, owl:Class ; . schema:name a rdf:Property ; schema:domainIncludes schema:Person ; schema:rangeIncludes schema:Text . ''' ontology = Ontology(rdf_content) kg = ''' { "@type": ["http://schema.org/Person"], "@id": "person1", "http://schema.org/name": "Person Name" } ''' return_value = ontology.is_valid('schema:name', "person name1", json.loads(kg)) self.assertEqual(return_value, {'@value': 'person name1'})
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})
def test_ontology_schema_org(self): import json rdf_content = rdf_prefix + ''' schema:Person a owl:Class ; . schema:relatedTo a rdf:Property ; schema:domainIncludes schema:Person ; schema:rangeIncludes schema:Person . ''' kg = ''' { "@type": ["http://schema.org/Person"], "@id": "person1", "http://schema.org/relatedTo": { "@type": ["http://schema.org/Person"], "@id": "person2" } } ''' ontology = Ontology(rdf_content) for entity in ontology.all_classes(): self.assertIsInstance(entity, OntologyEntity) self.assertIsInstance(entity, OntologyClass) self.assertEqual(len(ontology.all_properties()), 1) kg_json = json.loads(kg) config = ontology.merge_with_master_config(kg_json, delete_orphan_fields=True) self.assertTrue('fields' in config) fields = config['fields'] self.assertIn('relatedTo', fields) # self.assertTrue( ontology.is_valid('schema:relatedTo', kg_json["http://schema.org/relatedTo"], kg_json))