Пример #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);
    }
Пример #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();
        }
Пример #3
0
 public ArtifactStore(string storeLocation)
 {
     string ontology = "";
     string data = "";
     store = new MemoryStore();
     ontology = Read(Constants.OntologyUri);
     store.AddReasoner(new Euler(new N3Reader(new StringReader(ontology))));
     if (File.Exists(storeLocation))
     {
         switch (GetStoreFormat(storeLocation))
         {
             case StoreFormat.N3:
                 data = File.ReadAllText(storeLocation);
                 N3Reader reader = new N3Reader(new StringReader(data));
                 store.Import(reader);
                 break;
             case StoreFormat.RDF:
                 data = File.ReadAllText(storeLocation);
                 store.Import(new RdfXmlReader(new StringReader(data)));
                 break;
         }
     }
 }
Пример #4
0
    public static void Main()
    {
        // Create the instance data

        MemoryStore dataModel = new MemoryStore();

        BNode paris = new BNode("paris");
        BNode orleans = new BNode("orleans");
        BNode chartres = new BNode("chartres");
        BNode amiens = new BNode("amiens");
        BNode blois = new BNode("blois");
        BNode bourges = new BNode("bourges");
        BNode tours = new BNode("tours");
        BNode lemans = new BNode("lemans");
        BNode angers = new BNode("angers");
        BNode nantes = new BNode("nantes");

        Entity oneway = new Entity("http://www.agfa.com/w3c/euler/graph.axiom#oneway");
        Entity path = new Entity("http://www.agfa.com/w3c/euler/graph.axiom#path");

        dataModel.Add(new Statement(paris, oneway, orleans));
        dataModel.Add(new Statement(paris, oneway, chartres));
        dataModel.Add(new Statement(paris, oneway, amiens));
        dataModel.Add(new Statement(orleans, oneway, blois));
        dataModel.Add(new Statement(orleans, oneway, bourges));
        dataModel.Add(new Statement(blois, oneway, tours));
        dataModel.Add(new Statement(chartres, oneway, lemans));
        dataModel.Add(new Statement(lemans, oneway, angers));
        dataModel.Add(new Statement(lemans, oneway, tours));
        dataModel.Add(new Statement(angers, oneway, nantes));

        // Create the inference rules by reading them from a N3 string.

        string rules =
            "@prefix : <http://www.agfa.com/w3c/euler/graph.axiom#>.\n" +
            "\n" +
            "{ ?a :oneway ?b } => { ?a :path ?b } .\n" +
            "{ ?a :path ?b . ?b :path ?c . } => { ?a :path ?c } .\n";

        // Create our question in the form of a statement to test.

        Statement question = new Statement(paris, path, nantes);

        // Create the Euler engine

        Euler engine = new Euler(new N3Reader(new StringReader(rules)));

        // First Method of Inference:
        // Ask the engine whether there is a path from paris to nantes.
        // The Prove method will return a list of proofs, or an empty
        // array if it could not find a proof.

        foreach (Proof p in engine.Prove(dataModel, new Statement[] { question })) {
            Console.WriteLine(p.ToString());
        }

        // Second Method of Inference:
        // Apply the engine to the data model and then use the data
        // model's Contains method to see if the statement is "in"
        // the model + reasoning.

        dataModel.AddReasoner(engine);

        Console.WriteLine("Euler Says the Question is: " + dataModel.Contains(question));
    }
 //
 internal TripleStore CreateSparqlTripleStore()
 {
     string tasksOntology = Path.Combine(Settings.Default.taskStorePath, Settings.Default.tasksOntologyName);
     string tasks = Path.Combine(Settings.Default.taskStorePath, Settings.Default.tasksDataName);
     MemoryStore store = new MemoryStore();
     store.AddReasoner(new Euler(new N3Reader(tasksOntology)));
     //store.Import(new N3Reader(tasksOntology));
     store.Import(new N3Reader(tasks));
     return new TripleStore(store);
 }
Пример #6
0
 public void InitialiseStore(string storeLocation)
 {
     store = new MemoryStore();
     store.AddReasoner(new Euler(new N3Reader(MusicConstants.OntologyURL)));
     if (File.Exists(storeLocation))
     {
         switch(GetStoreFormat(storeLocation))
         {
         case StoreFormat.N3:
             store.Import(new N3Reader(storeLocation));
             break;
         case StoreFormat.RDF:
             store.Import(new RdfXmlReader(storeLocation));
             break;
         }
     }
 }