Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove -Likes #229

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pyshacl/constraints/advanced/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import typing
from typing import Dict, List

import rdflib
from rdflib import Literal

from pyshacl.constraints.constraint_component import ConstraintComponent
from pyshacl.consts import SH, SH_message
from pyshacl.errors import ConstraintLoadError
from pyshacl.helper.expression_helper import nodes_from_node_expression
from pyshacl.pytypes import GraphLike, SHACLExecutor
from pyshacl.pytypes import SHACLExecutor

SH_expression = SH.expression
SH_ExpressionConstraintComponent = SH.ExpressionConstraintComponent
Expand Down Expand Up @@ -42,11 +43,11 @@ def constraint_parameters(cls):
def constraint_name(cls):
return "ExpressionConstraintComponent"

def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) -> List[Literal]:
def make_generic_messages(self, datagraph: rdflib.Graph, focus_node, value_node) -> List[Literal]:
return [Literal("Expression evaluation generated constraint did not return true.")]

def evaluate(
self, executor: SHACLExecutor, data_graph: GraphLike, focus_value_nodes: Dict, _evaluation_path: List
self, executor: SHACLExecutor, data_graph: rdflib.Graph, focus_value_nodes: Dict, _evaluation_path: List
):
"""
:type executor: SHACLExecutor
Expand Down
11 changes: 6 additions & 5 deletions pyshacl/constraints/constraint_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import typing
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Set, Tuple

import rdflib
from rdflib import BNode, Literal, URIRef

from pyshacl.consts import (
Expand All @@ -33,7 +34,7 @@
)
from pyshacl.errors import ConstraintLoadError
from pyshacl.parameter import SHACLParameter
from pyshacl.pytypes import GraphLike, SHACLExecutor
from pyshacl.pytypes import SHACLExecutor
from pyshacl.rdfutil import stringify_node

if TYPE_CHECKING:
Expand Down Expand Up @@ -78,11 +79,11 @@ def constraint_name(cls):

@abc.abstractmethod
def evaluate(
self, executor: SHACLExecutor, target_graph: GraphLike, focus_value_nodes: Dict, _evaluation_path: List
self, executor: SHACLExecutor, target_graph: rdflib.Graph, focus_value_nodes: Dict, _evaluation_path: List
):
raise NotImplementedError() # pragma: no cover

def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) -> List[Literal]:
def make_generic_messages(self, datagraph: rdflib.Graph, focus_node, value_node) -> List[Literal]:
return []

def __str__(self):
Expand Down Expand Up @@ -127,7 +128,7 @@ def recursion_triggers(self, _evaluation_path, trigger_depth=3) -> Optional[List

def make_v_result_description(
self,
datagraph: GraphLike,
datagraph: rdflib.Graph,
focus_node: 'RDFNode',
severity: URIRef,
value_node: Optional['RDFNode'],
Expand Down Expand Up @@ -209,7 +210,7 @@ def make_v_result_description(

def make_v_result(
self,
datagraph: GraphLike,
datagraph: rdflib.Graph,
focus_node: 'RDFNode',
value_node: Optional['RDFNode'] = None,
result_path: Optional['RDFNode'] = None,
Expand Down
11 changes: 6 additions & 5 deletions pyshacl/constraints/core/cardinality_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"""
from typing import Dict, List

import rdflib
from rdflib.namespace import XSD
from rdflib.term import Literal

from pyshacl.constraints.constraint_component import ConstraintComponent
from pyshacl.consts import SH
from pyshacl.errors import ConstraintLoadError
from pyshacl.pytypes import GraphLike, SHACLExecutor
from pyshacl.pytypes import SHACLExecutor
from pyshacl.rdfutil import stringify_node

XSD_integer = XSD.integer
Expand Down Expand Up @@ -70,7 +71,7 @@ def constraint_parameters(cls):
def constraint_name(cls):
return "MinCountConstraintComponent"

def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) -> List[Literal]:
def make_generic_messages(self, datagraph: rdflib.Graph, focus_node, value_node) -> List[Literal]:
p = self.shape.path()
if p:
p = stringify_node(self.shape.sg.graph, p)
Expand All @@ -82,7 +83,7 @@ def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) ->
return [Literal(m)]

