public void HasCrossGraphBlank() { var rdf = new RdfData(new NodeFactory()); var g1 = rdf.GetGraph(rdf.BlankSelf()); var g2 = rdf.GetFullGraph("app:test"); var who = rdf.Uri("app:who"); var b1 = g1.Blank("b1"); //b1 in g1 points to blank in g2 for details. g1.Assert(b1, who, g2.Id); //b1 has name fred. var name = rdf.Uri("app:name"); g2.Assert(b1, name, rdf.New("Fred")); //Now find via cross graph query. var otherG = g1.Query.Single(x => x.Predicate == who && x.Object is Node <UriOrBlank>) .Object.Cast <UriOrBlank>(); var myName = rdf.GetGraph(otherG).Query.Where(x => x.Subject == b1 && x.Predicate == name) .Get <string>() .Single(); Assert.AreEqual("Fred", myName); }
public void AddListAndKeepingReferenceToStart() { var rdf = new RdfData(new NodeFactory()); var g = rdf.GetGraph(rdf.Uri("graph:/g1")) .Update .Let(out var graphId); //(http://www.snee.com/bobdc.blog/2014/04/rdf-lists-and-sparql.html) // x:sub rdfs:first "one" // x.sub rdfs:rest _:1 // _:1 rdfs:first "two" // _:1 rdfs:rest _:2 // _:2 rdfs:first "three" // _:2 rdfs:rest rsf:nil g.For(rdf.Uri("x:sub")) .Let(out var listStart) .List(rdf.New("one"), rdf.New("two"), rdf.New("three")) .With(rdf.Uri("x:p")).Add(rdf.New("Extra data on last item")) //And jump back to starting subject. .ThenFor(listStart); var listModel = new RdfsList(rdf, rdf.GetGraph(graphId)); var items = listModel.GetList(listStart) .ToList(); Assert.AreEqual(3, items.Count, "Got 3 items from list"); Assert.AreEqual("two", items[1].Value <string>(), "2nd is as expected"); }
public void QueryIncludesOtherGraphs() { var rdf = new RdfData(new NodeFactory()); var g1 = rdf.GetGraph(rdf.BlankSelf()); g1.Assert(rdf.Uri("app:test"), rdf.Uri("app:name"), rdf.New("baseName")); var g2 = rdf.GetGraph(rdf.BlankSelf()); g2.Assert(rdf.Uri("app:test"), rdf.Uri("app:name"), rdf.New("mainName")); var target = rdf.GetGraph(g2.Id, g1.Id); var names = target.Query.With(rdf, "app:name").ToArray(); Assert.AreEqual(2, names.Length, "Finds both entries"); //Get the name value. var name = names .Get <string>() .FirstOrNull(); Assert.AreEqual("mainName", name, "Main graph is first in the query"); }
public void RdfUpdate_AvailableInGraph() { var f = new NodeFactory(); var rdf = new RdfData(f); var g1 = f.BlankSelf(); var g2 = f.BlankSelf(); var graphPreUpdates = rdf.GetGraph(g1, g2); //add directly via rdf data. var sub = rdf.Uri("x:/s1"); var pred = rdf.Uri("x:/p1"); var val = rdf.New("text"); rdf.Assert(g1, sub, pred, val); rdf.Assert(g2, sub, pred, val); //immediately have the owned quad, //but not the data from other graph. Assert.AreEqual(1, graphPreUpdates.Query.Count, "Got the new entry"); var graphReInit = rdf.GetGraph(g1, g2); Assert.AreEqual(2, graphReInit.Query.Count, "Re-access graph gets latest"); }
public void QueryData() { var rdf = new RdfData(new NodeFactory()); //load data. if (!_dataFile.Exists()) { throw new Exception("Data file needs to be pre-built"); } var graph = rdf.GetGraph(rdf.BlankSelf("g1")); new NTripleFile(_dataFile).Read(graph).Wait(); //predicates. var root = rdf.Uri("app:root"); var rootFolder = graph.Query .With(root) .GetUri() .Single(); var expected = Uri.EscapeUriString(_rootFolder.AsUri().ToString()); Assert.AreEqual(expected, rootFolder); }
public void WriteTripleData() { var rdf = new RdfData(new NodeFactory()); var target = new NTripleFile(Files.AppDataDir.GetFile( nameof(NTripleFileTests), nameof(WriteTripleData) + ".nt")); var g = rdf.BlankSelf("g1"); rdf.Assert(g, rdf.Uri("x:sub1"), rdf.Uri("x:age"), rdf.New(23)); target.Write(rdf.GetGraph(g)).Wait(); }
public void ClearGraph() { var data = new RdfData(new NodeFactory()); data.Update.From("sys:/data/", out _) .For("sub:s1", out _) .With("x:/p1", out _).Add(123); var g = data.GetGraph(data.BlankSelf()) .Assert(data.Uri("x:/s1"), data.Uri("p:/1"), data.New("text")); Assert.AreEqual(2, data.Query.Count, "have the nodes"); g.Clear(); Assert.AreEqual(0, g.Query.Count, "no graph nodes"); Assert.AreEqual(1, data.Query.Count, "still have other data"); }
public void AddWithUpDownAndLet() { var f = new NodeFactory(); var rdf = new RdfData(f); var gId = f.BlankSelf("g1"); var g = rdf.GetGraph(gId).Update; // _:1 x:p1 "1". g.ForBlank("1", out _) .With(f.Uri("x:p1")) .Add(f.New("1")) // _:1 x:p2 "123" .Then().With(f.Uri("x:p2")).Add(f.New("123")) // _:1 x:p3 _:2 // _:2 x:p3 "fred" .Then().With(f.Uri("x:p3")).To(f.Blank(gId)) .With(f.Uri("x:p3")).Add(f.New("fred")) //get ref to _:2 .Then().Let(out _); }