def test_all_classes_no_sharps(self): shaper = Shaper(graph_file_input=_BASE_DIR + "sharp_chances.ttl", namespaces_dict=default_namespaces(), all_classes_mode=True, input_format=TURTLE, disable_comments=True) str_result = shaper.shex_graph(string_output=True) self.assertTrue(no_sharp_in_shepe_names(str_result))
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))
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_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))
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_dbpedia(self): shape_map_raw = "SPARQL'select ?s where {?s a <http://dbpedia.org/ontology/Person>} LIMIT 1'@<Flag>" shaper = Shaper(shape_map_raw=shape_map_raw, url_endpoint="https://dbpedia.org/sparql", namespaces_dict=default_namespaces(), disable_comments=True, depth_for_building_subgraph=1, track_classes_for_entities_at_last_depth_level=False, all_classes_mode=False) str_result = shaper.shex_graph(string_output=True) self.assertTrue(number_of_shapes(str_result) == 1)
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))
def test_enable(self): shaper = Shaper(all_classes_mode=True, graph_file_input=_BASE_DIR + "g2.ttl", namespaces_dict=default_namespaces(), input_format=TURTLE, disable_comments=False) str_result = shaper.shex_graph(string_output=True) self.assertTrue( file_vs_str_exact_comparison(target_str=str_result, file_path=_BASE_DIR + "g2_enable.shex"))
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))
def test_all_classes_mode(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, output_format=SHACL_TURTLE) self.assertTrue(graph_comparison_file_vs_str(file_path=_BASE_DIR + "g1_all_classes.ttl", 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_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_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_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))
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_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_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_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_some_classes_with_target_classes(self): shaper = Shaper( graph_file_input=G1, namespaces_dict=default_namespaces(), all_classes_mode=False, target_classes=["http://xmlns.com/foaf/0.1/Person"], input_format=TURTLE, disable_comments=True) str_result = shaper.shex_graph(string_output=True, output_format=SHACL_TURTLE) self.assertTrue(graph_comparison_file_vs_str(file_path=_BASE_DIR + "g1_person.ttl", str_target=str_result))
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))
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))
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_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_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))
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))
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_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))
def test_json_ld(self): shaper = Shaper(target_classes=[ "http://xmlns.com/foaf/0.1/Person", "http://xmlns.com/foaf/0.1/Document" ], graph_file_input=G1_JSON_LD, namespaces_dict=default_namespaces(), all_classes_mode=False, input_format=JSON_LD, disable_comments=True) str_result = shaper.shex_graph(string_output=True) self.assertTrue( file_vs_str_tunned_comparison(file_path=_BASE_DIR + "g1_all_classes_no_comments.shex", str_target=str_result))