Exemplo n.º 1
0
        /// <summary>
        /// Loads a Graph from the Store using the given RDF Handler
        /// </summary>
        /// <param name="handler">RDF Handler</param>
        /// <param name="graphUri">URI of the Graph to load</param>
        public virtual void LoadGraph(IRdfHandler handler, Uri graphUri)
        {
            try
            {
                this.Open(true);

                if (this.Exists(graphUri))
                {
                    //Load into an Empty Graph and then Merge
                    IGraph g = new Graph();

                    //Load Namespaces and Triples
                    String graphID = this.GetGraphID(graphUri);
                    this.LoadNamespaces(g, graphID);
                    this.LoadTriples(g, graphID);

                    handler.Apply(g);
                }
                else
                {
                    handler.Apply((IGraph)null);
                }

                this.Close(true);
            }
            catch
            {
                this.Close(true, true);
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads a Graph from the Dataset with the given Handler
        /// </summary>
        /// <param name="handler">RDF Handler</param>
        /// <param name="graphUri">URI of the Graph to load</param>
        public void LoadGraph(IRdfHandler handler, Uri graphUri)
        {
            IGraph g = null;

            if (graphUri == null)
            {
                if (this._store.HasGraph(graphUri))
                {
                    g = this._store.Graph(graphUri);
                }
                else
                {
                    foreach (Uri u in WriterHelper.StoreDefaultGraphURIs.Select(s => new Uri(s)))
                    {
                        if (this._store.HasGraph(u))
                        {
                            g = this._store.Graph(u);
                            break;
                        }
                    }
                }
            }
            else if (this._store.HasGraph(graphUri))
            {
                g = this._store.Graph(graphUri);
            }

            handler.Apply(g);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads a Graph from the Store.
        /// </summary>
        /// <param name="handler">RDF Handler.</param>
        /// <param name="graphUri">Graph URI to load.</param>
        public override void LoadGraph(IRdfHandler handler, Uri graphUri)
        {
            IGraph g = null;

            if (_dataset.HasGraph(graphUri))
            {
                g = _dataset[graphUri];
            }
            handler.Apply(g);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Loads a Graph from the Store
        /// </summary>
        /// <param name="handler">RDF Handler</param>
        /// <param name="graphUri">Graph URI to load</param>
        public void LoadGraph(IRdfHandler handler, Uri graphUri)
        {
            IGraph g = null;

            if (this._dataset.HasGraph(graphUri))
            {
                g = this._dataset[graphUri];
            }
            handler.Apply(g);
        }
Exemplo n.º 5
0
        public void ToHandler(IRdfHandler handler, IDocument <Document, Document> document)
        {
            Document mongoDoc = document.BeginRead();
            Document lookup   = new Document();

            lookup["graphuri"] = mongoDoc["uri"];
            document.EndRead();

            IEnumerable <Triple> ts = new MongoDBTripleCentricEnumerable(this._manager, lookup);

            handler.Apply(ts);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Loads a Graph from the Dataset with the given Handler
        /// </summary>
        /// <param name="handler">RDF Handler</param>
        /// <param name="graphUri">URI of the Graph to load</param>
        public override void LoadGraph(IRdfHandler handler, Uri graphUri)
        {
            IGraph g = null;

            if (graphUri == null)
            {
                if (this._store.HasGraph(graphUri))
                {
                    g = this._store[graphUri];
                }
            }
            else if (this._store.HasGraph(graphUri))
            {
                g = this._store[graphUri];
            }

            if (g == null)
            {
                return;
            }
            handler.Apply(g);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Processes a SPARQL Query against the Knowledge Base passing the results to the RDF or Results handler as appropriate
        /// </summary>
        /// <param name="rdfHandler">RDF Handler</param>
        /// <param name="resultsHandler">Results Handler</param>
        /// <param name="sparqlQuery">SPARQL Query</param>
        /// <param name="callback">Callback to invoke once handling of results has completed</param>
        /// <param name="state">State to pass to the callback</param>
        public void Query(IRdfHandler rdfHandler, ISparqlResultsHandler resultsHandler, String sparqlQuery, QueryCallback callback, Object state)
        {
            SparqlQueryParser parser = new SparqlQueryParser();
            SparqlQuery       q      = parser.ParseFromString(sparqlQuery);

            SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(UriFactory.Create(this._sparqlUri));

            switch (q.QueryType)
            {
            case SparqlQueryType.Ask:
            case SparqlQueryType.Select:
            case SparqlQueryType.SelectAll:
            case SparqlQueryType.SelectAllDistinct:
            case SparqlQueryType.SelectAllReduced:
            case SparqlQueryType.SelectDistinct:
            case SparqlQueryType.SelectReduced:
                endpoint.QueryWithResultSet(sparqlQuery, (rs, _) =>
                {
                    resultsHandler.Apply(rs);
                    callback(rdfHandler, resultsHandler, state);
                }, state);
                break;

            case SparqlQueryType.Construct:
            case SparqlQueryType.Describe:
            case SparqlQueryType.DescribeAll:
                endpoint.QueryWithResultGraph(sparqlQuery, (g, _) =>
                {
                    rdfHandler.Apply(g);
                    callback(rdfHandler, resultsHandler, state);
                }, state);
                break;

            default:
                throw new RdfQueryException("Cannot execute unknown query types against Pellet Server");
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Loads a Graph from the Dataset with the given Handler
        /// </summary>
        /// <param name="handler">RDF Handler</param>
        /// <param name="graphUri">URI of the Graph to load</param>
        public void LoadGraph(IRdfHandler handler, Uri graphUri)
        {
            IGraph g = null;
            if (graphUri == null)
            {
                if (this._store.HasGraph(graphUri))
                {
                    g = this._store.Graph(graphUri);
                }
                else
                {
                    foreach (Uri u in WriterHelper.StoreDefaultGraphURIs.Select(s => new Uri(s)))
                    {
                        if (this._store.HasGraph(u))
                        {
                            g = this._store.Graph(u);
                            break;
                        }
                    }
                }
            }
            else if (this._store.HasGraph(graphUri))
            {
                g = this._store.Graph(graphUri);
            }

            handler.Apply(g);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Loads a Graph from the Store
 /// </summary>
 /// <param name="handler">RDF Handler</param>
 /// <param name="graphUri">Graph URI to load</param>
 public void LoadGraph(IRdfHandler handler, Uri graphUri)
 {
     IGraph g = null;
     if (this._dataset.HasGraph(graphUri))
     {
         g = this._dataset[graphUri];
     }
     handler.Apply(g);
 }
Exemplo n.º 10
0
        /// <summary>
        /// Processes a SPARQL Query against the Knowledge Base passing the results to the RDF or Results handler as appropriate
        /// </summary>
        /// <param name="rdfHandler">RDF Handler</param>
        /// <param name="resultsHandler">Results Handler</param>
        /// <param name="sparqlQuery">SPARQL Query</param>
        /// <param name="callback">Callback to invoke once handling of results has completed</param>
        /// <param name="state">State to pass to the callback</param>
        public void Query(IRdfHandler rdfHandler, ISparqlResultsHandler resultsHandler, String sparqlQuery, QueryCallback callback, Object state)
        {
            SparqlQueryParser parser = new SparqlQueryParser();
            SparqlQuery q = parser.ParseFromString(sparqlQuery);

            SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(UriFactory.Create(this._sparqlUri));
            switch (q.QueryType)
            {
                case SparqlQueryType.Ask:
                case SparqlQueryType.Select:
                case SparqlQueryType.SelectAll:
                case SparqlQueryType.SelectAllDistinct:
                case SparqlQueryType.SelectAllReduced:
                case SparqlQueryType.SelectDistinct:
                case SparqlQueryType.SelectReduced:
                    endpoint.QueryWithResultSet(sparqlQuery, (rs, _) =>
                        {
                            resultsHandler.Apply(rs);
                            callback(rdfHandler, resultsHandler, state);
                        }, state);
                    break;
                case SparqlQueryType.Construct:
                case SparqlQueryType.Describe:
                case SparqlQueryType.DescribeAll:
                    endpoint.QueryWithResultGraph(sparqlQuery, (g, _) =>
                        {
                            rdfHandler.Apply(g);
                            callback(rdfHandler, resultsHandler, state);
                        }, state);
                    break;

                default:
                    throw new RdfQueryException("Cannot execute unknown query types against Pellet Server");
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Loads a Graph from the Store using the given RDF Handler
        /// </summary>
        /// <param name="handler">RDF Handler</param>
        /// <param name="graphUri">URI of the Graph to load</param>
        public virtual void LoadGraph(IRdfHandler handler, Uri graphUri)
        {
            try
            {
                this.Open(true);

                if (this.Exists(graphUri))
                {
                    //Load into an Empty Graph and then Merge
                    IGraph g = new Graph();

                    //Load Namespaces and Triples
                    String graphID = this.GetGraphID(graphUri);
                    this.LoadNamespaces(g, graphID);
                    this.LoadTriples(g, graphID);

                    handler.Apply(g);
                }
                else
                {
                    handler.Apply((IGraph)null);
                }

                this.Close(true);
            }
            catch
            {
                this.Close(true, true);
                throw;
            }
        }