Example #1
0
        public void GenerateVoidHtml(string targetFileName)
        {
            var rootTripleCollection = _quinceStore.GetTriplesForSubject(_graph.CreateUriNode(_repositoryUri)).ToList();

            try
            {
                var voidLink = new Uri(_repositoryUri, "data/void.nq");
                _addVariables.Remove("nquads");
                _addVariables.Add("nquads", voidLink.ToString());
                _addVariables.Remove("htmlPath");
                _addVariables.Add("htmlPath", targetFileName);

                var voidHtml = _viewEngine.Render(_repositoryUri, rootTripleCollection, new List <Triple>(),
                                                  _addVariables);
                using (var output = File.Open(targetFileName, FileMode.Create, FileAccess.Write))
                {
                    using (var writer = new StreamWriter(output))
                    {
                        writer.Write(voidHtml);
                    }
                }
            }
            catch (Exception ex)
            {
                _progressLog.Exception(ex, "Error writing dataset metadata HTML. Cause: {0}", ex.Message);
            }
        }
            public bool HandleTripleCollection(IList <Triple> tripleCollection)
            {
                var objectNode        = tripleCollection[0].Object;
                var subjectStatements = _store.GetTriplesForSubject(objectNode).ToList();

                return(_resourceStatementHandler.HandleResource(objectNode, subjectStatements, tripleCollection));
            }
