Пример #1
0
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
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
     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
 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
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
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
 def concrete(self):
     if "#" in self:
         return URIRef("/".join(rsplit(self, "#", 1)))
     else:
         return self