Skip to content

Commit e1af16e

Browse files
Merge branch 'develop'
2 parents 727d7b6 + 764db50 commit e1af16e

14 files changed

+41
-19
lines changed

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ def read(file_path):
88
setup(
99
name = 'shexer',
1010
packages = find_packages(exclude=["*.local_code.*"]), # this must be the same as the name above
11-
version = '2.5.6',
11+
version = '2.5.7',
1212
description = 'Automatic schema extraction for RDF graphs',
1313
author = 'Daniel Fernandez-Alvarez',
1414
author_email = '[email protected]',
1515
url = 'https://github.com/DaniFdezAlvarez/shexer',
16-
download_url = 'https://github.com/DaniFdezAlvarez/shexer/archive/2.5.6.tar.gz',
16+
download_url = 'https://github.com/DaniFdezAlvarez/shexer/archive/2.5.7.tar.gz',
1717
keywords = ['testing', 'shexer', 'shexerp3', "rdf", "shex", "shacl", "schema"],
1818
long_description = read('README.md'),
1919
long_description_content_type='text/markdown',

shexer/core/profiling/class_profiler.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from shexer.core.profiling.strategy.include_reverse_features_strategy import IncludeReverseFeaturesStrategy
1010
from shexer.core.profiling.consts import RDF_TYPE_STR
1111
from shexer.utils.structures.dicts import ShapeExampleFeaturesDict
12+
from shexer.model.shape import STARTING_CHAR_FOR_SHAPE_NAME
1213

13-
_MINIMAL_IRI_INIT = "@"
14+
_MINIMAL_IRI_INIT = STARTING_CHAR_FOR_SHAPE_NAME
1415

1516

1617

shexer/core/shexing/strategy/abstract_shexing_strategy.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from shexer.io.shex.formater.statement_serializers.st_serializers_factory import StSerializerFactory
55
from shexer.core.shexing.strategy.minimal_iri_strategy.annotate_min_iri_strategy import AnnotateMinIriStrategy
66
from shexer.core.shexing.strategy.minimal_iri_strategy.ignore_min_iri_strategy import IgnoreMinIriStrategy
7+
from shexer.model.shape import STARTING_CHAR_FOR_SHAPE_NAME
78

89

910
_DIRECT_ST_SERIALIZER = 0
@@ -261,7 +262,7 @@ def _manage_group_to_decide_with_or(self, group_to_decide):
261262
yield a_new_statement
262263

263264
def _is_an_IRI(self, statement_type):
264-
return statement_type == IRI_ELEM_TYPE or statement_type.startswith("@") # TODO careful here. Refactor
265+
return statement_type == IRI_ELEM_TYPE or statement_type.startswith(STARTING_CHAR_FOR_SHAPE_NAME) # TODO careful here. Refactor
265266

266267

267268
def _remove_IRI_statements_if_useles(self, group_of_statements):

shexer/io/shape_map/label/shape_map_label_parser.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from shexer.model.shape import STARTING_CHAR_FOR_SHAPE_NAME
2+
from shexer.io.shex.formater.consts import SHAPE_LINK_CHAR
23

34
class ShapeMapLabelParser(object):
45

@@ -9,7 +10,7 @@ def parse_shape_map_label(self, raw_label):
910

1011
if self._is_a_prefixed_uri(raw_label):
1112
return STARTING_CHAR_FOR_SHAPE_NAME + self._parse_prefixed_label(raw_label)
12-
return STARTING_CHAR_FOR_SHAPE_NAME + raw_label
13+
return raw_label # todo SURE?
1314
# return self._parse_unprefixed_label(raw_label)
1415

1516

shexer/io/shape_map/node_selector/node_selector_parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _parse_focus_expression(self, raw_selector):
6767
sgraph=self._sgraph)
6868

6969
def _turn_focus_exp_tokens_into_query(self, subj, pred, obj):
70-
return self._namespaces_to_string() + "SELECT " + _FOCUS_VARIABLE + " WHERE {" + subj + " " + pred + " " + obj + " . } " # LIMIT 20"
70+
return self._namespaces_to_string() + "SELECT " + _FOCUS_VARIABLE + " WHERE {" + subj + " " + pred + " " + obj + " . } "
7171
# return sparql.prepareQuery(string_query, initNs=self._prefix_namespace_dict)
7272

