public static void Main(String[] args) 
    {
	    //Fill in the code shown on this page here to build your hello world application
        Graph g = new Graph();

        IUriNode dotNetRDF = g.CreateUriNode(new Uri("http://www.dotnetrdf.org"));
        IUriNode says = g.CreateUriNode(new Uri("http://example.org/says"));
        ILiteralNode helloWorld = g.CreateLiteralNode("Hello World");
        ILiteralNode bonjourMonde = g.CreateLiteralNode("Bonjour tout le Monde", "fr");

        g.Assert(new Triple(dotNetRDF, says, helloWorld));
        g.Assert(new Triple(dotNetRDF, says, bonjourMonde));

        foreach (Triple t in g.Triples)
        {
            Console.WriteLine(t.ToString());
        }

        NTriplesWriter ntwriter = new NTriplesWriter();
        ntwriter.Save(g, "HelloWorld.nt");

        RdfXmlWriter rdfxmlwriter = new RdfXmlWriter();
        rdfxmlwriter.Save(g, "HelloWorld.rdf");

    }
Ejemplo n.º 2
0
        public void WritingBlankNodeOutput()
        {
            //Create a Graph and add a couple of Triples which when serialized have
            //potentially colliding IDs

            Graph g = new Graph();
            g.NamespaceMap.AddNamespace("ex", new Uri("http://example.org"));
            IUriNode subj = g.CreateUriNode("ex:subject");
            IUriNode pred = g.CreateUriNode("ex:predicate");
            IUriNode name = g.CreateUriNode("ex:name");
            IBlankNode b1 = g.CreateBlankNode("autos1");
            IBlankNode b2 = g.CreateBlankNode("1");

            g.Assert(subj, pred, b1);
            g.Assert(b1, name, g.CreateLiteralNode("First Triple"));
            g.Assert(subj, pred, b2);
            g.Assert(b2, name, g.CreateLiteralNode("Second Triple"));

            TurtleWriter ttlwriter = new TurtleWriter();
            ttlwriter.Save(g, "bnode-output-test.ttl");

            TestTools.ShowGraph(g);

            TurtleParser ttlparser = new TurtleParser();
            Graph h = new Graph();
            ttlparser.Load(h, "bnode-output-test.ttl");

            TestTools.ShowGraph(h);

            Assert.AreEqual(g.Triples.Count, h.Triples.Count, "Expected same number of Triples after serialization and reparsing");

        }
        public static IGraph CreateCommitMetadata(Uri indexUri, CommitMetadata commitMetadata)
        {
            IGraph graph = new Graph();

            if (commitMetadata.LastCreated != null)
            {
                graph.Assert(
                    graph.CreateUriNode(indexUri), 
                    graph.CreateUriNode(Schema.Predicates.LastCreated), 
                    graph.CreateLiteralNode(commitMetadata.LastCreated.Value.ToString("O"), Schema.DataTypes.DateTime));
            }
            if (commitMetadata.LastEdited != null)
            {
                graph.Assert(
                    graph.CreateUriNode(indexUri),
                    graph.CreateUriNode(Schema.Predicates.LastEdited),
                    graph.CreateLiteralNode(commitMetadata.LastEdited.Value.ToString("O"), Schema.DataTypes.DateTime));
            }
            if (commitMetadata.LastDeleted != null)
            {
                graph.Assert(
                    graph.CreateUriNode(indexUri), 
                    graph.CreateUriNode(Schema.Predicates.LastDeleted), 
                    graph.CreateLiteralNode(commitMetadata.LastDeleted.Value.ToString("O"), Schema.DataTypes.DateTime));
            }

            return graph;
        }
        public override bool Execute(PipelinePackage package, PackagePipelineContext context)
        {
            DateTime? commitTimeStamp = PackagePipelineHelpers.GetCommitTimeStamp(context);
            Guid? commitId = PackagePipelineHelpers.GetCommitId(context);

            IGraph graph = new Graph();

            INode resource = graph.CreateUriNode(context.Uri);

            if (commitTimeStamp != null)
            {
                graph.Assert(
                    resource,
                    graph.CreateUriNode(Schema.Predicates.CatalogTimeStamp),
                    graph.CreateLiteralNode(commitTimeStamp.Value.ToString("O"), Schema.DataTypes.DateTime));
            }

            if (commitId != null)
            {
                graph.Assert(
                    resource,
                    graph.CreateUriNode(Schema.Predicates.CatalogCommitId),
                    graph.CreateLiteralNode(commitId.Value.ToString()));
            }

            context.StageResults.Add(new GraphPackageMetadata(graph));

            return true;
        }
