def GenerateGraph(yaml_object, graph):
    """Utility function to populate in the graph yaml concepts.

  Populates an RDF graph from the yaml content.
  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
    # Construct the classes and the subclasses
    graph, multi_state = rdf_helper.CreateClassInGraph(
        graph=graph,
        class_name='State',
        class_description=None,
        parent_clazz=rdflib.OWL.Thing,
        entity_namespace=constants.STATES_NS)
    for clazz, clazz_content in yaml_object.items():
        graph, _ = rdf_helper.CreateClassInGraph(
            graph=graph,
            class_name=clazz.capitalize(),
            class_description=clazz_content,
            parent_clazz=multi_state[0],
            entity_namespace=constants.STATES_NS)
    return graph
Example #2
0
def GenerateGraph(yaml_object, graph):
  """Utility function to populate in the graph yaml concepts.

  Populates an RDF graph from the yaml content.
  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
  # Construct the classes and the subclasses
  graph, subfield = rdf_helper.CreateClassInGraph(
      graph=graph,
      class_name='SubField',
      class_description=None,
      parent_clazz=rdflib.OWL.Thing,
      entity_namespace=constants.SUBFIELDS_NS)
  for clazz in yaml_object.keys():
    graph, clazz_object = rdf_helper.CreateClassInGraph(
        graph=graph,
        class_name=clazz.capitalize(),
        class_description=None,
        parent_clazz=subfield[0],
        entity_namespace=constants.SUBFIELDS_NS)
    clazz_content = yaml_object.get(clazz)
    for each_item in clazz_content:
      graph, _ = rdf_helper.CreateClassInGraph(
          graph=graph,
          class_name=each_item.capitalize(),
          class_description=clazz_content[each_item],
          parent_clazz=clazz_object[0],
          entity_namespace=constants.SUBFIELDS_NS)
  return graph
Example #3
0
 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)
Example #4
0
    def testCreatesImplementsInGraph(self):
        # Prepare data
        graph = rdflib.Graph()
        implements_list = ['CONTROL', 'MONITORING']
        applications_set = set()
        graph, application_class = rdf_helper.CreateClassInGraph(
            graph=graph,
            class_name='Application',
            class_description=None,
            parent_clazz=rdflib.OWL.Thing)

        graph, clazz_object = rdf_helper.CreateClassInGraph(
            graph=graph,
            class_name='clazz',
            class_description='description',
            parent_clazz=application_class[0])

        graph, applications_set = rdf_helper.CreatesImplementsInGraph(
            graph, implements_list, applications_set, application_class,
            clazz_object)

        # Assertions that the applications_set is updated
        self.assertIn('Control', applications_set)
        self.assertIn('Monitoring', applications_set)

        # Assertions for the class relations creations
        self.assertIn(
            (application_class[0], rdflib.RDFS.subClassOf, rdflib.OWL.Thing),
            graph)
        self.assertIn(
            (clazz_object[0], rdflib.RDFS.subClassOf, application_class[0]),
            graph)
        self.assertIn((clazz_object[0], rdflib.RDFS.subClassOf,
                       constants.DIGITAL_BUILDINGS_NS['Control']), graph)
        self.assertIn((clazz_object[0], rdflib.RDFS.subClassOf,
                       constants.DIGITAL_BUILDINGS_NS['Control']), graph)
        self.assertIn((constants.DIGITAL_BUILDINGS_NS['Control'],
                       rdflib.RDFS.subClassOf, application_class[0]), graph)
        self.assertIn((constants.DIGITAL_BUILDINGS_NS['Monitoring'],
                       rdflib.RDFS.subClassOf, application_class[0]), graph)
Example #5
0
 def testClassHelperNoDescription(self):
     graph = rdflib.Graph()
     updated_graph, clazz_object = rdf_helper.CreateClassInGraph(
         graph=graph,
         class_name='class_name',
         class_description=None,
         parent_clazz=rdflib.OWL.Thing)
     clazz = rdflib.URIRef(constants.DIGITAL_BUILDINGS_NS['class_name'])
     clazz_object_test = (clazz, rdflib.RDF.type, rdflib.OWL.Class)
     self.assertEqual(clazz_object, clazz_object_test)
     self.assertIn(clazz_object_test, updated_graph)
     self.assertIn((clazz, rdflib.RDFS.subClassOf, rdflib.OWL.Thing),
                   updated_graph)
     self.assertIn((clazz, rdflib.RDFS.label, rdflib.Literal('class_name')),
                   updated_graph)
     self.assertNotIn((clazz, rdflib.RDFS.comment, rdflib.Literal('')),
                      updated_graph)
