Exemplo n.º 1
0
        public void Arrange(string sparqlQuery, out TripleStore store, out SparqlQuery query)
        {
            IGraph g = new VDS.RDF.Graph();                 //Load triples from file OWL

            g.LoadFromFile(@"D:\Stud\4 course\II semester\!Diploma work\Software\Code\SPARQLtoSQL\SPARQLtoSQL\bin\Debug\combined.owl");
            g.BaseUri = null;                           //!

            RdfsReasoner reasoner = new RdfsReasoner(); //Apply reasoner

            reasoner.Initialise(g);
            reasoner.Apply(g);

            g.BaseUri = null;   //!!!!!!!!
            store     = new TripleStore();
            store.Add(g);

            SparqlParameterizedString queryString = new SparqlParameterizedString();

            queryString.CommandText = sparqlQuery;

            SparqlQueryParser parser = new SparqlQueryParser();

            //SparqlQuery query = parser.ParseFromString(queryString.ToString());
            query = parser.ParseFromString(queryString.ToString());

            Dictionary <string, string> dbURIs = new Dictionary <string, string>();

            dbURIs.Add("http://www.semanticweb.org/KMS/", @"Data Source = ASUS\SQLEXPRESS; Initial Catalog = KMS; Integrated Security = True");
            dbURIs.Add("http://www.semanticweb.org/LMS/", @"Data Source = ASUS\SQLEXPRESS; Initial Catalog = LMS; Integrated Security = True");
            Program.ResolveBGPsFromDB(query.ToAlgebra(), g, dbURIs);

            Console.WriteLine(query.ToAlgebra());
            Console.WriteLine(query.ToString());
        }
Exemplo n.º 2
0
        /**
         * Aplica o Reasoner na ontologia
         * */
        public StaticRdfsReasoner Reasoner()
        {
            RdfsReasoner reasoner = new RdfsReasoner();

            reasoner.Initialise(Ontology); // ontologia base
            reasoner.Apply(Ontology, Ontology);

            return(reasoner);
        }
Exemplo n.º 3
0
        static void CustomQuery()
        {
            Uri prefixRDF  = new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
            Uri prefixFilm = new Uri("http://www.semprog.com/film#");

            //IGraph g = new Graph();                 //Load triples from file OWL
            //g.LoadFromFile("film-ontology.owl");
            //g.BaseUri = null; //!
            IGraph g = new VDS.RDF.Graph();             //Load triples from server (OWL)

            RdfsReasoner reasoner = new RdfsReasoner(); //Apply reasoner

            reasoner.Initialise(g);
            reasoner.Apply(g);


            g.BaseUri = null;   //!!!!!!!!
            TripleStore store = new TripleStore();

            store.Add(g);

            SparqlParameterizedString queryString = new SparqlParameterizedString();

            queryString.Namespaces.AddNamespace("rdf", prefixRDF);
            queryString.Namespaces.AddNamespace("film", prefixFilm);
            queryString.CommandText = "SELECT ?who WHERE { ?who rdf:type film:Person }";

            string sparql = "";

            sparql = File.ReadAllText("sparql1.txt");

            SparqlQueryParser parser = new SparqlQueryParser();
            //SparqlQuery query = parser.ParseFromString(queryString.ToString());
            SparqlQuery query = parser.ParseFromString(sparql);

            Console.WriteLine(query.ToAlgebra());
            Console.WriteLine(query.ToString());

            //ISparqlQueryProcessor processor = new LeviathanQueryProcessor(store);   //process query
            //SparqlResultSet results = processor.ProcessQuery(query) as SparqlResultSet;

            ISparqlQueryProcessor processor = new MirageQueryProcessor(mapping);//new LeviathanQueryProcessor(store);   //process query
            string results = processor.ProcessQuery(query) as string;

            Console.WriteLine(results);
            //if (results is SparqlResultSet)
            //{
            //    SparqlResultSet rset = (SparqlResultSet)results;
            //    foreach (SparqlResult result in rset)
            //    {
            //        Console.WriteLine(result);
            //    }
            //}
        }
