>
> Or create a second general dataset, then get the named graph objects
> (they are reference) and put it in this dataset and query that.
>
> (this is what using several FROM NAMED does anyway)
>
If I understand it correctly the following example is what you suggested:
Dataset createGeneral = DatasetFactory.createGeneral();
RDFConnectionRemoteBuilder builder = RDFConnectionFuseki.create()
.destination("http://x.x.x.x:3030/ds");
try ( RDFConnectionFuseki conn = (RDFConnectionFuseki)builder.build() ) {
Dataset fetchDataset = conn.fetchDataset();
Model namedModel = fetchDataset.getNamedModel(GRAPH_IRI_PREFIX + "R17");
Model namedModel2 = fetchDataset.getNamedModel(GRAPH_IRI_PREFIX + "R15");
createGeneral.addNamedModel(GRAPH_IRI_PREFIX + "R32", namedModel);
createGeneral.addNamedModel(GRAPH_IRI_PREFIX + "R33", namedModel2);
}
String queryString = "SELECT * { ?s ?p ?o }";
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query,
createGeneral);
try {
ResultSet results = qexec.execSelect();
while ( results.hasNext() ) {
QuerySolution soln = results.nextSolution();
System.out.println(soln);
}
Here getNamedModel and addNamedModel would be using references not
in-memory ?
On Fri, Apr 9, 2021 at 4:25 PM Andy Seaborne <[email protected]> wrote:
>
>
> On 09/04/2021 10:05, Lorenz Buehmann wrote:
> > You are using TDB which is an external database and indexes to the data
> > which resides on disk. Why do you think that all the graphs are loaded
> > into memory?
> >
> > Why can't you modify the given query in your code? You can either do
> > string hacks, or what I'd prefer, parse the query and work on the query
> > element structure. You could use FROM or FROM NAMED can't you?
>
> Indeed.
>
> >
> > There are methods
> >
> > addGraphURI and addNamedGraphURI for the Query object, maybe you could
> > try one of those methods?
>
> Or create a second general dataset, then get the named graph objects
> (they are reference) and put it in this dataset and query that.
>
> (this is what using several FROM NAMED does anyway)
>
> Andy
>
> >
> > On 09.04.21 10:28, Siddharth Trikha wrote:
> >> Hi all,
> >>
> >> I have a use case to run a SPARQL query over a limited set of Graphs
> >> in my
> >> TripleStore.
> >>
> >> For example:
> >>
> >> String directory = "MyDatabases/DB1" ;
> >> Dataset dataset = TDBFactory.createDataset(directory) ;
> >>
> >> // Potentially expensive query.
> >> String sparqlQueryString = "SELECT (count(*) AS ?count) { ?s ?p
> >> ?o }" ;
> >>
> >> Query query = QueryFactory.create(sparqlQueryString) ;
> >> QueryExecution qexec = QueryExecutionFactory.create(query,
> >> dataset) ;
> >> // ...............
> >>
> >> The above example would run on the whole Database.
> >>
> >> I want to run the above SPARQL Query over lets say just 5 named GRAPHS
> >> whose names I know.
> >>
> >> The sparqlQueryString will be provided by the application as given
> >> above without named GRAPHS specified inside the Query String, but
> >> passes the Graph names (IRIs) in another attribute separately.
> >>
> >> I wanted to avoid in-memory loading of all named GRAPHS as this number
> >> can increase.
> >>
> >> Is there an efficient way of achieving this use case ?
> >>
> >> Any help is appreciated.
> >>
> >>
>
--
Regards
Siddharth Trikha
Reserach Engineer at C-DOT (Center for Development of Telematics)
9958954669