Example #6
0
    def testAbstractGraphGeneration(self):

        fake_abstract = 'fake_resources/Abstract.yaml'

        file_contents = rdf_helper.ReadFile(fake_abstract)

        yaml_abstract = yaml_handler.ImportYamlFiles(file_contents)

        # Create global graph
        graph = rdflib.Graph()
        # Generate the graph by the function handler
        graph = rdflib_function_handler.GenerateGraph(yaml_abstract, graph)

        # Build a second graph manually in order to compare it with the one above:
        # DD:
        # description: "Dual duct flow control (hot deck, cold deck)."
        # is_abstract: true
        # opt_uses:
        # - discharge_air_temperature_sensor
        # - run_command
        # uses:
        # - heating_air_flowrate_sensor
        # - heating_air_flowrate_setpoint
        # implements:
        # - CONTROL

        expected_graph = rdflib.Graph()
        # Main Types
        functionality = rdflib.URIRef(constants.HVAC_NS['Functionality'])
        entity_type = rdflib.URIRef(
            constants.DIGITAL_BUILDINGS_NS['EntityType'])
        dd_description = 'Dual duct flow control (hot deck, cold deck).'
        # Main Classes
        dd_expected = infixowl.Class(identifier=constants.HVAC_NS['Dd'],
                                     graph=expected_graph,
                                     subClassOf=[functionality])
        expected_graph, _ = rdf_helper.CreateClassInGraph(
            graph=expected_graph,
            class_name='Dd',
            class_description=dd_description,
            parent_clazz=functionality,
            entity_namespace=constants.HVAC_NS)
        infixowl.Class(identifier=constants.SUBFIELDS_NS['Point_type'],
                       graph=expected_graph)

        uses_property = infixowl.Property(
            identifier=constants.DIGITAL_BUILDINGS_NS['uses'],
            baseType=infixowl.OWL_NS.ObjectProperty,
            graph=expected_graph)

        is_composed_of_property = infixowl.Property(
            identifier=constants.DIGITAL_BUILDINGS_NS['isComposedOf'],
            baseType=infixowl.OWL_NS.ObjectProperty,
            graph=expected_graph)
        uses_property_optionally = infixowl.Property(
            identifier=constants.DIGITAL_BUILDINGS_NS['usesOptional'],
            baseType=infixowl.OWL_NS.ObjectProperty,
            graph=expected_graph)

        infixowl.Class(identifier=constants.SUBFIELDS_NS['Air'],
                       graph=expected_graph)

        infixowl.Class(identifier=constants.SUBFIELDS_NS['Flowrate'],
                       graph=expected_graph)

        infixowl.Class(identifier=constants.SUBFIELDS_NS['Heating'],
                       graph=expected_graph)

        infixowl.Class(identifier=constants.SUBFIELDS_NS['Run'],
                       graph=expected_graph)

        infixowl.Class(identifier=constants.SUBFIELDS_NS['Command'],
                       graph=expected_graph)

        infixowl.Class(identifier=constants.SUBFIELDS_NS['Discharge'],
                       graph=expected_graph)

        infixowl.Class(identifier=constants.SUBFIELDS_NS['Temperature'],
                       graph=expected_graph)

        infixowl.Class(identifier=constants.SUBFIELDS_NS['Sensor'],
                       graph=expected_graph)

        infixowl.Class(identifier=constants.FIELDS_NS['Field'],
                       graph=expected_graph)

        heating_air_flowrate_sensor = infixowl.Class(
            identifier=constants.FIELDS_NS['Heating_air_flowrate_sensor'],
            graph=expected_graph,
            subClassOf=[constants.FIELDS_NS['Field']])
        heating_air_flowrate_setpoint = infixowl.Class(
            identifier=constants.FIELDS_NS['Heating_air_flowrate_setpoint'],
            graph=expected_graph,
            subClassOf=[constants.FIELDS_NS['Field']])

        concat = heating_air_flowrate_sensor & heating_air_flowrate_setpoint
        dd_expected.subClassOf = [uses_property | infixowl.only | concat]

        discharge_air_temperature_sensor = infixowl.Class(
            identifier=constants.FIELDS_NS['Discharge_air_temperature_sensor'],
            graph=expected_graph,
            subClassOf=[constants.FIELDS_NS['Field']])
        run_command = infixowl.Class(
            identifier=constants.FIELDS_NS['Run_command'],
            graph=expected_graph,
            subClassOf=[constants.FIELDS_NS['Field']])

        concat2 = discharge_air_temperature_sensor | run_command
        dd_expected.subClassOf = [
            uses_property_optionally | infixowl.some | concat2
        ]

        list_composition = rdf_helper.DecomposeStandardFieldName(
            'Discharge_air_temperature_sensor')
        expected_graph = rdf_helper.CreatesStandardFieldNameCompositionInGraph(
            graph=expected_graph,
            list_composition=list_composition,
            standard_field_name='Discharge_air_temperature_sensor',
            is_composed_of_property=is_composed_of_property)

        list_composition = rdf_helper.DecomposeStandardFieldName('Run_command')
        expected_graph = rdf_helper.CreatesStandardFieldNameCompositionInGraph(
            graph=expected_graph,
            list_composition=list_composition,
            standard_field_name='Run_command',
            is_composed_of_property=is_composed_of_property)

        list_composition = rdf_helper.DecomposeStandardFieldName(
            'Heating_air_flowrate_sensor')
        expected_graph = rdf_helper.CreatesStandardFieldNameCompositionInGraph(
            graph=expected_graph,
            list_composition=list_composition,
            standard_field_name='Heating_air_flowrate_sensor',
            is_composed_of_property=is_composed_of_property)

        list_composition = rdf_helper.DecomposeStandardFieldName(
            'Heating_air_flowrate_setpoint')
        expected_graph = rdf_helper.CreatesStandardFieldNameCompositionInGraph(
            graph=expected_graph,
            list_composition=list_composition,
            standard_field_name='Heating_air_flowrate_setpoint',
            is_composed_of_property=is_composed_of_property)

        expected_graph, functionality_class = rdf_helper.CreateClassInGraph(
            graph=expected_graph,
            class_name='Functionality',
            class_description=None,
            parent_clazz=entity_type,
            entity_namespace=constants.HVAC_NS)

        expected_graph, application = rdf_helper.CreateClassInGraph(
            graph=expected_graph,
            class_name='Application',
            class_description=None,
            parent_clazz=entity_type)

        expected_graph, control = rdf_helper.CreateClassInGraph(
            graph=expected_graph,
            class_name='Control',
            class_description=None,
            parent_clazz=application[0])

        expected_graph, _ = rdf_helper.CreateClassInGraph(
            graph=expected_graph,
            class_name='Dd',
            class_description=dd_description,
            parent_clazz=functionality_class[0],
            entity_namespace=constants.HVAC_NS)

        expected_graph, _ = rdf_helper.CreateClassInGraph(
            graph=expected_graph,
            class_name='Dd',
            class_description=dd_description,
            parent_clazz=control[0],
            entity_namespace=constants.HVAC_NS)

        # Check if they are similar
        self.assertTrue(compare.similar(graph, expected_graph))
