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 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 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 GraphIds_Ordered() { var rdf = new RdfData(new NodeFactory()); var g1 = rdf.BlankSelf("test"); rdf.Assert(g1, rdf.Blank(g1), rdf.Uri("a:pred"), rdf.New(123)); var graphs = rdf.GraphIds; Assert.AreEqual(3, graphs.Length); Assert.AreEqual(rdf.System, graphs.ElementAt(0)); Assert.AreEqual(rdf.Default, graphs.ElementAt(1)); }
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 async Task WriteWithCrossGraphBlank() { var rdf = new RdfData(new NodeFactory()); var g1 = rdf.GetBlankGraph(); g1.Assert(rdf.Uri("bad:link"), rdf.Uri("app:test"), rdf.BlankSelf("other")); var file = Files.AppDataDir.GetFile(nameof(NodeWriterTests), nameof(WriteWithCrossGraphBlank) + ".nt") .EnsureDelete(); var target = new NTripleFile(file); try { await target.Write(g1); Assert.Fail("Cannot write if blank is scoped to other graph"); }catch (BlankNodeScopedToInvalidGraph) {} }