pyshacl/shape.py
def focus_nodes(self, data_graph):
        """
        The set of focus nodes for a shape may be identified as follows:

        specified in a shape using target declarations
        specified in any constraint that references a shape in parameters of shape-expecting constraint parameters (e.g. sh:node)
        specified as explicit input to the SHACL processor for validating a specific RDF term against a shape
        :return:
        """
        (target_nodes, target_classes, implicit_classes, target_objects_of, target_subjects_of) = self.target()
        if self._advanced:
            advanced_targets = self.advanced_target()
        else:
            advanced_targets = False
        found_node_targets = set()
        # Just add _all_ target_nodes to the set,
        # they don't need to actually exist in the graph
        found_node_targets.update(iter(target_nodes))
        target_classes = set(target_classes)
        target_classes.update(set(implicit_classes))
        found_target_instances = set()
        for tc in target_classes:
            s = data_graph.subjects(RDF_type, tc)
            found_target_instances.update(s)
            subc = data_graph.transitive_subjects(RDFS_subClassOf, tc)
            for subclass in iter(subc):
                if subclass == tc:
                    continue
                s1 = data_graph.subjects(RDF_type, subclass)
                found_target_instances.update(s1)
        found_node_targets.update(found_target_instances)
        found_target_subject_of = set()
        for s_of in target_subjects_of:
            subs = {s for s, o in data_graph.subject_objects(s_of)}
            found_target_subject_of.update(subs)
        found_node_targets.update(found_target_subject_of)
        found_target_object_of = set()
        for o_of in target_objects_of:
            objs = {o for s, o in data_graph.subject_objects(o_of)}
            found_target_object_of.update(objs)
        found_node_targets.update(found_target_object_of)
        if advanced_targets:
            for at_node, at in advanced_targets.items():
                if at['type'] == SH_SPARQLTarget:
                    qh = at['qh']
                    select = qh.apply_prefixes(qh.select_text)
                    results = data_graph.query(select, initBindings=None)
                    if not results or len(results.bindings) < 1:
                        continue
                    for r in results:
                        t = r['this']
                        found_node_targets.add(t)
                elif at['type'] in (SH_JSTarget, SH_JSTargetType):
                    results = at['targeter'].find_targets(data_graph)
                    for r in results:
                        found_node_targets.add(r)
                else:
                    results = at['qt'].find_targets(data_graph)
                    if not results or len(results.bindings) < 1:
                        continue
                    for r in results:
                        t = r['this']
                        found_node_targets.add(t)
        return found_node_targets

        The set of focus nodes for a shape may be identified as follows:

        specified in a shape using target declarations
        specified in any constraint that references a shape in parameters of shape-expecting constraint parameters (e.g. sh:node)
        specified as explicit input to the SHACL processor for validating a specific RDF term against a shape
        :return:
        
The set of focus nodes for a shape may be identified as follows:
specified in a shape using target declarations
specified in any constraint that references a shape in parameters of shape-expecting constraint parameters
specified as explicit input to the SHACL processor for validating a specific RDF term against a shape
The set of focus nodes for a shape may be identified as follows : specified in a shape using target declarations specified in any constraint that references a shape in parameters of shape - expecting constraint parameters specified as explicit input to the SHACL processor for validating a specific RDF term against a shape
def focus_nodes(self, data_graph):
        (target_nodes, target_classes, implicit_classes, target_objects_of, target_subjects_of) = self.target()
        if self._advanced:
            advanced_targets = self.advanced_target()
        else:
            advanced_targets = False
        found_node_targets = set()
        found_node_targets.update(iter(target_nodes))
        target_classes = set(target_classes)
        target_classes.update(set(implicit_classes))
        found_target_instances = set()
        for tc in target_classes:
            s = data_graph.subjects(RDF_type, tc)
            found_target_instances.update(s)
            subc = data_graph.transitive_subjects(RDFS_subClassOf, tc)
            for subclass in iter(subc):
                if subclass == tc:
                    continue
                s1 = data_graph.subjects(RDF_type, subclass)
                found_target_instances.update(s1)
        found_node_targets.update(found_target_instances)
        found_target_subject_of = set()
        for s_of in target_subjects_of:
            subs = {s for s, o in data_graph.subject_objects(s_of)}
            found_target_subject_of.update(subs)
        found_node_targets.update(found_target_subject_of)
        found_target_object_of = set()
        for o_of in target_objects_of:
            objs = {o for s, o in data_graph.subject_objects(o_of)}
            found_target_object_of.update(objs)
        found_node_targets.update(found_target_object_of)
        if advanced_targets:
            for at_node, at in advanced_targets.items():
                if at['type'] == SH_SPARQLTarget:
                    qh = at['qh']
                    select = qh.apply_prefixes(qh.select_text)
                    results = data_graph.query(select, initBindings=None)
                    if not results or len(results.bindings) < 1:
                        continue
                    for r in results:
                        t = r['this']
                        found_node_targets.add(t)
                elif at['type'] in (SH_JSTarget, SH_JSTargetType):
                    results = at['targeter'].find_targets(data_graph)
                    for r in results:
                        found_node_targets.add(r)
                else:
                    results = at['qt'].find_targets(data_graph)
                    if not results or len(results.bindings) < 1:
                        continue
                    for r in results:
                        t = r['this']
                        found_node_targets.add(t)
        return found_node_targets
