コード例 #1
0
 def resourcePropertyElt(self, e):
     n = e.children[0]
     self.nodeElement(n)
     self.triple(e.parent.subject, self.uri(e.URI), n.subject)
     if e.attrs.has_key(rdf.ID):
         i = self.uri(urijoin(e.base, ('#' + e.attrs[rdf.ID])))
         self.reify(i, e.parent.subject, self.uri(e.URI), n.subject)
コード例 #2
0
ファイル: n3proc.py プロジェクト: ChunHungLiu/watchdog-1
 def __init__(self, uri, sink, baseURI=False):
     super(N3Processor, self).__init__(uri, branches, regexps)
     if baseURI is False:
         self.baseURI = uri
     else:
         self.baseURI = baseURI
     self.sink = sink
     self.bindings = {'': urijoin(self.baseURI, '#')}
     self.counter = 0
     self.prefix = False
     self.userkeys = False
     self.anonsubj = False
     self.litinfo = False
     self.forAll = False
     self.forSome = False
     self.universals = {}
     self.existentials = {}
     self.formulae = []
     self.labels = []
     self.mode = []
     self.triples = []
     self.pathmode = 'path'
     self.paths = []
     self.lists = []
     self.bnodes = {}
コード例 #3
0
 def resourcePropertyElt(self, e):
     n = e.children[0]
     self.nodeElement(n)
     self.triple(e.parent.subject, self.uri(e.URI), n.subject)
     if e.attrs.has_key(rdf.ID):
         i = self.uri(urijoin(e.base, ('#' + e.attrs[rdf.ID])))
         self.reify(i, e.parent.subject, self.uri(e.URI), n.subject)
コード例 #4
0
ファイル: rdfxml.py プロジェクト: OnToologyUser/NBAMovements2
   def emptyPropertyElt(self, e): 
      if e.attrs.keys() in ([], [rdf.ID]): 
         r = self.literal(e.text, e.language) # was o
         self.triple(e.parent.subject, self.uri(e.URI), r)
      else: 
         if e.attrs.has_key(rdf.resource): 
            r = self.uri(urijoin(e.base, e[rdf.resource]))
         elif e.attrs.has_key(rdf.nodeID): r = self.bNode(e[rdf.nodeID])
         else: r = self.bNode()

         for a in filter(lambda n: n not in self.disallowed, e.attrs.keys()): 
            if a != rdf.type: 
               o = self.literal(e.attrs[a], e.language)
               self.triple(r, self.uri(a), o)
            else: self.triple(r, self.uri(rdf.type), self.uri(e.attrs[a]))
         self.triple(e.parent.subject, self.uri(e.URI), r)
      if e.attrs.has_key(rdf.ID): 
         i = self.uri(urijoin(e.base, ('#' + e.attrs[rdf.ID])))
         self.reify(i, e.parent.subject, self.uri(e.URI), r)
コード例 #5
0
ファイル: n3proc.py プロジェクト: Ju2ender/watchdog
 def uri(self, tok):
    u = URIRef(urijoin(self.baseURI, tok))
    if self.universals.has_key(u):
       formula, var = self.universals[u]
       if formula in self.formulae:
          return var
    if self.existentials.has_key(u): # @@ elif?
       formula, bnode = self.existentials[u]
       if formula in self.formulae:
          return bnode
    return u
コード例 #6
0
ファイル: n3proc.py プロジェクト: ChunHungLiu/watchdog-1
 def uri(self, tok):
     u = URIRef(urijoin(self.baseURI, tok))
     if self.universals.has_key(u):
         formula, var = self.universals[u]
         if formula in self.formulae:
             return var
     if self.existentials.has_key(u):  # @@ elif?
         formula, bnode = self.existentials[u]
         if formula in self.formulae:
             return bnode
     return u
コード例 #7
0
 def parseTypeResourcePropertyElt(self, e):
     n = self.bNode()
     self.triple(e.parent.subject, self.uri(e.URI), n)
     if e.attrs.has_key(rdf.ID):
         e.subject = i = self.uri(urijoin(e.base, ('#' + e.attrs[rdf.ID])))
         self.reify(i, e.parent.subject, self.uri(e.URI), n)
     c = Element((rdf, 'Description'), e.qname, e.attrs, e.parent, e.base)
     c.subject = n
     for child in e.children:
         child.parent = c
         c.children += [child]
     self.nodeElement(c)
コード例 #8
0
 def parseTypeResourcePropertyElt(self, e):
     n = self.bNode()
     self.triple(e.parent.subject, self.uri(e.URI), n)
     if e.attrs.has_key(rdf.ID):
         e.subject = i = self.uri(urijoin(e.base, ('#' + e.attrs[rdf.ID])))
         self.reify(i, e.parent.subject, self.uri(e.URI), n)
     c = Element((rdf, 'Description'), e.qname, e.attrs, e.parent, e.base)
     c.subject = n
     for child in e.children:
         child.parent = c
         c.children += [child]
     self.nodeElement(c)
