Ejemplo n.º 1
0
        public void GeneralUsage()
        {
            var rdf = RdfDataFactory.CreateNoLock();

            //Self scoped blank node.
            var graph = rdf.BlankSelf("self-blank");

            //Blank node scoped to graph
            var subject = rdf.Blank(graph);

            //uri predicate, from Dublin core
            var predicate = rdf.Uri(Terms.Title);

            var @object = rdf.New("a title from my stuff");

            //add quad to rdf data
            rdf.Assert(graph, subject, predicate, @object);

            //query
            var quad = rdf.Query.Single();

            //remove
            rdf.Retract(quad);

            Assert.AreEqual(0, rdf.Query.Count);

            //replace.
            rdf.Replace(new[] {
                new Quad(graph, rdf.Blank(graph), rdf.Uri("a:pred"), rdf.New(123))
            }, new[] { quad });
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        public void AddDataToGraph()
        {
            //Assert some data for a graph.
            var rdf = RdfDataFactory.CreateNoLock();

            //My base graph.
            var baseGraph = rdf.GetFullGraph("app:base");

            //The inbuilt system graph
            var sys = rdf.GetSystem();

            //Assert some data.
            sys.Assert(baseGraph.Id, sys.Uri(RDF.A), sys.Uri("app:graphId"));
        }
Ejemplo n.º 5
0
        public void QueryWithConverters()
        {
            var rdf = RdfDataFactory.CreateNoLock();
            var g   = LoadSampleData(rdf, rdf.BlankSelf());

            //Read all linkTo URI's.
            var linkedUris = rdf.Query
                             .From(g)
                             .For(rdf, "x:me")
                             .With(rdf, "a:linkTo")
                             .GetUri()
                             .ToList();

            Assert.IsTrue(linkedUris.Any(), "found some links");
        }
Ejemplo n.º 6
0
        private void NewBlankProfile()
        {
            var rdf = RdfDataFactory.CreateNoLock();

            _data.EnsureDelete();

            var g = rdf.GetFullGraph(_myProfile);

            g.Update
            .For(g.Uri(_myProfile))
            .With(g.Uri(RDF.A))
            .Add(g.Uri("app:/profile"));

            new NTripleFile(_data).Write(g).Wait();
        }
Ejemplo n.º 7
0
        public void LoadAFile()
        {
            //Load a sample N-triple file
            var rdf = RdfDataFactory.CreateNoLock();

            var file = SampleFile();

            var g = rdf.GetBlankGraph();

            //Read file data into the graph g
            new NTripleFile(file).Read(g).Wait();

            var tripleCount = g.Query.Count;

            Assert.IsTrue(tripleCount > 0, "Loaded some data");
        }
Ejemplo n.º 8
0
        public void ConverterWithNormalization()
        {
            var rdf = RdfDataFactory.CreateNoLock();

            rdf.Update
            .FromBlank(out var g1)
            .For("x:me ", out _)
            .With("a:Name", out _)
            .Add("Fred");

            var aboutMe = rdf.Query.From(g1)
                          .For(rdf, "x:me")
                          .ToList();

            Assert.AreEqual(1, aboutMe.Count, "Found entry");
        }
Ejemplo n.º 9
0
        public void WriteAFile()
        {
            //Write a sample N-triple file
            var file = Files.AppDataDir.GetFile(
                nameof(UsingNTripleFile), nameof(WriteAFile) + ".nt");

            file.EnsureDelete();

            var rdf = RdfDataFactory.CreateNoLock();
            var g   = rdf.GetBlankGraph();

            g.Assert(g.Uri("test:sub"), g.Uri("test:pred"), g.New("a name"));

            new NTripleFile(file).Write(g).Wait();

            Assert.IsTrue(file.Exists() && file.Length > 0,
                          "File created with some data");
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        public void CreateFromRdfData()
        {
            //Create new Full graph
            var rdf = RdfDataFactory.CreateNoLock();

            //Full graph with new labeled blank node
            var myGraph = rdf.GetBlankGraph("test");

            //A new graph; after I got my first graph.
            var subject = rdf.Uri("test:sub");

            rdf.Assert(rdf.Uri("test:g1"),
                       subject, rdf.Uri("test:int"), rdf.New(123));

            var quadFromOther = myGraph.Query
                                .FirstOrNull(x => x.Subject == subject);

            Assert.IsNull(quadFromOther);
        }
Ejemplo n.º 12
0
        public void ReadDefaultValue()
        {
            var rdf = RdfDataFactory.CreateNoLock();

            LoadSettings(rdf);

            //schema
            var level = rdf.Uri("app:Log#Level");

            //create full graph with baseSettings as main.
            var g = rdf.GetBlankGraph("baseSettings");

            //log level for Microsoft; using base / default.
            g.Query
            .For(rdf, "app:Logger#Microsoft").ToArray()
            .Value <string>(level, out var logLevel)
            .For();

            Assert.AreEqual("Warning", logLevel, "Default is warning level");
        }
Ejemplo n.º 13
0
        public void FluentWithNodeCreator()
        {
            //Fluent builder with node creation
            var rdf = RdfDataFactory.CreateNoLock();

            rdf.Update
            .From("g:aGraph", out var aGraph)
            .For("x:me", out var me)
            .With("a:name", out var name)
            .Add("Fred", out var myName)
            .Then()
            //ignore created node
            .With("a:age", out _)
            .Add(123, out _);

            Assert.AreEqual("g:aGraph", aGraph.Uri);
            Assert.AreEqual("x:me", me.Uri);
            Assert.AreEqual("a:name", name.Value);
            Assert.AreEqual("Fred", myName.Value);
        }
Ejemplo n.º 14
0
        public void ConvertToSelfGraph()
        {
            //Convert from mixed to self only graph.
            var rdf = RdfDataFactory.CreateNoLock();

            //Mixed graph has main and some other graphs.
            var myGraph = rdf.GetGraph(
                rdf.BlankSelf("MainGraph"),
                rdf.BlankSelf("Other1"),
                rdf.BlankSelf("Other2"));

            //Self only graph.
            myGraph = myGraph.SelfOnly();

            Assert.IsFalse(myGraph.Other.Any());

            //Or directly get self-only from rdf.
            myGraph = rdf.GetSelfGraph(rdf.BlankSelf("MainGraph"));
            Assert.IsFalse(myGraph.Other.Any());
        }
Ejemplo n.º 15
0
        public void UseHelpersWithBuilders()
        {
            var rdf = RdfDataFactory.CreateNoLock();

            //Use let to collect generated node(s)
            rdf.Update
            .From("g:aGraph", out var aGraph)
            .For("x:me", out var me)
            .With("a:name", out _).Let(out var name)
            .Add("Fred")
            .Then().Then().Then()
            .From(aGraph)
            .For(me).With(name)
            .Add("Fredo", "fr", out var frName);

            Assert.IsNotNull(aGraph);
            Assert.IsNotNull(me);
            Assert.IsNotNull(name);
            Assert.IsNotNull(frName);
        }
Ejemplo n.º 16
0
        public void ReadActualValue()
        {
            var rdf = RdfDataFactory.CreateNoLock();

            LoadSettings(rdf);

            //schema
            var level = rdf.Uri("app:Log#Level");

            //create full graph with debugSettings as main.
            var g = rdf.GetBlankGraph("debugSettings");

            //log level for Microsoft; using base / default.
            g.Query
            .For(rdf, "app:Logger#Microsoft")
            .ToArray()
            .Value <string>(level, out var logLevel);

            Assert.AreEqual("Information", logLevel,
                            "Using debug setting");
        }
Ejemplo n.º 17
0
        private void GetBasicProfile()
        {
            var rdf = RdfDataFactory.CreateNoLock();

            new NTripleFile(_data).Read(rdf.GetFullGraph(_myProfile)).Wait();

            var profile = rdf.Query.For(rdf.Uri(_myProfile));

            profile
            .Value <DateTime>(rdf.Uri(Terms.DateModified), out var lastModified)
            .Value <string>(rdf.Uri(RDFS.Label), out var name)
            //The possible null alternate name
            .ValueOptional <string>(rdf.Uri(Terms.AlternativeTitle), out var altName);

            var bestName = altName is null ? name : altName.Value;

            var welcome =
                $"Hello {bestName}, " +
                $"your profile was last updated {lastModified.ToShortDateString()}";

            Assert.IsTrue(welcome.Contains("ME"), "Has my alt name");
        }
Ejemplo n.º 18
0
        public void ReadFromStart()
        {
            //Graph data ordered.
            var rdf = RdfDataFactory.CreateNoLock();

            var g1 = rdf.GetBlankGraph("g1");
            var g2 = rdf.GetBlankGraph("g2");

            var s = rdf.Uri("app:test");
            var p = rdf.Uri("app:count");

            var name = rdf.Uri(RDFS.Label);

            g1.Assert(s, p, g1.New(1))
            .Assert(s, name, g1.New("OriginalName"), out var qName);

            g2.Assert(s, p, g2.New(2));

            //Get Full data
            g2 = rdf.GetFullGraph(g2.Id);

            var theCount = g2.Query
                           .For(s).With(p)
                           .Get <int>().First();

            Assert.AreEqual(2, theCount);

            //isolated updates.

            //changing dependent graph g1:
            g1.Retract(qName);
            g1.Assert(s, name, g1.New("Updated"));

            //pre-existing g2 uses original g1 data.
            var theName = g2.Query
                          .For(s).With(name).Get <string>().First();

            Assert.AreEqual("OriginalName", theName);
        }
Ejemplo n.º 19
0
        private void GetMyFavorites()
        {
            var rdf = RdfDataFactory.CreateNoLock();

            var g = rdf.GetFullGraph(_myProfile);

            new NTripleFile(_data)
            .Read(g)
            .Wait();

            //the list of favs.
            var favsList = g.Query
                           .For(g.Id)
                           .With(g.Uri("app:favorites"))
                           .GetBlanks()
                           .First();

            //get list items.
            var myFavorites = new RdfsList(rdf, g)
                              .GetList(favsList).ToArray();

            Assert.IsTrue(myFavorites.Length > 0, "Got some favorites");
        }