예제 #1
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);
        }
        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
                {
                    _repository.Add(model, true);
                    tryMore = false;
                }
                catch (Exception ex)
                {
                    _logger.LogError("Exception was thrown while adding a model to the repository.", ex);
                }
            }
            _logger.LogTrace("Persisted {0} triples into the <{1}> graph.", triplesToPersist.Count, graphIri);
        }
예제 #3
0
        public NormalizedRdf NormalizeRdf(HashSet <Triple> triples)
        {
            var    model         = _rdf4jMapper.TriplesToGraph(triples);
            string modelAsJsonLd = _rdf4jMapper.GraphToSerialization(model, new VDS.RDF.Writing.JsonLdWriter());

            //fix for JsonLdWriter bug
            modelAsJsonLd = modelAsJsonLd.Replace("@language\": \"http:", "@type\": \"http:");
            try
            {
                var jsonObject           = JSONUtils.FromString(modelAsJsonLd);
                var normalizedJsonObject = JsonLdProcessor.Normalize(jsonObject, PrepareJsonLdOptions());

                return(new NormalizedRdf(new RdfDataset(triples), normalizedJsonObject.ToString(), RdfFormat.JSON_LD));
            }
            catch (IOException ex)
            {
                throw new NormalizingRdfException("Exception was thrown while normalizing JSON object.", ex);
            }
            catch (JsonLdError ex)
            {
                throw new NormalizingRdfException("Exception was thrown while normalizing JSON object.", ex);
            }
        }