sparqljenatdb

Query a model from Dataset in TDB


I have a lot of models in my dataset and i want to query specified model i used graph keyword in SPARQL query but it gives me an empty result set can anyone help me with this, Please ?

    public static void  SparqlForSentencesDuplicates()
{

     String querystr= "PREFIX aapi:<http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema#> "

            + "select  ?s where {"
            +"graph <RelationModel3> {"
            + "?id aapi:RelationSentence ?s } "
            +"}"; 

     Dataset ds=tdbconn.ds;
     ds.begin(ReadWrite.READ);
   QueryExecution qexe= QueryExecutionFactory.create( querystr, ds);  
    try {

        ResultSet result= qexe.execSelect();
        ResultSetFormatter.out(result);
    }finally{
        qexe.close(); 
        ds.close();
    }

}

and here how can i load the model

public Model loadModel( String modelName, StringBuilder Builder )
  {
 Model model = null;

ds.begin( ReadWrite.WRITE );
try
{
    //model = ds.getNamedModel( modelName );
     model = ModelFactory.createDefaultModel();

    model.read(new ByteArrayInputStream(Builder.toString().getBytes()), null);
    ds.addNamedModel(modelName, model);
    ds.commit();
}
finally
{
    ds.end();
}   return model;}

Solution

  • graph <RelationModel3> has a relative URI - it will be resolved by the parser into a full URI.

    Parse and print the query to see what the query really looks like.

    URIs for graphs in the data should not be relative URIs either.

    Check your data with:

    SELECT * { GRAPH ?g {} }
    

    and fix if necessary.