def GenerateGraph(yaml_object, graph, entity_namespace):
    """Utility function updates an RDF graph with the yaml content.

  Updates an RDF graph with the yaml content

  Args:
    yaml_object: the yaml content.
    graph: the global graph where the ontology is being built in RDF.
    entity_namespace: the namespace to be attributed to the given types

  Returns:
    a graph with the contents of the yaml file merged
  """

    # Ignore entities implementing the following keywords in their definition
    ignore_generation_set = {
        "DEPRECATED", "INCOMPLETE", "IGNORE", "REMAP_REQUIRED"
    }
    field = rdflib.URIRef(constants.FIELDS_NS["Field"])
    # Prepare properties to be added to the graph and not in the yaml
    uses_property = infixowl.Property(
        identifier=constants.DIGITAL_BUILDINGS_NS["uses"],
        baseType=infixowl.OWL_NS.ObjectProperty,
        graph=graph)
    uses_property_optionally = infixowl.Property(
        identifier=constants.DIGITAL_BUILDINGS_NS["usesOptional"],
        baseType=infixowl.OWL_NS.ObjectProperty,
        graph=graph)
    is_composed_of_property = infixowl.Property(
        identifier=constants.DIGITAL_BUILDINGS_NS["isComposedOf"],
        baseType=infixowl.OWL_NS.ObjectProperty,
        graph=graph)
    infixowl.Class(identifier=constants.SUBFIELDS_NS["Point_type"],
                   graph=graph)

    # Traverse the yaml content
    for clazz, clazz_content in yaml_object.items():
        class_name = clazz.capitalize()
        implements = clazz_content.get("implements")
        # implements content will decide if the class is added to the graph or not
        ignore_class = False
        if implements is not None:
            for implements_item in implements:
                if implements_item in ignore_generation_set:
                    ignore_class = True

        # Generate the class if it does not have implements field
        #   or no (DEPRECATED or INCOMPLETE)
        if ignore_class:
            continue

        # Create the class
        parent = (entity_namespace[implements[0].capitalize()]
                  if implements is not None else namespace.OWL.Thing)
        graph, _ = rdf_helper.CreateClassInGraph(
            graph=graph,
            class_name=class_name,
            class_description=clazz_content.get("description"),
            parent_clazz=parent,
            entity_namespace=entity_namespace)
        # update parents only if implements is not None
        if implements is not None:
            for implements_item in implements[1:]:
                graph.add((entity_namespace[class_name.capitalize()],
                           rdflib.RDFS.subClassOf,
                           entity_namespace[implements_item.capitalize()]))

        # check the mandatory fields
        uses = clazz_content.get("uses")
        if uses is not None and isinstance(uses, list):
            for each_item in uses:
                list_composition = rdf_helper.DecomposeStandardFieldName(
                    each_item)
                graph = rdf_helper.CreatesStandardFieldNameCompositionInGraph(
                    graph=graph,
                    list_composition=list_composition,
                    standard_field_name=each_item,
                    is_composed_of_property=is_composed_of_property)
                class_owl = infixowl.Class(
                    identifier=entity_namespace[class_name],
                    graph=graph,
                    subClassOf=[parent])
                graph = rdf_helper.CreateCompositionInGraph(
                    list_standard_field_names=uses,
                    composition_operator="&",
                    composition_property=uses_property,
                    restriction=infixowl.only,
                    class_owl=class_owl,
                    graph=graph,
                    entity_namespace=constants.FIELDS_NS,
                    sub_class_of=[field])

        # check the optional fields
        opt_uses = clazz_content.get("opt_uses")
        if opt_uses is not None and isinstance(opt_uses, list):
            for each_item in opt_uses:
                list_composition = rdf_helper.DecomposeStandardFieldName(
                    each_item)
                graph = rdf_helper.CreatesStandardFieldNameCompositionInGraph(
                    graph=graph,
                    list_composition=list_composition,
                    standard_field_name=each_item,
                    is_composed_of_property=is_composed_of_property)
                class_owl = infixowl.Class(
                    identifier=entity_namespace[class_name],
                    graph=graph,
                    subClassOf=[parent])
                graph = rdf_helper.CreateCompositionInGraph(
                    list_standard_field_names=opt_uses,
                    composition_operator="|",
                    composition_property=uses_property_optionally,
                    restriction=infixowl.some,
                    class_owl=class_owl,
                    graph=graph,
                    entity_namespace=constants.FIELDS_NS,
                    sub_class_of=[field])
    return graph
