Пример #1
0
    public static void Main()
    {
        Store store = new MemoryStore();

        store.Import(RdfReader.LoadFromUri(new Uri(example_foaf_file)));

        // Dump out the data, for fun
        using (RdfWriter writer = new RdfXmlWriter(Console.Out)) {
            writer.Write(store);
        }

        Console.WriteLine("These are the people in the file:");
        foreach (Statement s in store.Select(new Statement(null, rdftype, foafPerson)))
        {
            foreach (Resource r in store.SelectObjects(s.Subject, foafname))
            {
                Console.WriteLine(r);
            }
        }
        Console.WriteLine();

        Console.WriteLine("And here's RDF/XML just for some of the file:");
        using (RdfWriter w = new RdfXmlWriter(Console.Out)) {
            store.Select(new Statement(null, foafname, null), w);
            store.Select(new Statement(null, foafknows, null), w);
        }
        Console.WriteLine();
    }
Пример #2
0
        public void Run(IComponentsConfig config, string targetFile)
        {
            var rdfStore = new MemoryStore();

            rdfStore.Add(new Statement(NS.CSO.classEntity, NS.Rdfs.subClassOf, NS.Rdfs.ClassEntity));
            rdfStore.Add(new Statement(NS.CSO.interfaceEntity, NS.Rdfs.subClassOf, NS.Rdfs.ClassEntity));

            var assemblyExtractor = new AssemblyMetadata();

            assemblyExtractor.Extract(System.Web.HttpRuntime.BinDirectory, rdfStore);

            var configExtractor = new WinterMetadata();
            var baseUri         = String.IsNullOrEmpty(BaseUri) ?
                                  "file:///" + System.Web.HttpRuntime.AppDomainAppPath.Replace('\\', '/') + "#" :
                                  BaseUri;

            configExtractor.BaseNs = baseUri;
            configExtractor.Extract(config, rdfStore);

            using (RdfXmlWriter wr = new RdfXmlWriter(targetFile)) {
                wr.BaseUri = NS.NrMeta;
                wr.Namespaces.AddNamespace(NS.DotNet.Type, "type");
                wr.Namespaces.AddNamespace(NS.DotNet.Property, "prop");
                wr.Namespaces.AddNamespace(NS.NrMetaTerms, "nr");
                wr.Write(rdfStore);
            }
        }
Пример #3
0
        private static void SaveResults(MemoryStore store, Path file)
        {
            using (var writer = new RdfXmlWriter(file.FullPath))
                writer.Write(store);

            Console.WriteLine("Wrote {0} statements.", store.StatementCount);
        }
Пример #4
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Count() == 3)
                {
                    string projectName     = args[0];
                    string applicationName = args[1];
                    string filePath        = args[2];

                    string tripleStoreconnectionString = ConfigurationManager.AppSettings["TripleStoreConnectionString"];
                    string scopeName = projectName + "_" + applicationName;
                    string scopedConnectionString = ScopeConnectionString(tripleStoreconnectionString, scopeName);

                    Dictionary <string, string> namespaceCollection = new Dictionary <string, string> {
                        { "xsd", "http://www.w3.org/2001/XMLSchema#" },
                        { "rdl", "http://rdl.rdlfacade.org/data#" },
                        { "tpl", "http://tpl.rdlfacade.org/data#" },
                        { "owl", "http://www.w3.org/2002/07/owl#" },
                        { "eg", "http://www.example.com/data#" },
                        { "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#" },
                    };

                    using (Store store = Store.Create(scopedConnectionString))
                    {
                        using (RdfXmlWriter rdfWriter = new RdfXmlWriter(filePath))
                        {
                            foreach (KeyValuePair <string, string> aliasURI in namespaceCollection)
                            {
                                rdfWriter.Namespaces.AddNamespace(aliasURI.Value, aliasURI.Key);
                            }

                            rdfWriter.Write(store);
                        }
                    }

                    Console.WriteLine("SemWeb triplestore was successfully dumped to RDF: " + filePath);
                }
                else
                {
                    PrintUsage();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while dumping the RDF from SemWeb: \n" + ex.ToString());
            }
        }
Пример #5
0
    public static void Main()
    {
        MemoryStore store = new MemoryStore();

        Entity computer    = new Entity("http://example.org/computer");
        Entity says        = "http://example.org/says";
        Entity wants       = "http://example.org/wants";
        Entity desire      = new BNode();
        Entity description = new Entity("http://example.org/description");

        store.Add(new Statement(computer, says, (Literal)"Hello world!"));
        store.Add(new Statement(computer, wants, desire));
        store.Add(new Statement(desire, description, (Literal)"to be human"));
        store.Add(new Statement(desire, RDF + "type", (Entity)"http://example.org/Desire"));

        using (RdfWriter writer = new RdfXmlWriter(Console.Out)) {
            writer.Namespaces.AddNamespace("http://example.org/", "ex");
            writer.Write(store);
        }
    }
Пример #6
0
        static void Main(string[] args)
        {
            var rdfStore = new MemoryStore();

            //rdfStore.Add(new Statement(NS.CSO.classEntity, NS.Rdfs.subClassOf, NS.Rdfs.ClassEntity));
            //rdfStore.Add(new Statement(NS.CSO.interfaceEntity, NS.Rdfs.subClassOf, NS.Rdfs.ClassEntity));

            var rdfsReasoner = new RDFS();

            rdfsReasoner.LoadSchema(rdfStore);
            rdfStore.AddReasoner(rdfsReasoner);

            /*using (var wr = new RdfXmlWriter(Console.Out)) {
             *      wr.BaseUri = NS.NrMeta;
             *      wr.Write(rdfStore);
             * }*/


            /*var r = rdfStore.Contains(new Statement(
             *      (Entity)(NS.NrDotNetType + "NReco.Operations.ChainOperationCall"),
             *      (Entity)NS.Rdfs.subClassOfEntity,
             *      (Entity)(NS.NrDotNetType + "NReco.Operations.OperationCall") )); //
             * Console.WriteLine(r.ToString());*/
            /*foreach (Statement s in rdfStore.Select(new Statement(
             *              (Entity)(NS.NrDotNetProp+"ContextFilter"),
             *              (Entity)NS.Rdfs.domainEntity,
             *              null))) { //Entity)(NS.NrDotNetType + "NReco.IProvider`2")
             *      Console.WriteLine(s.Object.Uri.ToString());
             * }*/
            /*Query query = new GraphMatch(new N3Reader(new StringReader(rdfQuery)));
             * QueryResultSink sink = new SparqlXmlQuerySink(Console.Out);
             * query.Run(rdfStore, sink); */

            using (RdfXmlWriter wr = new RdfXmlWriter(@"c:\temp\_1.rdf")) {
                //wr.BaseUri = NS.NrMeta;
                //wr.Namespaces.AddNamespace(NS.DotNet.Type, "t");
                //wr.Namespaces.AddNamespace(NS.DotNet.Property, "p");
                wr.Write(rdfStore);
            }
            Console.ReadKey();
        }
Пример #7
0
        public void InteropSemWebWriteVia()
        {
            Graph g = new Graph();

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

            MemoryStore mem = new MemoryStore();

            SemWebConverter.ToSemWeb(g, mem);

            RdfWriter writer = new RdfXmlWriter("semweb.rdf");

            writer.Write(mem);
            writer.Close();

            //Read the output graph back in to check for equality
            Graph h = new Graph();

            FileLoader.Load(h, "semweb.rdf");

            Assert.AreEqual(g, h, "Graphs should have been equal");
        }