コード例 #9
0
ファイル: rdfxml.py プロジェクト: OnToologyUser/NBAMovements2
   def nodeElement(self, e): 
      assert e.URI not in self.disallowed, "Disallowed element used as node"

      if e.attrs.has_key(rdf.ID): 
         e.subject = self.uri(urijoin(e.base, "#" + e[rdf.ID]))
      elif e.attrs.has_key(rdf.about): 
         e.subject = self.uri(urijoin(e.base, e[rdf.about]))
      elif e.attrs.has_key(rdf.nodeID): e.subject = self.bNode(e[rdf.nodeID])
      elif not hasattr(e, 'subject'): e.subject = self.bNode()

      if e.URI != rdf.Description: 
         self.triple(e.subject, self.uri(rdf.type), self.uri(e.URI))
      if e.attrs.has_key(rdf.type): 
         self.triple(e.subject, self.uri(rdf.type), self.uri(e[rdf.type]))
      for attr in e.attrs.keys(): 
         if attr not in self.disallowed + [rdf.type]: 
            objt = self.literal(e[attr], e.language)
            self.triple(e.subject, self.uri(attr), objt)

      for element in e.children: 
         self.propertyElt(element)
コード例 #10
0
    def emptyPropertyElt(self, e):
        if e.attrs.keys() in ([], [rdf.ID]):
            r = self.literal(e.text, e.language)  # was o
            self.triple(e.parent.subject, self.uri(e.URI), r)
        else:
            if e.attrs.has_key(rdf.resource):
                r = self.uri(urijoin(e.base, e[rdf.resource]))
            elif e.attrs.has_key(rdf.nodeID):
                r = self.bNode(e[rdf.nodeID])
            else:
                r = self.bNode()

            for a in filter(lambda n: n not in self.disallowed,
                            e.attrs.keys()):
                if a != rdf.type:
                    o = self.literal(e.attrs[a], e.language)
                    self.triple(r, self.uri(a), o)
                else:
                    self.triple(r, self.uri(rdf.type), self.uri(e.attrs[a]))
            self.triple(e.parent.subject, self.uri(e.URI), r)
        if e.attrs.has_key(rdf.ID):
            i = self.uri(urijoin(e.base, ('#' + e.attrs[rdf.ID])))
            self.reify(i, e.parent.subject, self.uri(e.URI), r)
コード例 #11
0
    def nodeElement(self, e):
        assert e.URI not in self.disallowed, "Disallowed element used as node"

        if e.attrs.has_key(rdf.ID):
            e.subject = self.uri(urijoin(e.base, "#" + e[rdf.ID]))
        elif e.attrs.has_key(rdf.about):
            e.subject = self.uri(urijoin(e.base, e[rdf.about]))
        elif e.attrs.has_key(rdf.nodeID):
            e.subject = self.bNode(e[rdf.nodeID])
        elif not hasattr(e, 'subject'):
            e.subject = self.bNode()

        if e.URI != rdf.Description:
            self.triple(e.subject, self.uri(rdf.type), self.uri(e.URI))
        if e.attrs.has_key(rdf.type):
            self.triple(e.subject, self.uri(rdf.type), self.uri(e[rdf.type]))
        for attr in e.attrs.keys():
            if attr not in self.disallowed + [rdf.type]:
                objt = self.literal(e[attr], e.language)
                self.triple(e.subject, self.uri(attr), objt)

        for element in e.children:
            self.propertyElt(element)
コード例 #12
0
ファイル: n3proc.py プロジェクト: Ju2ender/watchdog
 def __init__(self, uri, sink, baseURI=False):
    super(N3Processor, self).__init__(uri, branches, regexps)
    if baseURI is False:
       self.baseURI = uri
    else: self.baseURI = baseURI
    self.sink = sink
    self.bindings = {'': urijoin(self.baseURI, '#')}
    self.counter = 0
    self.prefix = False
    self.userkeys = False
    self.anonsubj = False
    self.litinfo = False
    self.forAll = False
    self.forSome = False
    self.universals = {}
    self.existentials = {}
    self.formulae = []
    self.labels = []
    self.mode = []
    self.triples = []
    self.pathmode = 'path'
    self.paths = []
    self.lists = []
    self.bnodes = {}
コード例 #13
0
 def parseTypeLiteralOrOtherPropertyElt(self, e):
     o = self.literal(e.xtext[1], e.language, rdf.XMLLiteral)
     self.triple(e.parent.subject, self.uri(e.URI), o)
     if e.attrs.has_key(rdf.ID):
         e.subject = i = self.uri(urijoin(e.base, ('#' + e.attrs[rdf.ID])))
         self.reify(i, e.parent.subject, self.uri(e.URI), o)
コード例 #14
0
 def literalPropertyElt(self, e):
     o = self.literal(e.text, e.language, e.attrs.get(rdf.datatype))
     self.triple(e.parent.subject, self.uri(e.URI), o)
     if e.attrs.has_key(rdf.ID):
         i = self.uri(urijoin(e.base, ('#' + e.attrs[rdf.ID])))
         self.reify(i, e.parent.subject, self.uri(e.URI), o)
コード例 #15
0
 def parseTypeLiteralOrOtherPropertyElt(self, e):
     o = self.literal(e.xtext[1], e.language, rdf.XMLLiteral)
     self.triple(e.parent.subject, self.uri(e.URI), o)
     if e.attrs.has_key(rdf.ID):
         e.subject = i = self.uri(urijoin(e.base, ('#' + e.attrs[rdf.ID])))
         self.reify(i, e.parent.subject, self.uri(e.URI), o)
コード例 #16
0
 def literalPropertyElt(self, e):
     o = self.literal(e.text, e.language, e.attrs.get(rdf.datatype))
     self.triple(e.parent.subject, self.uri(e.URI), o)
     if e.attrs.has_key(rdf.ID):
         i = self.uri(urijoin(e.base, ('#' + e.attrs[rdf.ID])))
         self.reify(i, e.parent.subject, self.uri(e.URI), o)