コード例 #1
0
        private void AddFavorites()
        {
            var rdf = RdfDataFactory.CreateNoLock();

            var g    = rdf.GetFullGraph(_myProfile);
            var file = new NTripleFile(_data);

            file.Read(g).Wait();

            //some favorites.
            g.Update
            .ForBlank("favs", out var favs)
            .With(RDF.A, out _).Add(RDFS.List, out _)
            .Then()
            .List(g.Uri("https://duckduckgo.com/"),
                  g.Uri("https://inrupt.com/"),
                  g.Uri("https://github.com/"),
                  g.Uri("https://portal.azure.com/"))
            .Then()
            .For(g.Uri(_myProfile))
            .With(g.Uri("app:favorites")).Add(favs)
            //and I want to update the last modified.
            .Then()
            .With(Terms.DateModified, out _)
            .Set(DateTime.UtcNow);

            file.Write(g).Wait();
        }
コード例 #2
0
        private void AddBasicProfile()
        {
            var rdf = RdfDataFactory.CreateNoLock();

            if (!_data.Exists())
            {
                throw new Exception("Call start first");
            }

            var g    = rdf.GetFullGraph("app:/profile#me");
            var file = new NTripleFile(_data);

            file.Read(g).Wait();

            g.Update.For(g.Uri(_myProfile))
            .With(RDFS.Label, out _).Add("My Name")
            .Then()
            .With(Terms.DateModified, out _).Add(DateTime.UtcNow)
            .Then()
            .With(Terms.Description, out _).Add("My basic profile data")
            .Then()
            .With(Terms.AlternativeTitle, out _).Add("ME");

            file.Write(g).Wait();
        }
コード例 #3
0
        public async Task WriteRead()
        {
            var file = new FileInfo(
                Path.Combine(Files.AppData.NqFileTests.FullName,
                             nameof(WriteRead) + ".nt"));

            var rdf = new RdfData(new NodeFactory());

            var g = rdf.GetFullGraph("graph:1")
                    .Assert(rdf.Uri("sub1:/"), rdf.Uri("pred1:/"), rdf.New("basic text"));

            file.Directory.EnsureDelete();
            var t = new NTripleFile(file);
            await t.Write(g);

            file.Refresh();
            Assert.IsTrue(file.Exists);
            Assert.IsTrue(file.Length > 0, "wrote some data");

            //copy current so it doesn't delete.
            var gCopy = g.Query.ToList();

            g.Clear();
            await t.Read(g);

            IEqualityComparer <Quad> eq = new SameQuad();

            var gDiffs = g.Query.Except(gCopy, eq).ToList();

            Assert.IsFalse(gDiffs.Any(), "No difference");
        }
コード例 #4
0
 private Task DelayedDataRead(FileInfo srcFile, IRdfData rdf, int id)
 {
     return(new Task(() =>
     {
         var g = rdf.GetSelfGraph(rdf.BlankSelf($"g{id}"));
         using var rd = srcFile.OpenText();
         NTripleFile.Read(g, rd).Wait();
     }, TaskCreationOptions.LongRunning));
 }
コード例 #5
0
        public void ReadData()
        {
            var rdf = new RdfData(new NodeFactory());

            var target = new NTripleFile(Files.TestData.Sample1);

            var defaultGraph = rdf.GetBlankGraph("default");

            target.Read(defaultGraph).Wait();

            var quad = rdf.Query.With(rdf, "app:blank")
                       .Single();

            Assert.AreEqual(quad.Subject, quad.Object);
            Assert.AreEqual("b1", quad.ValueBlank());

            var txt = rdf.Query.With(rdf, "app:literal")
                      .Single().Value <string>();

            Assert.AreEqual("x", txt);

            var uriNode = rdf.Query.With(rdf, "app:uri")
                          .Select(x => x.Object)
                          .OfType <UriNode>().Single();

            txt = uriNode.Uri;

            Assert.AreEqual("http://a.example/s", txt);

            txt = rdf.Query.With(rdf, "app:text")
                  .Select(x => x.Object)
                  .OfType <Node <Text> >()
                  .Single(x => x.Value.Language == "fr")
                  .Value.Value;
            Assert.AreEqual("fredo", txt);

            var intValue = rdf.Query.With(rdf, "app:number")
                           .Single().Value <int>();

            Assert.AreEqual(123, intValue);
        }