7373
def _parse_subj_obj_focus_expression(self, token, focus_count):

shexer/io/shex/formater/statement_serializers/base_statement_serializer.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from shexer.io.shex.formater.consts import SPACES_GAP_BETWEEN_TOKENS, \
2-
COMMENT_INI, TARGET_LINE_LENGHT, SPACES_GAP_FOR_FREQUENCY, KLEENE_CLOSURE, POSITIVE_CLOSURE, OPT_CARDINALITY
2+
COMMENT_INI, TARGET_LINE_LENGHT, SPACES_GAP_FOR_FREQUENCY, KLEENE_CLOSURE, POSITIVE_CLOSURE, OPT_CARDINALITY, SHAPE_LINK_CHAR
33
from shexer.model.IRI import IRI_ELEM_TYPE
44
from shexer.model.shape import STARTING_CHAR_FOR_SHAPE_NAME
55
from shexer.utils.shapes import prefixize_shape_name_if_possible
@@ -53,16 +53,16 @@ def tune_token(a_token, namespaces_dict):
5353
# TODO: a lot to correct here for normal behaviour
5454
if a_token.startswith(STARTING_CHAR_FOR_SHAPE_NAME): # Shape
5555
# return STARTING_CHAR_FOR_SHAPE_NAME +":" + a_token.replace(STARTING_CHAR_FOR_SHAPE_NAME, "")
56-
return STARTING_CHAR_FOR_SHAPE_NAME \
56+
return SHAPE_LINK_CHAR \
5757
+ prefixize_shape_name_if_possible(a_shape_name=a_token,
5858
namespaces_prefix_dict=namespaces_dict)
5959
if a_token == IRI_ELEM_TYPE: # iri
6060
return a_token
6161
if ":" not in a_token:
6262
if "<" in a_token:
63-
return STARTING_CHAR_FOR_SHAPE_NAME + a_token
63+
return SHAPE_LINK_CHAR + a_token
6464
else:
65-
return STARTING_CHAR_FOR_SHAPE_NAME + "<" + a_token + ">"
65+
return SHAPE_LINK_CHAR + "<" + a_token + ">"
6666
candidate_prefixed = BaseStatementSerializer._prefixize_uri_if_possible(uri=a_token,
6767
namespaces_dict=namespaces_dict)
6868
if candidate_prefixed is not None:

shexer/io/uml/uml_serializer.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from shexer.utils.uri import prefixize_uri_if_possible
44
from shexer.model.fixed_prop_choice_statement import FixedPropChoiceStatement
55
from shexer.consts import RDF_TYPE
6+
from shexer.model.shape import STARTING_CHAR_FOR_SHAPE_NAME
67
import warnings
78

89

@@ -90,7 +91,7 @@ def _serialize_obj_of_non_shape_link(self, a_statement):
9091
return result
9192
types = []
9293
for a_type in a_statement.st_types:
93-
if a_type.startswith("@"):
94+
if a_type.startswith(STARTING_CHAR_FOR_SHAPE_NAME):
9495
types.append("@" + prefixize_uri_if_possible(target_uri=a_type[1:],
9596
namespaces_prefix_dict=self._namespaces_dict,
9697
corners=True))
@@ -104,7 +105,7 @@ def _is_a_type_declaration(self, a_statement):
104105
def _is_a_shape_link(self, statement):
105106
if type(statement) == FixedPropChoiceStatement:
106107
return False
107-
return statement.st_type.startswith("@")
108+
return statement.st_type.startswith(STARTING_CHAR_FOR_SHAPE_NAME)
108109

