def construct(self, tripleStore, bindings):
        """
        Add triples to a tripleStore based on a variable bindings of
        the patterns stored locally.  The triples are patterned by the
        current Graph Pattern. The method is used to construct a graph
        after a successful querying.

        :param tripleStore: an (rdflib) Triple Store
        :param bindings: dictionary

        """
        localBnodes = {}

        for c in self.bnodes:
            localBnodes[c] = BNode()

        def bind(st):
            if _isResQuest(st):

                if st in bindings:
                    return bindings[st]

                else:

                    if isinstance(self, GraphPattern):
                        return st
                    else:
                        return None

            elif isinstance(st, BNode):

                for c in self.bnodes:

                    if self.bnodes[c] == st:
                        # this is a BNode that was created as part of building
                        # up the pattern
                        return localBnodes[c]

                # if we got here, the BNode comes from somewhere else...
                return st

            else:
                return st

        for pattern in self.patterns:
            (s,p,o,f) = pattern
            triplet = []
            valid = True

            for res in (s,p,o):
                val = bind(res)

                if val != None:
                    triplet.append(val)
                else:
                    valid = False
                    break

            if valid:
                tripleStore.add(tuple(triplet))
dataset/ETHPy150Open RDFLib/rdfextras/rdfextras/sparql/graph.py/GraphPattern.construct/original