Ejemplo n.º 5
0
 public void TestCreateAssociationLinks()
 {
     var testGraph = new Graph {BaseUri = new Uri("http://dbpedia.org/resource/")};
     var film = testGraph.CreateUriNode(UriFactory.Create("http://dbpedia.org/resource/Un_Chien_Andalou"));
     var rdfType = testGraph.CreateUriNode(UriFactory.Create("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"));
     testGraph.Assert(film,
                      rdfType,
                      testGraph.CreateUriNode(UriFactory.Create("http://dbpedia.org/ontology/Film")));
     testGraph.Assert(film,
                      testGraph.CreateUriNode(UriFactory.Create("http://xmlns.com/foaf/0.1/name")),
                      testGraph.CreateLiteralNode("Un Chien Andalou"));
     var director = testGraph.CreateUriNode(UriFactory.Create("http://dbpedia.org/resource/Luis_Bunuel"));
     testGraph.Assert(director, rdfType, testGraph.CreateUriNode(UriFactory.Create("http://dbpedia.org/ontology/Person")));
     testGraph.Assert(film, testGraph.CreateUriNode(UriFactory.Create("http://dbpedia.org/property/director")), director);
     var mockRequest = new Mock<IODataRequestMessage>();
     mockRequest.Setup(m => m.Url).Returns(new Uri("http://example.org/odata/Films('Un_Chien_Andalou')"));
     var mock = new Mock<IODataResponseMessage>();
     var mockStream = new MemoryStream();
     mock.Setup(m => m.GetStream()).Returns(mockStream);
     var generator = new ODataFeedGenerator(mockRequest.Object, mock.Object, _dbpediaMap, "http://example.org/odata/", new ODataMessageWriterSettings { Indent = true });
     generator.CreateEntryFromGraph(testGraph, film.Uri.ToString(), "DBPedia.Film");
     mockStream.Seek(0, SeekOrigin.Begin);
     var streamXml = XDocument.Load(mockStream);
     Assert.IsNotNull(streamXml);
     Assert.IsNotNull(streamXml.Root);
     Assert.AreEqual(XName.Get("entry", "http://www.w3.org/2005/Atom"), streamXml.Root.Name);
     Console.WriteLine(streamXml.ToString());
 }
        IGraph CreatePageGraph(INode subject, IGraph graph)
        {
            Graph pageGraph = new Graph();

            Triple idTriple = graph.GetTriplesWithSubjectPredicate(subject, graph.CreateUriNode(Schema.Predicates.Id)).First();
            Triple versionTriple = graph.GetTriplesWithSubjectPredicate(subject, graph.CreateUriNode(Schema.Predicates.Version)).First();

            pageGraph.Assert(idTriple.CopyTriple(pageGraph));
            pageGraph.Assert(versionTriple.CopyTriple(pageGraph));

            return pageGraph;
        }
        public StorageContent CreateContent(CatalogContext context)
        {
            IGraph graph = new Graph();

            INode rdfTypePredicate = graph.CreateUriNode(Schema.Predicates.Type);
            INode timeStampPredicate = graph.CreateUriNode(Schema.Predicates.CatalogTimestamp);
            INode commitIdPredicate = graph.CreateUriNode(Schema.Predicates.CatalogCommitId);

            INode container = graph.CreateUriNode(_resourceUri);

            graph.Assert(container, rdfTypePredicate, graph.CreateUriNode(GetContainerType()));
            graph.Assert(container, timeStampPredicate, graph.CreateLiteralNode(_timeStamp.ToString("O"), Schema.DataTypes.DateTime));
            graph.Assert(container, commitIdPredicate, graph.CreateLiteralNode(_commitId.ToString()));

            if (_parent != null)
            {
                graph.Assert(container, graph.CreateUriNode(Schema.Predicates.Parent), graph.CreateUriNode(_parent));
            }

            AddCustomContent(container, graph);

            INode itemPredicate = graph.CreateUriNode(Schema.Predicates.CatalogItem);
            INode countPredicate = graph.CreateUriNode(Schema.Predicates.CatalogCount);

            foreach (KeyValuePair<Uri, CatalogContainerItem> item in _items)
            {
                INode itemNode = graph.CreateUriNode(item.Key);

                graph.Assert(container, itemPredicate, itemNode);
                graph.Assert(itemNode, rdfTypePredicate, graph.CreateUriNode(item.Value.Type));

                if (item.Value.PageContent != null)
                {
                    graph.Merge(item.Value.PageContent);
                }

                graph.Assert(itemNode, timeStampPredicate, graph.CreateLiteralNode(item.Value.TimeStamp.ToString("O"), Schema.DataTypes.DateTime));
                graph.Assert(itemNode, commitIdPredicate, graph.CreateLiteralNode(item.Value.CommitId.ToString()));

                if (item.Value.Count != null)
                {
                    graph.Assert(itemNode, countPredicate, graph.CreateLiteralNode(item.Value.Count.ToString(), Schema.DataTypes.Integer));
                }
            }

            JObject frame = context.GetJsonLdContext("context.Container.json", GetContainerType());

            // The below code could be used to compact data storage by using relative URIs.
            //frame = (JObject)frame.DeepClone();
            //frame["@context"]["@base"] = _resourceUri.ToString();

            StorageContent content = new StringStorageContent(Utils.CreateJson(graph, frame), "application/json", "no-store");

            return content;
        }
        public override StorageContent CreateContent(CatalogContext context)
        {
            using (IGraph graph = new Graph())
            {
                INode entry = graph.CreateUriNode(GetItemAddress());

                //  catalog infrastructure fields
                graph.Assert(entry, graph.CreateUriNode(Schema.Predicates.Type), graph.CreateUriNode(GetItemType()));
                graph.Assert(entry, graph.CreateUriNode(Schema.Predicates.Type), graph.CreateUriNode(Schema.DataTypes.Permalink));
                graph.Assert(entry, graph.CreateUriNode(Schema.Predicates.CatalogTimeStamp), graph.CreateLiteralNode(TimeStamp.ToString("O"), Schema.DataTypes.DateTime));
                graph.Assert(entry, graph.CreateUriNode(Schema.Predicates.CatalogCommitId), graph.CreateLiteralNode(CommitId.ToString()));

                graph.Assert(entry, graph.CreateUriNode(Schema.Predicates.Published), graph.CreateLiteralNode(_published.ToString("O"), Schema.DataTypes.DateTime));

                graph.Assert(entry, graph.CreateUriNode(Schema.Predicates.Id), graph.CreateLiteralNode(_id));
                graph.Assert(entry, graph.CreateUriNode(Schema.Predicates.OriginalId), graph.CreateLiteralNode(_id));
                graph.Assert(entry, graph.CreateUriNode(Schema.Predicates.Version), graph.CreateLiteralNode(_version));

                SetIdVersionFromGraph(graph);

                //  create JSON content
                JObject frame = context.GetJsonLdContext("context.Catalog.json", GetItemType());
                StorageContent content = new StringStorageContent(Utils.CreateArrangedJson(graph, frame), "application/json", "no-store");
               
                return content;
            }
        }
        public override bool Execute(PipelinePackage package, PackagePipelineContext context)
        {
            string hash = GetHash(package.Stream);
            long size = GetSize(package.Stream);

            IGraph graph = new Graph();
            INode subject = graph.CreateUriNode(context.Uri);
            graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.PackageHashAlgorithm), graph.CreateLiteralNode("SHA512"));
            graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.PackageHash), graph.CreateLiteralNode(hash));
            graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.PackageSize), graph.CreateLiteralNode(size.ToString(), Schema.DataTypes.Integer));

            context.StageResults.Add(new GraphPackageMetadata(graph));

            return true;
        }
        public static IGraph ReplaceResourceUris(IGraph original, IDictionary<string, Uri> replacements)
        {
            IGraph modified = new Graph();
            foreach (Triple triple in original.Triples)
            {
                Uri subjectUri;
                if (!replacements.TryGetValue(triple.Subject.ToString(), out subjectUri))
                {
                    subjectUri = ((IUriNode)triple.Subject).Uri;
                }

                INode subjectNode = modified.CreateUriNode(subjectUri);
                INode predicateNode = triple.Predicate.CopyNode(modified);

                INode objectNode;
                if (triple.Object is IUriNode)
                {
                    Uri objectUri;
                    if (!replacements.TryGetValue(triple.Object.ToString(), out objectUri))
                    {
                        objectUri = ((IUriNode)triple.Object).Uri;
                    }
                    objectNode = modified.CreateUriNode(objectUri);
                }
                else
                {
                    objectNode = triple.Object.CopyNode(modified);
                }

                modified.Assert(subjectNode, predicateNode, objectNode);
            }

            return modified;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Adds the literal triple to a graph.
        /// </summary>
        /// <param name="graph">The graph.</param>
        /// <param name="subject">The subject.</param>
        /// <param name="predicate">The predicate.</param>
        /// <param name="obj">The object (resource).</param>
        /// <remarks></remarks>
        public static void AddTripleLiteral(Graph graph, string subject, string predicate, string obj, string datatype)
        {
            string xmlSchemaDatatype;
            switch (datatype)
            {
                case "Url":
                    xmlSchemaDatatype = XmlSpecsHelper.XmlSchemaDataTypeAnyUri;
                    break;
                case "Date":
                    xmlSchemaDatatype = XmlSpecsHelper.XmlSchemaDataTypeDateTime;
                    break;
                case "Integer":
                    xmlSchemaDatatype = XmlSpecsHelper.XmlSchemaDataTypeInteger;
                    break;
                case "Ntext":
                    xmlSchemaDatatype = XmlSpecsHelper.XmlSchemaDataTypeString;
                    break;
                case "Nvarchar":
                    xmlSchemaDatatype = XmlSpecsHelper.XmlSchemaDataTypeString;
                    break;
                default:
                    xmlSchemaDatatype = XmlSpecsHelper.XmlSchemaDataTypeString;
                    break;
            }

            Triple triple = null;
            if (subject.StartsWith("http") && predicate.StartsWith("http"))
            {
                triple = new Triple(
                        graph.CreateUriNode(new Uri(subject)),
                        graph.CreateUriNode(new Uri(predicate)),
                        graph.CreateLiteralNode(obj, new Uri(xmlSchemaDatatype))
                        );
            }
            else if (!subject.StartsWith("http") && predicate.StartsWith("http"))
            {
                triple = new Triple(
                        graph.CreateUriNode(subject),
                        graph.CreateUriNode(new Uri(predicate)),
                        graph.CreateLiteralNode(obj, new Uri(xmlSchemaDatatype))
                        );
            }
            else if (subject.StartsWith("http") && !predicate.StartsWith("http"))
            {
                triple = new Triple(
                        graph.CreateUriNode(new Uri(subject)),
                        graph.CreateUriNode(predicate),
                        graph.CreateLiteralNode(obj, new Uri(xmlSchemaDatatype))
                        );
            }
            else if (!subject.StartsWith("http") && !predicate.StartsWith("http"))
            {
                triple = new Triple(
                        graph.CreateUriNode(subject),
                        graph.CreateUriNode(predicate),
                        graph.CreateLiteralNode(obj, new Uri(xmlSchemaDatatype))
                        );
            }
            graph.Assert(triple);
        }
        public override string CreateContent(CatalogContext context)
        {
            IGraph graph = new Graph();

            graph.NamespaceMap.AddNamespace("rdf", new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#"));
            graph.NamespaceMap.AddNamespace("nuget", new Uri("http://nuget.org/schema#"));

            INode subject = graph.CreateUriNode(new Uri(GetBaseAddress() + GetItemIdentity()));

            graph.Assert(subject, graph.CreateUriNode("rdf:type"), graph.CreateUriNode("nuget:DeleteRegistration"));
            graph.Assert(subject, graph.CreateUriNode("nuget:id"), graph.CreateLiteralNode(_id));

            JObject frame = context.GetJsonLdContext("context.DeletePackage.json", GetItemType());

            string content = Utils.CreateJson(graph, frame);

            return content;
        }
        public static void Main(string[] args)
        {
            //Create a new Empty Graph
            Graph g = new Graph();

            //Define Namespaces
            g.NamespaceMap.AddNamespace("pets", new Uri("http://example.org/pets"));
            
            //Create Uri Nodes
            IUriNode dog, fido, rob, owner, name, species, breed, lab;
            dog = g.CreateUriNode("pets:Dog");
            fido = g.CreateUriNode("pets:abc123");
            rob = g.CreateUriNode("pets:def456");
            owner = g.CreateUriNode("pets:hasOwner");
            name = g.CreateUriNode("pets:hasName");
            species = g.CreateUriNode("pets:isAnimal");
            breed = g.CreateUriNode("pets:isBreed");
            lab = g.CreateUriNode("pets:Labrador");

            //Assert Triples
            g.Assert(new Triple(fido, species, dog));
            g.Assert(new Triple(fido, owner, rob));
            g.Assert(new Triple(fido, name, g.CreateLiteralNode("Fido")));
            g.Assert(new Triple(rob, name, g.CreateLiteralNode("Rob")));
            g.Assert(new Triple(fido, breed, lab));

            //Attempt to output GraphViz
            try
            {
                Console.WriteLine("Writing GraphViz DOT file graph_building_example2.dot");
                GraphVizWriter gvzwriter = new GraphVizWriter();
                gvzwriter.Save(g, "graph_building_example2.dot");

                Console.WriteLine("Creating a PNG got this Graph called graph_building_example2.png");
                GraphVizGenerator gvzgen = new GraphVizGenerator("svg", "C:\\Program Files (x86)\\Graphviz2.20\\bin");
                gvzgen.Format = "png";
                gvzgen.Generate(g, "graph_building_example2.png", false);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }
        public override IGraph CreatePageContent(CatalogContext context)
        {
            Uri resourceUri = new Uri(GetBaseAddress() + GetRelativeAddress());

            Graph graph = new Graph();

            INode subject = graph.CreateUriNode(resourceUri);
            INode count = graph.CreateUriNode(new Uri("http://nuget.org/schema#count"));
            INode itemGUID = graph.CreateUriNode(new Uri("http://nuget.org/schema#itemGUID"));
            INode minDownloadTimestamp = graph.CreateUriNode(new Uri("http://nuget.org/schema#minDownloadTimestamp"));
            INode maxDownloadTimestamp = graph.CreateUriNode(new Uri("http://nuget.org/schema#maxDownloadTimestamp"));

            graph.Assert(subject, count, graph.CreateLiteralNode(_data.Count.ToString(), Schema.DataTypes.Integer));
            graph.Assert(subject, itemGUID, graph.CreateLiteralNode(_itemGUID.ToString()));
            graph.Assert(subject, minDownloadTimestamp, graph.CreateLiteralNode(_minDownloadTimestamp.ToString("O"), Schema.DataTypes.DateTime));
            graph.Assert(subject, maxDownloadTimestamp, graph.CreateLiteralNode(_maxDownloadTimestamp.ToString("O"), Schema.DataTypes.DateTime));

            return graph;
        }
Ejemplo n.º 15
0
        public void WritingRdfXmlLiteralsWithLanguageTags()
        {
            Graph g = new Graph();
            INode s = g.CreateUriNode(new Uri("http://example.org/subject"));
            INode p = g.CreateUriNode(new Uri("http://example.org/predicate"));
            INode o = g.CreateLiteralNode("string", "en");
            g.Assert(s, p, o);

            this.CheckRoundTrip(g);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="g"></param>
        /// <param name="LO"></param>
        public void insertLearningObject(ref Graph g, LearningObjectContextModel LO)
        {
            g.NamespaceMap.AddNamespace("onto", new Uri("http://www.owl-ontologies.com/OntoAdapt2.owl#"));

            IUriNode sujeito = g.CreateUriNode("onto:" + LO.LearningObject_ID);
            INode rdfType = g.CreateUriNode("rdf:type");
            INode objeto = g.CreateUriNode("onto:LearningObject");

            Triple triple = new Triple(sujeito, rdfType, objeto);
            g.Assert(triple);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="g"></param>
        public void insertComunidadeMoodle(ref Graph g)
        {
            g = new Graph();
            g.NamespaceMap.AddNamespace("onto", new Uri("http://www.owl-ontologies.com/OntoAdapt2.owl#"));

            IUriNode sujeito = g.CreateUriNode("onto:" + student.Matricula);
            INode rdfType = g.CreateUriNode("onto:ComunidadeMoodle");
            ILiteralNode literal = g.CreateLiteralNode(student.ComunidadeMoodle);

            Triple triple = new Triple(sujeito, rdfType, literal);
            g.Assert(triple);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="g"></param>
        /// <param name="strLearningStyle"></param>
        public void insertDeviceMediaPreference(ref Graph g)
        {
            g = new Graph();
            g.NamespaceMap.AddNamespace("onto", new Uri("http://www.owl-ontologies.com/OntoAdapt2.owl#"));

            IUriNode sujeito = g.CreateUriNode("onto:" + Device.model_name);
                INode rdfType = g.CreateUriNode("onto:hasDeviceMediaPreference");
                IUriNode objeto = g.CreateUriNode(new Uri("http://www.owl-ontologies.com/OntoAdapt2.owl#" + Device.MediaPreference));

                Triple triple = new Triple(sujeito, rdfType, objeto);
                g.Assert(triple);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Insere LO a comunidade
        /// </summary>
        /// <param name="g"></param>
        /// <param name="LO"></param>
        public void insertLearningObjectComunidade(ref Graph g, LearningObjectContextModel LO)
        {
            g = new Graph();
            g.NamespaceMap.AddNamespace("onto", new Uri("http://www.owl-ontologies.com/OntoAdapt2.owl#"));

            IUriNode sujeito = g.CreateUriNode("onto:" + LO.LearningObject_ID);
            INode rdfType = g.CreateUriNode("onto:LO_MoodleCommunity");
            ILiteralNode objeto = g.CreateLiteralNode(LO.MoodleCommunity);

            Triple triple = new Triple(sujeito, rdfType, objeto);
            g.Assert(triple);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="g"></param>
        public void InsertDeviceBrand(ref Graph g)
        {
            g = new Graph();
            g.NamespaceMap.AddNamespace("onto", new Uri("http://www.owl-ontologies.com/OntoAdapt2.owl#"));

            IUriNode sujeito = g.CreateUriNode("onto:" + Device.model_name);
            INode rdfType = g.CreateUriNode("onto:Brand");
            ILiteralNode literal = g.CreateLiteralNode(Device.Brand_Name);

            Triple triple = new Triple(sujeito, rdfType, literal);
            g.Assert(triple);
        }
        public string CreateContent(CatalogContext context)
        {
            IGraph graph = new Graph();

            graph.NamespaceMap.AddNamespace("rdf", new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#"));
            graph.NamespaceMap.AddNamespace("catalog", new Uri("http://nuget.org/catalog#"));

            INode rdfTypePredicate = graph.CreateUriNode("rdf:type");
            INode timeStampPredicate = graph.CreateUriNode("catalog:timeStamp");

            Uri dateTimeDatatype = new Uri("http://www.w3.org/2001/XMLSchema#dateTime");

            INode container = graph.CreateUriNode(_resourceUri);

            graph.Assert(container, rdfTypePredicate, graph.CreateUriNode(GetContainerType()));
            graph.Assert(container, timeStampPredicate, graph.CreateLiteralNode(_timeStamp.ToString(), dateTimeDatatype));

            if (_parent != null)
            {
                graph.Assert(container, graph.CreateUriNode("catalog:parent"), graph.CreateUriNode(_parent));
            }

            AddCustomContent(container, graph);

            INode itemPredicate = graph.CreateUriNode("catalog:item");
            INode countPredicate = graph.CreateUriNode("catalog:count");

            foreach (KeyValuePair<Uri, Tuple<Uri, IGraph, DateTime, int?>> item in GetItems())
            {
                INode itemNode = graph.CreateUriNode(item.Key);

                graph.Assert(container, itemPredicate, itemNode);
                graph.Assert(itemNode, rdfTypePredicate, graph.CreateUriNode(item.Value.Item1));

                if (item.Value.Item2 != null)
                {
                    graph.Merge(item.Value.Item2);
                }

                graph.Assert(itemNode, timeStampPredicate, graph.CreateLiteralNode(item.Value.Item3.ToString(), dateTimeDatatype));
                if (item.Value.Item4 != null)
                {
                    Uri integerDatatype = new Uri("http://www.w3.org/2001/XMLSchema#integer");
                    graph.Assert(itemNode, countPredicate, graph.CreateLiteralNode(item.Value.Item4.ToString(), integerDatatype));
                }
            }

            JObject frame = context.GetJsonLdContext("context.Container.json", GetContainerType());

            string content = Utils.CreateJson(graph, frame);

            return content;
        }
        public override bool Execute(PipelinePackage package, PackagePipelineContext context)
        {
            IGraph graph = new Graph();

            INode subject = graph.CreateUriNode(context.Uri);

            graph.Assert(
                subject,
                graph.CreateUriNode(Schema.Predicates.Published), 
                graph.CreateLiteralNode(package.Published.ToString("O"), Schema.DataTypes.DateTime));

            if (package.Owner != null)
            {
                graph.Assert(
                    subject,
                    graph.CreateUriNode(Schema.Predicates.Owner),
                    graph.CreateLiteralNode(package.Owner));
            }

            context.StageResults.Add(new GraphPackageMetadata(graph));

            return true;
        }
        static KeyValuePair<string, IGraph> CreateTestCatalogEntry(string id, string version, bool isDelete = false)
        {
            Uri packageContentUri = new Uri(string.Format("https://content/{0}.zip", Guid.NewGuid()));

            IGraph graph = new Graph();
            Uri subjectUri = new Uri(string.Format("https://catalog/{0}", Guid.NewGuid()));
            INode subject = graph.CreateUriNode(subjectUri);
            graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.Id), graph.CreateLiteralNode(id));
            graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.Version), graph.CreateLiteralNode(version));

            if (isDelete)
            {
                graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.Type), graph.CreateUriNode(Schema.DataTypes.CatalogDelete));
            }
            else
            {
                graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.Published), graph.CreateLiteralNode(DateTime.UtcNow.ToString("O"), Schema.DataTypes.DateTime));
                graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.PackageContent), graph.CreateUriNode(packageContentUri));
            }

            Console.WriteLine(subjectUri);

            return new KeyValuePair<string, IGraph>(subjectUri.AbsoluteUri, graph);
        }
