Example #1
0
        protected void ImportData(string dataPath, string defaultGraphUri = null)
        {
            var g        = new Graph();
            var importId = Guid.NewGuid();

#if PORTABLE
            using (var s = File.OpenRead(dataPath))
            {
                StreamLoader.Load(g, dataPath, s);
            }
#else
            FileLoader.Load(g, dataPath);
#endif
            _bnodeMappings = new Dictionary <string, string>();
            var sw       = new StringWriter();
            var ntWriter = new NQuadsWriter(sw);
            foreach (var t in g.Triples)
            {
                if (t.Object.NodeType == NodeType.Literal)
                {
                    var litNode = t.Object as LiteralNode;
                    ntWriter.Triple(
                        GetNodeString(t.Subject),
                        false,
                        GetNodeString(t.Predicate),
                        false,
                        litNode.Value,
                        false,
                        true,
                        litNode.DataType == null ? null : litNode.DataType.ToString(),
                        litNode.Language,
                        defaultGraphUri ?? Constants.DefaultGraphUri
                        );
                }
                else
                {
                    ntWriter.Triple(
                        GetNodeString(t.Subject),
                        false,
                        GetNodeString(t.Predicate),
                        false,
                        GetNodeString(t.Object),
                        false,
                        false,
                        null,
                        null,
                        defaultGraphUri ?? Constants.DefaultGraphUri
                        );
                }
            }
            _service.ExecuteTransaction(_storeName, new UpdateTransactionData {
                InsertData = sw.ToString()
            });
            //_store.Commit(Guid.NewGuid());
        }
Example #2
0
        public void ParsingFileLoaderGraphHandlerExplicitTurtle()
        {
            Graph        g       = new Graph();
            GraphHandler handler = new GraphHandler(g);

#if PORTABLE
            using (var input = File.OpenRead(TestDataFile))
            {
                StreamLoader.Load(handler, TestDataFile, input);
            }
#else
            FileLoader.Load(handler, TestDataFile);
#endif

            TestTools.ShowGraph(g);
            Assert.IsFalse(g.IsEmpty, "Graph should not be empty");
        }
Example #3
0
        public void ParsingFileLoaderCountHandlerTurtle()
        {
            Graph orig = new Graph();

            orig.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            CountHandler handler = new CountHandler();

#if PORTABLE
            using (var input = File.OpenRead(TestDataFile))
            {
                StreamLoader.Load(handler, TestDataFile, input);
            }
#else
            FileLoader.Load(handler, "temp.ttl");
#endif

            Assert.AreEqual(orig.Triples.Count, handler.Count);
        }
Example #4
0
        public static void LoadFromFile(this IGraph g, string filename, IRdfReader parser)
        {
            var path = System.IO.Path.GetFullPath(filename);

            if (g.IsEmpty && g.BaseUri == null)
            {
                if (System.IO.Path.IsPathRooted(filename))
                {
                    g.BaseUri = UriFactory.Create("file:///" + filename);
                }
                else
                {
                    g.BaseUri = UriFactory.Create("file:///" + path);
                }
            }
            using (var stream = System.IO.File.OpenRead(path))
            {
                StreamLoader.Load(g, filename, stream, parser);
            }
        }
Example #5
0
        private void CompareResultGraphs(string results, string expectedResultsPath, bool reduced)
        {
            var expectedResultGraph = new Graph();

#if PORTABLE
            using (var s = File.OpenRead(expectedResultsPath))
            {
                StreamLoader.Load(expectedResultGraph, expectedResultsPath, s);
            }
#else
            FileLoader.Load(expectedResultGraph, expectedResultsPath);
#endif
            var resultSet = expectedResultGraph.GetUriNode(new Uri("http://www.w3.org/2001/sw/DataAccess/tests/result-set#ResultSet"));
            if (resultSet != null)
            {
                var rdfParser         = new SparqlRdfParser();
                var xmlParser         = new SparqlXmlParser();
                var actualResultSet   = new SparqlResultSet();
                var expectedResultSet = new SparqlResultSet();
                using (var tr = new StringReader(results))
                {
                    xmlParser.Load(actualResultSet, tr);
                }
#if PORTABLE
                rdfParser.Load(expectedResultSet, new StreamReader(expectedResultsPath));
#else
                rdfParser.Load(expectedResultSet, expectedResultsPath);
#endif
                var bnodeMap = new Dictionary <string, string>();
                CompareSparqlResults(actualResultSet, expectedResultSet, reduced, bnodeMap);
            }
            else
            {
                // This is a constructed graph
                var actualGraph = new Graph();
                actualGraph.LoadFromString(results);
                CompareTripleCollections(actualGraph.Triples, expectedResultGraph.Triples, reduced);
            }
        }