def __init__(self, g: Optional[Graph], s: Schema,
                 external_shape_resolver: Optional[Callable[[ShExJ.IRIREF], Optional[ShExJ.Shape]]]=None,
                 base_namespace: Optional[Namespace]=None,
                 shape_importer: Optional[Callable[[ShExJ.IRIREF], Optional[ShExJ.Schema]]]=None) -> None:
        """
        Create a context consisting of an RDF Graph and a ShEx Schema and generate a identifier to
        item map.

        :param g: RDF graph
        :param s: ShExJ Schema instance
        :param external_shape_resolver: External resolution function
        :param base_namespace:
        """
        self.is_valid: bool = True
        self.error_list: List[str] = []
        self.graph: Graph = g
        self.n3_mapper = N3Mapper(g)
        self.schema: ShExJ.Schema = s
        self.schema_id_map: Dict[ShExJ.shapeExprLabel, ShExJ.shapeExpr] = {}
        self.te_id_map: Dict[ShExJ.tripleExprLabel, ShExJ.tripleExpr] = {}
        self.external_shape_for = external_shape_resolver if external_shape_resolver \
            else default_external_shape_resolver
        self.base_namespace = base_namespace if isinstance(base_namespace, Namespace) \
            else Namespace(base_namespace) if base_namespace else None
        self.shape_importer = shape_importer if shape_importer else default_shape_importer

        # For SPARQL API's, true means pull ALL predicate objects for a given subject, false means only the
        # predicates that are needed
        self.over_slurp = True

        # A list of node selectors/shape expressions that are being evaluated.  If we attempt to evaluate
        # an entry for a second time, we, instead, put the entry into the assumptions table.  We start with 'true'
        # and, if the result is 'true' then we count it as success.  If not, we switch to false and try again
        self.evaluating: Set[Tuple[Node, ShExJ.shapeExprLabel]] = set()
        self.assumptions: Dict[Tuple[Node, ShExJ.shapeExprLabel], bool] = {}

        # Known results -- a cache of existing evaluation results
        self.known_results: Dict[Tuple[Node, ShExJ.shapeExprLabel], bool] = {}

        # Debugging options
        self.debug_context = DebugContext()

        # Process imports
        if self.schema.imports is not None:
            for uri in self.schema.imports:
                imp_shape = self.shape_importer(uri, self)
                if not imp_shape:
                    # TODO: what to do on import failure
                    self.is_valid = False
                    self.error_list.append(f"Import failure on {uri}")

        if self.schema.start is not None:
            if not isinstance_(self.schema.start, ShExJ.shapeExprLabel) and\
                    'id' in self.schema.start and self.schema.start.id is None:
                self.schema.start.id = "_:start"
            self._gen_schema_xref(self.schema.start)
            # TODO: The logic below really belongs in the parser.  We shouldn't be messing with the schema here...
            if not isinstance_(self.schema.start, ShExJ.shapeExprLabel):
                if self.schema.shapes is None:
                    self.schema.shapes = [self.schema.start]
                else:
                    self.schema.shapes.append(self.schema.start)
                self.schema.start = self.schema.start.id
        if self.schema.shapes is not None:
            for e in self.schema.shapes:
                self._gen_schema_xref(e)

        self.current_node: ParseNode = None
        self.evaluate_stack: List[Tuple[Union[BNode, URIRef], Optional[str]]] = []  # Node / shape evaluation stacks
        self.bnode_map: Dict[BNode, str] = {}
def __init__ ( self , g : Optional [ Graph ] , s : Schema , external_shape_resolver : Optional [ Callable [ [ ShExJ . IRIREF ] , Optional [ ShExJ . Shape ] ] ] = None , base_namespace : Optional [ Namespace ] = None , shape_importer : Optional [ Callable [ [ ShExJ . IRIREF ] , Optional [ ShExJ . Schema ] ] ] = None ) -> None : self . is_valid : bool = True self . error_list : List [ str ] = [ ] self . graph : Graph = g self . n3_mapper = N3Mapper ( g ) self . schema : ShExJ . Schema = s self . schema_id_map : Dict [ ShExJ . shapeExprLabel , ShExJ . shapeExpr ] = { } self . te_id_map : Dict [ ShExJ . tripleExprLabel , ShExJ . tripleExpr ] = { } self . external_shape_for = external_shape_resolver if external_shape_resolver else default_external_shape_resolver self . base_namespace = base_namespace if isinstance ( base_namespace , Namespace ) else Namespace ( base_namespace ) if base_namespace else None self . shape_importer = shape_importer if shape_importer else default_shape_importer self . over_slurp = True self . evaluating : Set [ Tuple [ Node , ShExJ . shapeExprLabel ] ] = set ( ) self . assumptions : Dict [ Tuple [ Node , ShExJ . shapeExprLabel ] , bool ] = { } self . known_results : Dict [ Tuple [ Node , ShExJ . shapeExprLabel ] , bool ] = { } self . debug_context = DebugContext ( ) if self . schema . imports is not None : for uri in self . schema . imports : imp_shape = self . shape_importer ( uri , self ) if not imp_shape : self . is_valid = False self . error_list . append ( f"Import failure on {uri}" ) if self . schema . start is not None : if not isinstance_ ( self . schema . start , ShExJ . shapeExprLabel ) and 'id' in self . schema . start and self . schema . start . id is None : self . schema . start . id = "_:start" self . _gen_schema_xref ( self . schema . start ) if not isinstance_ ( self . schema . start , ShExJ . shapeExprLabel ) : if self . schema . shapes is None : self . schema . shapes = [ self . schema . start ] else : self . schema . shapes . append ( self . schema . start ) self . schema . start = self . schema . start . id if self . schema . shapes is not None : for e in self . schema . shapes : self . _gen_schema_xref ( e ) self . current_node : ParseNode = None self . evaluate_stack : List [ Tuple [ Union [ BNode , URIRef ] , Optional [ str ] ] ] = [ ] self . bnode_map : Dict [ BNode , str ] = { }
Create a context consisting of an RDF Graph and a ShEx Schema and generate a identifier to
        item map.

        :param g: RDF graph
        :param s: ShExJ Schema instance
        :param external_shape_resolver: External resolution function
        :param base_namespace: