Exemple #1
0
    public static void Main()
    {
        // Create the instance data

        MemoryStore dataModel = new MemoryStore();

        BNode me  = new BNode("me");
        BNode you = new BNode("you");

        Entity rdfType    = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
        Entity rdfsLabel  = "http://www.w3.org/2000/01/rdf-schema#label";
        Entity foafPerson = "http://xmlns.com/foaf/0.1/Person";
        Entity foafAgent  = "http://xmlns.com/foaf/0.1/Agent";
        Entity foafName   = "http://xmlns.com/foaf/0.1/name";

        dataModel.Add(new Statement(me, rdfType, foafPerson));
        dataModel.Add(new Statement(you, rdfType, foafPerson));
        dataModel.Add(new Statement(me, foafName, (Literal)"John Doe"));
        dataModel.Add(new Statement(you, foafName, (Literal)"Sam Smith"));

        // Create the RDFS engine and apply it to the data model.

        RDFS engine = new RDFS();

        engine.LoadSchema(RdfReader.LoadFromUri(new Uri("http://xmlns.com/foaf/0.1/index.rdf")));

        dataModel.AddReasoner(engine);

        // Query the data model

        // Ask for who are typed as Agents.  Note that the people are
        // typed as foaf:Person, and the schema asserts that foaf:Person
        // is a subclass of foaf:Agent.
        Console.WriteLine("Who are Agents?");
        foreach (Entity r in dataModel.SelectSubjects(rdfType, foafAgent))
        {
            Console.WriteLine("\t" + r);
        }

        // Ask for the rdfs:labels of everyone.  Note that the data model
        // has foaf:names for the people, and the schema asserts that
        // foaf:name is a subproperty of rdfs:label.
        Console.WriteLine("People's labels:");
        foreach (Statement s in dataModel.Select(new Statement(null, rdfsLabel, null)))
        {
            Console.WriteLine("\t" + s);
        }
    }
Exemple #2
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();
        }