Exemplo n.º 1
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)
Exemplo n.º 2
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
Exemplo n.º 3
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