def evaluate(
self, executor: SHACLExecutor, target_graph: GraphLike, focus_value_nodes: Dict, _evaluation_path: List
self, executor: SHACLExecutor, target_graph: rdflib.Graph, focus_value_nodes: Dict, _evaluation_path: List
):
"""
:type executor: SHACLExecutor
Expand Down Expand Up @@ -153,7 +154,7 @@ def constraint_parameters(cls):
def constraint_name(cls):
return "MaxCountConstraintComponent"

def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) -> List[Literal]:
def make_generic_messages(self, datagraph: rdflib.Graph, focus_node, value_node) -> List[Literal]:
p = self.shape.path()
if p:
p = stringify_node(self.shape.sg.graph, p)
Expand All @@ -165,7 +166,7 @@ def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) ->
return [Literal(m)]

def evaluate(
self, executor: SHACLExecutor, target_graph: GraphLike, focus_value_nodes: Dict, _evaluation_path: List
self, executor: SHACLExecutor, target_graph: rdflib.Graph, focus_value_nodes: Dict, _evaluation_path: List
):
"""
:type executor: SHACLExecutor
Expand Down
20 changes: 11 additions & 9 deletions pyshacl/constraints/core/logical_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pyshacl.constraints.constraint_component import ConstraintComponent
from pyshacl.consts import SH
from pyshacl.errors import ConstraintLoadError, ReportableRuntimeError, ShapeRecursionWarning, ValidationFailure
from pyshacl.pytypes import GraphLike, SHACLExecutor
from pyshacl.pytypes import SHACLExecutor
from pyshacl.rdfutil import stringify_node

SH_not = SH["not"]
Expand Down Expand Up @@ -55,15 +55,17 @@ def constraint_parameters(cls):
def constraint_name(cls):
return "NotConstraintComponent"

def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) -> List[rdflib.Literal]:
def make_generic_messages(self, datagraph: rdflib.Graph, focus_node, value_node) -> List[rdflib.Literal]:
if len(self.not_list) == 1:
m = f"Node {stringify_node(datagraph, value_node)} conforms to shape {stringify_node(self.shape.sg.graph, self.not_list[0])}"
else:
nots_list = " , ".join(stringify_node(self.shape.sg.graph, n) for n in self.not_list)
m = f"Node {stringify_node(datagraph, value_node)} conforms to one or more shapes in {nots_list}"
return [rdflib.Literal(m)]

def evaluate(self, executor: SHACLExecutor, datagraph: GraphLike, focus_value_nodes: Dict, _evaluation_path: List):
def evaluate(
self, executor: SHACLExecutor, datagraph: rdflib.Graph, focus_value_nodes: Dict, _evaluation_path: List
):
"""
:type executor: SHACLExecutor
:type datagraph: rdflib.Graph
Expand Down Expand Up @@ -158,15 +160,15 @@ def constraint_parameters(cls):
def constraint_name(cls):
return "AndConstraintComponent"

def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) -> List[rdflib.Literal]:
def make_generic_messages(self, datagraph: rdflib.Graph, focus_node, value_node) -> List[rdflib.Literal]:
and_list = " , ".join(
stringify_node(self.shape.sg.graph, a_c) for a in self.and_list for a_c in self.shape.sg.graph.items(a)
)
m = "Node {} does not conform to all shapes in {}".format(stringify_node(datagraph, value_node), and_list)
return [rdflib.Literal(m)]

def evaluate(
self, executor: SHACLExecutor, target_graph: GraphLike, focus_value_nodes: Dict, _evaluation_path: List
self, executor: SHACLExecutor, target_graph: rdflib.Graph, focus_value_nodes: Dict, _evaluation_path: List
):
"""
:type executor: SHACLExecutor
Expand Down Expand Up @@ -254,7 +256,7 @@ def constraint_parameters(cls):
def constraint_name(cls):
return "OrConstraintComponent"

def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) -> List[rdflib.Literal]:
def make_generic_messages(self, datagraph: rdflib.Graph, focus_node, value_node) -> List[rdflib.Literal]:
or_list = " , ".join(
stringify_node(self.shape.sg.graph, o_c) for o in self.or_list for o_c in self.shape.sg.graph.items(o)
)
Expand All @@ -264,7 +266,7 @@ def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) ->
return [rdflib.Literal(m)]

