Skip to content

Commit

Permalink
Avoid repeatedly checking if rule adds a new triple, if we already kn…
Browse files Browse the repository at this point in the history
…ow the rule adds one triple.

Fix linter error in cli.py
  • Loading branch information
ashleysommer committed May 25, 2021
1 parent 5ae62e8 commit 7a86d6b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions pyshacl/cli.py
Expand Up @@ -135,6 +135,7 @@ def __call__(self, parser, namespace, values, option_string=None):
)
# parser.add_argument('-h', '--help', action="help", help='Show this help text.')


def main():
basename = os.path.basename(sys.argv[0])
if basename == "__main__.py":
Expand Down
4 changes: 2 additions & 2 deletions pyshacl/extras/js/rules.py
Expand Up @@ -45,9 +45,9 @@ def apply(self, data_graph: 'GraphLike') -> int:
set_to_add = set()
for t in triples:
s, p, o = tr = t[:3]
if tr not in data_graph:
if not this_added and tr not in data_graph:
this_added = True
set_to_add.add(tr)
set_to_add.add(tr)
sets_to_add.append(set_to_add)
if this_added:
added += 1
Expand Down
2 changes: 1 addition & 1 deletion pyshacl/rules/sparql/__init__.py
Expand Up @@ -74,7 +74,7 @@ def apply(self, data_graph: 'GraphLike') -> int:
raise ReportableRuntimeError("Query executed by a SHACL SPARQLRule must be CONSTRUCT query.")
this_added = False
for i in results.graph:
if i not in data_graph:
if not this_added and i not in data_graph:
this_added = True
# We only need to know at least one triple was added, then break!
break
Expand Down
6 changes: 3 additions & 3 deletions pyshacl/rules/triple/__init__.py
Expand Up @@ -190,7 +190,7 @@ def apply(self, data_graph: 'GraphLike') -> int:
iterate_limit = 100
while True:
if iterate_limit < 1:
raise ReportableRuntimeError("Local rule iteration exceeded iteration limit of 100.")
raise ReportableRuntimeError("sh:rule iteration exceeded iteration limit of 100.")
iterate_limit -= 1
added = 0
to_add = []
Expand All @@ -201,9 +201,9 @@ def apply(self, data_graph: 'GraphLike') -> int:
new_triples = itertools.product(s_set, p_set, o_set)
this_added = False
for i in iter(new_triples):
if i not in data_graph:
to_add.append(i)
if not this_added and i not in data_graph:
this_added = True
to_add.append(i)
if this_added:
added += 1
if added > 0:
Expand Down

0 comments on commit 7a86d6b

Please sign in to comment.