Example #1
0
    def test_wikidata_virus_and_qualifiers(self):
        shape_map_raw = "SPARQL'SELECT DISTINCT ?virus WHERE {   VALUES ?virus {  wd:Q82069695  }  }'@<Virus>  "
        # wd:Q8351095  wd:Q16983356 wd:Q4902157  wd:Q278567 wd:Q16983360 wd:Q16991954

        namespaces_dict = {
            "http://www.w3.org/2000/01/rdf-schema#": "rdfs",
            "http://www.wikidata.org/prop/": "p",
            "http://www.wikidata.org/prop/direct/": "wdt",
            "http://www.wikidata.org/entity/": "wd",
            "http://www.w3.org/2001/XMLSchema#": "xsd",
            "http://www.w3.org/1999/02/22-rdf-syntax-ns#": "rdf",
            "http://www.w3.org/XML/1998/namespace": "xml",
            "http://wikiba.se/ontology#": "wikibase",
            "http://schema.org/": "schema",
            "http://www.w3.org/2004/02/skos/core#": "skos"
        }

        shaper = Shaper(shape_map_raw=shape_map_raw,
                        graph_file_input=_BASE_DIR + "virus_wikidata_depth2.ttl",
                        input_format=TURTLE,
                        all_instances_are_compliant_mode=True,
                        infer_numeric_types_for_untyped_literals=True,
                        discard_useless_constraints_with_positive_closure=True,
                        keep_less_specific=True,
                        instantiation_property="http://www.wikidata.org/prop/direct/P31",
                        namespaces_dict=namespaces_dict,
                        namespaces_for_qualifier_props=["http://www.wikidata.org/prop/"],
                        shape_qualifiers_mode=True,
                        disable_comments=True,
                        all_classes_mode=False,
                        allow_opt_cardinality=False)
        str_result = shaper.shex_graph(string_output=True)
        self.assertTrue(file_vs_str_tunned_comparison(file_path=_BASE_DIR + "virus_qualifiers.shex",
                                                      str_target=str_result))
Example #2
0
 def test_one_target(self):
     shaper = Shaper(target_classes=["http://xmlns.com/foaf/0.1/Person"],
                     graph_file_input=G1,
                     all_classes_mode=False,
                     input_format="turtle",
                     disable_comments=True)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=_BASE_DIR + "one_target.shex",
                                                   str_target=str_result))
Example #3
0
 def test_several_targets(self):
     shaper = Shaper(file_target_classes=_BASE_DIR + "input_classes_two_targets.tsv",
                     graph_file_input=G1,
                     all_classes_mode=False,
                     input_format="turtle",
                     disable_comments=True)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=_BASE_DIR + "two_targets.shex",
                                                   str_target=str_result))
 def test_no_annotation(self):
     shaper = Shaper(all_classes_mode=True,
                     graph_file_input=_BASE_DIR + "wiki_example.ttl",
                     instantiation_property="http://www.wikidata.org/prop/direct/P31",
                     input_format="turtle",
                     disable_comments=True,
                     )
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=_BASE_DIR + "wiki_example_noanot.shex",
                                                   str_target=str_result))
Example #5
0
 def test_one_target_prefixed_targets(self):
     shaper = Shaper(file_target_classes=_BASE_DIR + "input_classes_one_target_prefixed.tsv",  # Not written yet
                     namespaces_dict={"http://xmlns.com/foaf/0.1/" : "foaf"},
                     graph_file_input=G1,
                     all_classes_mode=False,
                     input_format="turtle",
                     disable_comments=True)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=_BASE_DIR + "one_target.shex",
                                                   str_target=str_result))
Example #6
0
 def test_all_classes_g1(self):
     shaper = Shaper(graph_file_input=G1,
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=True,
                     input_format=TURTLE,
                     disable_comments=True)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(
         file_vs_str_tunned_comparison(file_path=G1_ALL_CLASSES_NO_COMMENTS,
                                       str_target=str_result))
