Given an RDF node URI (and it's associated schema), return an
        object from the ``graph`` that represents the information available
        about this node.
517041
def _objectify(self, node, binding, depth, path):
        
        if binding.is_object:
            obj = {'$schema': binding.path}
            for (s, p, o) in self.graph.triples((node, None, None)):
                prop = binding.get_property(p)
                if prop is None or depth <= 1 or o in path:
                    continue
                # This is slightly odd but yield purty objects:
                if depth <= 2 and (prop.is_array or prop.is_object):
                    continue
                sub_path = path.union([node])
                value = self._objectify(o, prop, depth - 1, sub_path)
                if prop.is_array and prop.name in obj:
                    obj[prop.name].extend(value)
                else:
                    obj[prop.name] = value
            return obj
        elif binding.is_array:
            for item in binding.items:
                return [self._objectify(node, item, depth, path)]
        else:
            return node.toPython()
1364226
def rdf2dot( g, stream, opts={} ):
    

    accept_lang = set( opts.get('lang',[]) )
    do_literal = opts.get('literal')
    nodes = {}
    links = []

    def node_id(x):
        if x not in nodes:
            nodes[x] = "node%d" % len(nodes)
        return nodes[x]

    def qname(x, g):
        try:
            q = g.compute_qname(x)
            return q[0] + ":" + q[2]
        except:
            return x

    def accept( node ):
        if isinstance( node, (rdflib.URIRef,rdflib.BNode) ):
            return True
        if not do_literal:
            return False
        return (not accept_lang) or (node.language in accept_lang)


    stream.write( u'digraph { \n node [ fontname="DejaVu Sans,Tahoma,Geneva,sans-serif" ] ; \n' )

    # Write all edges. In the process make a list of all nodes
    for s, p, o in g:
        # skip triples for labels
        if p == rdflib.RDFS.label:
            continue

        # Create a link if both objects are graph nodes
        # (or, if literals are also included, if their languages match)
        if not (accept(s) and accept(o)):
            continue

        # add the nodes to the list
        sn = node_id(s)
        on = node_id(o)

        # add the link
        q = qname(p,g)
        if isinstance(p, rdflib.URIRef):
            opstr = u'\t%s -> %s [ arrowhead="open", color="#9FC9E560", fontsize=9, fontcolor="#204080", label="%s", href="%s", target="_other" ] ;\n' % (sn,on,q,p)
        else:
            opstr = u'\t%s -> %s [ arrowhead="open", color="#9FC9E560", fontsize=9, fontcolor="#204080", label="%s" ] ;\n'%(sn,on,q)
        stream.write( opstr )

    # Write all nodes
    for u, n in nodes.items():
        lbl = escape( label(u,g,accept_lang), True )
        if isinstance(u, rdflib.URIRef):
            opstr = u'%s [ shape=none, fontsize=10, fontcolor=%s, label="%s", href="%s", target=_other ] \n' % (n, 'blue', lbl, u )
        else:
            opstr = u'%s [ shape=none, fontsize=10, fontcolor=%s, label="%s" ] \n' % (n, 'black', lbl )
        stream.write( u"# %s %s\n" % (u, n) )
        stream.write( opstr )

    stream.write(u'}\n')
232986
def get_node(name):
	
	if name in _ops:
		return _ops[name]
	else:
		g=tf.get_default_graph()
		return g.as_graph_element(name)
1251960
def arcsIn(G: Graph, n: Node) -> RDFGraph:
    
    return RDFGraph(G.triples((None, None, n)))
32060
def __serializedDot(self):
		
		temp = ""
		for x,y,z in self.rdflib_graph.triples((None, None, None)):
			temp += """"%s" -> "%s" [label="%s"];\n""" % (self.namespace_manager.normalizeUri(x), self.namespace_manager.normalizeUri(z), self.namespace_manager.normalizeUri(y))
		temp = "digraph graphname {\n%s}" % temp
		return temp
1200616
def load_from_rdf_file(self, rdf_file):
        
        self.graph = rdflib.Graph()
        self.graph.parse(os.path.abspath(rdf_file), format='nt')
        self.initialize()
808612
def get_node(self, goid, goobj):
        """"""
        # pydot.Node.objdict holds this information. pydot.Node.objdict['name']
        return pydot.Node(
            self.get_node_text(goid, goobj),
            shape="box",
            style="rounded, filled",
            fillcolor=self.go2color.get(goid, "white"),
            color=self.objcolor.get_bordercolor(goid))
1161302
def startGraph(self):
        """"""
        g = r.Graph()
        g.namespace_manager.bind("rdf", r.namespace.RDF)    
        g.namespace_manager.bind("foaf", r.namespace.FOAF)    
        g.namespace_manager.bind("xsd", r.namespace.XSD)    
        g.namespace_manager.bind("opa", "http://purl.org/socialparticipation/opa/")    
        g.namespace_manager.bind("ops", "http://purl.org/socialparticipation/ops/")    
        g.namespace_manager.bind("wsg", "http://www.w3.org/2003/01/geo/wgs84_pos#")    
        g.namespace_manager.bind("dc2", "http://purl.org/dc/elements/1.1/")    
        g.namespace_manager.bind("dc", "http://purl.org/dc/terms/")    
        g.namespace_manager.bind("sioc", "http://rdfs.org/sioc/ns#")    
        g.namespace_manager.bind("tsioc", "http://rdfs.org/sioc/types#")    
        g.namespace_manager.bind("schema", "http://schema.org/")
        g.namespace_manager.bind("part", "http://participa.br/")
        self.g=g
372064
def get_uri(self, alias):
        
        if alias in self.aliases.keys():
            return self.aliases[alias]
        if alias in self.aliases.values():
            return alias
        raise GraphException('No such schema: %r' % alias)
330206
def __extract_pattern_nodes(graph):
    
    tp_nodes = graph.subjects(RDF.type, AGORA.TriplePattern)
    for tpn in tp_nodes:
        subject = list(graph.objects(tpn, AGORA.subject)).pop()
        predicate = list(graph.objects(tpn, AGORA.predicate)).pop()
        obj = list(graph.objects(tpn, AGORA.object)).pop()
        subject_str = list(graph.objects(subject, RDFS.label)).pop().toPython()
        predicate_str = graph.qname(predicate)
        if (obj, RDF.type, AGORA.Variable) in graph:
            object_str = list(graph.objects(obj, RDFS.label)).pop().toPython()
        else:
            object_str = list(graph.objects(obj, AGORA.value)).pop().toPython()
        __plan_patterns[tpn] = '{} {} {}'.format(subject_str, predicate_str, object_str)
364191
def nt(graph):
    """"""
    from rdflib import ConjunctiveGraph
    from rdflib.plugin import register, Parser

    register('json-ld', Parser, 'rdflib_jsonld.parser', 'JsonLDParser')

    click.echo(
        ConjunctiveGraph().parse(
            data=_jsonld(graph, 'expand'),
            format='json-ld',
        ).serialize(format='nt')
    )
789666
def user_to_rdf(user, graph=None):
    '''
    
    '''
    graph = graph or Graph(namespace_manager=namespace_manager)
    if user.id:
        user_url = url_for('users.show_redirect',
                           user=user.id,
                           _external=True)
        id = URIRef(user_url)
    else:
        id = BNode()
    o = graph.resource(id)
    o.set(RDF.type, FOAF.Person)
    o.set(FOAF.name, Literal(user.fullname))
    o.set(RDFS.label, Literal(user.fullname))
    if user.website:
        o.set(FOAF.homepage, URIRef(user.website))
    return o
719324
def parse_owl_rdf(iri):
    
    g = nx.DiGraph(IRI=iri)
    o = Ontospy(iri)

    for cls in o.classes:
        g.add_node(cls.locale, type='Class')

        for parent in cls.parents():
            g.add_edge(cls.locale, parent.locale, type='SubClassOf')

        for instance in cls.instances():
            _, frag = urldefrag(instance)
            g.add_edge(frag, cls.locale, type='ClassAssertion')

    return g
1352823
def _resources_from_graph(graph, uris_and_graphs)
      repo = add_data_to_repository(graph)
      resources = []

      # TODO: ? if uris_and_graphs not passed in, we could get the
      # uris from the graph, and just not create the resoruces with a graph
      # (but they won't be persistable).

      uris_and_graphs.each do |(u,g)|

        # instantiate a new resource
        g ||= {}
        r = self.new(u, g)

        # make a graph of data for this resource's uri
        data_graph = RDF::Graph.new
        repo.query( [RDF::URI.new(u), :predicate, :object] ) do |statement|
          data_graph << statement

          if statement.object.is_a? RDF::Node
            repo.query( [statement.object, :predicate, :object] ) {|s| data_graph << s}
          end
        end

        # use it to hydrate this resource
        r.hydrate!(:graph => data_graph)
        r.new_record = false
        resources << r
      end

      resources
    end
796384
def ToURN(self):
    """"""

    if self.path_type in [PathInfo.PathType.OS, PathInfo.PathType.TSK]:
      return rdfvalue.RDFURN(self.client_id).Add("fs").Add(
          self.path_type.name.lower()).Add("/".join(self.path_components))
    elif self.path_type == PathInfo.PathType.REGISTRY:
      return rdfvalue.RDFURN(self.client_id).Add("registry").Add("/".join(
          self.path_components))
    elif self.path_type == PathInfo.PathType.TEMP:
      return rdfvalue.RDFURN(self.client_id).Add("temp").Add("/".join(
          self.path_components))

    raise ValueError("Unsupported path type: %s" % self.path_type)
487386
def Graph2Pandas_converter(self):
        ''''''

        if isinstance(self.path, str) or isinstance(self.path, p):
            self.path = str(self.path)
            filetype = p(self.path).suffix
            if filetype == '.pickle':
                self.g = pickle.load(open(self.path, 'rb'))
                if isinstance(self.g, rdflib.graph.Graph):
                    return self.get_sparql_dataframe()
                else:
                    print('WARNING:: function df() wont work unless an ontology source is loaded')
                    return self.g
            elif filetype == '.ttl' or filetype == '.rdf':
                self.g = rdflib.Graph()
                self.g.parse(self.path, format='turtle')
                return self.get_sparql_dataframe()
            elif filetype == '.nt':
                self.g = rdflib.Graph()
                self.g.parse(self.path, format='nt')
                return self.get_sparql_dataframe()
            elif filetype == '.owl' or filetype == '.xrdf':
                self.g = rdflib.Graph()
                try:
                    self.g.parse(self.path, format='xml')
                except:
                    # some owl formats are more rdf than owl
                    self.g.parse(self.path, format='turtle')
                return self.get_sparql_dataframe()
            else:
                exit('Format options: owl, ttl, df_pickle, rdflib.Graph()')
            try:
                return self.get_sparql_dataframe()
                self.path = None
            except:
                exit('Format options: owl, ttl, df_pickle, rdflib.Graph()')

        elif isinstance(self.g, rdflib.graph.Graph):
            self.path = None
            return self.get_sparql_dataframe()

        else:
            exit('Obj given is not str, pathlib obj, or an rdflib.Graph()')
4641
def _getnode(self, curie):
        
        if re.match(r'^_:', curie):
            if self.are_bnodes_skized is True:
                node = self.skolemizeBlankNode(curie)
            else:
                node = curie
        elif re.match(r'^http|^ftp', curie):
            node = curie
        elif len(curie.split(':')) == 2:
            node = StreamedGraph.curie_util.get_uri(curie)
        else:
            raise TypeError("Cannot process curie {}".format(curie))
        return node