Example #3
0
        /// <summary>
        /// Adds content to a dataset graph in the DataDock repository, optionally overwriting existing dataset content
        /// </summary>
        /// <param name="insertTriples"></param>
        /// <param name="datasetIri"></param>
        /// <param name="dropExistingGraph"></param>
        /// <param name="metadataGraph"></param>
        /// <param name="metadataGraphIri"></param>
        /// <param name="definitionsGraph"></param>
        /// <param name="definitionsGraphIri"></param>
        /// <param name="publisherIri"></param>
        /// <param name="publisherInfo"></param>
        /// <param name="repositoryTitle"></param>
        /// <param name="repositoryDescription"></param>
        /// <param name="rootMetadataGraphIri"></param>
        public void UpdateDataset(
            IGraph insertTriples, Uri datasetIri, bool dropExistingGraph,
            IGraph metadataGraph, Uri metadataGraphIri,
            IGraph definitionsGraph, Uri definitionsGraphIri,
            Uri publisherIri, ContactInfo publisherInfo,
            string repositoryTitle, string repositoryDescription,
            Uri rootMetadataGraphIri)
        {
            try
            {
                _progressLog.Info("Updating RDF repository");

                if (dropExistingGraph)
                {
                    // Drop dataset data graph
                    _progressLog.Info("Dropping all existing RDF data in graph {0}", datasetIri);
                    _quinceStore.DropGraph(datasetIri);
                }

                // Drop dataset metadata graph
                _progressLog.Info("Dropping all metadata in graph {0}", metadataGraphIri);
                _quinceStore.DropGraph(metadataGraphIri);

                // Add triples to dataset data graph
                _progressLog.Info("Adding new RDF data to graph {0} ({1} triples)", datasetIri, insertTriples.Triples.Count);
                var addCount = 0;
                foreach (var t in insertTriples.Triples)
                {
                    _quinceStore.Assert(t.Subject, t.Predicate, t.Object, datasetIri);
                    addCount++;
                    if (addCount % 1000 == 0)
                    {
                        _progressLog.Info("Added {0} / {1} triples ({2}%)", addCount, insertTriples.Triples.Count,
                                          addCount * 100 / insertTriples.Triples.Count);
                    }
                }

                // Add triples to dataset metadata graph
                _progressLog.Info("Adding dataset metadata to graph {0} ({1} triples)", metadataGraphIri, metadataGraph.Triples.Count);
                foreach (var t in metadataGraph.Triples)
                {
                    _quinceStore.Assert(t.Subject, t.Predicate, t.Object, metadataGraphIri);
                }

                // Add triples to the definitions graph
                _progressLog.Info("Adding column definition metadata to graph {0} ({1} triples)", definitionsGraphIri, definitionsGraph.Triples.Count);
                foreach (var t in definitionsGraph.Triples)
                {
                    _quinceStore.Assert(t.Subject, t.Predicate, t.Object, definitionsGraphIri);
                }

                // Update the root metadata graph to ensure it includes this dataset as a subset
                _progressLog.Info("Updating root metadata");
                var repositoryNode     = insertTriples.CreateUriNode(_repositoryUri);
                var subset             = insertTriples.CreateUriNode(new Uri("http://rdfs.org/ns/void#subset"));
                var rdfType            = insertTriples.CreateUriNode(new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"));
                var rdfsLabel          = insertTriples.CreateUriNode(new Uri("http://www.w3.org/2000/01/rdf-schema#label"));
                var foafName           = insertTriples.CreateUriNode(new Uri("http://xmlns.com/foaf/0.1/name"));
                var foafMbox           = insertTriples.CreateUriNode(new Uri("http://xmlns.com/foaf/0.1/mbox"));
                var foafHomepage       = insertTriples.CreateUriNode(new Uri("http://xmlns.com/foaf/0.1/homepage"));
                var dctermsPublisher   = insertTriples.CreateUriNode(new Uri("http://purl.org/dc/terms/publisher"));
                var dctermsTitle       = insertTriples.CreateUriNode(new Uri("http://purl.org/dc/terms/title"));
                var dctermsDescription = insertTriples.CreateUriNode(new Uri("http://purl.org/dc/terms/description"));
                var publisherNode      = insertTriples.CreateUriNode(publisherIri);
                _quinceStore.Assert(repositoryNode, rdfType, insertTriples.CreateUriNode(new Uri("http://rdfs.org/ns/void#Dataset")), rootMetadataGraphIri);
                _quinceStore.Assert(repositoryNode, subset, insertTriples.CreateUriNode(datasetIri), rootMetadataGraphIri);
                _quinceStore.Assert(repositoryNode, dctermsPublisher, publisherNode, rootMetadataGraphIri);


                // Update repository title and description
                foreach (var t in _quinceStore.GetTriplesForSubject(_repositoryUri))
                {
                    if (t.GraphUri.Equals(rootMetadataGraphIri))
                    {
                        if (t.Predicate.Equals(dctermsTitle) || t.Predicate.Equals(dctermsDescription))
                        {
                            _quinceStore.Retract(t.Subject, t.Predicate, t.Object, rootMetadataGraphIri);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(repositoryTitle))
                {
                    _quinceStore.Assert(repositoryNode, dctermsTitle, insertTriples.CreateLiteralNode(repositoryTitle), rootMetadataGraphIri);
                }
                if (!string.IsNullOrEmpty(repositoryDescription))
                {
                    _quinceStore.Assert(repositoryNode, dctermsDescription, insertTriples.CreateLiteralNode(repositoryDescription), rootMetadataGraphIri);
                }

                // Update publisher information
                foreach (var t in _quinceStore.GetTriplesForSubject(publisherIri))
                {
                    if (t.GraphUri.Equals(rootMetadataGraphIri))
                    {
                        _quinceStore.Retract(t.Subject, t.Predicate, t.Object, rootMetadataGraphIri);
                    }
                }
                if (!string.IsNullOrEmpty(publisherInfo?.Type))
                {
                    var publisherType = insertTriples.CreateUriNode(new Uri(publisherInfo.Type));
                    _quinceStore.Assert(publisherNode, rdfType, publisherType, rootMetadataGraphIri);
                }
                if (!string.IsNullOrEmpty(publisherInfo?.Label))
                {
                    var publisherLabel = insertTriples.CreateLiteralNode(publisherInfo.Label);
                    _quinceStore.Assert(publisherNode, rdfsLabel, publisherLabel, rootMetadataGraphIri);
                    _quinceStore.Assert(publisherNode, foafName, publisherLabel, rootMetadataGraphIri);
                }
                if (!string.IsNullOrEmpty(publisherInfo?.Email))
                {
                    _quinceStore.Assert(publisherNode, foafMbox, insertTriples.CreateLiteralNode(publisherInfo.Email), rootMetadataGraphIri);
                }
                if (!string.IsNullOrEmpty(publisherInfo?.Website))
                {
                    _quinceStore.Assert(publisherNode, foafHomepage, insertTriples.CreateUriNode(new Uri(publisherInfo.Website)), rootMetadataGraphIri);
                }

                // Flush all data to disk
                _quinceStore.Flush();
            }
            catch (Exception ex)
            {
                Log.Error(ex, "CSV conversion failed");
                throw new WorkerException(ex, "CSV conversion failed. Error updating RDF repository.");
            }
        }