def testInstanceHelperNoDescription(self): graph = rdflib.Graph() updated_graph, clazz_object = rdf_helper.CreateClassInGraph( graph=graph, class_name='class_name', class_description='description', parent_clazz=rdflib.OWL.Thing) updated_graph, instance_object = rdf_helper.CreateInstanceInGraph( graph=updated_graph, instance_name='instance_name', instance_description=None, parent_clazz=clazz_object) instance = rdflib.URIRef( constants.DIGITAL_BUILDINGS_NS['instance_name']) instance_object_test = (instance, rdflib.RDF.type, rdflib.OWL.NamedIndividual) self.assertEqual(instance_object, instance_object_test) self.assertIn(instance_object_test, updated_graph) self.assertIn((instance, rdflib.RDF.type, clazz_object[0]), updated_graph) self.assertIn( (instance, rdflib.RDFS.label, rdflib.Literal('instance_name')), updated_graph) self.assertNotIn((instance, rdflib.RDFS.comment, rdflib.Literal('')), updated_graph)
def GenerateGraph(yaml_object, graph): """Utility function to populate in the graph yaml concepts. Populates an RDF graph from the yaml content. The units yaml content is either a string or a dictionary, example below: - kelvins: STANDARD - degrees_celsius - degrees_fahrenheit Args: yaml_object: the yaml content. graph: the global graph where the ontology is being built in RDF. Returns: a graph with the newly built class """ # Create the node to add to the Graph unit = rdflib.URIRef(constants.UNITS_NS['Unit']) graph, _ = rdf_helper.CreateClassInGraph( graph, 'Unit', 'Class of all units', rdflib.OWL.Thing, entity_namespace=constants.UNITS_NS) graph, standard_unit_data_property_object = rdf_helper.CreateDataPropertyInGraph( graph, data_property_name='is_standard_unit', data_property_description= 'The International System of Units (abbreviated SI from systeme internationale , the French version of the name) is a scientific method of expressing the magnitudes or quantities of important natural phenomena. There are seven base units in the system, from which other units are derived.' ) # Construct the classes and the subclasses for clazz in yaml_object.keys(): graph, clazz_object = rdf_helper.CreateClassInGraph( graph=graph, class_name=clazz.capitalize(), class_description=None, parent_clazz=unit, entity_namespace=constants.UNITS_NS) clazz_content = yaml_object.get(clazz) for each_item in clazz_content: # When a unit is standard it is a dict, example: kelvins: STANDARD. if isinstance(each_item, dict): instance_name = list(each_item.keys())[0] is_standard = each_item[instance_name] else: is_standard = False instance_name = each_item # Construct the instances graph, instance_object = rdf_helper.CreateInstanceInGraph( graph=graph, instance_name=instance_name, instance_description=None, parent_clazz=clazz_object, entity_namespace=constants.UNITS_NS) if is_standard: graph.add( (instance_object[0], standard_unit_data_property_object[0], rdflib.Literal(True))) else: graph.add( (instance_object[0], standard_unit_data_property_object[0], rdflib.Literal(False))) return graph