コード例 #1
0
ファイル: _sqlobject.py プロジェクト: msaelices/django-rdflib
def splituri(uri):
    if uri.startswith('<') and uri.endswith('>'):
        uri = uri[1:-1]
    if uri.startswith('_'):
        uid = ''.join(uri.split('_'))
        return '_', uid
    if '#' in uri:
        ns, local = rsplit(uri, '#', 1)
        return ns + '#', local
    if '/' in uri:
        ns, local = rsplit(uri, '/', 1)
        return ns + '/', local
    return NO_URI, uri
コード例 #2
0
ファイル: _sqlobject.py プロジェクト: NezbiT/watchdog
def splituri(uri):
    if uri.startswith("<") and uri.endswith(">"):
        uri = uri[1:-1]
    if uri.startswith("_"):
        uid = "".join(uri.split("_"))
        return "_", uid
    if "#" in uri:
        ns, local = rsplit(uri, "#", 1)
        return ns + "#", local
    if "/" in uri:
        ns, local = rsplit(uri, "/", 1)
        return ns + "/", local
    return NO_URI, uri
コード例 #3
0
    def localname_for_uri(self, uri):

        if "#" not in uri:
            scheme, netloc, path, params, query, fragment = urlparse(uri)
            if path:
                return (rsplit(uri, "/", 1))[1]
            else:
                return uri

        return uri.rsplit("#")[1].strip()
コード例 #4
0
ファイル: parser.py プロジェクト: imclab/eatdrinkfeelgood
     def localname_for_uri (self, uri) :

          if "#" not in uri:
               scheme, netloc, path, params, query, fragment = urlparse(uri)
               if path:
                    return (rsplit(uri, "/", 1))[1]
               else :
                    return uri

          return uri.rsplit("#")[1].strip()
コード例 #5
0
 def abstract(self):
     if "#" not in self:
         scheme, netloc, path, params, query, fragment = urlparse(self)
         if path:
             return URIRef("#".join(rsplit(self, "/", 1)))
         else:
             if not self.endswith("#"):
                 return URIRef("%s#" % self)
             else:
                 return self
     else:
         return self
コード例 #6
0
ファイル: URIRef.py プロジェクト: ChunHungLiu/watchdog-1
 def abstract(self):
     if "#" not in self:
         scheme, netloc, path, params, query, fragment = urlparse(self)
         if path:
             return URIRef("#".join(rsplit(self, "/", 1)))
         else:
             if not self.endswith("#"):
                 return URIRef("%s#" % self)
             else:
                 return self
     else:
         return self
コード例 #7
0
ファイル: util.py プロジェクト: ChunHungLiu/watchdog-1
def from_n3(s, default=None, backend=None):
    """ Creates the Identifier corresponding to the given n3 string. WARNING: untested, may contain bugs. TODO: add test cases."""
    if not s:
        return default
    if s.startswith('<'):
        return URIRef(s[1:-1])
    elif s.startswith('"'):
        # TODO: would a regex be faster?
        value, rest = rsplit(s, '"', 1)
        value = value[1:]  # strip leading quote
        if rest.startswith("@"):
            if "^^" in rest:
                language, rest = rsplit(rest, '^^', 1)
                language = language[1:]  # strip leading at sign
            else:
                language = rest[1:]  # strip leading at sign
                rest = ''
        else:
            language = None
        if rest.startswith("^^"):
            datatype = rest[3:-1]
        else:
            datatype = None
        value = value.replace('\\"',
                              '"').replace('\\\\',
                                           '\\').decode("unicode-escape")
        return Literal(value, language, datatype)
    elif s.startswith('{'):
        identifier = from_n3(s[1:-1])
        return QuotedGraph(backend, identifier)
    elif s.startswith('['):
        identifier = from_n3(s[1:-1])
        return Graph(backend, identifier)
    else:
        if s.startswith("_:"):
            return BNode(s[2:])
        else:
            return BNode(s)
コード例 #8
0
ファイル: util.py プロジェクト: ResearchEngr/openpowersystem
def from_n3(s, default=None, backend=None):
    """ Creates the Identifier corresponding to the given n3 string. WARNING: untested, may contain bugs. TODO: add test cases."""
    if not s:
        return default
    if s.startswith('<'):
        return URIRef(s[1:-1])
    elif s.startswith('"'):
        # TODO: would a regex be faster?
        value, rest = rsplit(s, '"', 1)
        value = value[1:] # strip leading quote
        if rest.startswith("@"):
            if "^^" in rest:
                language, rest = rsplit(rest, '^^', 1)
                language = language[1:] # strip leading at sign
            else:
                language = rest[1:] # strip leading at sign
                rest = ''
        else:
            language = None
        if rest.startswith("^^"):
            datatype = rest[3:-1]
        else:
            datatype = None
        value = value.replace('\\"', '"').replace('\\\\', '\\').decode("unicode-escape")
        return Literal(value, language, datatype)
    elif s.startswith('{'):
        identifier = from_n3(s[1:-1])
        return QuotedGraph(backend, identifier)
    elif s.startswith('['):
        identifier = from_n3(s[1:-1])
        return Graph(backend, identifier)
    else:
        if s.startswith("_:"):
            return BNode(s[2:])
        else:
            return BNode(s)
コード例 #9
0
 def concrete(self):
     if "#" in self:
         return URIRef("/".join(rsplit(self, "#", 1)))
     else:
         return self
コード例 #10
0
ファイル: URIRef.py プロジェクト: ChunHungLiu/watchdog-1
 def concrete(self):
     if "#" in self:
         return URIRef("/".join(rsplit(self, "#", 1)))
     else:
         return self