Beispiel #1
0
        public void QueryMatchesUpdateForm()
        {
            var rdf = RdfDataFactory.CreateDefault();

            var g         = rdf.BlankSelf();
            var subject   = rdf.Blank(g, "test");
            var predicate = rdf.Uri(RDF.A);
            var value     = rdf.Uri("test:query#basic");

            //add some data
            rdf.Update
            .From(g)
            .For(subject)
            .With(predicate)
            .Add(value);

            //query some data.
            var qry      = rdf.Query;
            var uriValue = qry
                           .From(g)
                           .For(subject)
                           .With(predicate)
                           .GetUri(out var result) //inline get with result
                           .GetUri();              //get with select.

            Assert.AreEqual(value.Uri, result.Single(), "from inline select");
            Assert.AreEqual(value.Uri, uriValue.Single(), "from query select");
        }
Beispiel #2
0
        public void AssertVsFluent()
        {
            //Assert vs Fluent
            var rdf = RdfDataFactory.CreateDefault();

            var myGraph = rdf.Uri("g:other");
            var linkTo  = rdf.Uri("a:linkTo");

            //link to other graph: using assert
            var g = rdf.BlankSelf();

            rdf.Assert(g, g, linkTo, myGraph);

            //link to other graph: using fluent
            rdf.Update
            .From(rdf.BlankSelf())        //a graph
            .Let(out var demo)            //inline graph.
            .For(demo)                    //subject is demo
            .With(linkTo)                 //predicate is linkTo
            .Add(myGraph);                //Assert

            var links = rdf.Query.With(linkTo).ToList();

            Assert.IsTrue(links.Any(), "Have a link");
        }
Beispiel #3
0
        public void Go()
        {
            //Create a store
            var rdf = RdfDataFactory.CreateDefault();

            //new graph node.
            var sample = rdf.GetBlankGraph("SampleDataGraph");

            //load some data.
            //  n-triple file read / write.
            new NTripleFile(_sampleData).Read(sample).Wait();

            //find some data.
            var brazil = rdf.Uri(SubjectId);
            var name   = sample.Query
                         .For(brazil)
                         .With(rdf, RDFS.Label)
                         .Get <string>()
                         .FirstOrNull();

            Assert.IsNotNull(name);

            //Add some data.
            var haveVisited = rdf.Uri("app:haveVisited");

            sample.Update
            .For(brazil)
            .With(haveVisited)
            .Add(false);

            //Save some data
            new NTripleFile(Files.AppDataDir.GetFile("Updated.nt"))
            .Write(sample).Wait();
        }
Beispiel #4
0
        public void Stats_()
        {
            var rdf = RdfDataFactory.CreateDefault();

            var g = rdf.GetBlankGraph();

            new NTripleFile(Files.TestData.Brazil)
            .Read(g).Wait();

            var stats = rdf.Stats();

            Assert.AreEqual(80, stats.TotalNodes - stats.BlankNodes,
                            "Total non blank nodes");

            Assert.AreEqual(1, stats.AutoNodes, "Graph is only auto blank");

            Assert.AreEqual(31 + 1, stats.BlankNodes,
                            "Total blank nodes (plus graph itself)");
        }
Beispiel #5
0
        public void CreateRdfStore()
        {
            //create default thread-locked version.
            IRdfData rdf = RdfDataFactory.CreateDefault();

            Assert.IsTrue(rdf is RdfDataThreadLock);

            //create basic version.
            rdf = RdfDataFactory.CreateNoLock();
            Assert.IsTrue(rdf is RdfData);

            //setup app singleton
            RdfDataFactory.Init(RdfDataFactory.CreateNoLock());

            //use singleton
            rdf = RdfDataFactory.AppData;

            Assert.IsNotNull(rdf);
        }
Beispiel #6
0
        public void IsolatedFromOtherGraphs()
        {
            var rdf = RdfDataFactory.CreateDefault();

            //Get 2 graphs.
            var g1 = rdf.GetFullGraph(rdf.BlankSelf("graph1"));
            var g2 = rdf.GetFullGraph(rdf.BlankSelf("graph2"));

            //update g2.
            g2.Assert(g2.Uri("app:me"), g2.Uri("app:update"), g2.New(true));

            //graph1 isolated from change in graph2
            Assert.AreEqual(0, g1.Query.Count,
                            "Update in graph2 not reflected in graph1 snapshot");

            //graph2 has the update ready to use.
            Assert.AreEqual(1, g2.Query.Count,
                            "Update in graph 2 is available");
        }
Beispiel #7
0
        public void LinksInMyGraph()
        {
            var rdf     = RdfDataFactory.CreateDefault();
            var myGraph = rdf.Uri("x:myGraph");

            LoadSampleData(rdf, myGraph);

            var linkedTo = rdf.Uri("a:linkTo");

            //all quads in myGraph, with linkedTo predicate
            var linkedUris = rdf.Query
                             .From(myGraph)
                             .With(linkedTo)
                             //select the quad object nodes that are URI's
                             .GetUri()
                             .ToList();

            Assert.IsTrue(linkedUris.Any(), "found some links");
        }
Beispiel #8
0
        public void LinksAndNamedInMyGraph()
        {
            var rdf     = RdfDataFactory.CreateDefault();
            var myGraph = rdf.Uri("x:myGraph");

            LoadSampleData(rdf, myGraph);

            var linkedTo = rdf.Uri("a:linkTo");
            var name     = rdf.Uri("a:name");

            //Select all links and names within graph g.
            var linksAndNames = rdf.Query
                                .From(myGraph)
                                .With(p => p == linkedTo || p == name)
                                .Select(x => x.Object)
                                .ToList();

            Assert.IsTrue(linksAndNames.Any(x => x is Node <string>), "Has literals");
            Assert.IsTrue(linksAndNames.Any(x => x is UriNode), "Has urls");
        }
Beispiel #9
0
        public void LoadFromMultipleThreads()
        {
            var rdf  = RdfDataFactory.CreateDefault();
            var data = Files.TestDataDir.GetFile("brazil.nt");

            var tasks = new[] {
                DelayedDataRead(CopyDataFile(data, 1), rdf, 1),
                DelayedDataRead(CopyDataFile(data, 1), rdf, 2),
                DelayedDataRead(CopyDataFile(data, 1), rdf, 3),
                DelayedDataRead(CopyDataFile(data, 1), rdf, 4),
            };

            //start in fast-loop so they run at same time.
            foreach (var item in tasks)
            {
                item.Start();
            }

            Task.WaitAll(tasks);

            var g1 = rdf.GetSelfGraph(rdf.BlankSelf("g1"));
            var g2 = rdf.GetSelfGraph(rdf.BlankSelf("g2"));
            var g3 = rdf.GetSelfGraph(rdf.BlankSelf("g3"));
            var g4 = rdf.GetSelfGraph(rdf.BlankSelf("g4"));

            //138 quads per graph.
            Assert.AreEqual(138, g1.Query.Count, "Count for graph-1");
            Assert.AreEqual(138, g2.Query.Count, "Count for graph-2");
            Assert.AreEqual(138, g3.Query.Count, "Count for graph-3");
            Assert.AreEqual(138, g4.Query.Count, "Count for graph-4");

            //the nodes in doc, and extras for graphs.
            var expectedCount = 80 +               //normal nodes.
                                32 * tasks.Length; //blanks from doc and graph.

            var stats = rdf.Stats();

            Assert.AreEqual(expectedCount, stats.TotalNodes, "no dupe nodes");
        }