Exemple #1
0
    def dumpLists(self, context):
        "Dump lists out as first and rest. Not used in pretty."
        listList = {}
        result = []
        #context = self.workingContext
        #sink = self.sink
        lists = []
        for s in context.statements:
            #print "s:", s
            for x in s.predicate(), s.subject(), s.object():
                if isinstance(x, term.NonEmptyList):
                    self._listsWithinLists(x, lists)

        for l in lists:
            list = l
            while not isinstance(list, term.EmptyList):
                if list not in listList:
                    #print list, " rdf:type rdf:list"
                    #self._outputStatement(sink, (context, self.store.forSome, context, list))
                    listList[list] = 1
                list = list.rest

        listList = {}
        for l in lists:
            list = l
            while (not isinstance(list,
                                  term.EmptyList)) and list not in listList:
                result.append(
                    terms.Pattern(
                        terms.Exivar("_:" + str(list)),
                        "http://www.w3.org/1999/02/22-rdf-syntax-ns#first",
                        self.convType(list.first, self.workingContext,
                                      context)))
                if isinstance(list.rest, term.EmptyList):
                    #print "_:", list, " rdf:rest rdf:nil"
                    result.append(
                        terms.Pattern(
                            terms.Exivar("_:" + str(list)),
                            "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest",
                            "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"))
                else:
                    result.append(
                        terms.Pattern(
                            terms.Exivar("_:" + str(list)),
                            "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest",
                            self.convType(list.rest, self.workingContext,
                                          context)))
                    #print list, " rdf:rest ", list.rest
                #self._outputStatement(sink, (context, self.store.first, list, list.first))
                #self._outputStatement(sink, (context, self.store.rest,  list, list.rest))
                listList[list] = 1
                list = list.rest

        return result
Exemple #2
0
    def convType(self, t, F, K=None):
        #        print "type:",t, type(t)
        """print "t:", t
        print type(t)
        print "f unis:", F.universals()
        if (K): print "k exis:", K.existentials()"""

        if isinstance(t, term.NonEmptyList):
            #convert the name of the list to an exivar and return it
            #self.convertListToRDF(t, listId, self.extra)
            #return terms.Exivar('_:' + str(t))
            return '_:' + str(t)
            #raise RuntimeError
        if t in F.universals():
            return terms.Variable(t)
        if K is not None and t in K.existentials():
            #            print "returning existential:", t
            return terms.Exivar(t)
        if isinstance(t, term.Symbol):
            return terms.URIRef(t.uri)
        if isinstance(t, term.BuiltIn):
            return t.uriref()
        if isinstance(t, term.Fragment):
            #                print "uriref:",terms.URIRef(t.uriref())
            #                print type(t.uriref())
            return terms.URIRef(t.uriref())
#        print type(t)
#        print "returning URI",t
        return str(t)
Exemple #3
0
 def _convert(node):
     if isinstance(node, Variable):
         return terms.Variable(node)
         # return node
     elif isinstance(node, BNode):
         return terms.Exivar(node)
     elif isinstance(node, URIRef):
         # return terms.URI(node)
         return node
     elif isinstance(node, Literal):
         return node
     else:
         raise Exception("Unexpected Type: %s" % type(node))