示例#1
0
        private void InsertGraph(AllegroGraphConnector connector, IGraph g)
        {
            var length = 10000;

            if (g.Triples.Count > length)
            {
                var newGraph = new Graph
                {
                    BaseUri = g.BaseUri
                };
                connector.SaveGraph(newGraph);
                var section = new List <Triple>(length);
                foreach (var t in g.Triples)
                {
                    section.Add(t);
                    if (section.Count == length)
                    {
                        connector.UpdateGraph(g.BaseUri, section, null);
                        section = new List <Triple>(length);
                    }
                }
                if (section.Count > 0)
                {
                    connector.UpdateGraph(g.BaseUri, section, null);
                }
            }
            else
            {
                connector.SaveGraph(g);
            }
        }
示例#2
0
        public void PersistTriples(string graphIri, HashSet <model.rdf.Triple> triplesToPersist)
        {
            _logger.LogTrace("Persisting triples into graph with IRI '{0}'. Triples: {1}", graphIri, triplesToPersist);
            IGraph model   = _rdf4jMapper.TriplesToGraph(triplesToPersist);
            var    tryMore = true;

            model.BaseUri = new Uri(graphIri);
            for (var i = 0; i < NUMBER_OF_ATTEMPTS && tryMore; i++)
            {
                try
                {
                    if (_repository.HasGraph(model.BaseUri))
                    {
                        _allegroGraphConnector.UpdateGraph(model.BaseUri, model.Triples, null);
                    }
                    else
                    {
                        InsertGraph(_allegroGraphConnector, model);
                    }
                    tryMore = false;
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Exception was thrown while adding a model to the repository.");
                }
            }
            _logger.LogTrace("Persisted {0} triples into the <{1}> graph.", triplesToPersist.Count, graphIri);
        }