/// <summary>
        /// Executes a SparqlQuery on the store.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public override ISparqlQueryResult ExecuteQuery(ISparqlQuery query, ITransaction transaction = null)
        {
            if (query.IsInferenceEnabled && _reasoner != null)
            {
                _store.AddInferenceEngine(_reasoner);
            }
            else
            {
                _store.ClearInferenceEngines();
            }

            string q = query.ToString();

            object results = ExecuteQuery(q);

            if (results is IGraph)
            {
                return(new dotNetRDFQueryResult(this, query, results as IGraph));
            }
            else if (results is SparqlResultSet)
            {
                return(new dotNetRDFQueryResult(this, query, results as SparqlResultSet));
            }

            return(null);
        }
        public void SparqlViewAndReasonerInteraction1()
        {
            TripleStore store = new TripleStore();
            SparqlView  view  = new SparqlView("CONSTRUCT { ?s a ?type } WHERE { GRAPH ?g { ?s a ?type } }", store);

            view.BaseUri = new Uri("http://example.org/view");
            store.Add(view);

            Console.WriteLine("SPARQL View Empty");
            TestTools.ShowGraph(view);
            Console.WriteLine();

            //Load a Graph into the Store to cause the SPARQL View to update
            Graph g = new Graph();

            FileLoader.Load(g, "resources\\InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/data");
            store.Add(g);

            Thread.Sleep(500);
            if (view.Triples.Count == 0)
            {
                view.UpdateView();
            }

            Console.WriteLine("SPARQL View Populated");
            TestTools.ShowGraph(view);
            Console.WriteLine();

            Assert.True(view.Triples.Count > 0, "View should have updated to contain some Triples");
            int lastCount = view.Triples.Count;

            //Apply an RDFS reasoner
            StaticRdfsReasoner reasoner = new StaticRdfsReasoner();

            reasoner.Initialise(g);
            store.AddInferenceEngine(reasoner);

            Thread.Sleep(200);
            if (view.Triples.Count == lastCount)
            {
                view.UpdateView();
            }
            Console.WriteLine("SPARQL View Populated after Reasoner added");
            TestTools.ShowGraph(view);
        }
Beispiel #3
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);
            }
        }
        /// <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);
                }
            }
        }
Beispiel #5
0
        public void SparqlViewAndReasonerInteraction()
        {
            try
            {
                TripleStore store = new TripleStore();
                SparqlView view = new SparqlView("CONSTRUCT { ?s a ?type } WHERE { ?s a ?type }", store);
                view.BaseUri = new Uri("http://example.org/view");
                store.Add(view);

                Console.WriteLine("SPARQL View Empty");
                TestTools.ShowGraph(view);
                Console.WriteLine();

                //Load a Graph into the Store to cause the SPARQL View to update
                Graph g = new Graph();
                FileLoader.Load(g, "InferenceTest.ttl");
                g.BaseUri = new Uri("http://example.org/data");
                store.Add(g);

                Thread.Sleep(200);
                if (view.Triples.Count == 0) view.UpdateView();

                Console.WriteLine("SPARQL View Populated");
                TestTools.ShowGraph(view);
                Console.WriteLine();

                Assert.IsTrue(view.Triples.Count > 0, "View should have updated to contain some Triples");
                int lastCount = view.Triples.Count;

                //Apply an RDFS reasoner
                StaticRdfsReasoner reasoner = new StaticRdfsReasoner();
                reasoner.Initialise(g);
                store.AddInferenceEngine(reasoner);

                Thread.Sleep(200);
                if (view.Triples.Count == lastCount) view.UpdateView();
                Console.WriteLine("SPARQL View Populated after Reasoner added");
                TestTools.ShowGraph(view);
            }
            catch (RdfQueryException queryEx)
            {
                TestTools.ReportError("Query Error", queryEx, true);
            }
            catch (RdfException ex)
            {
                TestTools.ReportError("Error", ex, true);
            }
        }