Try to automatically detect the URI namespace of the vocabulary.

    Return namespace as URIRef.
962568
def detect_namespace(rdf):
    

    # pick a concept
    conc = rdf.value(None, RDF.type, SKOS.Concept, any=True)
    if conc is None:
        logging.critical(
            "Namespace auto-detection failed. "
            "Set namespace using the --namespace option.")
        sys.exit(1)

    ln = localname(conc)
    ns = URIRef(conc.replace(ln, ''))
    if ns.strip() == '':
        logging.critical(
            "Namespace auto-detection failed. "
            "Set namespace using the --namespace option.")
        sys.exit(1)

    logging.info(
        "Namespace auto-detected to '%s' "
        "- you can override this with the --namespace option.", ns)
    return ns
1171414
def remove_namespace(self, ns_uri):
        """"""
        if not self.contains_namespace(ns_uri):
            return

        ni = self.__ns_uri_map.pop(ns_uri)
        for prefix in ni.prefixes:
            del self.__prefix_map[prefix]
1243023
public synchronized String getNamespaceURIByPrefix(String prefix) throws NamespaceException
   {
      if (!prefixToURI.containsKey(prefix))
      {
         throw new NamespaceException(prefix + ": is not a registered namespace prefix.");
      }
      return prefixToURI.get(prefix);
   }
445888
def has_namespace(self, namespace):
        
        result = requests.get(self._make_url(namespace))
        if result.status_code == 200:
            return True
        elif result.status_code == 404:
            return False
234137
def _getIdentifier(self, url):
        
        for prefix, namespace in self._rdfGraph.namespaces():
            if namespace in url:
                return url.replace(namespace, '')
839791
def _discover_uri_type(uri):
    """"""
    parsed_uri = urlparse(uri)
    if not parsed_uri.netloc:
        if parsed_uri.scheme == 'data':
            type_ = INLINE_REFERENCE_TYPE
        else:
            type_ = INTERNAL_REFERENCE_TYPE
    else:
        type_ = EXTERNAL_REFERENCE_TYPE
    return type_
815331
@Override
    public String getNamespaceURI(String prefix){
        if(prefix==null)
            throw new IllegalArgumentException("prefix is null");

        return get(prefix);
    }
645796
def find_namespace(dtd)
      return unless dtd.system_id
      dtd_uri = URI.parse(dtd.system_id)
      return unless dtd_uri.path
      @dtd_uri = dtd_uri
      File.basename(@dtd_uri.path, '.dtd')
    end
408266
def ensure_namespace(self, name):
        # type: (str) -> ApiNamespace
        
        if name not in self.namespaces:
            self.namespaces[name] = ApiNamespace(name)
        return self.namespaces[name]
535387
def geturi(self):
        """"""
        fragment = self.fragment
        if fragment is None:
            return self.uri
        elif isinstance(fragment, bytes):
            return self.uri + b'#' + fragment
        else:
            return self.uri + u'#' + fragment
1150824
def get_namespace_from_name(name):
    
    if not re.match(NAMESPACE_PATTERN, name):
        sys.exit(("Argument '%s' doesn't match any recognized pattern:\n"
                  "\tfloyd [data] init <project_or_dataset_name>\n"
                  "\tfloyd [data] init <namespace>/<project_or_dataset_name>\n"
                  "\tfloyd [data] init <namespace>/[projects|dataset]/<project_or_dataset_name>\n"
                  "\n Note: Argument can only contain alphanumeric, hyphen-minus '-' , underscore '_' and dot '.' characters."
                  ) % name)

    name_parts = name.split("/", 2)
    if len(name_parts) > 1:
        return name_parts[0], name_parts[-1]
    else:
        return current_username(), name
112750
def normalize_uri(u: URI) -> URIRef:
    
    return u if isinstance(u, URIRef) else URIRef(str(u))
591471
def get_uri_name(url):
    """"""
    url_parsed = urlparse(url)

    url_parts = url_parsed.path.split('/')

    log.info('url parts: %s', url_parts)

    return url_parts[-1]
368890
def _build_qname(self, uri=None, namespaces=None):
        
        if not uri:
            uri = self.uri
        if not namespaces:
            namespaces = self.namespaces
        return uri2niceString(uri, namespaces)
434404
def _fixNS(self, namespace):
        
        if namespace == OPENID_NS:
            if self._openid_ns_uri is None:
                raise UndefinedOpenIDNamespace('OpenID namespace not set')
            else:
                namespace = self._openid_ns_uri

        if namespace != BARE_NS and type(namespace) not in [str, unicode]:
            raise TypeError(
                "Namespace must be BARE_NS, OPENID_NS or a string. got %r"
                % (namespace,))

        if namespace != BARE_NS and ':' not in namespace:
            fmt = 'OpenID 2.0 namespace identifiers SHOULD be URIs. Got %r'
            warnings.warn(fmt % (namespace,), DeprecationWarning)

            if namespace == 'sreg':
                fmt = 'Using %r instead of "sreg" as namespace'
                warnings.warn(fmt % (SREG_URI,), DeprecationWarning,)
                return SREG_URI

        return namespace
1024856
def safe_uriref(text):
    
    url_ = url.parse(text).sanitize().deuserinfo().canonical()
    return URIRef(url_.punycode().unicode())
648963
def find_namespace_uri(ns_stack, prefix, uri_check=nil)
      tns = ns_stack.reverse.find{|ns| ns.has_key?(prefix)}
      uri = tns[prefix] if tns
      raise "prefix: '#{prefix}' is bound to uri: '#{uri}', but should be '#{uri_check}'" if uri_check && uri && uri!=uri_check
      uri
    end