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 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");

    }
Exemplo n.º 3
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 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;
        }
Exemplo n.º 5
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 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 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 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");
 }
        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;
        }
Exemplo n.º 10
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());
 }
        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);
            }
        }
Exemplo n.º 12
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);
        }
        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:DeletePackage"));
            graph.Assert(subject, graph.CreateUriNode("nuget:id"), graph.CreateLiteralNode(_id));
            graph.Assert(subject, graph.CreateUriNode("nuget:version"), graph.CreateLiteralNode(_version));

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

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

            return content;
        }
        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;
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Insere o formato do LO
        /// </summary>
        /// <param name="g"></param>
        /// <param name="LO"></param>
        public void insertLearningObjectFormat(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_MediaFormat");
            ILiteralNode objeto = g.CreateLiteralNode(LO.MediaFormat);

            Triple triple = new Triple(sujeito, rdfType, objeto);
            g.Assert(triple);
        }
        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;
            }
        }
Exemplo n.º 19
0
        public void NodeCompareToMixedNodes()
        {
            Graph g = new Graph();
            Graph h = new Graph();

            IBlankNode b = g.CreateBlankNode();
            ILiteralNode plain = g.CreateLiteralNode("plain");
            IUriNode u = g.CreateUriNode("rdf:type");
            List<INode> nodes = new List<INode>()
            {
                b,
                g.CreateBlankNode(),
                g.CreateBlankNode("id"),
                h.CreateBlankNode(),
                h.CreateBlankNode("id"),
                b,
                plain,
                g.CreateLiteralNode("plain english","en"),
                g.CreateLiteralNode("plain french","fr"),
                g.CreateLiteralNode("typed", new Uri(XmlSpecsHelper.XmlSchemaDataTypeString)),
                (1234).ToLiteral(g),
                (12.34m).ToLiteral(g),
                (12.34d).ToLiteral(g),
                (false).ToLiteral(g),
                (true).ToLiteral(g),
                plain,
                u,
                g.CreateUriNode(new Uri("http://example.org")),
                g.CreateUriNode(new Uri("http://example.org:8080")),
                g.CreateUriNode(new Uri("http://www.dotnetrdf.org")),
                g.CreateUriNode(new Uri("http://www.dotnetrdf.org/configuration#")),
                g.CreateUriNode(new Uri("http://www.dotnetrdf.org/Configuration#")),
                g.CreateUriNode(new Uri("mailto:[email protected]")),
                u
            };

            this.ShowOrdering(nodes);

            this.CheckCombinations(nodes);
        }
        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;
        }
Exemplo n.º 21
0
        public void IndexingNodesInMultiDictionary2()
        {
            Graph        g         = new Graph();
            ILiteralNode canonical = (1).ToLiteral(g);
            ILiteralNode alternate = g.CreateLiteralNode("01", UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeInteger));

            MultiDictionary <INode, int> dictionary = new MultiDictionary <INode, int>();

            dictionary.Add(canonical, 1);
            Assert.Equal(1, dictionary[canonical]);
            dictionary.Add(alternate, 2);
            Assert.Equal(2, dictionary.Count);
            Assert.Equal(2, dictionary[alternate]);
        }
Exemplo n.º 22
0
        public void NodeCompareToLiteralNodesXsdDateTimes()
        {
            Graph g = new Graph();

            List <INode> nodes = new List <INode>()
            {
                g.CreateLiteralNode("something", new Uri(XmlSpecsHelper.XmlSchemaDataTypeDateTime)),
                DateTime.Now.ToLiteral(g),
                DateTime.Now.AddYears(3).AddDays(1).ToLiteral(g),
                DateTime.Now.AddYears(-25).AddMinutes(-17).ToLiteral(g),
                new DateTime(1, 2, 3, 4, 5, 6).ToLiteral(g),
                new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTimeKind.Utc).ToLiteral(g),
                g.CreateLiteralNode("thing", new Uri(XmlSpecsHelper.XmlSchemaDataTypeDateTime)),
                g.CreateLiteralNode("1", new Uri(XmlSpecsHelper.XmlSchemaDataTypeDateTime)),
                g.CreateLiteralNode("-3", new Uri(XmlSpecsHelper.XmlSchemaDataTypeDateTime)),
            };

            this.ShowOrdering(nodes);

            this.CheckCombinations(nodes);
            this.CheckCombinations <ILiteralNode>(nodes.OfType <ILiteralNode>().ToList());
            this.CheckCombinations <LiteralNode>(nodes.OfType <LiteralNode>().ToList());
        }
        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;
        }
Exemplo n.º 24
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);
        }
        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);
        }
        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;
        }
Exemplo 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
     }
 }
Exemplo n.º 29
0
        public void IndexingNodesInMultiDictionary1()
        {
            Graph        g         = new Graph();
            ILiteralNode canonical = (1).ToLiteral(g);
            ILiteralNode alternate = g.CreateLiteralNode("01", UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeInteger));

            //Use a dud hash function to put everything into a single bucket
            MultiDictionary <INode, int> dictionary = new MultiDictionary <INode, int>(n => 1, false);

            dictionary.Add(canonical, 1);
            Assert.Equal(1, dictionary[canonical]);
            dictionary[alternate] = 2;

            //With everything in a single bucket the keys should be considered
            //equal by the default comparer hence the key count will only be one
            //and retrieving with either 2 gives the value from the second Add()
            Assert.Single(dictionary);
            Assert.Equal(2, dictionary[alternate]);
            Assert.Equal(2, dictionary[canonical]);
        }