def evaluate(
self, executor: SHACLExecutor, target_graph: GraphLike, focus_value_nodes: Dict, _evaluation_path: List
self, executor: SHACLExecutor, target_graph: rdflib.Graph, focus_value_nodes: Dict, _evaluation_path: List
):
"""
:type executor: SHACLExecutor
Expand Down Expand Up @@ -352,7 +354,7 @@ def constraint_parameters(cls):
def constraint_name(cls):
return "XoneConstraintComponent"

def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) -> List[rdflib.Literal]:
def make_generic_messages(self, datagraph: rdflib.Graph, focus_node, value_node) -> List[rdflib.Literal]:
xone_list = " , ".join(
stringify_node(self.shape.sg.graph, a_c) for a in self.xone_nodes for a_c in self.shape.sg.graph.items(a)
)
Expand All @@ -362,7 +364,7 @@ def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) ->
return [rdflib.Literal(m)]

def evaluate(
self, executor: SHACLExecutor, target_graph: GraphLike, focus_value_nodes: Dict, _evaluation_path: List
self, executor: SHACLExecutor, target_graph: rdflib.Graph, focus_value_nodes: Dict, _evaluation_path: List
):
"""
:type executor: SHACLExecutor
Expand Down
14 changes: 7 additions & 7 deletions pyshacl/constraints/core/other_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pyshacl.constraints.constraint_component import ConstraintComponent
from pyshacl.consts import RDFS, SH, RDF_type, SH_property
from pyshacl.errors import ConstraintLoadError, ReportableRuntimeError
from pyshacl.pytypes import GraphLike, RDFNode, SHACLExecutor
from pyshacl.pytypes import RDFNode, SHACLExecutor
from pyshacl.rdfutil import stringify_node

SH_InConstraintComponent = SH.InConstraintComponent
Expand Down Expand Up @@ -61,13 +61,13 @@ def constraint_parameters(cls):
def constraint_name(cls):
return "InConstraintComponent"

def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) -> List[rdflib.Literal]:
def make_generic_messages(self, datagraph: rdflib.Graph, focus_node, value_node) -> List[rdflib.Literal]:
list1 = [stringify_node(self.shape.sg.graph, val) for val in self.in_vals]
m = "Value {} not in list {}".format(stringify_node(datagraph, value_node), list1)
return [rdflib.Literal(m)]

def evaluate(
self, executor: SHACLExecutor, target_graph: GraphLike, focus_value_nodes: Dict, _evaluation_path: List
self, executor: SHACLExecutor, target_graph: rdflib.Graph, focus_value_nodes: Dict, _evaluation_path: List
):
"""
:type executor: SHACLExecutor
Expand Down Expand Up @@ -140,14 +140,14 @@ def constraint_parameters(cls):
def constraint_name(cls):
return "ClosedConstraintComponent"

def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) -> List[rdflib.Literal]:
def make_generic_messages(self, datagraph: rdflib.Graph, focus_node, value_node) -> List[rdflib.Literal]:
m = "Node {} is closed. It cannot have value: {}".format(
stringify_node(datagraph, focus_node), stringify_node(datagraph, value_node)
)
return [rdflib.Literal(m)]

def evaluate(
self, executor: SHACLExecutor, target_graph: GraphLike, focus_value_nodes: Dict, _evaluation_path: List
self, executor: SHACLExecutor, target_graph: rdflib.Graph, focus_value_nodes: Dict, _evaluation_path: List
):
"""
:type executor: SHACLExecutor
Expand Down Expand Up @@ -221,7 +221,7 @@ def constraint_parameters(cls):
def constraint_name(cls):
return "HasValueConstraintComponent"

def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) -> List[rdflib.Literal]:
def make_generic_messages(self, datagraph: rdflib.Graph, focus_node, value_node) -> List[rdflib.Literal]:
the_set = [stringify_node(self.shape.sg.graph, s) for s in self.has_value_set]
p = self.shape.path()
if p:
Expand All @@ -236,7 +236,7 @@ def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) ->
return [rdflib.Literal(m)]

