当前位置: 首页>>代码示例>>C#>>正文


C# RDF.Graph类代码示例

本文整理汇总了C#中VDS.RDF.Graph的典型用法代码示例。如果您正苦于以下问题:C# Graph类的具体用法?C# Graph怎么用?C# Graph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Graph类属于VDS.RDF命名空间,在下文中一共展示了Graph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

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

    }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:25,代码来源:DocumentationHelloWorld.cs

示例2: TestCreateAssociationLinks

 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());
 }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:28,代码来源:ODataGeneratorTests.cs

示例3: Main

        public static void Main(String[] args)
        {
            try
            {
                String server = "localhost";
                Console.WriteLine("Enter Database Server: ");
                server = Console.ReadLine();
                if (server.Equals(String.Empty)) server = "localhost";
                String db = "bbcdemo";
                Console.WriteLine("Enter Database to check: ");
                db = Console.ReadLine();
                if (db.Equals(String.Empty)) db = "bbcdemo";

                Console.WriteLine("Checking Node Hash Codes for Database '" + db + "' on Server '" + server + "'");

                MicrosoftSqlStoreManager manager = new MicrosoftSqlStoreManager(server, db, "example", "password");

                DataTable nodeData = manager.ExecuteQuery("SELECT nodeID, nodeHash FROM NODES");
                Graph g = new Graph();

                int valid = 0;
                int invalid = 0;
                foreach (DataRow r in nodeData.Rows)
                {
                    INode n = manager.LoadNode(g, r["nodeID"].ToString());
                    int hash = Int32.Parse(r["nodeHash"].ToString());

                    if (hash == n.GetHashCode())
                    {
                        valid++;
                    }
                    else
                    {
                        invalid++;
                    }
                }

                manager.Dispose();

                Console.WriteLine(valid + " Nodes had Valid Hash Codes");
                Console.WriteLine(invalid + " Nodes had Invalid Hash Codes");

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                Exception innerEx = ex.InnerException;
                while (innerEx != null)
                {
                    Console.WriteLine();
                    Console.WriteLine(innerEx.Message);
                    Console.WriteLine(innerEx.StackTrace);
                    innerEx = innerEx.InnerException;
                }

                Console.ReadLine();
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:60,代码来源:StoreHashCodeChecker.cs

示例4: ProcessManifest

 private void ProcessManifest()
 {
     var baseGraph = new Graph();
     FileLoader.Load(baseGraph, ManifestFilePath);
     ProcessIncludes(baseGraph);
     ProcessEntries(baseGraph);
 }
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:7,代码来源:TestManifest.cs

示例5: ParsingN3Reasoner

        public void ParsingN3Reasoner()
        {
            String rules = "@prefix rdfs: <" + NamespaceMapper.RDFS + "> . { ?s rdfs:subClassOf ?class } => { ?s a ?class } .";

            Graph rulesGraph = new Graph();
            StringParser.Parse(rulesGraph, rules, new Notation3Parser());

            Graph data = new Graph();
            FileLoader.Load(data, "InferenceTest.ttl");

            Console.WriteLine("Original Graph - " + data.Triples.Count + " Triples");
            int origCount = data.Triples.Count;
            foreach (Triple t in data.Triples)
            {
                Console.WriteLine(t.ToString());
            }

            SimpleN3RulesReasoner reasoner = new SimpleN3RulesReasoner();
            reasoner.Initialise(rulesGraph);

            reasoner.Apply(data);

            Console.WriteLine("Graph after Reasoner application - " + data.Triples.Count + " Triples");
            foreach (Triple t in data.Triples)
            {
                Console.WriteLine(t.ToString());
            }

            Assert.IsTrue(data.Triples.Count > origCount, "Number of Triples should have increased after the reasoner was run");
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:30,代码来源:VariableNodeTests.cs

示例6: btnCadUser_Click

        private void btnCadUser_Click(object sender, EventArgs e)
        {
            Graph g = new Graph();
            UserContextModel ctx = new UserContextModel();
            SingletonStarDog dog = SingletonStarDog.getDbInstance();

            //ctx.userID = txtAlunoID.Text;
            //ctx.ComunidadeMoodle = txtAlunoComunidade.Text;
            HardwareModel device = new HardwareModel();
            //device.Device_ID = txtDeviceID.Text;
            //ctx.DeviceList.Add(device);

            OntoStudent obj = new OntoStudent(ctx, device);
            dog.GetDBConnection().Begin();
            obj.insertStudent(ref g);
            dog.GetDBConnection().SaveGraph(g);
               // obj.insertHasDevice(ref g);
            dog.GetDBConnection().SaveGraph(g);
            obj.insertComunidadeMoodle(ref g);
            dog.GetDBConnection().SaveGraph(g);
            dog.GetDBConnection().Commit();

            Ontology.Ontology.ListAllDevices(txtComunidades.Text);

            Ontology.Ontology onto2 = new Ontology.Ontology();
            onto2.ListAllUserDevice();
        }
开发者ID:mabech,项目名称:Projeto-Mestrado,代码行数:27,代码来源:Form_Test.cs

示例7: fclsGraphBrowser

        public fclsGraphBrowser()
        {
            InitializeComponent();

            //Connect to Virtuoso
            this._manager = new VirtuosoManager(Properties.Settings.Default.Server, Properties.Settings.Default.Port, VirtuosoQuadStoreDB, Properties.Settings.Default.Username, Properties.Settings.Default.Password);

            //Add some fake test data
            DataTable data = new DataTable();
            data.Columns.Add("Subject");
            data.Columns.Add("Predicate");
            data.Columns.Add("Object");
            data.Columns["Subject"].DataType = typeof(INode);
            data.Columns["Predicate"].DataType = typeof(INode);
            data.Columns["Object"].DataType = typeof(INode);

            Graph g = new Graph();
            DataRow row = data.NewRow();
            row["Subject"] = g.CreateUriNode(new Uri("http://example.org/subject"));
            row["Predicate"] = g.CreateUriNode(new Uri("http://example.org/predicate"));
            row["Object"] = g.CreateUriNode(new Uri("http://example.org/object"));
            data.Rows.Add(row);

            this.BindGraph(data);
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:25,代码来源:fclsGraphBrowser.cs

示例8: CreateCommitMetadata

        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;
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:28,代码来源:PackageCatalog.cs

示例9: MetadataSource

 public MetadataSource(Options opts)
 {
     if (!String.IsNullOrEmpty(opts.EndpointUri))
     {
         if (String.IsNullOrEmpty(opts.DefaultGraphUri))
         {
             this._processor = new RemoteQueryProcessor(new SparqlRemoteEndpoint(new Uri(opts.EndpointUri)));
         }
         else
         {
             this._processor = new RemoteQueryProcessor(new SparqlRemoteEndpoint(new Uri(opts.EndpointUri), opts.DefaultGraphUri));
         }
     }
     else if (!String.IsNullOrEmpty(opts.SourceFile))
     {
         TripleStore store = new TripleStore();
         Graph g = new Graph();
         FileLoader.Load(g, opts.SourceFile);
         store.Add(g);
         this._processor = new LeviathanQueryProcessor(store);
     }
     else
     {
         throw new Exception("Must specify an endpoint or a file to query");
     }
 }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:26,代码来源:MetadataSource.cs

示例10: CreateNuspecGraph

        public static IGraph CreateNuspecGraph(XDocument nuspec, string baseAddress)
        {
            nuspec = NormalizeNuspecNamespace(nuspec);

            XslCompiledTransform transform = CreateTransform("xslt.nuspec.xslt");

            XsltArgumentList arguments = new XsltArgumentList();
            arguments.AddParam("base", "", baseAddress + "packages/");
            arguments.AddParam("extension", "", ".json");

            arguments.AddExtensionObject("urn:helper", new XsltHelper());

            XDocument rdfxml = new XDocument();
            using (XmlWriter writer = rdfxml.CreateWriter())
            {
                transform.Transform(nuspec.CreateReader(), arguments, writer);
            }

            RdfXmlParser rdfXmlParser = new RdfXmlParser();
            XmlDocument doc = new XmlDocument();
            doc.Load(rdfxml.CreateReader());
            IGraph graph = new Graph();
            rdfXmlParser.Load(graph, doc);

            return graph;
        }
开发者ID:rvesse,项目名称:NuGet.Services.Metadata,代码行数:26,代码来源:Utils.cs

示例11: ImportData

		private void ImportData(string dataPath, string defaultGraphUri = null)
        {
            var g = new Graph();
            FileLoader.Load(g, dataPath);
            foreach (var t in g.Triples)
            {
                if (t.Object.NodeType == NodeType.Literal)
                {
                    var litNode = t.Object as LiteralNode;
                    _store.InsertTriple(
                        GetNodeString(t.Subject),
                        GetNodeString(t.Predicate),
                        litNode.Value,
                        true,
                        litNode.DataType == null ? null : litNode.DataType.ToString(),
                        litNode.Language,
                        defaultGraphUri ?? Constants.DefaultGraphUri
                        );
                }
                else
                {
                    _store.InsertTriple(
                        GetNodeString(t.Subject),
                        GetNodeString(t.Predicate),
                        GetNodeString(t.Object),
                        false,
                        null,
                        null,
                        defaultGraphUri ?? Constants.DefaultGraphUri
                        );
                }
            }
            _store.Commit(Guid.Empty);
        }
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:34,代码来源:ManifestSyntax.cs

示例12: ReplaceResourceUris

        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;
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:34,代码来源:GraphSplitting.cs

示例13: WritingBlankNodeOutput

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

        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:32,代码来源:WriterTests.cs

示例14: RunVocab

        public void RunVocab(String[] args)
        {
            if (args.Length < 2)
            {
                Console.Error.WriteLine("rdfWebDeploy: Error: 2 Arguments are required in order to use the -vocab mode");
                return;
            }

            if (File.Exists(args[1]))
            {
                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot output the configuration vocabulary to " + args[1] + " as a file already exists at that location");
                return;
            }

            TurtleParser ttlparser = new TurtleParser();
            StreamReader reader = new StreamReader(Assembly.GetAssembly(typeof(IGraph)).GetManifestResourceStream("VDS.RDF.Configuration.configuration.ttl"));
            Graph g = new Graph();
            ttlparser.Load(g, reader);

            IRdfWriter writer;
            try
            {
                writer = MimeTypesHelper.GetWriter(MimeTypesHelper.GetMimeType(Path.GetExtension(args[1])));
            }
            catch (RdfWriterSelectionException)
            {
                writer = new CompressingTurtleWriter(WriterCompressionLevel.High);
            }
            writer.Save(g, args[1]);
            Console.WriteLine("rdfWebDeploy: Configuration Vocabulary output to " + args[1]);
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:31,代码来源:Vocab.cs

示例15: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            String uri = context.Request.QueryString["uri"];
            if (uri == null)
            {
                context.Response.Write("Bad request");
            }
            else
            {
                //Load the Graph from that URI
                Graph g = new Graph();
                try
                {
                    UriLoader.Load(g, new Uri(uri));
                }
                catch (Exception)
                {
                    //Supress the exception
                    //TODO: Show an error message to the end user
                }

                //Write out as a HTML page
                HtmlWriter writer = new HtmlWriter();
                writer.Stylesheet = "../sparql.css";
                writer.UriPrefix = "?uri=";

                context.Response.ContentType = "text/html";
                writer.Save(g, context.Response.Output);
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:30,代码来源:BrowserHandler.cs


注:本文中的VDS.RDF.Graph类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。