Example #7
0
 def test_exact_disabled(self):
     shaper = Shaper(
         graph_file_input=_BASE_DIR + "g6_exact_cardinality.ttl",
         namespaces_dict=default_namespaces(),
         all_classes_mode=True,
         input_format=TURTLE,
         disable_comments=True,
         disable_exact_cardinality=True)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=_BASE_DIR + "g6_exact_disabled.shex",
                                                   str_target=str_result))
 def test_one_nt(self):  # Should be nt
     shaper = Shaper(target_classes=["http://xmlns.com/foaf/0.1/Person",
                                     "http://xmlns.com/foaf/0.1/Document"],
                     graph_list_of_files_input=[G1_NT],
                     namespaces_dict=default_namespaces(),
                     input_format=NT,
                     all_classes_mode=False,
                     disable_comments=True)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=BASE_FILES_GENERAL + "g1_all_classes_no_comments.shex",
                                                   str_target=str_result))
 def test_same_namespaces_as_source_ttl_file(self):
     shaper = Shaper(target_classes=["http://xmlns.com/foaf/0.1/Person",
                                     "http://xmlns.com/foaf/0.1/Document"],
                     graph_file_input=G1,
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=False,
                     input_format=TURTLE,
                     disable_comments=True)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=G1_ALL_CLASSES_NO_COMMENTS,
                                                   str_target=str_result))
Example #10
0
 def test_or_disabled(self):
     shaper = Shaper(graph_file_input=_BASE_DIR + "g3_or_example.ttl",
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=True,
                     input_format=TURTLE,
                     disable_comments=True,
                     disable_or_statements=True)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=_BASE_DIR + "or_disabled.shex",
                                                   str_target=str_result,
                                                   or_shapes=False))
Example #11
0
 def test_all_classes_ex_a(self):
     shaper = Shaper(graph_file_input=_BASE_DIR + "G1_ex_a.ttl",
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=True,
                     input_format=TURTLE,
                     instantiation_property="http://example.org/a",
                     disable_comments=True)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(
         file_vs_str_tunned_comparison(file_path=_BASE_DIR + "G1_ex_a.shex",
                                       str_target=str_result))
Example #12
0
 def test_base_g1(self):
     shaper = Shaper(graph_file_input=G1,
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=True,
                     input_format=TURTLE,
                     disable_comments=True,
                     inverse_paths=True)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(
         file_vs_str_tunned_comparison(file_path=_BASE_DIR +
                                       "g1_inverse.shex",
                                       str_target=str_result))
