fetch all rdfs:label assertions for a URI
358849
def anyont_fetch_label(id):
    
    iri = expand_uri(id, strict=False)
    query = """
    SELECT ?label WHERE {{
    <{iri}> rdfs:label ?label
    }}
    """.format(iri=iri)
    bindings = run_sparql(query)
    rows = [r['label']['value'] for r in bindings]
    return rows[0]
493486
def fetchall_triples_xrefs(prefix):
    
    logging.info("fetching xrefs for: "+prefix)
    query = """
    SELECT * WHERE {{
    ?c <{p}> ?x
    }}
    """.format(p=prefixmap[prefix])
    bindings = run_sparql(query)
    rows = [(r['c']['value'], r['x']['value']) for r in bindings]
    return rows
1225984
def get_label_map(opts):
    '''  '''
    result = {}
    try:  # get labels from filesystem
        for entry in os.scandir(diskdir):
            if entry.name.startswith('.'):
                continue
            if islink(entry.path):
                target = os.readlink(entry.path)
            else:
                target = entry.path
            result[target] = entry.name
        if opts.debug:
            print('\n\nlabel_map:', result)
    except FileNotFoundError:
        pass

    return result
991499
def RegistryKeyFromClient(args):
  
  for path in _GetExpandedPaths(args):
    pathspec = rdf_paths.PathSpec(
        path=path, pathtype=rdf_paths.PathSpec.PathType.REGISTRY)
    with vfs.VFSOpen(pathspec) as file_obj:
      yield file_obj.Stat()
699379
public static String getJcrNamespaceForRDFNamespace(
            final String rdfNamespaceUri) {
        if (rdfNamespacesToJcrNamespaces.containsKey(rdfNamespaceUri)) {
            return rdfNamespacesToJcrNamespaces.get(rdfNamespaceUri);
        }
        return rdfNamespaceUri;
    }
1224331
def get_uris(self, base_uri, filter_list=None):
        """"""
        return {
            re.sub(r'^/', base_uri, link.attrib['href'])
            for link in self.parsedpage.get_nodes_by_selector('a')
            if 'href' in link.attrib and (
                link.attrib['href'].startswith(base_uri) or
                link.attrib['href'].startswith('/')
            ) and
            not is_uri_to_be_filtered(link.attrib['href'], filter_list)
        }
955146
def conceptscheme_from_uri(conceptscheme_uri, **kwargs):
    '''
    
    '''

    # get the conceptscheme
    # ensure it only ends in one slash
    conceptscheme_uri = conceptscheme_uri.strip('/') + '/'
    s = kwargs.get('session', requests.Session())
    graph = uri_to_graph('%s.rdf' % (conceptscheme_uri), session=s)

    notes = []
    labels = []
    if graph is not False:
        for s, p, o in graph.triples((URIRef(conceptscheme_uri), RDFS.label, None)):
            label = Label(o.toPython(), "prefLabel", 'en')
            labels.append(label)

    conceptscheme = ConceptScheme(
        conceptscheme_uri,
        labels=labels,
        notes=notes
    )
    return conceptscheme
517977
def _GetFilePaths(self, path, pathtype, kb):
    """"""

    environ_vars = artifact_utils.GetWindowsEnvironmentVariablesMap(kb)
    path_guesses = path_detection_windows.DetectExecutablePaths([path],
                                                                environ_vars)

    if not path_guesses:
      # TODO(user): yield a ParserAnomaly object
      return []

    return [
        rdf_paths.PathSpec(path=path, pathtype=pathtype)
        for path in path_guesses
    ]
121096
def rdfgraph_to_ontol(rg):
    
    digraph = networkx.MultiDiGraph()
    from rdflib.namespace import RDF
    label_map = {}
    for c in rg.subjects(RDF.type, OWL.Class):
        cid = contract_uri_wrap(c)
        logging.info("C={}".format(cid))
        for lit in rg.objects(c, RDFS.label):
            label_map[cid] = lit.value
            digraph.add_node(cid, label=lit.value)
        for s in rg.objects(c, RDFS.subClassOf):
            # todo - blank nodes
            sid = contract_uri_wrap(s)
            digraph.add_edge(sid, cid, pred='subClassOf')

    logging.info("G={}".format(digraph))
    payload = {
        'graph': digraph,
        #'xref_graph': xref_graph,
        #'graphdoc': obographdoc,
        #'logical_definitions': logical_definitions
    }
            
    ont = Ontology(handle='wd', payload=payload)
    return ont
1031563
def Validate(self, type_names):
    """"""
    errs = [n for n in self._RDFTypes(type_names) if not self._GetClass(n)]
    if errs:
      raise DefinitionError("Undefined RDF Types: %s" % ",".join(errs))
1144285
def getAllClasses(self, hide_base_schemas=True):
        
        query = """SELECT DISTINCT ?x ?c
                 WHERE {
                         {
                             { ?x a owl:Class }
                             union
                             { ?x a rdfs:Class }
                             union
                             { ?x rdfs:subClassOf ?y }
                             union
                             { ?z rdfs:subClassOf ?x }
                             union
                             { ?y rdfs:domain ?x }
                             union
                             { ?y rdfs:range ?x }
                             # union
                             # { ?y rdf:type ?x }
                         } .

                         ?x a ?c

                    %s

                 }
                 ORDER BY  ?x
                 """
        if hide_base_schemas:
            query = query %  """FILTER(
                     !STRSTARTS(STR(?x), "http://www.w3.org/2002/07/owl")
                     && !STRSTARTS(STR(?x), "http://www.w3.org/1999/02/22-rdf-syntax-ns")
                     && !STRSTARTS(STR(?x), "http://www.w3.org/2000/01/rdf-schema")
                     && !STRSTARTS(STR(?x), "http://www.w3.org/2001/XMLSchema")
                     && !STRSTARTS(STR(?x), "http://www.w3.org/XML/1998/namespace")
                     && (!isBlank(?x))
                      ) ."""
        else:
            query = query % ""

        qres = self.rdfgraph.query(query)
        return list(qres)
1217812
def rdf_bind_to_string(rdf_type):
    
    string_type = unicode if sys.version_info < (3,) else str  # noqa
    bind(rdf_type, string_type)
483309
def payload(self):
    """"""
    if self.args_rdf_name:
      # Now try to create the correct RDFValue.
      result_cls = self.classes.get(self.args_rdf_name, rdfvalue.RDFString)

      result = result_cls.FromSerializedString(
          self.Get("args"), age=self.args_age)
      return result
886084
def get_querystring(uri):
    
    parts = urlparse.urlsplit(uri)
    return urlparse.parse_qs(parts.query)
234137
def _getIdentifier(self, url):
        
        for prefix, namespace in self._rdfGraph.namespaces():
            if namespace in url:
                return url.replace(namespace, '')
871975
def get_labels(self, field):
        """"""
        return {c: self.cluster_meta.get(field, c)
                for c in self.clustering.cluster_ids}
732542
def organization_to_rdf(org, graph=None):
    '''
    
    '''
    graph = graph or Graph(namespace_manager=namespace_manager)
    if org.id:
        org_url = url_for('organizations.show_redirect',
                          org=org.id,
                          _external=True)
        id = URIRef(org_url)
    else:
        id = BNode()
    o = graph.resource(id)
    o.set(RDF.type, FOAF.Organization)
    o.set(FOAF.name, Literal(org.name))
    o.set(RDFS.label, Literal(org.name))
    if org.url:
        o.set(FOAF.homepage, URIRef(org.url))
    return o