Store the graph in the triplestore cache

 @param [RDF::Graph] graph
 @return [RDF::Graph]
 @raise [Exception] if client fails to store the graph
558470
def store(graph)
      begin
        statements = graph.each_statement.to_a
        @client.insert(statements)
        graph
      rescue => e
        raise TriplestoreAdapter::TriplestoreException, "store graph in triplestore cache failed with exception: #{e.message}"
      end
    end
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
257603
def new_graph(self, name, data=None, **attr):
        
        self._init_graph(name, 'Graph')
        g = Graph(self, name, data, **attr)
        self._graph_objs[name] = g
        return g
415954
public static void saveGraph(DirectedGraph<Integer, DefaultEdge> graph, String location) throws IOException {
		File file = new File(location);
		file.createNewFile();
		if (!file.canWrite()) {
			throw new IOException("Cannot write to file " + location);
		}
		GraphSerialization.saveGraph(graph, file);
	}
158753
def cache(self):
        """"""
        if not self._cache:
            self._cache = self.graph.get('%s' % self.id)

        return self._cache
58782
@Override
    public void putGraph(URI graphUri, Model data) {
        if (graphUri == null || data == null)
            return;

        // Use HTTP protocol if possible
        if (this.sparqlServiceEndpoint != null) {
            datasetAccessor.putModel(graphUri.toASCIIString(), data);
        } else {
            this.putGraphSparqlQuery(graphUri, data);
        }

        log.info("Graph added to store: {}", graphUri.toASCIIString());
    }
984459
def create(self, graph):
        
        scoped_config = self.get_scoped_config(graph)
        scoped_graph = ScopedGraph(graph, scoped_config)
        return self.func(scoped_graph)
925898
def open(self):
        
        try:
            self.graph.open(self.cache_uri, create=False)
            self._add_namespaces(self.graph)
            self.is_open = True
        except Exception:
            raise InvalidCacheException('The cache is invalid or not created')
1070167
def record_store(store)
      store = RecordCache::Base.stores[store] || ActiveSupport::Cache.lookup_store(store) if store.is_a?(Symbol)
      store ||= Rails.cache if defined?(::Rails)
      store ||= ActiveSupport::Cache.lookup_store(:memory_store)
      RecordCache::MultiRead.test(store)
    end
657441
def as_graph(self, depth=0):
        
        if depth in self._graph_cache:
            return self._graph_cache[depth]
        self._graph_cache[depth] = graph = Graph(self, depth=depth)
        return graph
457277
def get_digraph(ont, relations=None, writecache=False):
    
    digraph = networkx.MultiDiGraph()
    logging.info("Getting edges (may be cached)")
    for (s,p,o) in get_edges(ont):
        p = map_legacy_pred(p)
        if relations is None or p in relations:
            digraph.add_edge(o,s,pred=p)
    logging.info("Getting labels (may be cached)")
    for (n,label) in fetchall_labels(ont):
        digraph.add_node(n, **{'label':label})
    return digraph
1120861
def describe_uris(uris)
      graph = RDF::Graph.new

      if uris.length > 0
        uris_sparql_str = uris.map{ |u| "<#{u.to_s}>" }.join(" ")

        # Do a big describe statement, and read the results into an in-memory repo
        ntriples_string = Tripod::SparqlClient::Query.query("CONSTRUCT { ?s ?p ?o } WHERE { VALUES ?s { #{uris_sparql_str} }.  ?s ?p ?o . }", Tripod.ntriples_header_str)
        graph = _rdf_graph_from_ntriples_string(ntriples_string, graph)
      end

      graph
    end
78926
def populate(self):
        
        if self.exists:
            raise CacheAlreadyExistsException('location: %s' % self.cache_uri)

        self._populate_setup()

        with closing(self.graph):
            with self._download_metadata_archive() as metadata_archive:
                for fact in self._iter_metadata_triples(metadata_archive):
                    self._add_to_graph(fact)
943494
def fetch(rdf_url, from_remote: nil)
      begin
        graph = fetch_cached_graph(rdf_url)

        if graph.nil? && !from_remote
          raise TriplestoreAdapter::TriplestoreException, "graph not found in cache. Skipping fetch from remote graph"
        elsif graph.nil?
          graph = fetch_and_cache_graph(rdf_url)
        end

        graph
      rescue => e
        raise TriplestoreAdapter::TriplestoreException, e.message
      end
    end
710358
def to_database(graph, manager: Optional[Manager] = None, store_parts: bool = True, use_tqdm: bool = False):
    
    if manager is None:
        manager = Manager()

    try:
        return manager.insert_graph(graph, store_parts=store_parts, use_tqdm=use_tqdm)
    except (IntegrityError, OperationalError):
        manager.session.rollback()
        log.exception('Error storing graph')
    except Exception as e:
        manager.session.rollback()
        raise e
32678
def get_graph(self, name):
        
        if name in self._graph_objs:
            return self._graph_objs[name]
        graphtypes = {
            'Graph': Graph,
            'DiGraph': DiGraph,
            'MultiGraph': MultiGraph,
            'MultiDiGraph': MultiDiGraph
        }
        type_s = self.query.graph_type(name)
        if type_s not in graphtypes:
            raise GraphNameError(
                "I don't know of a graph named {}".format(name)
            )
        g = graphtypes[type_s](self, name)
        self._graph_objs[name] = g
        return g
1238240
def replace_graph(cls, response, serialized):
		
		if cls.is_graph(response):	# single graph object
			return serialized

		if hasattr(response, '__getitem__'):	# indexable tuple
			if len(response) > 0 and \
			   cls.is_graph(response[0]):	# graph object
				return (serialized,) + response[1:]
		return response