pyshacl/monkey/memory2.py
def __add_triple_context(self, triple, context, quoted):
        """add the given context to the set of contexts for the triple"""
        ctx = self.__ctx_to_str(context)
        quoted = bool(quoted)
        try:
            subj, pred, obj = triple
            _ = self.__spo[subj][pred][obj]
            # we know the triple exists somewhere in the store
            if triple not in self.__tripleContexts:
                # triple exists with default ctx info
                # start with a copy of the default ctx info
                self.__tripleContexts[triple] = self.__defaultContexts.copy()

            self.__tripleContexts[triple][ctx] = quoted
            if not quoted:
                self.__tripleContexts[triple][None] = quoted
        except KeyError:
            # the triple didn't exist before in the store
            if quoted:  # this context only
                self.__tripleContexts[triple] = {ctx: quoted}
            else:  # default context as well
                self.__tripleContexts[triple] = {ctx: quoted, None: quoted}

        # if the triple is not quoted add it to the default context
        if not quoted:
            self.__contextTriples[None].add(triple)

        # always add the triple to given context, making sure it's initialized
        if ctx not in self.__contextTriples:
            self.__contextTriples[ctx] = set()
        self.__contextTriples[ctx].add(triple)

        # if this is the first ever triple in the store, set default ctx info
        if self.__defaultContexts is None:
            self.__defaultContexts = self.__tripleContexts[triple]

        # if the context info is the same as default, no need to store it
        if self.__tripleContexts[triple] == self.__defaultContexts:
            del self.__tripleContexts[triple]
add the given context to the set of contexts for the triple
add the given context to the set of contexts for the triple
add the given context to the set of contexts for the triple
def __add_triple_context(self, triple, context, quoted):
        ctx = self.__ctx_to_str(context)
        quoted = bool(quoted)
        try:
            subj, pred, obj = triple
            _ = self.__spo[subj][pred][obj]
            if triple not in self.__tripleContexts:
                self.__tripleContexts[triple] = self.__defaultContexts.copy()
            self.__tripleContexts[triple][ctx] = quoted
            if not quoted:
                self.__tripleContexts[triple][None] = quoted
        except KeyError:
            if quoted:  
                self.__tripleContexts[triple] = {ctx: quoted}
            else:  
                self.__tripleContexts[triple] = {ctx: quoted, None: quoted}
        if not quoted:
            self.__contextTriples[None].add(triple)
        if ctx not in self.__contextTriples:
            self.__contextTriples[ctx] = set()
        self.__contextTriples[ctx].add(triple)
        if self.__defaultContexts is None:
            self.__defaultContexts = self.__tripleContexts[triple]
        if self.__tripleContexts[triple] == self.__defaultContexts:
            del self.__tripleContexts[triple]
def __add_triple_context ( self , triple , context , quoted ) : ctx = self . __ctx_to_str ( context ) quoted = bool ( quoted ) try : subj , pred , obj = triple _ = self . __spo [ subj ] [ pred ] [ obj ] if triple not in self . __tripleContexts : self . __tripleContexts [ triple ] = self . __defaultContexts . copy ( ) self . __tripleContexts [ triple ] [ ctx ] = quoted if not quoted : self . __tripleContexts [ triple ] [ None ] = quoted except KeyError : if quoted : self . __tripleContexts [ triple ] = { ctx : quoted } else : self . __tripleContexts [ triple ] = { ctx : quoted , None : quoted } if not quoted : self . __contextTriples [ None ] . add ( triple ) if ctx not in self . __contextTriples : self . __contextTriples [ ctx ] = set ( ) self . __contextTriples [ ctx ] . add ( triple ) if self . __defaultContexts is None : self . __defaultContexts = self . __tripleContexts [ triple ] if self . __tripleContexts [ triple ] == self . __defaultContexts : del self . __tripleContexts [ triple ]
add the given context to the set of contexts for the triple
add the given context to the set of contexts for the triple
"""add the given context to the set of contexts for the triple""" # we know the triple exists somewhere in the store # triple exists with default ctx info # start with a copy of the default ctx info # the triple didn't exist before in the store # this context only # default context as well # if the triple is not quoted add it to the default context # always add the triple to given context, making sure it's initialized # if this is the first ever triple in the store, set default ctx info # if the context info is the same as default, no need to store it
self
triple
context
quoted