def evaluate(
self, executor: SHACLExecutor, target_graph: GraphLike, focus_value_nodes: Dict, _evaluation_path: List
self, executor: SHACLExecutor, target_graph: rdflib.Graph, focus_value_nodes: Dict, _evaluation_path: List
):
"""
:type executor: SHACLExecutor
Expand Down
18 changes: 9 additions & 9 deletions pyshacl/constraints/core/property_pair_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pyshacl.constraints.constraint_component import ConstraintComponent
from pyshacl.consts import SH
from pyshacl.errors import ConstraintLoadError, ReportableRuntimeError
from pyshacl.pytypes import GraphLike, SHACLExecutor
from pyshacl.pytypes import SHACLExecutor
from pyshacl.rdfutil import stringify_node

SH_equals = SH.equals
Expand Down Expand Up @@ -52,7 +52,7 @@ def constraint_parameters(cls):
def constraint_name(cls):
return "EqualsConstraintComponent"

def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) -> List[rdflib.Literal]:
def make_generic_messages(self, datagraph: rdflib.Graph, focus_node, value_node) -> List[rdflib.Literal]:
if len(self.property_compare_set) < 2:
m = "Value of {}->{} != {}".format(
stringify_node(datagraph, focus_node),
Expand All @@ -67,7 +67,7 @@ def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) ->
return [rdflib.Literal(m)]

def evaluate(
self, executor: SHACLExecutor, target_graph: GraphLike, focus_value_nodes: Dict, _evaluation_path: List
self, executor: SHACLExecutor, target_graph: rdflib.Graph, focus_value_nodes: Dict, _evaluation_path: List
):
"""
:type executor: SHACLExecutor
Expand Down Expand Up @@ -134,7 +134,7 @@ def constraint_parameters(cls):
def constraint_name(cls):
return "DisjointConstraintComponent"

def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) -> List[rdflib.Literal]:
def make_generic_messages(self, datagraph: rdflib.Graph, focus_node, value_node) -> List[rdflib.Literal]:
if len(self.property_compare_set) < 2:
m = "Value of {}->{} == {}".format(
stringify_node(datagraph, focus_node),
Expand All @@ -149,7 +149,7 @@ def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) ->
return [rdflib.Literal(m)]

def evaluate(
self, executor: SHACLExecutor, target_graph: GraphLike, focus_value_nodes: Dict, _evaluation_path: List
self, executor: SHACLExecutor, target_graph: rdflib.Graph, focus_value_nodes: Dict, _evaluation_path: List
):
"""
:type executor: SHACLExecutor
Expand Down Expand Up @@ -218,7 +218,7 @@ def constraint_parameters(cls):
def constraint_name(cls):
return "LessThanConstraintComponent"

def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) -> List[rdflib.Literal]:
def make_generic_messages(self, datagraph: rdflib.Graph, focus_node, value_node) -> List[rdflib.Literal]:
if len(self.property_compare_set) < 2:
m = "Value of {}->{} <= {}".format(
stringify_node(datagraph, focus_node),
Expand All @@ -233,7 +233,7 @@ def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) ->
return [rdflib.Literal(m)]

def evaluate(
self, executor: SHACLExecutor, target_graph: GraphLike, focus_value_nodes: Dict, _evaluation_path: List
self, executor: SHACLExecutor, target_graph: rdflib.Graph, focus_value_nodes: Dict, _evaluation_path: List
):
"""
:type executor: SHACLExecutor
Expand Down Expand Up @@ -326,7 +326,7 @@ def constraint_parameters(cls):
def constraint_name(cls):
return "LessThanOrEqualsConstraintComponent"

def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) -> List[rdflib.Literal]:
def make_generic_messages(self, datagraph: rdflib.Graph, focus_node, value_node) -> List[rdflib.Literal]:
if len(self.property_compare_set) < 2:
m = "Value of {}->{} < {}".format(
stringify_node(datagraph, focus_node),
Expand All @@ -341,7 +341,7 @@ def make_generic_messages(self, datagraph: GraphLike, focus_node, value_node) ->
return [rdflib.Literal(m)]

def evaluate(
self, executor: SHACLExecutor, target_graph: GraphLike, focus_value_nodes: Dict, _evaluation_path: List
self, executor: SHACLExecutor, target_graph: rdflib.Graph, focus_value_nodes: Dict, _evaluation_path: List
):
"""
:type executor: SHACLExecutor
Expand Down
Loading