Example #8
0
def GenerateGraph(yaml_object, graph):
    """Utility function updates an RDF graph with the yaml content of the GeneralTypes.yaml.

  The content of each object is similar to the following:
   CHL:
    id: "9950288448474578944"
    description: "Tag for chillers."
    is_abstract: true
    implements:
    - EQUIPMENT
    opt_uses:
    - cooling_thermal_power_capacity
    - power_capacity
    - efficiency_percentage_specification
    - flowrate_requirement

  Updates an RDF graph with the yaml content.

  Args:
    yaml_object: the yaml content.
    graph: the global graph where the ontology is being built in RDF.

  Returns:
    a graph with the contents of the yaml file merged
  """
    # Applications Set used to avoid recreating applications again in the graph
    applications_set = {"Equipment"}
    # Prepare classes to be added to the graph and not in the yaml
    equipment = rdflib.URIRef(constants.DIGITAL_BUILDINGS_NS["Equipment"])
    entity_type = rdflib.URIRef(constants.DIGITAL_BUILDINGS_NS["EntityType"])
    field = rdflib.URIRef(constants.FIELDS_NS["Field"])
    infixowl.Class(identifier=constants.FIELDS_NS["Field"], graph=graph)
    infixowl.Class(identifier=constants.SUBFIELDS_NS["Point_type"],
                   graph=graph)
    graph, application_class = rdf_helper.CreateClassInGraph(
        graph=graph,
        class_name="Application",
        class_description=None,
        parent_clazz=entity_type)
    graph, _ = rdf_helper.CreateClassInGraph(graph=graph,
                                             class_name="Equipment",
                                             class_description=None,
                                             parent_clazz=entity_type)
    # Prepare properties to be added to the graph and not in the yaml
    uses_property = infixowl.Property(
        identifier=constants.DIGITAL_BUILDINGS_NS["uses"],
        baseType=infixowl.OWL_NS.ObjectProperty,
        graph=graph)
    uses_property_optionally = infixowl.Property(
        identifier=constants.DIGITAL_BUILDINGS_NS["usesOptional"],
        baseType=infixowl.OWL_NS.ObjectProperty,
        graph=graph)
    is_composed_of_property = infixowl.Property(
        identifier=constants.DIGITAL_BUILDINGS_NS["isComposedOf"],
        baseType=infixowl.OWL_NS.ObjectProperty,
        graph=graph)

    # Traverse the yaml content
    for clazz in yaml_object.keys():
        clazz_content = yaml_object.get(clazz)
        class_name = clazz.capitalize()
        implements = clazz_content.get("implements")
        # implements will decide if the entity gets generated in the graph,
        # for now the mother class is equipment, this might change in the near
        # future due to changes in the ontology, keeping the implementation as it is
        if implements is None:
            continue
        else:
            mother_class = equipment

        # Create the class
        graph, clazz_object = rdf_helper.CreateClassInGraph(
            graph=graph,
            class_name=class_name,
            class_description=clazz_content.get("description"),
            parent_clazz=mother_class,
            entity_namespace=constants.HVAC_NS)

        if implements is not None:
            graph, applications_set = rdf_helper.CreatesImplementsInGraph(
                graph=graph,
                implements_list=implements,
                applications_set=applications_set,
                application_class=application_class,
                class_object=clazz_object)

        uses = clazz_content.get("uses")
        if uses is not None:
            if isinstance(uses, list):
                for each_item in uses:
                    list_composition = rdf_helper.DecomposeStandardFieldName(
                        each_item)
                    graph = rdf_helper.CreatesStandardFieldNameCompositionInGraph(
                        graph=graph,
                        list_composition=list_composition,
                        standard_field_name=each_item,
                        is_composed_of_property=is_composed_of_property)
                class_owl = infixowl.Class(
                    identifier=constants.HVAC_NS[class_name],
                    graph=graph,
                    sub_class_of=[equipment])
                graph = rdf_helper.CreateCompositionInGraph(
                    list_standard_field_names=uses,
                    composition_operator="&",
                    composition_property=uses_property,
                    restriction=infixowl.only,
                    class_owl=class_owl,
                    graph=graph,
                    entity_namespace=constants.FIELDS_NS,
                    sub_class_of=[field])

        opt_uses = clazz_content.get("opt_uses")
        if opt_uses is not None:
            if isinstance(opt_uses, list):
                for each_item in opt_uses:
                    list_composition = rdf_helper.DecomposeStandardFieldName(
                        each_item)
                    graph = rdf_helper.CreatesStandardFieldNameCompositionInGraph(
                        graph=graph,
                        list_composition=list_composition,
                        standard_field_name=each_item,
                        is_composed_of_property=is_composed_of_property)
                class_owl = infixowl.Class(
                    identifier=constants.HVAC_NS[class_name],
                    graph=graph,
                    subClassOf=[equipment])
                graph = rdf_helper.CreateCompositionInGraph(
                    list_standard_field_names=opt_uses,
                    composition_operator="|",
                    composition_property=uses_property_optionally,
                    restriction=infixowl.some,
                    class_owl=class_owl,
                    graph=graph,
                    entity_namespace=constants.FIELDS_NS,
                    sub_class_of=[field])

    return graph
