コード例 #1
0
 def known_match(self) -> bool:
     """ Return True if graphs DO match, false if we don't actually know """
     if similar(self.expected_graph, self.actual_graph):
         self.in_both, self.old_len, self.new_len = self.new_len, 0, 0
         self.passed = True
         return True
     return False
コード例 #2
0
    def testCreatesCompositionInGraphSomeRestriction(self):
        # Prepare data

        # Build First Graph with the method
        graph = rdflib.Graph()
        # Bind the OWL and Digital Buildings name spaces
        namespace_manager = namespace.NamespaceManager(rdflib.Graph())
        namespace_manager.bind('owl', rdflib.OWL)
        namespace_manager.bind('db', constants.DIGITAL_BUILDINGS_NS)
        graph.namespace_manager = namespace_manager
        list_standard_field_name = [
            'cooling_air_flowrate_sensor_1', 'run_command'
        ]
        uses_property = infixowl.Property(
            identifier=constants.DIGITAL_BUILDINGS_NS['uses'],
            baseType=infixowl.OWL_NS.ObjectProperty,
            graph=graph)
        class_owl = infixowl.Class(
            identifier=constants.DIGITAL_BUILDINGS_NS['DFSS'], graph=graph)

        graph = rdf_helper.CreateCompositionInGraph(
            composition_operator='|',
            list_standard_field_names=list_standard_field_name,
            restriction=infixowl.some,
            composition_property=uses_property,
            class_owl=class_owl,
            graph=graph)

        # Build a second graph that is expected
        expected_graph = rdflib.Graph()
        # Bind the OWL and Digital Buildings name spaces
        namespace_manager_expected = namespace.NamespaceManager(rdflib.Graph())
        namespace_manager_expected.bind('owl', rdflib.OWL)
        namespace_manager_expected.bind('db', constants.DIGITAL_BUILDINGS_NS)
        expected_graph.namespace_manager = namespace_manager_expected
        class_owl_expected = infixowl.Class(
            identifier=constants.DIGITAL_BUILDINGS_NS['DFSS'],
            graph=expected_graph)

        sfn1_expected = infixowl.Class(
            identifier=constants.
            DIGITAL_BUILDINGS_NS['Cooling_air_flowrate_sensor_1'],
            graph=expected_graph)
        sfn2_expected = infixowl.Class(
            identifier=constants.DIGITAL_BUILDINGS_NS['Run_command'],
            graph=expected_graph)
        uses_property_expected = infixowl.Property(
            identifier=constants.DIGITAL_BUILDINGS_NS['uses'],
            baseType=infixowl.OWL_NS.ObjectProperty,
            graph=expected_graph)

        concat = sfn1_expected | sfn2_expected
        class_owl_expected.subClassOf = [
            uses_property_expected | infixowl.some | concat
        ]

        # Check if they are similar
        self.assertTrue(compare.similar(graph, expected_graph))
コード例 #3
0
ファイル: api.py プロジェクト: aarroyoc/lyncex
def step_diff_content(context, file):
    f = tempfile.NamedTemporaryFile()
    f.write(context.request.content)

    a = rdflib.Graph()
    a.parse(file, format="turtle")
    b = rdflib.Graph()
    b.parse(f.name, format="turtle")
    assert similar(a, b)
コード例 #4
0
 def __init__(self, expected_graph: Graph, actual_graph: Graph) -> None:
     self.old_len, self.new_len = 0, 0
     if similar(expected_graph, actual_graph):
         self.expected_graph = expected_graph
         self.actual_graph = actual_graph
         self.in_both = self.expected_graph
         self.in_old = Graph()
         self.in_new = Graph()
         self.passed = True
     else:
         self.expected_graph = LoggingGraph(expected_graph)
         self.actual_graph = LoggingGraph(actual_graph)
         self.in_both: Graph = Graph()
         self.in_old = expected_graph
         self.in_new = actual_graph
         self.passed = False
     self._upd_lens()
コード例 #5
0
def test_get_subtract_graph():
    g = Graph()
    g.namespace_manager = ns_mgr
    #g.add((D['sample'], RDF.type, FOAF.person))
    g.add((D['sample'], VIVO.overview,
           Literal("Researcher studying economics.")))
    base = BaseBackend()
    base.graph = g

    trip = {}
    trip['subject'] = D['sample']
    trip['predicate'] = 'vivo:overview'
    trip['object'] = "My new overview"

    remove = base.get_subtract_graph(trip)
    #Use similar comparison from rdflib.
    #http://rdflib.readthedocs.org/en/latest/apidocs/rdflib.html#rdflib.compare.similar
    assert (similar(remove, g) is True)