Exemplo n.º 30
0
        public void NodeCompareToEquivalentLiterals2()
        {
            Graph g = new Graph();
            ILiteralNode canonical = (true).ToLiteral(g);
            ILiteralNode alternate = g.CreateLiteralNode("TRUE", UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeBoolean));

            List<INode> ns = new List<INode>()
            {
                canonical,
                alternate                
            };

            Assert.AreNotEqual(canonical, alternate, "Alternate lexical forms should not be equal");
            Assert.AreEqual(0, canonical.CompareTo(alternate), "Comparison should compare alternate lexical forms as equal");

            this.ShowOrdering(ns);
            this.CheckCombinations(ns);
            this.CheckCombinations<ILiteralNode>(ns.OfType<ILiteralNode>().ToList());
            this.CheckCombinations(ns, new FastNodeComparer());
        }
Exemplo n.º 31
0
        public void NodeCompareToEquivalentLiterals3()
        {
            Graph        g         = new Graph();
            ILiteralNode canonical = (1d).ToLiteral(g);
            ILiteralNode alternate = g.CreateLiteralNode("1.00000", UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeDouble));

            List <INode> ns = new List <INode>()
            {
                canonical,
                alternate
            };

            Assert.NotEqual(canonical, alternate);
            Assert.Equal(0, canonical.CompareTo(alternate));

            this.ShowOrdering(ns);
            this.CheckCombinations(ns);
            this.CheckCombinations <ILiteralNode>(ns.OfType <ILiteralNode>().ToList());
            this.CheckCombinations(ns, new FastNodeComparer());
        }
Exemplo n.º 32
0
        public void IndexingNodesInMultiDictionary3()
        {
            Graph        g         = new Graph();
            ILiteralNode canonical = (1).ToLiteral(g);
            ILiteralNode alternate = g.CreateLiteralNode("01", UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeInteger));

            //Use a dud hash function to put everything into a single bucket and use
            //the FastNodeComparer
            MultiDictionary <INode, int> dictionary = new MultiDictionary <INode, int>(n => 1, false, new FastNodeComparer(), MultiDictionaryMode.AVL);

            dictionary.Add(canonical, 1);
            Assert.Equal(1, dictionary[canonical]);
            dictionary.Add(alternate, 2);

            //With everything in a single bucket the keys should be considered
            //non-equal by FastNodeComparer so should see key count of 2 and be able
            //to retrieve the specific values by their keys
            Assert.Equal(2, dictionary.Count);
            Assert.Equal(2, dictionary[alternate]);
            Assert.Equal(1, dictionary[canonical]);
            Assert.NotEqual(2, dictionary[canonical]);
        }
Exemplo n.º 33
0
        public void IndexingNodesInBinaryTree2()
        {
            Graph        g         = new Graph();
            ILiteralNode canonical = (1).ToLiteral(g);
            ILiteralNode alternate = g.CreateLiteralNode("01", UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeInteger));

            AVLTree <INode, int> tree = new AVLTree <INode, int>(new FastNodeComparer());

            tree.Add(canonical, 1);
            Assert.Equal(1, tree[canonical]);
            tree.Add(alternate, 2);

            //With the FastNodeComparer the keys are non-equal so should
            //create separate key value pairs in the tree
            Assert.Equal(2, tree[alternate]);
            Assert.Equal(1, tree[canonical]);
            Assert.NotEqual(2, tree[canonical]);

            //With the FastNodeComparer there should be 2 keys in the tree
            //because the keys are not considered equal
            Assert.Equal(2, tree.Keys.Count());
        }
Exemplo n.º 34
0
        public void IndexingNodesInBinaryTree1()
        {
            Graph        g         = new Graph();
            ILiteralNode canonical = (1).ToLiteral(g);
            ILiteralNode alternate = g.CreateLiteralNode("01", UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeInteger));

            AVLTree <INode, int> tree = new AVLTree <INode, int>();

            tree.Add(canonical, 1);
            Assert.Equal(1, tree[canonical]);
            tree[alternate] = 2;

            //Since the default comparer considers the keys to be equal
            //lookup via either key should now give the value 2 rather than the originally
            //set value since the 2nd Add() just changes the existing value for the key
            //rather than adding a new key value pair
            Assert.Equal(2, tree[alternate]);
            Assert.Equal(2, tree[canonical]);

            //With the default comparer we expect to see 1 here rather than 2 because
            //the keys are considered equal
            Assert.Single(tree.Keys);
        }