Example #9
0
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
Example #10
0
def GenerateGraph(yaml_object, graph):
    """Utility function updates an RDF graph with the yaml content of the Abstract.yaml.

  The content of each object is similar to the following:
    DXRC:
      description: "Compressor run control on return air side (RC)."
      opt_uses:
        discharge_air_temperature_sensor
        leaving_cooling_coil_temperature_sensor
        cooling_thermal_power_capacity
      uses:
        return_air_temperature_setpoint
        return_air_temperature_sensor
        compressor_run_command
        compressor_run_status
      implements:
        CONTROL

  Updates an RDF graph with the yaml content.

  Args:
    yaml_object: the yaml content.
    graph: the global graph where the ontology is being built in RDF.

  Returns:
    a graph with the contents of the yaml file merged
  """
    # Applications Set used to avoid recreating applications again in the graph
    applications_set = set()
    # Prepare classes to be added to the graph and not in the yaml
    functionality = rdflib.URIRef(constants.HVAC_NS["Functionality"])
    entity_type = rdflib.URIRef(constants.DIGITAL_BUILDINGS_NS["EntityType"])
    field = rdflib.URIRef(constants.FIELDS_NS["Field"])
    infixowl.Class(identifier=constants.FIELDS_NS["Field"], graph=graph)
    infixowl.Class(identifier=constants.SUBFIELDS_NS["Point_type"],
                   graph=graph)
    graph, _ = rdf_helper.CreateClassInGraph(
        graph=graph,
        class_name="Functionality",
        class_description=None,
        parent_clazz=entity_type,
        entity_namespace=constants.HVAC_NS)

    graph, application_class = rdf_helper.CreateClassInGraph(
        graph=graph,
        class_name="Application",
        class_description=None,
        parent_clazz=entity_type)

    # Prepare properties to be added to the graph and not in the yaml
    uses_property = infixowl.Property(
        identifier=constants.DIGITAL_BUILDINGS_NS["uses"],
        baseType=infixowl.OWL_NS.ObjectProperty,
        graph=graph)
    uses_property_optionally = infixowl.Property(
        identifier=constants.DIGITAL_BUILDINGS_NS["usesOptional"],
        baseType=infixowl.OWL_NS.ObjectProperty,
        graph=graph)
    is_composed_of_property = infixowl.Property(
        identifier=constants.DIGITAL_BUILDINGS_NS["isComposedOf"],
        baseType=infixowl.OWL_NS.ObjectProperty,
        graph=graph)

    # Traverse the yaml content
    for clazz, clazz_content in yaml_object.items():
        class_name = clazz.capitalize()
        graph, clazz_object = rdf_helper.CreateClassInGraph(
            graph=graph,
            class_name=class_name,
            class_description=clazz_content.get("description"),
            parent_clazz=functionality,
            entity_namespace=constants.HVAC_NS)

        implements = clazz_content.get("implements")
        if implements is not None:
            graph, applications_set = rdf_helper.CreatesImplementsInGraph(
                graph=graph,
                implements_list=implements,
                applications_set=applications_set,
                application_class=application_class,
                class_object=clazz_object)

        uses = clazz_content.get("uses")
        if uses is not None:
            if isinstance(uses, list):
                for each_item in uses:
                    list_composition = rdf_helper.DecomposeStandardFieldName(
                        each_item)
                    graph = rdf_helper.CreatesStandardFieldNameCompositionInGraph(
                        graph=graph,
                        list_composition=list_composition,
                        standard_field_name=each_item,
                        is_composed_of_property=is_composed_of_property)
                class_owl = infixowl.Class(
                    identifier=constants.HVAC_NS[class_name],
                    graph=graph,
                    subClassOf=[functionality])
                graph = rdf_helper.CreateCompositionInGraph(
                    list_standard_field_names=uses,
                    composition_operator="&",
                    composition_property=uses_property,
                    restriction=infixowl.only,
                    class_owl=class_owl,
                    graph=graph,
                    entity_namespace=constants.FIELDS_NS,
                    sub_class_of=[field])

        opt_uses = clazz_content.get("opt_uses")
        if opt_uses is not None:
            if isinstance(opt_uses, list):
                for each_item in opt_uses:
                    list_composition = rdf_helper.DecomposeStandardFieldName(
                        each_item)
                    graph = rdf_helper.CreatesStandardFieldNameCompositionInGraph(
                        graph=graph,
                        list_composition=list_composition,
                        standard_field_name=each_item,
                        is_composed_of_property=is_composed_of_property)
                class_owl = infixowl.Class(
                    identifier=constants.HVAC_NS[class_name],
                    graph=graph,
                    subClassOf=[functionality])
                graph = rdf_helper.CreateCompositionInGraph(
                    list_standard_field_names=opt_uses,
                    composition_operator="|",
                    composition_property=uses_property_optionally,
                    restriction=infixowl.some,
                    class_owl=class_owl,
                    graph=graph,
                    entity_namespace=constants.FIELDS_NS,
                    sub_class_of=[field])

    return graph