def focus_nodes ( self , data_graph ) : ( target_nodes , target_classes , implicit_classes , target_objects_of , target_subjects_of ) = self . target ( ) if self . _advanced : advanced_targets = self . advanced_target ( ) else : advanced_targets = False found_node_targets = set ( ) found_node_targets . update ( iter ( target_nodes ) ) target_classes = set ( target_classes ) target_classes . update ( set ( implicit_classes ) ) found_target_instances = set ( ) for tc in target_classes : s = data_graph . subjects ( RDF_type , tc ) found_target_instances . update ( s ) subc = data_graph . transitive_subjects ( RDFS_subClassOf , tc ) for subclass in iter ( subc ) : if subclass == tc : continue s1 = data_graph . subjects ( RDF_type , subclass ) found_target_instances . update ( s1 ) found_node_targets . update ( found_target_instances ) found_target_subject_of = set ( ) for s_of in target_subjects_of : subs = { s for s , o in data_graph . subject_objects ( s_of ) } found_target_subject_of . update ( subs ) found_node_targets . update ( found_target_subject_of ) found_target_object_of = set ( ) for o_of in target_objects_of : objs = { o for s , o in data_graph . subject_objects ( o_of ) } found_target_object_of . update ( objs ) found_node_targets . update ( found_target_object_of ) if advanced_targets : for at_node , at in advanced_targets . items ( ) : if at [ 'type' ] == SH_SPARQLTarget : qh = at [ 'qh' ] select = qh . apply_prefixes ( qh . select_text ) results = data_graph . query ( select , initBindings = None ) if not results or len ( results . bindings ) < 1 : continue for r in results : t = r [ 'this' ] found_node_targets . add ( t ) elif at [ 'type' ] in ( SH_JSTarget , SH_JSTargetType ) : results = at [ 'targeter' ] . find_targets ( data_graph ) for r in results : found_node_targets . add ( r ) else : results = at [ 'qt' ] . find_targets ( data_graph ) if not results or len ( results . bindings ) < 1 : continue for r in results : t = r [ 'this' ] found_node_targets . add ( t ) return found_node_targets
The set of focus nodes for a shape may be identified as follows:
specified in a shape using target declarations
specified in any constraint that references a shape in parameters of shape-expecting constraint parameters (e.g.
The set of focus nodes for a shape may be identified as follows : specified in a shape using target declarations specified in any constraint that references a shape in parameters of shape - expecting constraint parameters ( e . g .
"""
        The set of focus nodes for a shape may be identified as follows:

        specified in a shape using target declarations
        specified in any constraint that references a shape in parameters of shape-expecting constraint parameters (e.g. sh:node)
        specified as explicit input to the SHACL processor for validating a specific RDF term against a shape
        :return:
        """ # Just add _all_ target_nodes to the set, # they don't need to actually exist in the graph
None
self
data_graph