Exemplo n.º 35
0
        public void NodeCompareToMixedNodes2()
        {
            Graph         g = new Graph();
            IBlankNode    b = g.CreateBlankNode();
            ILiteralNode  l = g.CreateLiteralNode("literal", "en");
            IUriNode      u = g.CreateUriNode(new Uri("http://example.org"));
            IVariableNode v = g.CreateVariableNode("var");

            int c = b.CompareTo(l);

            Assert.Equal(c * -1, l.CompareTo(b));
            c = b.CompareTo(u);
            Assert.Equal(c * -1, u.CompareTo(b));
            c = b.CompareTo(v);
            Assert.Equal(c * -1, v.CompareTo(b));

            c = l.CompareTo(b);
            Assert.Equal(c * -1, b.CompareTo(l));
            c = l.CompareTo(u);
            Assert.Equal(c * -1, u.CompareTo(l));
            c = l.CompareTo(v);
            Assert.Equal(c * -1, v.CompareTo(l));

            c = u.CompareTo(b);
            Assert.Equal(c * -1, b.CompareTo(u));
            c = u.CompareTo(l);
            Assert.Equal(c * -1, l.CompareTo(u));
            c = u.CompareTo(v);
            Assert.Equal(c * -1, v.CompareTo(u));

            c = v.CompareTo(b);
            Assert.Equal(c * -1, b.CompareTo(v));
            c = v.CompareTo(l);
            Assert.Equal(c * -1, l.CompareTo(v));
            c = v.CompareTo(u);
            Assert.Equal(c * -1, u.CompareTo(v));
        }
Exemplo n.º 36
0
        public void NodeCompareToMixedNodes2()
        {
            Graph         g = new Graph();
            IBlankNode    b = g.CreateBlankNode();
            ILiteralNode  l = g.CreateLiteralNode("literal", "en");
            IUriNode      u = g.CreateUriNode(new Uri("http://example.org"));
            IVariableNode v = g.CreateVariableNode("var");

            int c = b.CompareTo(l);

            Assert.AreEqual(c * -1, l.CompareTo(b), "Expected l compareTo b to be inverse of b compareTo l");
            c = b.CompareTo(u);
            Assert.AreEqual(c * -1, u.CompareTo(b), "Expected l compareTo u to be inverse of u compareTo l");
            c = b.CompareTo(v);
            Assert.AreEqual(c * -1, v.CompareTo(b), "Expected l compareTo v to be inverse of v compareTo l");

            c = l.CompareTo(b);
            Assert.AreEqual(c * -1, b.CompareTo(l), "Expected b compareTo l to be inverse of l compareTo b");
            c = l.CompareTo(u);
            Assert.AreEqual(c * -1, u.CompareTo(l), "Expected u compareTo l to be inverse of l compareTo u");
            c = l.CompareTo(v);
            Assert.AreEqual(c * -1, v.CompareTo(l), "Expected v compareTo l to be inverse of l compareTo v");

            c = u.CompareTo(b);
            Assert.AreEqual(c * -1, b.CompareTo(u), "Expected b compareTo u to be inverse of u compareTo b");
            c = u.CompareTo(l);
            Assert.AreEqual(c * -1, l.CompareTo(u), "Expected l compareTo u to be inverse of u compareTo l");
            c = u.CompareTo(v);
            Assert.AreEqual(c * -1, v.CompareTo(u), "Expected v compareTo u to be inverse of u compareTo v");

            c = v.CompareTo(b);
            Assert.AreEqual(c * -1, b.CompareTo(v), "Expected b compareTo v to be inverse of v compareTo b");
            c = v.CompareTo(l);
            Assert.AreEqual(c * -1, l.CompareTo(v), "Expected l compareTo v to be inverse of v compareTo l");
            c = v.CompareTo(u);
            Assert.AreEqual(c * -1, u.CompareTo(v), "Expected u compareTo v to be inverse of v compareTo u");
        }
Exemplo n.º 37
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;
        }
Exemplo n.º 38
0
        public void IndexingTriplesInBinaryTree2()
        {
            Graph        g         = new Graph();
            ILiteralNode canonical = (1).ToLiteral(g);
            ILiteralNode alternate = g.CreateLiteralNode("01", UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeInteger));
            Triple       a         = new Triple(g.CreateVariableNode("s"), g.CreateVariableNode("p"), canonical);
            Triple       b         = new Triple(g.CreateVariableNode("s"), g.CreateVariableNode("p"), alternate);

            AVLTree <Triple, int> tree = new AVLTree <Triple, int>(new FullTripleComparer(new FastNodeComparer()));

            tree.Add(a, 1);
            Assert.Equal(1, tree[a]);
            tree.Add(b, 2);

            //With the FastNodeComparer the keys are non-equal so should
            //create separate key value pairs in the tree
            Assert.Equal(2, tree[b]);
            Assert.Equal(1, tree[a]);
            Assert.NotEqual(2, tree[a]);

            //With the FastNodeComparer there should be 2 keys in the tree
            //because the keys are not considered equal
            Assert.Equal(2, tree.Keys.Count());
        }