Exemplo n.º 4
0
        public dotNetRDFStore(string[] schema)
        {
            _store           = new TripleStore();
            _updateProcessor = new LeviathanUpdateProcessor(_store);
            _queryProcessor  = new LeviathanQueryProcessor(_store);
            _parser          = new SparqlUpdateParser();

            if (schema == null)
            {
                return;
            }

            _reasoner = new RdfsReasoner();
            _store.AddInferenceEngine(_reasoner);

            foreach (string m in schema)
            {
                IGraph schemaGraph = LoadSchema(m);

                _store.Add(schemaGraph);
                _reasoner.Initialise(schemaGraph);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a new dotNetRDFStore.
        /// </summary>
        /// <param name="schemes">A list of ontology file paths relative to this assembly. The store will be populated with these ontologies.</param>
        public dotNetRDFStore(string[] schemes)
        {
            _store           = new TripleStore();
            _updateProcessor = new LeviathanUpdateProcessor(_store);
            _queryProcessor  = new LeviathanQueryProcessor(_store);
            _parser          = new SparqlUpdateParser();

            if (schemes != null)
            {
                _reasoner = new RdfsReasoner();
                _store.AddInferenceEngine(_reasoner);

                foreach (string s in schemes)
                {
                    var directory = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
                    var file      = new FileInfo(Path.Combine(directory.FullName, s));

                    IGraph schemaGraph = LoadSchema(file.FullName);

                    _store.Add(schemaGraph);
                    _reasoner.Initialise(schemaGraph);
                }
            }
        }
Exemplo n.º 6
0
        static void CustomQueryLMS_KMS()
        {
            IGraph g = new VDS.RDF.Graph();                 //Load triples from file OWL

            g.LoadFromFile("combined.owl");
            g.BaseUri = null; //!

            //INode subj = g.CreateUriNode(new Uri("http://www.semanticweb.org/KMS/User/1"));
            //INode pred = g.CreateUriNode(new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"));
            //INode obj = g.CreateUriNode(new Uri("http://www.semanticweb.org/KMS/User"));
            //g.Assert(new Triple(subj,pred,obj));


            RdfsReasoner reasoner = new RdfsReasoner(); //Apply reasoner

            reasoner.Initialise(g);
            reasoner.Apply(g);



            g.BaseUri = null;   //!!!!!!!!
            TripleStore store = new TripleStore();

            store.Add(g);

            SparqlParameterizedString queryString = new SparqlParameterizedString();

            //queryString.CommandText = @"SELECT * WHERE { ?user <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.semanticweb.org/KMS/User>.
            //                                             OPTIONAL {?user <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.semanticweb.org/LMS/User>}}";
            // queryString.CommandText = @"SELECT *
            //WHERE { ?usr <http://www.semanticweb.org/LMS/User#EMAIL> ?email.
            //                                ?usr1 <http://www.semanticweb.org/KMS/User#EMAIL> ?email}";
            //queryString.CommandText = @"SELECT *
            //WHERE { ?usr <http://www.semanticweb.org/LMS/User#ROLE_ID> ?roleID.
            //                                ?role <http://www.semanticweb.org/LMS/Role#ID> ?roleID.
            //                                ?role <http://www.semanticweb.org/LMS/Role#NAME> ""Teacher""}";

            //queryString.Namespaces.AddNamespace("owl", new Uri("http://www.w3.org/2002/07/owl#"));
            //queryString.CommandText = @"SELECT * WHERE {
            //                                            ?property owl:equivalentProperty ?property1
            //                                            filter regex(str(?property), '^http://www.semanticweb.org/FEDERATED/Kunde#NAME$')}";

            queryString.CommandText = @"SELECT *
								        WHERE { ?s <http://www.semanticweb.org/FEDERATED/Kunde#EMAIL> ?email.
                                                ?s1 <http://www.semanticweb.org/LMS/User#EMAIL> ?email}";

            SparqlQueryParser parser = new SparqlQueryParser();
            //SparqlQuery query = parser.ParseFromString(queryString.ToString());
            SparqlQuery query = parser.ParseFromString(queryString.ToString());

            Dictionary <string, string> dbURIs = new Dictionary <string, string>();

            dbURIs.Add("http://www.semanticweb.org/KMS/", @"Data Source = ASUS\SQLEXPRESS; Initial Catalog = KMS; Integrated Security = True");
            dbURIs.Add("http://www.semanticweb.org/LMS/", @"Data Source = ASUS\SQLEXPRESS; Initial Catalog = LMS; Integrated Security = True");
            ResolveBGPsFromDB(query.ToAlgebra(), g, dbURIs);

            Console.WriteLine(query.ToAlgebra());
            Console.WriteLine(query.ToString());

            //ISparqlQueryProcessor processor = new LeviathanQueryProcessor(store);   //process query
            //SparqlResultSet results = processor.ProcessQuery(query) as SparqlResultSet;

            ISparqlQueryProcessor processor = new QuantumQueryProcessor(store);//new LeviathanQueryProcessor(store);   //process query
            var results = processor.ProcessQuery(query) as SparqlResultSet;

            if (results is SparqlResultSet)
            {
                SparqlResultSet rset = (SparqlResultSet)results;
                foreach (SparqlResult result in rset)
                {
                    Console.WriteLine(result);
                }
            }
        }