Example #13
0
 def test_different_namespace(self):
     shaper = Shaper(graph_file_input=G1,
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=True,
                     input_format=TURTLE,
                     disable_comments=True,
                     shapes_namespace="http://weso.es/DIfferentShapes#")
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(
         file_vs_str_tunned_comparison(file_path=_BASE_DIR +
                                       "different_namespace.shex",
                                       str_target=str_result))
 def test_sparql_selector(self):
     shape_map = "SPARQL \"select ?p where { ?p a foaf:Person }\"@<Person>"
     shaper = Shaper(graph_file_input=G1,
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=False,
                     input_format=TURTLE,
                     disable_comments=True,
                     shape_map_raw=shape_map
                     )
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=_BASE_DIR + "focus_nodes.shex",
                                                   str_target=str_result))
 def test_focus_wildcard(self):
     shape_map = "{FOCUS foaf:name _}@<WithName>"
     shaper = Shaper(graph_file_input=G1,
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=False,
                     input_format=TURTLE,
                     disable_comments=True,
                     shape_map_raw=shape_map
                     )
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=_BASE_DIR + "focus_and_wildcard.shex",
                                                   str_target=str_result))
 def test_untyped_int_and_float(self):
     shaper = Shaper(target_classes=["http://xmlns.com/foaf/0.1/Person",
                                     "http://xmlns.com/foaf/0.1/Document"],
                     graph_file_input=_BASE_DIR + "g1_untyped_age.nt",  # TODO CHANGE THIS AND MORE
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=False,
                     infer_numeric_types_for_untyped_literals=True,
                     input_format=NT,
                     disable_comments=True)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=G1_ALL_CLASSES_NO_COMMENTS,
                                                   str_target=str_result))
 def test_some_empty_not_remove(self):
     shaper = Shaper(target_classes=["http://xmlns.com/foaf/0.1/Machine",
                                     "http://xmlns.com/foaf/0.1/Person",
                                     "http://xmlns.com/foaf/0.1/Document"],
                     graph_file_input=G1,
                     all_classes_mode=False,
                     input_format="turtle",
                     disable_comments=True,
                     remove_empty_shapes=False)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=_BASE_DIR + "some_empty_not_remove.shex",
                                                   str_target=str_result))
 def test_prefixed_node(self):
     shape_map = "ex:Jimmy@<Person>"
     shaper = Shaper(graph_file_input=G1,
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=False,
                     input_format=TURTLE,
                     disable_comments=True,
                     shape_map_raw=shape_map)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(
         file_vs_str_tunned_comparison(file_path=_BASE_DIR + "a_node.shex",
                                       str_target=str_result))
 def test_several_turtle(self):
     shaper = Shaper(target_classes=["http://xmlns.com/foaf/0.1/Person",
                                     "http://xmlns.com/foaf/0.1/Document"],
                     graph_list_of_files_input=[_BASE_DIR + "g1_p1.ttl",
                                                _BASE_DIR + "g1_p2.ttl"],
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=False,
                     input_format=TURTLE,
                     disable_comments=True)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=BASE_FILES_GENERAL + "g1_all_classes_no_comments.shex",
                                                   str_target=str_result))
Example #20
0
 def test_outgoing_links(self):
     shaper = Shaper(graph_file_input=_BASE_DIR + "g_sort.ttl",
                     namespaces_dict=default_namespaces(),
                     target_classes=["foaf:Person"],
                     input_format=TURTLE,
                     disable_comments=True,
                     shapes_namespace=SHAPES_DEFAULT_NAMESPACE)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(
         file_vs_str_tunned_comparison(file_path=_BASE_DIR + "g_sort.shex",
                                       str_target=str_result,
                                       check_order=True))
 def test_one_nt(self):  # Should be nt
     shaper = Shaper(target_classes=["http://xmlns.com/foaf/0.1/Person",
                                     "http://xmlns.com/foaf/0.1/Document"],
                     list_of_url_input=[
                         "https://raw.githubusercontent.com/DaniFdezAlvarez/shexerp3/develop/test/t_files/t_graph_1.nt"],
                     namespaces_dict=default_namespaces(),
                     input_format=NT,
                     all_classes_mode=False,
                     disable_comments=True)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=BASE_FILES_GENERAL + "g1_all_classes_no_comments.shex",
                                                   str_target=str_result))