Ejemplo n.º 24
0
        private Graph CreateGraph(IEnumerable<RDFTriple> triples)
        {
            var g = new Graph();
            foreach (var triple in triples)
            {
                if(triple.Subject.IsNull() || triple.Predicate.IsNull() || triple.Object.IsNull()) continue;
                IUriNode subject = g.CreateUriNode(UriFactory.Create(triple.Subject));
                IUriNode predicate = g.CreateUriNode(UriFactory.Create(triple.Predicate));

                switch (triple.Object.DataType)
                {
                    case Constants.UriDataType:
                        IUriNode objectUri = g.CreateUriNode(UriFactory.Create(triple.Object.Uri));
                        g.Assert(new Triple(subject, predicate, objectUri));
                        break;
                    case Constants.LiteralDataType:
                        ILiteralNode objecto = g.CreateLiteralNode(triple.Object.Literal);
                        g.Assert(new Triple(subject, predicate, objecto));
                        break;
                }
            }

            return g;
        }
        public override IGraph CreatePageContent(CatalogContext context)
        {
            Uri resourceUri = new Uri(GetBaseAddress() + GetRelativeAddress());

            Graph graph = new Graph();

            INode subject = graph.CreateUriNode(resourceUri);
            INode galleryKeyPredicate = graph.CreateUriNode(new Uri("http://nuget.org/gallery#key"));

            string key = _export.Package["Key"].ToString();

            Uri integerDatatype = new Uri("http://www.w3.org/2001/XMLSchema#integer");
            graph.Assert(subject, galleryKeyPredicate, graph.CreateLiteralNode(key, integerDatatype));

            return graph;
        }
 public override StorageContent CreateContent(CatalogContext context)
 {
     IGraph graph = new Graph();
     INode subject = graph.CreateUriNode(GetItemAddress());
     graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.Type), graph.CreateUriNode(Schema.DataTypes.Package));
     graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.Type), graph.CreateUriNode(Schema.DataTypes.Permalink));
     graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.CatalogEntry), graph.CreateUriNode(_catalogUri));
     graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.Registration), graph.CreateUriNode(GetRegistrationAddress()));
     graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.PackageContent), graph.CreateUriNode(GetPackageContentAddress()));
     graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.Published), graph.CreateLiteralNode(GetPublishedDate().ToString("O"), Schema.DataTypes.DateTime));
     graph.Assert(subject, graph.CreateUriNode(Schema.Predicates.Listed), graph.CreateLiteralNode(_listed.ToString(), Schema.DataTypes.Boolean));
     JObject frame = context.GetJsonLdContext("context.Package.json", Schema.DataTypes.Package);
     return new JTokenStorageContent(Utils.CreateJson(graph, frame), "application/json", "no-store");
 }