コード例 #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))
コード例 #7
0
 def compare_for_similarity(self, template_graph):
     # Checks if the two graphs are “similar”, by comparing sorted triples where all bnodes have been replaced
     # by a singular mock bnode (the _MOCK_BNODE).
     return similar(self.processed_graph, template_graph.processed_graph)
コード例 #8
0
    def testCreatesStandardFieldNameCompositionInGraph(self):
        # Prepare data

        # Build First Graph with the method
        graph = rdflib.Graph()
        # Bind the OWL and Digital Buildings name spaces
        namespace_manager = namespace.NamespaceManager(graph)
        namespace_manager.bind('owl', rdflib.OWL)
        namespace_manager.bind('db', constants.DIGITAL_BUILDINGS_NS)
        graph.namespace_manager = namespace_manager
        list_composition = ['Cooling', 'Air', 'Flowrate', 'Sensor']
        standard_field_name = 'cooling_air_flowrate_sensor_1'
        is_composed_of_property = infixowl.Property(
            identifier=constants.DIGITAL_BUILDINGS_NS['isComposedOf'],
            baseType=infixowl.OWL_NS.ObjectProperty,
            graph=graph)
        point_type = infixowl.Class(
            identifier=constants.SUBFIELDS_NS['Point_type'], graph=graph)

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

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

        infixowl.Class(
            identifier=constants.FIELDS_NS['Cooling_air_flowrate_sensor_1'],
            graph=graph,
            subClassOf=[field])
        graph = rdf_helper.CreatesStandardFieldNameCompositionInGraph(
            list_composition=list_composition,
            standard_field_name=standard_field_name,
            is_composed_of_property=is_composed_of_property,
            graph=graph)

        # Build a second graph that is expected
        expected_graph = rdflib.Graph()
        # Bind the OWL and Digital Buildings name spaces
        namespace_manager_expected = namespace.NamespaceManager(expected_graph)
        namespace_manager_expected.bind('owl', rdflib.OWL)
        namespace_manager_expected.bind('db', constants.DIGITAL_BUILDINGS_NS)
        expected_graph.namespace_manager = namespace_manager_expected
        field_expected = infixowl.Class(
            identifier=constants.FIELDS_NS['Field'], graph=expected_graph)
        point_type_expected = infixowl.Class(
            identifier=constants.SUBFIELDS_NS['Point_type'],
            graph=expected_graph)
        cooling_expected = infixowl.Class(
            identifier=constants.SUBFIELDS_NS['Cooling'], graph=expected_graph)
        air_expected = infixowl.Class(identifier=constants.SUBFIELDS_NS['Air'],
                                      graph=expected_graph)
        flowrate_expected = infixowl.Class(
            identifier=constants.SUBFIELDS_NS['Flowrate'],
            graph=expected_graph)
        sensor_expected = infixowl.Class(
            identifier=constants.SUBFIELDS_NS['Sensor'],
            graph=expected_graph,
            subClassOf=[point_type_expected])
        sfn_expected = infixowl.Class(
            identifier=constants.FIELDS_NS['Cooling_air_flowrate_sensor_1'],
            graph=expected_graph,
            subClassOf=[field_expected])
        is_composed_of_property_expected = infixowl.Property(
            identifier=constants.DIGITAL_BUILDINGS_NS['isComposedOf'],
            baseType=infixowl.OWL_NS.ObjectProperty,
            graph=expected_graph)

        concat = sensor_expected & flowrate_expected
        concat += air_expected
        concat += cooling_expected
        sfn_expected.subClassOf = [
            is_composed_of_property_expected | infixowl.only | concat
        ]

        # Check if they are similar
        self.assertTrue(compare.similar(graph, expected_graph))
コード例 #9
0
 query = query.strip()
 if (len(query) == 0 or query == 'OUT OF SCOPE' or query == '{}'):
     query_row_index += 1
     continue
 else:
     if not query[:6] == 'PREFIX':
         query = eval(query)['sparql']
 q_graph = QueryGraph(query, {})
 template_row_index = 0
 for template_triples_list in template_store_df[
         "template_processed_triples"]:
     # template_graph = template_store_df["template_structure_graph"][2]
     template_graph = triples_list_to_graph(eval(template_triples_list))
     try:
         if isomorphic(q_graph.processed_graph,
                       template_graph) or similar(
                           q_graph.processed_graph, template_graph):
             # print("query_graph and template_graph are isomorphic or similar")
             # print("template structure")
             # print("\n")
             qald_stat_with_templates_df = qald_stat_with_templates_df.append(
                 {
                     "query_question":
                     qald_queries_df.iloc[query_row_index]
                     ['sentence_en'],
                     "template_question":
                     template_store_df.iloc[template_row_index]
                     ["question"],
                     "query_triples":
                     q_graph.triples_list,
                     "template_triples":
                     template_store_df.iloc[template_row_index]