Example #22
0
 def test_t_051(self):
     shaper = Shaper(target_classes=["http://xmlns.com/foaf/0.1/Person",
                                     "http://xmlns.com/foaf/0.1/Document"],
                     graph_file_input=G1,
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=False,
                     input_format=TURTLE,
                     disable_comments=True)
     str_result = shaper.shex_graph(string_output=True,
                                    acceptance_threshold=.51)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=_BASE_DIR + "g1_t051.shex",
                                                   str_target=str_result))
 def test_keep_less_compliant(self):
     shaper = Shaper(target_classes=["http://xmlns.com/foaf/0.1/Person",
                                     "http://xmlns.com/foaf/0.1/Document"],
                     graph_file_input=_G1_SEV_NAMES,
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=False,
                     input_format=TURTLE,
                     disable_comments=True,
                     all_instances_are_compliant_mode=True)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=_BASE_DIR + "keep_less_compliant.shex",
                                                   str_target=str_result))
 def test_several_shapemap_items(self):
     shape_map_file = _BASE_DIR + "several_shm_items.sm"
     shaper = Shaper(graph_file_input=G1,
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=False,
                     input_format=TURTLE,
                     disable_comments=True,
                     shape_map_file=shape_map_file
                     )
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=_BASE_DIR + "several_shm_items.shex",
                                                   str_target=str_result))
 def test_some_fixed_shape_map(self):
     shape_map = "<http://example.org/Jimmy>@<Person>"
     shaper = Shaper(graph_file_input=G1,
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=False,
                     input_format=TURTLE,
                     disable_comments=True,
                     shape_map_raw=shape_map,
                     shape_map_format=FIXED_SHAPE_MAP)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(
         file_vs_str_tunned_comparison(file_path=_BASE_DIR + "a_node.shex",
                                       str_target=str_result))
 def test_some_classes_all_instances(self):
     shaper = Shaper(target_classes=["http://xmlns.com/foaf/0.1/Person"],
                     graph_file_input=G1_NT,
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=False,
                     input_format=NT,
                     disable_comments=True,
                     instances_file_input=_BASE_DIR + "g1_all_instances.nt")
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(
         file_vs_str_tunned_comparison(file_path=_BASE_DIR +
                                       "some_classes_all_instances.shex",
                                       str_target=str_result))
 def test_json_node(self):
     # shape_map = "<http://example.org/Jimmy>@<Person>"
     shape_map = '[{"nodeSelector" : "<http://example.org/Jimmy>", "shapeLabel": "<Person>"}]'
     shaper = Shaper(graph_file_input=G1,
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=False,
                     input_format=TURTLE,
                     disable_comments=True,
                     shape_map_raw=shape_map,
                     shape_map_format=JSON)
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(
         file_vs_str_tunned_comparison(file_path=_BASE_DIR + "a_node.shex",
                                       str_target=str_result))
Example #28
0
 def test_empty_prefix_used_and_no_default(self):
     namespaces = default_namespaces()
     namespaces["http://unuseful.but.yet/here/"] = ""
     shaper = Shaper(graph_file_input=G1,
                     namespaces_dict=namespaces,
                     all_classes_mode=True,
                     input_format=TURTLE,
                     disable_comments=True,
                     shapes_namespace="http://weso.es/DIfferentShapes#")
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(
         file_vs_str_tunned_comparison(file_path=_BASE_DIR +
                                       "empty_prefix_used_and_no_def.shex",
                                       str_target=str_result))
Example #29
0
 def test_json_focus(self):
     shape_map = '[{"nodeSelector" : "{FOCUS a foaf:Person}", "shapeLabel": "<Person>"}]'
     # shape_map = "{FOCUS a foaf:Person}@<Person>"
     shaper = Shaper(graph_file_input=G1,
                     namespaces_dict=default_namespaces(),
                     all_classes_mode=False,
                     input_format=TURTLE,
                     disable_comments=True,
                     shape_map_raw=shape_map,
                     shape_map_format=JSON
                     )
     str_result = shaper.shex_graph(string_output=True)
     self.assertTrue(file_vs_str_tunned_comparison(file_path=_BASE_DIR + "focus_nodes.shex",
                                                   str_target=str_result))
    def test_overwrite_empty(self):
        namespaces = default_namespaces()
        namespaces["http://unuseful.but.yet/here/"] = ""

        shaper = Shaper(target_classes=["http://xmlns.com/foaf/0.1/Person",
                                        "http://xmlns.com/foaf/0.1/Document"],
                        graph_file_input=G1,
                        namespaces_dict=namespaces,
                        all_classes_mode=False,
                        input_format=TURTLE,
                        disable_comments=True)
        str_result = shaper.shex_graph(string_output=True)
        self.assertTrue(file_vs_str_tunned_comparison(file_path=_BASE_DIR + "\\overwrite_empty.shex",
                                                      str_target=str_result))