Ejemplo n.º 27
0
        public Graph CreateExampleGraph(string uri)
        {
            Graph newGraph = new Graph();
            newGraph.BaseUri = UriFactory.Create(uri);

            Triple triple = new Triple(
                newGraph.CreateUriNode(UriFactory.Create("http://example/book1")),
                newGraph.CreateUriNode(UriFactory.Create("http://example.org/ns#price")),
                newGraph.CreateLiteralNode("42", new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger))
                );
            newGraph.Assert(triple);

            connector.SaveGraph(newGraph);

            return newGraph;
        }
 public void TestWriteSimpleRdf()
 {
     var g = new Graph();
     g.Assert(g.CreateUriNode(new Uri("http://example.org/s")),
         g.CreateUriNode(new Uri("http://example.org/p")),
         g.CreateLiteralNode("o"));
     //g.Assert(g.CreateUriNode(new Uri("http://example.org/s")),
     //    g.CreateUriNode(new Uri("http://example.org/ns2/p")),
     //    g.CreateLiteralNode("Another o"));
     using (var stringWriter = new System.IO.StringWriter())
     {
         var writer = new RdfXmlWriter();
         writer.Save(g, stringWriter);
         var buff = stringWriter.ToString();
         XDocument doc = XDocument.Parse(buff); // Fails
     }
 }