109110
def _declare_and_open_shape(self, a_shape):
110111
target_name = prefixize_shape_name_if_possible(a_shape_name=a_shape.name,

shexer/model/shape.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
STARTING_CHAR_FOR_SHAPE_NAME = "@"
1+
STARTING_CHAR_FOR_SHAPE_NAME = "%"
22

33

44
class Shape(object):

shexer/shaper.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from shexer.utils.factories.shape_serializer_factory import get_shape_serializer, get_uml_serializer
1313
from shexer.utils.namespaces import find_adequate_prefix_for_shapes_namespaces
1414
from shexer.utils.log import log_msg
15+
from shexer.utils.uri import unprefixize_uri_if_possible
16+
from shexer.utils.dict import reverse_keys_and_values
1517
from shexer.consts import RATIO_INSTANCES
1618

1719

@@ -150,7 +152,10 @@ def __init__(self, target_classes=None,
150152
self._list_of_url_input = list_of_url_input
151153
self._rdflib_graph = rdflib_graph
152154
self._namespaces_dict = namespaces_dict if namespaces_dict is not None else {}
153-
self._instantiation_property = instantiation_property
155+
self._instantiation_property = \
156+
unprefixize_uri_if_possible(instantiation_property,
157+
include_corners=False,
158+
prefix_namespaces_dict=reverse_keys_and_values(self._namespaces_dict))
154159
self._namespaces_to_ignore = namespaces_to_ignore
155160
self._infer_numeric_types_for_untyped_literals = infer_numeric_types_for_untyped_literals
156161
self._discard_useles_constraints_with_positive_closure = discard_useless_constraints_with_positive_closure

shexer/utils/shapes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ def build_shape_name_for_qualifier_prop_uri(prop_uri, shapes_namespace): # TODO
3939

4040

4141
def prefixize_shape_name_if_possible(a_shape_name, namespaces_prefix_dict):
42-
result = prefixize_uri_if_possible(target_uri=a_shape_name[1:], # Avoid the "@" starting char
42+
result = prefixize_uri_if_possible(target_uri=a_shape_name[1:], # Avoid the "from shexer.model.shape. STARTING_CHAR_FOR_SHAPE_NAME starting char
4343
namespaces_prefix_dict=namespaces_prefix_dict)
4444
return result

shexer/utils/uri.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from shexer.model.shape import STARTING_CHAR_FOR_SHAPE_NAME
12

23
XSD_NAMESPACE = "http://www.w3.org/2001/XMLSchema#"
34
XSD_PREFIX = "xsd"
@@ -104,7 +105,7 @@ def is_a_correct_uri(target_uri, prefix_namespace_dict):
104105

105106

106107
def there_is_arroba_after_last_quotes(target_str):
107-
if target_str.rfind("@") > target_str.rfind('"'):
108+
if target_str.rfind(STARTING_CHAR_FOR_SHAPE_NAME) > target_str.rfind('"'):
108109
return True
109110
return False
110111

test/test_disable_endpoint_cache.py

-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,5 @@ def test_all_classes_mode(self):
5555
limit_remote_instances=5,
5656
disable_endpoint_cache=True)
5757
str_result = shaper.shex_graph(string_output=True)
58-
print(str_result)
5958
self.assertTrue(number_of_shapes(str_result) > 2)
6059
pass #

test/test_instantiation_property.py

+13
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ def test_explicit_ex_a(self):
4848
self.assertTrue(file_vs_str_tunned_comparison(file_path=_BASE_DIR + "G1_ex_a.shex",
4949
str_target=str_result))
5050

51+
def test_explicit_ex_a_prefixed(self):
52+
shaper = Shaper(target_classes=["http://xmlns.com/foaf/0.1/Person",
53+
"http://xmlns.com/foaf/0.1/Document"],
54+
graph_file_input=_BASE_DIR + "G1_ex_a.ttl",
55+
instantiation_property="ex:a",
56+
namespaces_dict=default_namespaces(),
57+
all_classes_mode=False,
58+
input_format=TURTLE,
59+
disable_comments=True)
60+
str_result = shaper.shex_graph(string_output=True)
61+
self.assertTrue(file_vs_str_tunned_comparison(file_path=_BASE_DIR + "G1_ex_a.shex",
62+
str_target=str_result))
63+
5164
def test_explicit_ex_a_rdf_type_mixed(self):
5265
# G1_ex_a_some_rdftype
5366
shaper = Shaper(target_classes=["http://xmlns.com/foaf/0.1/Person",

test/test_url_endpoint.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ def test_all_classes_mode(self):
4848
track_classes_for_entities_at_last_depth_level=False,
4949
limit_remote_instances=5)
5050
str_result = shaper.shex_graph(string_output=True)
51-
print(str_result)
5251
self.assertTrue(number_of_shapes(str_result) > 2)
53-
pass #
52+
53+

0 commit comments

Comments
 (0)