def GenerateGraph(yaml_object, graph):
    """Utility function updates an RDF graph with the yaml content.

  Updates an RDF graph with the yaml content

  Args:
    yaml_object: the yaml content.
    graph: the global graph where the ontology is being built in RDF.

  Returns:
    a graph with the contents of the yaml file merged
  """
    # Create the node to add to the Graph
    physical_location = rdflib.URIRef(
        constants.FACILITIES_NS["PhysicalLocation"])
    entity_type = rdflib.URIRef(constants.DIGITAL_BUILDINGS_NS["EntityType"])
    has_physical_location = rdflib.URIRef(
        constants.DIGITAL_BUILDINGS_NS["hasPhysicalLocation"])
    has_floor = rdflib.URIRef(constants.DIGITAL_BUILDINGS_NS["hasFloor"])
    has_room = rdflib.URIRef(constants.DIGITAL_BUILDINGS_NS["hasRoom"])

    has_room_property = infixowl.Property(
        identifier=constants.DIGITAL_BUILDINGS_NS["hasRoom"],
        baseType=infixowl.OWL_NS.ObjectProperty,
        graph=graph)

    has_floor_property = infixowl.Property(
        identifier=constants.DIGITAL_BUILDINGS_NS["hasFloor"],
        baseType=infixowl.OWL_NS.ObjectProperty,
        graph=graph)

    # Add the OWL data to the graph
    graph.add((physical_location, rdflib.RDF.type, rdflib.OWL.Class))
    graph.add((physical_location, rdflib.RDFS.subClassOf, entity_type))
    graph.add((physical_location, rdflib.RDFS.label,
               rdflib.Literal("PhysicalLocation")))
    graph.add((physical_location, rdflib.RDFS.comment,
               rdflib.Literal("The class of all physical locations")))

    # Construct the classes and the subclasses
    map_name_object = {}
    for clazz in yaml_object.keys():
        clazz_content = yaml_object.get(clazz)
        description = clazz_content.get("description")
        clazz_object = rdf_helper.CreateClassInGraph(
            graph,
            clazz.capitalize(),
            description,
            physical_location,
            entity_namespace=constants.FACILITIES_NS)
        map_name_object[clazz.capitalize()] = clazz_object

    # Construct the object properties
    graph.add(
        (has_physical_location, rdflib.RDF.type, rdflib.OWL.ObjectProperty))
    graph.add((has_physical_location, rdflib.RDF.type,
               rdflib.OWL.TransitiveProperty))
    graph.add((has_floor, rdflib.RDF.type, rdflib.OWL.ObjectProperty))
    graph.add((has_room, rdflib.RDF.type, rdflib.OWL.ObjectProperty))

    # Construct the sub object properties
    graph.add((has_floor, rdflib.RDFS.subPropertyOf, has_physical_location))
    graph.add((has_room, rdflib.RDFS.subPropertyOf, has_physical_location))

    # Link the graph together, done manually until the yaml evolves
    class_floor = infixowl.Class(identifier=constants.FACILITIES_NS["Floor"],
                                 graph=graph)
    class_room = infixowl.Class(identifier=constants.FACILITIES_NS["Room"],
                                graph=graph)
    class_building = infixowl.Class(
        identifier=constants.FACILITIES_NS["Building"], graph=graph)
    class_building.subClassOf = [
        has_floor_property | infixowl.only | class_floor
    ]
    class_floor.subClassOf = [has_room_property | infixowl.only | class_room]

    return graph