Exemplo n.º 39
0
        public void NodeCompareToMixedNodes3()
        {
            Graph g = new Graph();
            Graph h = new Graph();

            IBlankNode   b     = g.CreateBlankNode();
            ILiteralNode plain = g.CreateLiteralNode("plain");
            IUriNode     u     = g.CreateUriNode("rdf:type");
            List <INode> nodes = new List <INode>()
            {
                b,
                g.CreateBlankNode(),
                g.CreateBlankNode("id"),
                g.CreateLiteralNode("1.2e3", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                g.CreateLiteralNode("1.2", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                g.CreateLiteralNode("1.2e1", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                g.CreateLiteralNode("10", new Uri(XmlSpecsHelper.XmlSchemaDataTypeShort)),
                g.CreateLiteralNode("-3", new Uri(XmlSpecsHelper.XmlSchemaDataTypeShort)),
                g.CreateLiteralNode("1.2E4", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                g.CreateLiteralNode("http://example.org:8080", new Uri(XmlSpecsHelper.XmlSchemaDataTypeAnyUri)),
                g.CreateLiteralNode("http://example.org/path", new Uri(XmlSpecsHelper.XmlSchemaDataTypeAnyUri)),
                g.CreateLiteralNode("ftp://ftp.example.org", new Uri(XmlSpecsHelper.XmlSchemaDataTypeAnyUri)),
                g.CreateLiteralNode("1.2e0", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                DateTime.Now.ToLiteral(g),
                DateTime.Now.AddYears(3).AddDays(1).ToLiteral(g),
                DateTime.Now.AddYears(-25).AddMinutes(-17).ToLiteral(g),
                g.CreateLiteralNode("1.2e-1", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                g.CreateLiteralNode("10", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                g.CreateLiteralNode("10e14", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                h.CreateBlankNode(),
                h.CreateBlankNode("id"),
                b,
                plain,
                g.CreateLiteralNode("plain english", "en"),
                g.CreateLiteralNode("1", new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger)),
                g.CreateLiteralNode("10", new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger)),
                g.CreateLiteralNode("plain french", "fr"),
                g.CreateLiteralNode("typed", new Uri(XmlSpecsHelper.XmlSchemaDataTypeString)),
                (1234).ToLiteral(g),
                (12.34m).ToLiteral(g),
                (12.34d).ToLiteral(g),
                (false).ToLiteral(g),
                g.CreateLiteralNode((1).ToString("X2"), new Uri(XmlSpecsHelper.XmlSchemaDataTypeHexBinary)),
                g.CreateLiteralNode((10).ToString("X2"), new Uri(XmlSpecsHelper.XmlSchemaDataTypeHexBinary)),
                (true).ToLiteral(g),
                plain,
                u,
                g.CreateUriNode(new Uri("http://example.org")),
                g.CreateUriNode(new Uri("http://example.org:8080")),
                g.CreateLiteralNode("1", new Uri(XmlSpecsHelper.XmlSchemaDataTypeByte)),
                g.CreateLiteralNode("10", new Uri(XmlSpecsHelper.XmlSchemaDataTypeByte)),
                g.CreateLiteralNode("-3", new Uri(XmlSpecsHelper.XmlSchemaDataTypeByte)),
                g.CreateUriNode(new Uri("http://www.dotnetrdf.org")),
                g.CreateUriNode(new Uri("http://www.dotnetrdf.org/configuration#")),
                g.CreateUriNode(new Uri("http://www.dotnetrdf.org/Configuration#")),
                g.CreateUriNode(new Uri("mailto:[email protected]")),
                u
            };

            this.ShowOrdering(nodes);

            this.CheckCombinations(nodes);
        }
Exemplo n.º 40
0
        public static void Main(string[] args)
        {
            StreamWriter output = new StreamWriter("HashCodeTests.txt");
            Console.SetOut(output);

            try
            {
                Console.WriteLine("## Hash Code Tests");
                Console.WriteLine("Tests that Literal and URI Nodes produce different Hashes");
                Console.WriteLine();

                //Create the Nodes
                Graph g = new Graph();
                IUriNode u = g.CreateUriNode(new Uri("http://www.google.com"));
                ILiteralNode l = g.CreateLiteralNode("http://www.google.com/");

                Console.WriteLine("Created a URI and Literal Node both referring to 'http://www.google.com'");
                Console.WriteLine("String form of URI Node is:");
                Console.WriteLine(u.ToString());
                Console.WriteLine("String form of Literal Node is:");
                Console.WriteLine(l.ToString());
                Console.WriteLine("Hash Code of URI Node is " + u.GetHashCode());
                Console.WriteLine("Hash Code of Literal Node is " + l.GetHashCode());
                Console.WriteLine("Hash Codes are Equal? " + u.GetHashCode().Equals(l.GetHashCode()));
                Console.WriteLine("Nodes are equal? " + u.Equals(l));

                //Create Triples
                IBlankNode b = g.CreateBlankNode();
                IUriNode type = g.CreateUriNode("rdf:type");
                Triple t1, t2;
                t1 = new Triple(b, type, u);
                t2 = new Triple(b, type, l);

                Console.WriteLine();
                Console.WriteLine("Created two Triples stating a Blank Node has rdf:type of the Nodes created earlier");
                Console.WriteLine("String form of Triple 1 (using URI Node) is:");
                Console.WriteLine(t1.ToString());
                Console.WriteLine("String form of Triple 2 (using Literal Node) is:");
                Console.WriteLine(t2.ToString());
                Console.WriteLine("Hash Code of Triple 1 is " + t1.GetHashCode());
                Console.WriteLine("Hash Code of Triple 2 is " + t2.GetHashCode());
                Console.WriteLine("Hash Codes are Equal? " + t1.GetHashCode().Equals(t2.GetHashCode()));
                Console.WriteLine("Triples are Equal? " + t1.Equals(t2));

                //Now going to look at the Hash Code collisions from the dotNetRDF Store
                Console.WriteLine();
                Console.WriteLine("Examing the Hash Code Collisions from one of our SQL Store test data sets");

//                MicrosoftSqlStoreManager manager = new MicrosoftSqlStoreManager("localhost", "bbcone", "example", "password");
//                DataTable collisions = manager.ExecuteQuery(@"SELECT * FROM TRIPLES WHERE tripleHash IN 
//	(
//	SELECT tripleHash FROM TRIPLES GROUP BY tripleHash HAVING COUNT(tripleID)>1
//	) ORDER BY tripleHash");

//                foreach (DataRow r in collisions.Rows)
//                {
//                    String s, p, o;
//                    int hash;
//                    s = r["tripleSubject"].ToString();
//                    p = r["triplePredicate"].ToString();
//                    o = r["tripleObject"].ToString();
//                    hash = Int32.Parse(r["tripleHash"].ToString());

//                    INode subj = manager.LoadNode(g, s);
//                    INode pred = manager.LoadNode(g, p);
//                    INode obj = manager.LoadNode(g, o);

//                    Triple t = new Triple(subj, pred, obj);

//                    Console.WriteLine("Subject (ID " + s + "): " + subj.ToString() + " (Hash " + subj.GetHashCode() + ")");
//                    Console.WriteLine("Predicate (ID " + p + "): " + pred.ToString() + " (Hash " + pred.GetHashCode() + ")");
//                    Console.WriteLine("Object (ID " + o + "): " + obj.ToString() + " (Hash " + obj.GetHashCode() + ")");
//                    Console.WriteLine(t.ToString());
//                    Console.WriteLine("Triple Hash " + t.GetHashCode());
//                    Console.WriteLine("Triple Hash Code Construct " + subj.GetHashCode().ToString() + pred.GetHashCode().ToString() + obj.GetHashCode().ToString());
//                    Console.WriteLine("Triple Hash in Store " + hash);
//                    Console.WriteLine();
//                }

//                manager.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                output.Close();
            }
        }
        public override IGraph CreatePageContent(CatalogContext context)
        {
            Uri resourceUri = new Uri(GetBaseAddress() + GetRelativeAddress());
                        
            Graph graph = new Graph();

            INode subject = graph.CreateUriNode(resourceUri);
                        
            INode idPredicate = graph.CreateUriNode(Schema.Predicates.Id);
            INode versionPredicate = graph.CreateUriNode(Schema.Predicates.Version);

            if (_id != null)
            {
                graph.Assert(subject, idPredicate, graph.CreateLiteralNode(_id));
            }

            if (_version != null)
            {
                graph.Assert(subject, versionPredicate, graph.CreateLiteralNode(_version));
            }

            return graph;
        }
        static IGraph CreatePageSummary(Uri newPageUri, string lower, string upper)
        {
            IGraph graph = new Graph();

            INode resourceUri = graph.CreateUriNode(newPageUri);

            graph.Assert(resourceUri, graph.CreateUriNode(Schema.Predicates.Lower), graph.CreateLiteralNode(lower));
            graph.Assert(resourceUri, graph.CreateUriNode(Schema.Predicates.Upper), graph.CreateLiteralNode(upper));

            return graph;
        }
Exemplo n.º 43
0
        public void NodeCompareToLiteralNodesXsdFloats()
        {
            Graph g = new Graph();

            List <INode> nodes = new List <INode>()
            {
                g.CreateLiteralNode("something", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                g.CreateLiteralNode("thing", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                g.CreateLiteralNode("1.2e4", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                g.CreateLiteralNode("1.2e3", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                g.CreateLiteralNode("1.2", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                g.CreateLiteralNode("1.2e1", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                g.CreateLiteralNode("1.2E4", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                g.CreateLiteralNode("1.2e0", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                g.CreateLiteralNode("1.2e-1", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                g.CreateLiteralNode("10", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                g.CreateLiteralNode("10e14", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
                g.CreateLiteralNode("-3", new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat)),
            };

            this.ShowOrdering(nodes);

            this.CheckCombinations(nodes);
            this.CheckCombinations <ILiteralNode>(nodes.OfType <ILiteralNode>().ToList());
            this.CheckCombinations <LiteralNode>(nodes.OfType <LiteralNode>().ToList());
        }
Exemplo n.º 44
0
        public void NodeCompareToLiteralNodesXsdUris()
        {
            Graph g = new Graph();

            List <INode> nodes = new List <INode>()
            {
                g.CreateLiteralNode("something", new Uri(XmlSpecsHelper.XmlSchemaDataTypeAnyUri)),
                g.CreateLiteralNode("thing", new Uri(XmlSpecsHelper.XmlSchemaDataTypeAnyUri)),
                g.CreateLiteralNode("1", new Uri(XmlSpecsHelper.XmlSchemaDataTypeAnyUri)),
                g.CreateLiteralNode("http://example.org", new Uri(XmlSpecsHelper.XmlSchemaDataTypeAnyUri)),
                g.CreateLiteralNode("http://example.org:8080", new Uri(XmlSpecsHelper.XmlSchemaDataTypeAnyUri)),
                g.CreateLiteralNode("http://example.org/path", new Uri(XmlSpecsHelper.XmlSchemaDataTypeAnyUri)),
                g.CreateLiteralNode("ftp://ftp.example.org", new Uri(XmlSpecsHelper.XmlSchemaDataTypeAnyUri)),
                g.CreateLiteralNode("mailto:[email protected]", new Uri(XmlSpecsHelper.XmlSchemaDataTypeAnyUri)),
                g.CreateLiteralNode("ex:custom", new Uri(XmlSpecsHelper.XmlSchemaDataTypeAnyUri)),
                g.CreateLiteralNode("10", new Uri(XmlSpecsHelper.XmlSchemaDataTypeAnyUri)),
                g.CreateLiteralNode("-3", new Uri(XmlSpecsHelper.XmlSchemaDataTypeAnyUri)),
            };

            this.ShowOrdering(nodes);

            this.CheckCombinations(nodes);
            this.CheckCombinations <ILiteralNode>(nodes.OfType <ILiteralNode>().ToList());
            this.CheckCombinations <LiteralNode>(nodes.OfType <LiteralNode>().ToList());
        }
 static IGraph CreateExtraGraph(Uri pageUri, string lower, string upper)
 {
     IGraph graph = new Graph();
     INode resourceNode = graph.CreateUriNode(pageUri);
     graph.Assert(resourceNode, graph.CreateUriNode(Schema.Predicates.Lower), graph.CreateLiteralNode(lower));
     graph.Assert(resourceNode, graph.CreateUriNode(Schema.Predicates.Upper), graph.CreateLiteralNode(upper));
     return graph;
 }
Exemplo n.º 46
0
        public static Graph Json2Graph(JObject json)
        {
            Graph graph = new Graph();

            foreach (JProperty subjectProperty in json.Properties())
            {
                INode subjectNode = graph.CreateUriNode(new Uri(subjectProperty.Name));

                foreach (JProperty predicateProperty in ((JObject)subjectProperty.Value).Properties())
                {
                    INode predicateNode = graph.CreateUriNode(new Uri(predicateProperty.Name));

                    foreach (JObject objectObject in (JArray)predicateProperty.Value)
                    {
                        JToken t;
                        if (!objectObject.TryGetValue("type", out t))
                        {
                            throw new FormatException(string.Format("type is required on {0}, {1}", subjectProperty.Name, predicateProperty.Name));
                        }

                        JToken v;
                        if (!objectObject.TryGetValue("value", out v))
                        {
                            throw new FormatException(string.Format("value is required on {0}, {1}", subjectProperty.Name, predicateProperty.Name));
                        }

                        string type = t.ToString();

                        INode objectNode;

                        switch (type)
                        {
                            case "uri":
                                objectNode = graph.CreateUriNode(new Uri(v.ToString()));
                                break;

                            case "literal":

                                JToken l;
                                if (objectObject.TryGetValue("lang", out l))
                                {
                                    objectNode = graph.CreateLiteralNode(v.ToString(), l.ToString());
                                }
                                else
                                {
                                    JToken d;
                                    if (objectObject.TryGetValue("datatype", out d))
                                    {
                                        objectNode = graph.CreateLiteralNode(v.ToString(), new Uri(d.ToString()));
                                    }
                                    else
                                    {
                                        objectNode = graph.CreateLiteralNode(v.ToString());
                                    }
                                }

                                break;

                            case "bnode":
                                throw new NotImplementedException("blank nodes");

                            default:
                                throw new FormatException(string.Format("type should be uri|literal|bnode on {0}, {1}", subjectProperty.Name, predicateProperty.Name));
                        }

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

            return graph;
        }
Exemplo n.º 47
0
        public void NodesHashCodes()
        {
            Console.WriteLine("Tests that Literal and URI Nodes produce different Hashes");
            Console.WriteLine();

            //Create the Nodes
            Graph        g = new Graph();
            IUriNode     u = g.CreateUriNode(new Uri("http://www.google.com"));
            ILiteralNode l = g.CreateLiteralNode("http://www.google.com/");

            Console.WriteLine("Created a URI and Literal Node both referring to 'http://www.google.com'");
            Console.WriteLine("String form of URI Node is:");
            Console.WriteLine(u.ToString());
            Console.WriteLine("String form of Literal Node is:");
            Console.WriteLine(l.ToString());
            Console.WriteLine("Hash Code of URI Node is " + u.GetHashCode());
            Console.WriteLine("Hash Code of Literal Node is " + l.GetHashCode());
            Console.WriteLine("Hash Codes are Equal? " + u.GetHashCode().Equals(l.GetHashCode()));
            Console.WriteLine("Nodes are equal? " + u.Equals(l));

            Assert.NotEqual(u.GetHashCode(), l.GetHashCode());
            Assert.NotSame(u, l);
            //Assert.NotEqual(u, l);

            //Create some plain and typed literals which may have colliding Hash Codes
            ILiteralNode plain = g.CreateLiteralNode("test^^http://example.org/type");
            ILiteralNode typed = g.CreateLiteralNode("test", new Uri("http://example.org/type"));

            Console.WriteLine();
            Console.WriteLine("Created a Plain and Typed Literal where the String representations are identical");
            Console.WriteLine("Plain Literal String form is:");
            Console.WriteLine(plain.ToString());
            Console.WriteLine("Typed Literal String from is:");
            Console.WriteLine(typed.ToString());
            Console.WriteLine("Hash Code of Plain Literal is " + plain.GetHashCode());
            Console.WriteLine("Hash Code of Typed Literal is " + typed.GetHashCode());
            Console.WriteLine("Hash Codes are Equal? " + plain.GetHashCode().Equals(typed.GetHashCode()));
            Console.WriteLine("Nodes are equal? " + plain.Equals(typed));

            Assert.NotEqual(plain.GetHashCode(), typed.GetHashCode());
            Assert.NotEqual(plain, typed);

            //Create Triples
            IBlankNode b = g.CreateBlankNode();
            IUriNode   type = g.CreateUriNode("rdf:type");
            Triple     t1, t2;

            t1 = new Triple(b, type, u);
            t2 = new Triple(b, type, l);

            Console.WriteLine();
            Console.WriteLine("Created two Triples stating a Blank Node has rdf:type of the URI Nodes created earlier");
            Console.WriteLine("String form of Triple 1 (using URI Node) is:");
            Console.WriteLine(t1.ToString());
            Console.WriteLine("String form of Triple 2 (using Literal Node) is:");
            Console.WriteLine(t2.ToString());
            Console.WriteLine("Hash Code of Triple 1 is " + t1.GetHashCode());
            Console.WriteLine("Hash Code of Triple 2 is " + t2.GetHashCode());
            Console.WriteLine("Hash Codes are Equal? " + t1.GetHashCode().Equals(t2.GetHashCode()));
            Console.WriteLine("Triples are Equal? " + t1.Equals(t2));

            Assert.NotEqual(t1.GetHashCode(), t2.GetHashCode());
            Assert.NotEqual(t1, t2);

            //Create Triples from the earlier Literal Nodes
            t1 = new Triple(b, type, plain);
            t2 = new Triple(b, type, typed);

            Console.WriteLine();
            Console.WriteLine("Created two Triples stating a Blank Node has rdf:type of the Literal Nodes created earlier");
            Console.WriteLine("String form of Triple 1 (using Plain Literal) is:");
            Console.WriteLine(t1.ToString());
            Console.WriteLine("String form of Triple 2 (using Typed Literal) is:");
            Console.WriteLine(t2.ToString());
            Console.WriteLine("Hash Code of Triple 1 is " + t1.GetHashCode());
            Console.WriteLine("Hash Code of Triple 2 is " + t2.GetHashCode());
            Console.WriteLine("Hash Codes are Equal? " + t1.GetHashCode().Equals(t2.GetHashCode()));
            Console.WriteLine("Triples are Equal? " + t1.Equals(t2));

            Assert.NotEqual(t1.GetHashCode(), t2.GetHashCode());
            Assert.NotEqual(t1, t2);
        }
Exemplo n.º 48
0
        public void NodesLiteralNodeEquality()
        {
            try
            {
                Graph g = new Graph();

                //Strict Mode Tests
                Console.WriteLine("Doing a load of Strict Literal Equality Tests");
                Options.LiteralEqualityMode = LiteralEqualityMode.Strict;

                //Test Literals with Language Tags
                ILiteralNode hello, helloEn, helloEnUS, helloAgain;
                hello      = g.CreateLiteralNode("hello");
                helloEn    = g.CreateLiteralNode("hello", "en");
                helloEnUS  = g.CreateLiteralNode("hello", "en-US");
                helloAgain = g.CreateLiteralNode("hello");

                Assert.NotEqual(hello, helloEn);
                Assert.NotEqual(hello, helloEnUS);
                Assert.NotEqual(helloEn, helloEnUS);
                Assert.NotEqual(helloEn, helloAgain);
                Assert.NotEqual(helloEnUS, helloAgain);

                Assert.Equal(hello, helloAgain);

                //Test Plain Literals
                ILiteralNode plain1, plain2, plain3, plain4;
                plain1 = g.CreateLiteralNode("plain literal");
                plain2 = g.CreateLiteralNode("another plain literal");
                plain3 = g.CreateLiteralNode("Plain Literal");
                plain4 = g.CreateLiteralNode("plain literal");

                Assert.NotEqual(plain1, plain2);
                Assert.NotEqual(plain1, plain3);
                Assert.Equal(plain1, plain4);
                Assert.NotEqual(plain2, plain3);
                Assert.NotEqual(plain2, plain4);
                Assert.NotEqual(plain3, plain4);

                //Typed Literals
                Uri intType  = new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger);
                Uri boolType = new Uri(XmlSpecsHelper.XmlSchemaDataTypeBoolean);

                ILiteralNode one1, one2, one3, one4;
                one1 = g.CreateLiteralNode("1");
                one2 = g.CreateLiteralNode("1", intType);
                one3 = g.CreateLiteralNode("0001", intType);
                one4 = g.CreateLiteralNode("1", intType);

                Assert.NotEqual(one1, one2);
                Assert.NotEqual(one1, one3);
                Assert.NotEqual(one1, one4);
                Assert.NotEqual(one2, one3);
                Assert.Equal(one2, one4);
                Assert.NotEqual(one3, one4);

                Assert.NotEqual(0, one1.CompareTo(one2));
                Assert.Equal(0, one2.CompareTo(one3));
                Assert.Equal(0, one3.CompareTo(one2));
                Assert.Equal(0, one3.CompareTo(one4));

                ILiteralNode t, f, one5;
                t    = g.CreateLiteralNode("true", boolType);
                f    = g.CreateLiteralNode("false", boolType);
                one5 = g.CreateLiteralNode("1", boolType);

                Assert.NotEqual(t, f);
                Assert.Equal(t, t);
                Assert.Equal(f, f);

                Assert.NotEqual(t, one5);

                //Loose Mode Tests
                Console.WriteLine("Doing a load of Loose Equality Tests");
                Options.LiteralEqualityMode = LiteralEqualityMode.Loose;

                Assert.Equal(one2, one3);
                Assert.Equal(one3, one4);
                Assert.NotEqual(t, one5);
            }
            catch (Exception ex)
            {
                //Reset Literal Equality Mode
                Options.LiteralEqualityMode = LiteralEqualityMode.Strict;

                throw;
            }
            finally
            {
                //Reset Literal Equality Mode
                Options.LiteralEqualityMode = LiteralEqualityMode.Strict;
            }
        }
Exemplo n.º 49
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);
            }
        }
Exemplo n.º 50
0
        public void NodesSortingSparqlOrder()
        {
            SparqlOrderingComparer comparer = new SparqlOrderingComparer();

            //Stream for Output
            Console.WriteLine("## Sorting Test");
            Console.WriteLine("NULLs < Blank Nodes < URI Nodes < Untyped Literals < Typed Literals");
            Console.WriteLine();

            //Create a Graph
            Graph g = new Graph();

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

            //Create a list of various Nodes
            List <INode> nodes = new List <INode>();

            nodes.Add(g.CreateUriNode(":someUri"));
            nodes.Add(g.CreateBlankNode());
            nodes.Add(null);
            nodes.Add(g.CreateBlankNode());
            nodes.Add(g.CreateLiteralNode("cheese"));
            nodes.Add(g.CreateLiteralNode("aardvark"));
            nodes.Add(g.CreateLiteralNode(DateTime.Now.AddDays(-25).ToString(XmlSpecsHelper.XmlSchemaDateTimeFormat), new Uri(XmlSpecsHelper.XmlSchemaDataTypeDateTime)));
            nodes.Add(g.CreateLiteralNode("duck"));
            nodes.Add(g.CreateUriNode(":otherUri"));
            nodes.Add(g.CreateLiteralNode("1.5", new Uri(XmlSpecsHelper.XmlSchemaDataTypeDouble)));
            nodes.Add(g.CreateUriNode(new Uri("http://www.google.com")));
            nodes.Add(g.CreateLiteralNode(DateTime.Now.AddYears(3).ToString(XmlSpecsHelper.XmlSchemaDateTimeFormat), new Uri(XmlSpecsHelper.XmlSchemaDataTypeDateTime)));
            nodes.Add(g.CreateLiteralNode("23", new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger)));
            nodes.Add(g.CreateLiteralNode("M43d", new Uri(XmlSpecsHelper.XmlSchemaDataTypeBase64Binary)));
            nodes.Add(g.CreateUriNode(new Uri("http://www.dotnetrdf.org")));
            nodes.Add(g.CreateLiteralNode("12", new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger)));
            nodes.Add(g.CreateBlankNode("monkey"));
            nodes.Add(g.CreateBlankNode());
            nodes.Add(g.CreateLiteralNode("chaese"));
            nodes.Add(g.CreateLiteralNode("1.0456345", new Uri(XmlSpecsHelper.XmlSchemaDataTypeDouble)));
            nodes.Add(g.CreateLiteralNode("cheese"));
            nodes.Add(g.CreateLiteralNode(Convert.ToBase64String(new byte[] { Byte.Parse("32") }), new Uri(XmlSpecsHelper.XmlSchemaDataTypeBase64Binary)));
            nodes.Add(g.CreateLiteralNode("TA==", new Uri(XmlSpecsHelper.XmlSchemaDataTypeBase64Binary)));
            nodes.Add(g.CreateLiteralNode("-45454", new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger)));
            nodes.Add(g.CreateLiteralNode(DateTime.Now.ToString(XmlSpecsHelper.XmlSchemaDateTimeFormat), new Uri(XmlSpecsHelper.XmlSchemaDataTypeDateTime)));
            nodes.Add(g.CreateLiteralNode("-3", new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger)));
            nodes.Add(g.CreateLiteralNode("242344.3456435", new Uri(XmlSpecsHelper.XmlSchemaDataTypeDouble)));
            nodes.Add(g.CreateLiteralNode("true", new Uri(XmlSpecsHelper.XmlSchemaDataTypeBoolean)));
            nodes.Add(g.CreateUriNode(":what"));
            nodes.Add(null);
            nodes.Add(g.CreateLiteralNode("false", new Uri(XmlSpecsHelper.XmlSchemaDataTypeBoolean)));
            nodes.Add(g.CreateLiteralNode("invalid-value", new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger)));

            nodes.Sort(comparer);

            //Output the Results
            foreach (INode n in nodes)
            {
                if (n == null)
                {
                    Console.WriteLine("NULL");
                }
                else
                {
                    Console.WriteLine(n.ToString());
                }
            }

            Console.WriteLine();
            Console.WriteLine("Now in reverse...");
            Console.WriteLine();

            nodes.Reverse();

            //Output the Results
            foreach (INode n in nodes)
            {
                if (n == null)
                {
                    Console.WriteLine("NULL");
                }
                else
                {
                    Console.WriteLine(n.ToString());
                }
            }
        }