Ejemplo n.º 29
0
        public void GraphTripleCreation()
        {
            //Create two Graphs
            Graph g = new Graph();
            Graph h = new Graph();

            g.NamespaceMap.AddNamespace("ex", new Uri("http://example.org/"));
            h.NamespaceMap.AddNamespace("ex", new Uri("http://example.org/"));

            //Create a Triple in First Graph
            g.Assert(g.CreateBlankNode(), g.CreateUriNode("rdf:type"), g.CreateUriNode("ex:Triple"));
            Assert.Equal(1, g.Triples.Count);

            //Create a Triple in Second Graph
            h.Assert(h.CreateBlankNode(), h.CreateUriNode("rdf:type"), h.CreateUriNode("ex:Triple"));
            Assert.Equal(1, h.Triples.Count);
        }
Ejemplo n.º 30
0
        public void GraphEventBubbling()
        {
            try
            {
                this._graphAdded   = false;
                this._graphRemoved = false;
                this._graphChanged = false;

                //Create Store and Graph add attach handlers to Store
                TripleStore store = new TripleStore();
                Graph       g     = new Graph();
                store.GraphAdded   += this.HandleGraphAdded;
                store.GraphRemoved += this.HandleGraphRemoved;
                store.GraphChanged += this.HandleGraphChanged;

                //Add the Graph to the Store which should fire the GraphAdded event
                store.Add(g);
                Assert.IsTrue(this._graphAdded, "GraphAdded event of the Triple Store should have fired");

                //Assert a Triple
                INode  s = g.CreateBlankNode();
                INode  p = g.CreateUriNode("rdf:type");
                INode  o = g.CreateUriNode("rdfs:Class");
                Triple t = new Triple(s, p, o);
                g.Assert(t);
                Assert.IsTrue(this._graphChanged, "GraphChanged event of the Triple Store should have fired");

                //Retract the Triple
                this._graphChanged = false;
                g.Retract(t);
                Assert.IsTrue(this._graphChanged, "GraphChanged event of the Triple Store should have fired");

                //Remove the Graph from the Store which should fire the GraphRemoved event
                store.Remove(g.BaseUri);
                Assert.IsTrue(this._graphRemoved, "GraphRemoved event of the Triple Store should have fired");
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public void GraphDiffAddedMSG()
        {
            Graph g = new Graph();
            Graph h = new Graph();

            g.LoadFromFile("resources\\InferenceTest.ttl");
            h.LoadFromFile("resources\\InferenceTest.ttl");

            //Add additional Triple to 2nd Graph
            INode    blank    = h.CreateBlankNode();
            IUriNode subClass = h.CreateUriNode("rdfs:subClassOf");
            IUriNode vehicle  = h.CreateUriNode("eg:Vehicle");

            h.Assert(new Triple(blank, subClass, vehicle));

            GraphDiffReport report = g.Difference(h);

            TestTools.ShowDifferences(report);

            Assert.False(report.AreEqual, "Graphs should not have been reported as equal");
            Assert.True(report.AddedMSGs.Any(), "Difference should have reported some Added MSGs");
        }
Ejemplo n.º 32
0
        public void GraphDiffAddedGroundTriples()
        {
            Graph g = new Graph();
            Graph h = new Graph();

            FileLoader.Load(g, "InferenceTest.ttl");
            FileLoader.Load(h, "InferenceTest.ttl");

            //Add additional Triple to 2nd Graph
            IUriNode spaceVehicle = h.CreateUriNode("eg:SpaceVehicle");
            IUriNode subClass     = h.CreateUriNode("rdfs:subClassOf");
            IUriNode vehicle      = h.CreateUriNode("eg:Vehicle");

            h.Assert(new Triple(spaceVehicle, subClass, vehicle));

            GraphDiffReport report = g.Difference(h);

            TestTools.ShowDifferences(report);

            Assert.IsFalse(report.AreEqual, "Graphs should not have been reported as equal");
            Assert.IsTrue(report.AddedTriples.Any(), "Difference should have reported some Added Triples");
        }
        public override bool Execute(PipelinePackage package, PackagePipelineContext context)
        {
            ZipArchive zipArchive = PackagePipelineHelpers.GetZipArchive(package, context);

            IEnumerable<PackageEntry> entries = GetEntries(zipArchive);

            IGraph graph = new Graph();

            if (entries != null)
            {
                INode packageEntryPredicate = graph.CreateUriNode(Schema.Predicates.PackageEntry);
                INode packageEntryType = graph.CreateUriNode(Schema.DataTypes.PackageEntry);
                INode fullNamePredicate = graph.CreateUriNode(Schema.Predicates.FullName);
                INode namePredicate = graph.CreateUriNode(Schema.Predicates.Name);
                INode lengthPredicate = graph.CreateUriNode(Schema.Predicates.Length);
                INode compressedLengthPredicate = graph.CreateUriNode(Schema.Predicates.CompressedLength);
                INode rdfTypePredicate = graph.CreateUriNode(Schema.Predicates.Type);

                INode resource = graph.CreateUriNode(context.Uri);

                foreach (PackageEntry entry in entries)
                {
                    Uri entryUri = new Uri(context.Uri.AbsoluteUri + "#" + entry.FullName);

                    INode entryNode = graph.CreateUriNode(entryUri);

                    graph.Assert(resource, packageEntryPredicate, entryNode);
                    graph.Assert(entryNode, rdfTypePredicate, packageEntryType);
                    graph.Assert(entryNode, fullNamePredicate, graph.CreateLiteralNode(entry.FullName));
                    graph.Assert(entryNode, namePredicate, graph.CreateLiteralNode(entry.Name));
                    graph.Assert(entryNode, lengthPredicate, graph.CreateLiteralNode(entry.Length.ToString(), Schema.DataTypes.Integer));
                    graph.Assert(entryNode, compressedLengthPredicate, graph.CreateLiteralNode(entry.CompressedLength.ToString(), Schema.DataTypes.Integer));
                }
            }

            context.StageResults.Add(new GraphPackageMetadata(graph));

            return true;
        }
Ejemplo n.º 34
0
        public void GraphMatchTrivial2()
        {
            Graph      g    = new Graph();
            IBlankNode a    = g.CreateBlankNode("b1");
            IBlankNode b    = g.CreateBlankNode("b2");
            IBlankNode c    = g.CreateBlankNode("b3");
            INode      pred = g.CreateUriNode(UriFactory.Create("http://predicate"));

            g.Assert(a, pred, g.CreateLiteralNode("A"));
            g.Assert(a, pred, b);
            g.Assert(b, pred, g.CreateLiteralNode("B"));
            g.Assert(b, pred, c);
            g.Assert(c, pred, g.CreateLiteralNode("C"));
            g.Assert(c, pred, a);

            Graph      h     = new Graph();
            IBlankNode a2    = h.CreateBlankNode("b4");
            IBlankNode b2    = h.CreateBlankNode("b5");
            IBlankNode c2    = h.CreateBlankNode("b3");
            INode      pred2 = h.CreateUriNode(UriFactory.Create("http://predicate"));

            h.Assert(a2, pred2, h.CreateLiteralNode("A"));
            h.Assert(a2, pred2, b2);
            h.Assert(b2, pred2, h.CreateLiteralNode("B"));
            h.Assert(b2, pred2, c2);
            h.Assert(c2, pred2, h.CreateLiteralNode("C"));
            h.Assert(c2, pred2, a2);

            GraphDiffReport report = g.Difference(h);

            if (!report.AreEqual)
            {
                TestTools.ShowDifferences(report);
            }
            Assert.IsTrue(report.AreEqual);
        }
Ejemplo n.º 35
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="grafo"></param>
        /// <param name="user"></param>
        public void InsertDeviceOwner(ref Graph grafo, UserContextModel user)
        {
            grafo.NamespaceMap.AddNamespace("onto", new Uri("http://www.owl-ontologies.com/OntoAdapt2.owl#"));
            INode sujeito = grafo.CreateUriNode("onto:" + user.Matricula);
            INode rdfType = grafo.CreateUriNode("onto:hasDevice");
            INode objeto = grafo.CreateUriNode("onto:" + Device.model_name);

            Triple triple = new Triple(sujeito, rdfType, objeto);
            grafo.Assert(triple);
        }
Ejemplo n.º 36
0
        public void GraphCreation1()
        {
            //Create a new Empty Graph
            Graph g = new Graph();

            Assert.NotNull(g);

            //Define Namespaces
            g.NamespaceMap.AddNamespace("vds", new Uri("http://www.vdesign-studios.com/dotNetRDF#"));
            g.NamespaceMap.AddNamespace("ecs", new Uri("http://id.ecs.soton.ac.uk/person/"));

            //Check we set the Namespace OK
            Assert.True(g.NamespaceMap.HasNamespace("vds"), "Failed to set a Namespace");

            //Set Base Uri
            g.BaseUri = g.NamespaceMap.GetNamespaceUri("vds");
            Assert.NotNull(g.BaseUri);
            Assert.Equal(g.NamespaceMap.GetNamespaceUri("vds"), g.BaseUri);

            //Create Uri Nodes
            IUriNode rav08r, wh, lac, hcd;

            rav08r = g.CreateUriNode("ecs:11471");
            wh     = g.CreateUriNode("ecs:1650");
            hcd    = g.CreateUriNode("ecs:46");
            lac    = g.CreateUriNode("ecs:60");

            //Create Uri Nodes for some Predicates
            IUriNode supervises, collaborates, advises, has;

            supervises   = g.CreateUriNode("vds:supervises");
            collaborates = g.CreateUriNode("vds:collaborates");
            advises      = g.CreateUriNode("vds:advises");
            has          = g.CreateUriNode("vds:has");

            //Create some Literal Nodes
            ILiteralNode singleLine = g.CreateLiteralNode("Some string");
            ILiteralNode multiLine  = g.CreateLiteralNode("This goes over\n\nseveral\n\nlines");
            ILiteralNode french     = g.CreateLiteralNode("Bonjour", "fr");
            ILiteralNode number     = g.CreateLiteralNode("12", new Uri(g.NamespaceMap.GetNamespaceUri("xsd") + "integer"));

            g.Assert(new Triple(wh, supervises, rav08r));
            g.Assert(new Triple(lac, supervises, rav08r));
            g.Assert(new Triple(hcd, advises, rav08r));
            g.Assert(new Triple(wh, collaborates, lac));
            g.Assert(new Triple(wh, collaborates, hcd));
            g.Assert(new Triple(lac, collaborates, hcd));
            g.Assert(new Triple(rav08r, has, singleLine));
            g.Assert(new Triple(rav08r, has, multiLine));
            g.Assert(new Triple(rav08r, has, french));
            g.Assert(new Triple(rav08r, has, number));

            //Now print all the Statements
            Console.WriteLine("All Statements");
            foreach (Triple t in g.Triples)
            {
                Console.WriteLine(t.ToString());
            }

            //Get statements about Rob Vesse
            Console.WriteLine();
            Console.WriteLine("Statements about Rob Vesse");
            foreach (Triple t in g.GetTriples(rav08r))
            {
                Console.WriteLine(t.ToString());
            }

            //Get Statements about Collaboration
            Console.WriteLine();
            Console.WriteLine("Statements about Collaboration");
            foreach (Triple t in g.GetTriples(collaborates))
            {
                Console.WriteLine(t.ToString());
            }

            //Attempt to output Turtle for this Graph
            try
            {
                Console.WriteLine("Writing Turtle file graph_building_example.ttl");
                TurtleWriter ttlwriter = new TurtleWriter();
                ttlwriter.Save(g, "graph_building_example.ttl");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }