You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by "Dimov, Stefan" <st...@sap.com> on 2017/04/10 21:06:31 UTC

When using named graphs, can't query the data

Hi,

I’m using in-mem base and loading multiple named graphs in one data set, iterating thru :

private static boolean loadGraphT(Dataset ds) {
    …
    String filename = …
    String graphName = …
   …
    Model model = ds.getNamedModel(graphName);
    ds.begin(ReadWrite.WRITE);
    FileManager.get().readModel(model, fileName);
    ds.commit();
    ds.end();
    return true;
}



At start, after everything is read and data set is committed, I’m printing out the graph names and their sizes, to check, if everything was loaded:

2017-04-10 13:50:50 INFO  Ontology:50 - Named graph aaa - 7855 triples
2017-04-10 13:50:50 INFO  Ontology:50 - Named graph bbb - 26 triples
2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ccc - 4 triples
2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ddd - 20000 triples
…

After that I’m trying to query some data from a named graph:

SELECT count ($s)
FROM NAMED <aaa>
{
    { ?s ?p ?o }
}

or trying to query it without specifying graph:

SELECT count ($s)
{
    { ?s ?p ?o }
}

The result is empty:

{
  "head": {
    "vars": [ ".1" ]
  } ,
  "results": {
    "bindings": [
      {
        ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
      }
    ]
  }
}

What am I doing wrong?

S.

Re: When using named graphs, can't query the data

Posted by "Dimov, Stefan" <st...@sap.com>.
Thanks!

S.

On 4/11/17, 2:15 AM, "Andy Seaborne" <an...@apache.org> wrote:

    
    
    On 11/04/17 01:09, Dimov, Stefan wrote:
    > Got it - it’s gotta be a real URI, with http and everything:
    >
    >        http://ao.com/aaa
    >
    >  The simple names, like:
    >
    >        aaa
    >
    > don’t work …
    
    Relative URIs are resolved (BASE <...>) so tyhey don't sytay as the 
    plain name in the query or data.
    
         Andy
    
    
    
    >
    > S.
    >
    >
    > On 4/10/17, 4:22 PM, "Dimov, Stefan" <st...@sap.com> wrote:
    >
    >     I (almost) got it.
    >
    >     Apparently, the data was loaded correctly. Now I can query the names of all the graphs:
    >
    >     SELECT DISTINCT $g
    >     {
    >        GRAPH ?g { ?s ?p ?o }
    >     }
    >
    >     returns:
    >
    >     {
    >       "head": {
    >         "vars": [ "g" ]
    >       } ,
    >       "results": {
    >         "bindings": [
    >           {
    >             "g": { "type": "uri" , "value": "aaa" }
    >           } ,
    >           {
    >             "g": { "type": "uri" , "value": "bbb" }
    >           } ,
    >           {
    >             "g": { "type": "uri" , "value": "ccc" }
    >           } ,
    >           {
    >             "g": { "type": "uri" , "value": "ddd" }
    >           } ,
    >           …
    >
    >     or the data:
    >
    >     SELECT count(*)
    >     {
    >        GRAPH ?g { ?s ?p ?o }
    >     }
    >
    >     returns:
    >
    >     {
    >       "head": {
    >         "vars": [ ".1" ]
    >       } ,
    >       "results": {
    >         "bindings": [
    >           {
    >             ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "395721" }
    >           }
    >         ]
    >       }
    >     }
    >
    >     but I still can’t figure out how to query specific named graph. This:
    >
    >     SELECT count(*)
    >     {
    >        GRAPH <aaa> { ?s ?p ?o }
    >     }
    >
    >     should work. But actually it returns zero results:
    >
    >     {
    >       "head": {
    >         "vars": [ ".1" ]
    >       } ,
    >       "results": {
    >         "bindings": [
    >           {
    >             ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
    >           }
    >         ]
    >       }
    >     }
    >
    >     Any idea?
    >
    >     S.
    >
    >
    >     On 4/10/17, 2:06 PM, "Dimov, Stefan" <st...@sap.com> wrote:
    >
    >         Hi,
    >
    >         I’m using in-mem base and loading multiple named graphs in one data set, iterating thru :
    >
    >         private static boolean loadGraphT(Dataset ds) {
    >             …
    >             String filename = …
    >             String graphName = …
    >            …
    >             Model model = ds.getNamedModel(graphName);
    >             ds.begin(ReadWrite.WRITE);
    >             FileManager.get().readModel(model, fileName);
    >             ds.commit();
    >             ds.end();
    >             return true;
    >         }
    >
    >
    >
    >         At start, after everything is read and data set is committed, I’m printing out the graph names and their sizes, to check, if everything was loaded:
    >
    >         2017-04-10 13:50:50 INFO  Ontology:50 - Named graph aaa - 7855 triples
    >         2017-04-10 13:50:50 INFO  Ontology:50 - Named graph bbb - 26 triples
    >         2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ccc - 4 triples
    >         2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ddd - 20000 triples
    >         …
    >
    >         After that I’m trying to query some data from a named graph:
    >
    >         SELECT count ($s)
    >         FROM NAMED <aaa>
    >         {
    >             { ?s ?p ?o }
    >         }
    >
    >         or trying to query it without specifying graph:
    >
    >         SELECT count ($s)
    >         {
    >             { ?s ?p ?o }
    >         }
    >
    >         The result is empty:
    >
    >         {
    >           "head": {
    >             "vars": [ ".1" ]
    >           } ,
    >           "results": {
    >             "bindings": [
    >               {
    >                 ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
    >               }
    >             ]
    >           }
    >         }
    >
    >         What am I doing wrong?
    >
    >         S.
    >
    >
    >
    >
    


Re: When using named graphs, can't query the data

Posted by Andy Seaborne <an...@apache.org>.

On 11/04/17 01:09, Dimov, Stefan wrote:
> Got it - it\u2019s gotta be a real URI, with http and everything:
>
>        http://ao.com/aaa
>
>  The simple names, like:
>
>        aaa
>
> don\u2019t work \u2026

Relative URIs are resolved (BASE <...>) so tyhey don't sytay as the 
plain name in the query or data.

     Andy



>
> S.
>
>
> On 4/10/17, 4:22 PM, "Dimov, Stefan" <st...@sap.com> wrote:
>
>     I (almost) got it.
>
>     Apparently, the data was loaded correctly. Now I can query the names of all the graphs:
>
>     SELECT DISTINCT $g
>     {
>        GRAPH ?g { ?s ?p ?o }
>     }
>
>     returns:
>
>     {
>       "head": {
>         "vars": [ "g" ]
>       } ,
>       "results": {
>         "bindings": [
>           {
>             "g": { "type": "uri" , "value": "aaa" }
>           } ,
>           {
>             "g": { "type": "uri" , "value": "bbb" }
>           } ,
>           {
>             "g": { "type": "uri" , "value": "ccc" }
>           } ,
>           {
>             "g": { "type": "uri" , "value": "ddd" }
>           } ,
>           \u2026
>
>     or the data:
>
>     SELECT count(*)
>     {
>        GRAPH ?g { ?s ?p ?o }
>     }
>
>     returns:
>
>     {
>       "head": {
>         "vars": [ ".1" ]
>       } ,
>       "results": {
>         "bindings": [
>           {
>             ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "395721" }
>           }
>         ]
>       }
>     }
>
>     but I still can\u2019t figure out how to query specific named graph. This:
>
>     SELECT count(*)
>     {
>        GRAPH <aaa> { ?s ?p ?o }
>     }
>
>     should work. But actually it returns zero results:
>
>     {
>       "head": {
>         "vars": [ ".1" ]
>       } ,
>       "results": {
>         "bindings": [
>           {
>             ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
>           }
>         ]
>       }
>     }
>
>     Any idea?
>
>     S.
>
>
>     On 4/10/17, 2:06 PM, "Dimov, Stefan" <st...@sap.com> wrote:
>
>         Hi,
>
>         I\u2019m using in-mem base and loading multiple named graphs in one data set, iterating thru :
>
>         private static boolean loadGraphT(Dataset ds) {
>             \u2026
>             String filename = \u2026
>             String graphName = \u2026
>            \u2026
>             Model model = ds.getNamedModel(graphName);
>             ds.begin(ReadWrite.WRITE);
>             FileManager.get().readModel(model, fileName);
>             ds.commit();
>             ds.end();
>             return true;
>         }
>
>
>
>         At start, after everything is read and data set is committed, I\u2019m printing out the graph names and their sizes, to check, if everything was loaded:
>
>         2017-04-10 13:50:50 INFO  Ontology:50 - Named graph aaa - 7855 triples
>         2017-04-10 13:50:50 INFO  Ontology:50 - Named graph bbb - 26 triples
>         2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ccc - 4 triples
>         2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ddd - 20000 triples
>         \u2026
>
>         After that I\u2019m trying to query some data from a named graph:
>
>         SELECT count ($s)
>         FROM NAMED <aaa>
>         {
>             { ?s ?p ?o }
>         }
>
>         or trying to query it without specifying graph:
>
>         SELECT count ($s)
>         {
>             { ?s ?p ?o }
>         }
>
>         The result is empty:
>
>         {
>           "head": {
>             "vars": [ ".1" ]
>           } ,
>           "results": {
>             "bindings": [
>               {
>                 ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
>               }
>             ]
>           }
>         }
>
>         What am I doing wrong?
>
>         S.
>
>
>
>

Re: When using named graphs, can't query the data

Posted by "A. Soroka" <aj...@virginia.edu>.
FROM is for a different use:

https://jena.apache.org/tutorials/sparql_datasets.html#describing-rdf-datasets-from-and-from-named

---
A. Soroka
The University of Virginia Library

> On Apr 11, 2017, at 5:20 AM, Andy Seaborne <an...@apache.org> wrote:
> 
> 
> 
> On 11/04/17 01:29, Dimov, Stefan wrote:
>> Another question in that order:
>> 
>> Now:
>> 
>> SELECT count(*)
>> FROM <http://ao.com/namedGraph/aaa>
>> {
>>  { ?s ?p ?o }
>> }
>> 
>> returns the number of the triples in aaa, correctly, but:
>> 
>> SELECT count(*)
>> FROM NAMED <http://ao.com/namedGraph/aaa>
>> {
>>  { ?s ?p ?o }
>> }
>> 
> 
> If you are querying the dataset, you don't need FROM / FROM NAMED: use GRAPH to access a named graph:
> 
> SELECT count(*)
> {
>  GRAPH <http://ao.com/namedGraph/aaa>
>  { ?s ?p ?o }
> }
> 
>    Andy
> 
>> returns zero.
>> 
>> The explanation (in the docs) of the difference between FROM and FROM NAMED is a bit confusing and it’s not enough (for me) to understand, why the first is working and the second is not …
>> 
>> S.
>> 
>> On 4/10/17, 5:09 PM, "Dimov, Stefan" <st...@sap.com> wrote:
>> 
>>    Got it - it’s gotta be a real URI, with http and everything:
>> 
>>           http://ao.com/aaa
>> 
>>     The simple names, like:
>> 
>>           aaa
>> 
>>    don’t work …
>> 
>>    S.
>> 
>> 
>>    On 4/10/17, 4:22 PM, "Dimov, Stefan" <st...@sap.com> wrote:
>> 
>>        I (almost) got it.
>> 
>>        Apparently, the data was loaded correctly. Now I can query the names of all the graphs:
>> 
>>        SELECT DISTINCT $g
>>        {
>>           GRAPH ?g { ?s ?p ?o }
>>        }
>> 
>>        returns:
>> 
>>        {
>>          "head": {
>>            "vars": [ "g" ]
>>          } ,
>>          "results": {
>>            "bindings": [
>>              {
>>                "g": { "type": "uri" , "value": "aaa" }
>>              } ,
>>              {
>>                "g": { "type": "uri" , "value": "bbb" }
>>              } ,
>>              {
>>                "g": { "type": "uri" , "value": "ccc" }
>>              } ,
>>              {
>>                "g": { "type": "uri" , "value": "ddd" }
>>              } ,
>>              …
>> 
>>        or the data:
>> 
>>        SELECT count(*)
>>        {
>>           GRAPH ?g { ?s ?p ?o }
>>        }
>> 
>>        returns:
>> 
>>        {
>>          "head": {
>>            "vars": [ ".1" ]
>>          } ,
>>          "results": {
>>            "bindings": [
>>              {
>>                ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "395721" }
>>              }
>>            ]
>>          }
>>        }
>> 
>>        but I still can’t figure out how to query specific named graph. This:
>> 
>>        SELECT count(*)
>>        {
>>           GRAPH <aaa> { ?s ?p ?o }
>>        }
>> 
>>        should work. But actually it returns zero results:
>> 
>>        {
>>          "head": {
>>            "vars": [ ".1" ]
>>          } ,
>>          "results": {
>>            "bindings": [
>>              {
>>                ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
>>              }
>>            ]
>>          }
>>        }
>> 
>>        Any idea?
>> 
>>        S.
>> 
>> 
>>        On 4/10/17, 2:06 PM, "Dimov, Stefan" <st...@sap.com> wrote:
>> 
>>            Hi,
>> 
>>            I’m using in-mem base and loading multiple named graphs in one data set, iterating thru :
>> 
>>            private static boolean loadGraphT(Dataset ds) {
>>                …
>>                String filename = …
>>                String graphName = …
>>               …
>>                Model model = ds.getNamedModel(graphName);
>>                ds.begin(ReadWrite.WRITE);
>>                FileManager.get().readModel(model, fileName);
>>                ds.commit();
>>                ds.end();
>>                return true;
>>            }
>> 
>> 
>> 
>>            At start, after everything is read and data set is committed, I’m printing out the graph names and their sizes, to check, if everything was loaded:
>> 
>>            2017-04-10 13:50:50 INFO  Ontology:50 - Named graph aaa - 7855 triples
>>            2017-04-10 13:50:50 INFO  Ontology:50 - Named graph bbb - 26 triples
>>            2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ccc - 4 triples
>>            2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ddd - 20000 triples
>>            …
>> 
>>            After that I’m trying to query some data from a named graph:
>> 
>>            SELECT count ($s)
>>            FROM NAMED <aaa>
>>            {
>>                { ?s ?p ?o }
>>            }
>> 
>>            or trying to query it without specifying graph:
>> 
>>            SELECT count ($s)
>>            {
>>                { ?s ?p ?o }
>>            }
>> 
>>            The result is empty:
>> 
>>            {
>>              "head": {
>>                "vars": [ ".1" ]
>>              } ,
>>              "results": {
>>                "bindings": [
>>                  {
>>                    ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
>>                  }
>>                ]
>>              }
>>            }
>> 
>>            What am I doing wrong?
>> 
>>            S.
>> 
>> 
>> 
>> 
>> 
>> 


Re: When using named graphs, can't query the data

Posted by "Dimov, Stefan" <st...@sap.com>.
Thanks, Andy!

S.

On 4/11/17, 2:20 AM, "Andy Seaborne" <an...@apache.org> wrote:

    
    
    On 11/04/17 01:29, Dimov, Stefan wrote:
    > Another question in that order:
    >
    > Now:
    >
    > SELECT count(*)
    > FROM <http://ao.com/namedGraph/aaa>
    > {
    >   { ?s ?p ?o }
    > }
    >
    > returns the number of the triples in aaa, correctly, but:
    >
    > SELECT count(*)
    > FROM NAMED <http://ao.com/namedGraph/aaa>
    > {
    >   { ?s ?p ?o }
    > }
    >
    
    If you are querying the dataset, you don't need FROM / FROM NAMED: use 
    GRAPH to access a named graph:
    
    SELECT count(*)
    {
       GRAPH <http://ao.com/namedGraph/aaa>
       { ?s ?p ?o }
    }
    
         Andy
    
    > returns zero.
    >
    > The explanation (in the docs) of the difference between FROM and FROM NAMED is a bit confusing and it’s not enough (for me) to understand, why the first is working and the second is not …
    >
    > S.
    >
    > On 4/10/17, 5:09 PM, "Dimov, Stefan" <st...@sap.com> wrote:
    >
    >     Got it - it’s gotta be a real URI, with http and everything:
    >
    >            http://ao.com/aaa
    >
    >      The simple names, like:
    >
    >            aaa
    >
    >     don’t work …
    >
    >     S.
    >
    >
    >     On 4/10/17, 4:22 PM, "Dimov, Stefan" <st...@sap.com> wrote:
    >
    >         I (almost) got it.
    >
    >         Apparently, the data was loaded correctly. Now I can query the names of all the graphs:
    >
    >         SELECT DISTINCT $g
    >         {
    >            GRAPH ?g { ?s ?p ?o }
    >         }
    >
    >         returns:
    >
    >         {
    >           "head": {
    >             "vars": [ "g" ]
    >           } ,
    >           "results": {
    >             "bindings": [
    >               {
    >                 "g": { "type": "uri" , "value": "aaa" }
    >               } ,
    >               {
    >                 "g": { "type": "uri" , "value": "bbb" }
    >               } ,
    >               {
    >                 "g": { "type": "uri" , "value": "ccc" }
    >               } ,
    >               {
    >                 "g": { "type": "uri" , "value": "ddd" }
    >               } ,
    >               …
    >
    >         or the data:
    >
    >         SELECT count(*)
    >         {
    >            GRAPH ?g { ?s ?p ?o }
    >         }
    >
    >         returns:
    >
    >         {
    >           "head": {
    >             "vars": [ ".1" ]
    >           } ,
    >           "results": {
    >             "bindings": [
    >               {
    >                 ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "395721" }
    >               }
    >             ]
    >           }
    >         }
    >
    >         but I still can’t figure out how to query specific named graph. This:
    >
    >         SELECT count(*)
    >         {
    >            GRAPH <aaa> { ?s ?p ?o }
    >         }
    >
    >         should work. But actually it returns zero results:
    >
    >         {
    >           "head": {
    >             "vars": [ ".1" ]
    >           } ,
    >           "results": {
    >             "bindings": [
    >               {
    >                 ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
    >               }
    >             ]
    >           }
    >         }
    >
    >         Any idea?
    >
    >         S.
    >
    >
    >         On 4/10/17, 2:06 PM, "Dimov, Stefan" <st...@sap.com> wrote:
    >
    >             Hi,
    >
    >             I’m using in-mem base and loading multiple named graphs in one data set, iterating thru :
    >
    >             private static boolean loadGraphT(Dataset ds) {
    >                 …
    >                 String filename = …
    >                 String graphName = …
    >                …
    >                 Model model = ds.getNamedModel(graphName);
    >                 ds.begin(ReadWrite.WRITE);
    >                 FileManager.get().readModel(model, fileName);
    >                 ds.commit();
    >                 ds.end();
    >                 return true;
    >             }
    >
    >
    >
    >             At start, after everything is read and data set is committed, I’m printing out the graph names and their sizes, to check, if everything was loaded:
    >
    >             2017-04-10 13:50:50 INFO  Ontology:50 - Named graph aaa - 7855 triples
    >             2017-04-10 13:50:50 INFO  Ontology:50 - Named graph bbb - 26 triples
    >             2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ccc - 4 triples
    >             2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ddd - 20000 triples
    >             …
    >
    >             After that I’m trying to query some data from a named graph:
    >
    >             SELECT count ($s)
    >             FROM NAMED <aaa>
    >             {
    >                 { ?s ?p ?o }
    >             }
    >
    >             or trying to query it without specifying graph:
    >
    >             SELECT count ($s)
    >             {
    >                 { ?s ?p ?o }
    >             }
    >
    >             The result is empty:
    >
    >             {
    >               "head": {
    >                 "vars": [ ".1" ]
    >               } ,
    >               "results": {
    >                 "bindings": [
    >                   {
    >                     ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
    >                   }
    >                 ]
    >               }
    >             }
    >
    >             What am I doing wrong?
    >
    >             S.
    >
    >
    >
    >
    >
    >
    


Re: When using named graphs, can't query the data

Posted by Andy Seaborne <an...@apache.org>.

On 11/04/17 01:29, Dimov, Stefan wrote:
> Another question in that order:
>
> Now:
>
> SELECT count(*)
> FROM <http://ao.com/namedGraph/aaa>
> {
>   { ?s ?p ?o }
> }
>
> returns the number of the triples in aaa, correctly, but:
>
> SELECT count(*)
> FROM NAMED <http://ao.com/namedGraph/aaa>
> {
>   { ?s ?p ?o }
> }
>

If you are querying the dataset, you don't need FROM / FROM NAMED: use 
GRAPH to access a named graph:

SELECT count(*)
{
   GRAPH <http://ao.com/namedGraph/aaa>
   { ?s ?p ?o }
}

     Andy

> returns zero.
>
> The explanation (in the docs) of the difference between FROM and FROM NAMED is a bit confusing and it\u2019s not enough (for me) to understand, why the first is working and the second is not \u2026
>
> S.
>
> On 4/10/17, 5:09 PM, "Dimov, Stefan" <st...@sap.com> wrote:
>
>     Got it - it\u2019s gotta be a real URI, with http and everything:
>
>            http://ao.com/aaa
>
>      The simple names, like:
>
>            aaa
>
>     don\u2019t work \u2026
>
>     S.
>
>
>     On 4/10/17, 4:22 PM, "Dimov, Stefan" <st...@sap.com> wrote:
>
>         I (almost) got it.
>
>         Apparently, the data was loaded correctly. Now I can query the names of all the graphs:
>
>         SELECT DISTINCT $g
>         {
>            GRAPH ?g { ?s ?p ?o }
>         }
>
>         returns:
>
>         {
>           "head": {
>             "vars": [ "g" ]
>           } ,
>           "results": {
>             "bindings": [
>               {
>                 "g": { "type": "uri" , "value": "aaa" }
>               } ,
>               {
>                 "g": { "type": "uri" , "value": "bbb" }
>               } ,
>               {
>                 "g": { "type": "uri" , "value": "ccc" }
>               } ,
>               {
>                 "g": { "type": "uri" , "value": "ddd" }
>               } ,
>               \u2026
>
>         or the data:
>
>         SELECT count(*)
>         {
>            GRAPH ?g { ?s ?p ?o }
>         }
>
>         returns:
>
>         {
>           "head": {
>             "vars": [ ".1" ]
>           } ,
>           "results": {
>             "bindings": [
>               {
>                 ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "395721" }
>               }
>             ]
>           }
>         }
>
>         but I still can\u2019t figure out how to query specific named graph. This:
>
>         SELECT count(*)
>         {
>            GRAPH <aaa> { ?s ?p ?o }
>         }
>
>         should work. But actually it returns zero results:
>
>         {
>           "head": {
>             "vars": [ ".1" ]
>           } ,
>           "results": {
>             "bindings": [
>               {
>                 ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
>               }
>             ]
>           }
>         }
>
>         Any idea?
>
>         S.
>
>
>         On 4/10/17, 2:06 PM, "Dimov, Stefan" <st...@sap.com> wrote:
>
>             Hi,
>
>             I\u2019m using in-mem base and loading multiple named graphs in one data set, iterating thru :
>
>             private static boolean loadGraphT(Dataset ds) {
>                 \u2026
>                 String filename = \u2026
>                 String graphName = \u2026
>                \u2026
>                 Model model = ds.getNamedModel(graphName);
>                 ds.begin(ReadWrite.WRITE);
>                 FileManager.get().readModel(model, fileName);
>                 ds.commit();
>                 ds.end();
>                 return true;
>             }
>
>
>
>             At start, after everything is read and data set is committed, I\u2019m printing out the graph names and their sizes, to check, if everything was loaded:
>
>             2017-04-10 13:50:50 INFO  Ontology:50 - Named graph aaa - 7855 triples
>             2017-04-10 13:50:50 INFO  Ontology:50 - Named graph bbb - 26 triples
>             2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ccc - 4 triples
>             2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ddd - 20000 triples
>             \u2026
>
>             After that I\u2019m trying to query some data from a named graph:
>
>             SELECT count ($s)
>             FROM NAMED <aaa>
>             {
>                 { ?s ?p ?o }
>             }
>
>             or trying to query it without specifying graph:
>
>             SELECT count ($s)
>             {
>                 { ?s ?p ?o }
>             }
>
>             The result is empty:
>
>             {
>               "head": {
>                 "vars": [ ".1" ]
>               } ,
>               "results": {
>                 "bindings": [
>                   {
>                     ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
>                   }
>                 ]
>               }
>             }
>
>             What am I doing wrong?
>
>             S.
>
>
>
>
>
>

Re: When using named graphs, can't query the data

Posted by "Dimov, Stefan" <st...@sap.com>.
Another question in that order:

Now:

SELECT count(*)
FROM <http://ao.com/namedGraph/aaa>
{
  { ?s ?p ?o }
}

returns the number of the triples in aaa, correctly, but:

SELECT count(*)
FROM NAMED <http://ao.com/namedGraph/aaa>
{
  { ?s ?p ?o }
}

returns zero.

The explanation (in the docs) of the difference between FROM and FROM NAMED is a bit confusing and it’s not enough (for me) to understand, why the first is working and the second is not …

S.

On 4/10/17, 5:09 PM, "Dimov, Stefan" <st...@sap.com> wrote:

    Got it - it’s gotta be a real URI, with http and everything:
    
           http://ao.com/aaa
    
     The simple names, like:
    
           aaa
    
    don’t work …
    
    S.
    
    
    On 4/10/17, 4:22 PM, "Dimov, Stefan" <st...@sap.com> wrote:
    
        I (almost) got it.
        
        Apparently, the data was loaded correctly. Now I can query the names of all the graphs:
        
        SELECT DISTINCT $g
        {
           GRAPH ?g { ?s ?p ?o }
        }
        
        returns:
        
        {
          "head": {
            "vars": [ "g" ]
          } ,
          "results": {
            "bindings": [
              {
                "g": { "type": "uri" , "value": "aaa" }
              } ,
              {
                "g": { "type": "uri" , "value": "bbb" }
              } ,
              {
                "g": { "type": "uri" , "value": "ccc" }
              } ,
              {
                "g": { "type": "uri" , "value": "ddd" }
              } ,
              …
        
        or the data:
        
        SELECT count(*)
        {
           GRAPH ?g { ?s ?p ?o }
        }
        
        returns:
        
        {
          "head": {
            "vars": [ ".1" ]
          } ,
          "results": {
            "bindings": [
              {
                ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "395721" }
              }
            ]
          }
        }
        
        but I still can’t figure out how to query specific named graph. This:
        
        SELECT count(*)
        {
           GRAPH <aaa> { ?s ?p ?o }
        }
        
        should work. But actually it returns zero results:
        
        {
          "head": {
            "vars": [ ".1" ]
          } ,
          "results": {
            "bindings": [
              {
                ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
              }
            ]
          }
        }
        
        Any idea?
        
        S.
        
        
        On 4/10/17, 2:06 PM, "Dimov, Stefan" <st...@sap.com> wrote:
        
            Hi,
            
            I’m using in-mem base and loading multiple named graphs in one data set, iterating thru :
            
            private static boolean loadGraphT(Dataset ds) {
                …
                String filename = …
                String graphName = …
               …
                Model model = ds.getNamedModel(graphName);
                ds.begin(ReadWrite.WRITE);
                FileManager.get().readModel(model, fileName);
                ds.commit();
                ds.end();
                return true;
            }
            
            
            
            At start, after everything is read and data set is committed, I’m printing out the graph names and their sizes, to check, if everything was loaded:
            
            2017-04-10 13:50:50 INFO  Ontology:50 - Named graph aaa - 7855 triples
            2017-04-10 13:50:50 INFO  Ontology:50 - Named graph bbb - 26 triples
            2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ccc - 4 triples
            2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ddd - 20000 triples
            …
            
            After that I’m trying to query some data from a named graph:
            
            SELECT count ($s)
            FROM NAMED <aaa>
            {
                { ?s ?p ?o }
            }
            
            or trying to query it without specifying graph:
            
            SELECT count ($s)
            {
                { ?s ?p ?o }
            }
            
            The result is empty:
            
            {
              "head": {
                "vars": [ ".1" ]
              } ,
              "results": {
                "bindings": [
                  {
                    ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
                  }
                ]
              }
            }
            
            What am I doing wrong?
            
            S.
            
        
        
    
    


Re: When using named graphs, can't query the data

Posted by "Dimov, Stefan" <st...@sap.com>.
Got it - it’s gotta be a real URI, with http and everything:

       http://ao.com/aaa

 The simple names, like:

       aaa

don’t work …

S.


On 4/10/17, 4:22 PM, "Dimov, Stefan" <st...@sap.com> wrote:

    I (almost) got it.
    
    Apparently, the data was loaded correctly. Now I can query the names of all the graphs:
    
    SELECT DISTINCT $g
    {
       GRAPH ?g { ?s ?p ?o }
    }
    
    returns:
    
    {
      "head": {
        "vars": [ "g" ]
      } ,
      "results": {
        "bindings": [
          {
            "g": { "type": "uri" , "value": "aaa" }
          } ,
          {
            "g": { "type": "uri" , "value": "bbb" }
          } ,
          {
            "g": { "type": "uri" , "value": "ccc" }
          } ,
          {
            "g": { "type": "uri" , "value": "ddd" }
          } ,
          …
    
    or the data:
    
    SELECT count(*)
    {
       GRAPH ?g { ?s ?p ?o }
    }
    
    returns:
    
    {
      "head": {
        "vars": [ ".1" ]
      } ,
      "results": {
        "bindings": [
          {
            ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "395721" }
          }
        ]
      }
    }
    
    but I still can’t figure out how to query specific named graph. This:
    
    SELECT count(*)
    {
       GRAPH <aaa> { ?s ?p ?o }
    }
    
    should work. But actually it returns zero results:
    
    {
      "head": {
        "vars": [ ".1" ]
      } ,
      "results": {
        "bindings": [
          {
            ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
          }
        ]
      }
    }
    
    Any idea?
    
    S.
    
    
    On 4/10/17, 2:06 PM, "Dimov, Stefan" <st...@sap.com> wrote:
    
        Hi,
        
        I’m using in-mem base and loading multiple named graphs in one data set, iterating thru :
        
        private static boolean loadGraphT(Dataset ds) {
            …
            String filename = …
            String graphName = …
           …
            Model model = ds.getNamedModel(graphName);
            ds.begin(ReadWrite.WRITE);
            FileManager.get().readModel(model, fileName);
            ds.commit();
            ds.end();
            return true;
        }
        
        
        
        At start, after everything is read and data set is committed, I’m printing out the graph names and their sizes, to check, if everything was loaded:
        
        2017-04-10 13:50:50 INFO  Ontology:50 - Named graph aaa - 7855 triples
        2017-04-10 13:50:50 INFO  Ontology:50 - Named graph bbb - 26 triples
        2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ccc - 4 triples
        2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ddd - 20000 triples
        …
        
        After that I’m trying to query some data from a named graph:
        
        SELECT count ($s)
        FROM NAMED <aaa>
        {
            { ?s ?p ?o }
        }
        
        or trying to query it without specifying graph:
        
        SELECT count ($s)
        {
            { ?s ?p ?o }
        }
        
        The result is empty:
        
        {
          "head": {
            "vars": [ ".1" ]
          } ,
          "results": {
            "bindings": [
              {
                ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
              }
            ]
          }
        }
        
        What am I doing wrong?
        
        S.
        
    
    


Re: When using named graphs, can't query the data

Posted by "Dimov, Stefan" <st...@sap.com>.
I (almost) got it.

Apparently, the data was loaded correctly. Now I can query the names of all the graphs:

SELECT DISTINCT $g
{
   GRAPH ?g { ?s ?p ?o }
}

returns:

{
  "head": {
    "vars": [ "g" ]
  } ,
  "results": {
    "bindings": [
      {
        "g": { "type": "uri" , "value": "aaa" }
      } ,
      {
        "g": { "type": "uri" , "value": "bbb" }
      } ,
      {
        "g": { "type": "uri" , "value": "ccc" }
      } ,
      {
        "g": { "type": "uri" , "value": "ddd" }
      } ,
      …

or the data:

SELECT count(*)
{
   GRAPH ?g { ?s ?p ?o }
}

returns:

{
  "head": {
    "vars": [ ".1" ]
  } ,
  "results": {
    "bindings": [
      {
        ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "395721" }
      }
    ]
  }
}

but I still can’t figure out how to query specific named graph. This:

SELECT count(*)
{
   GRAPH <aaa> { ?s ?p ?o }
}

should work. But actually it returns zero results:

{
  "head": {
    "vars": [ ".1" ]
  } ,
  "results": {
    "bindings": [
      {
        ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
      }
    ]
  }
}

Any idea?

S.


On 4/10/17, 2:06 PM, "Dimov, Stefan" <st...@sap.com> wrote:

    Hi,
    
    I’m using in-mem base and loading multiple named graphs in one data set, iterating thru :
    
    private static boolean loadGraphT(Dataset ds) {
        …
        String filename = …
        String graphName = …
       …
        Model model = ds.getNamedModel(graphName);
        ds.begin(ReadWrite.WRITE);
        FileManager.get().readModel(model, fileName);
        ds.commit();
        ds.end();
        return true;
    }
    
    
    
    At start, after everything is read and data set is committed, I’m printing out the graph names and their sizes, to check, if everything was loaded:
    
    2017-04-10 13:50:50 INFO  Ontology:50 - Named graph aaa - 7855 triples
    2017-04-10 13:50:50 INFO  Ontology:50 - Named graph bbb - 26 triples
    2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ccc - 4 triples
    2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ddd - 20000 triples
    …
    
    After that I’m trying to query some data from a named graph:
    
    SELECT count ($s)
    FROM NAMED <aaa>
    {
        { ?s ?p ?o }
    }
    
    or trying to query it without specifying graph:
    
    SELECT count ($s)
    {
        { ?s ?p ?o }
    }
    
    The result is empty:
    
    {
      "head": {
        "vars": [ ".1" ]
      } ,
      "results": {
        "bindings": [
          {
            ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
          }
        ]
      }
    }
    
    What am I doing wrong?
    
    S.
    


Re: When using named graphs, can't query the data

Posted by "Dimov, Stefan" <st...@sap.com>.
Thanks!

S.

On 4/11/17, 2:19 AM, "Andy Seaborne" <an...@apache.org> wrote:

    
    
    On 10/04/17 22:06, Dimov, Stefan wrote:
    > Hi,
    >
    > I’m using in-mem base and loading multiple named graphs in one data set, iterating thru :
    >
    > private static boolean loadGraphT(Dataset ds) {
    >     …
    >     String filename = …
    >     String graphName = …
    >    …
    >     Model model = ds.getNamedModel(graphName);
    Put this inside the transaction
    
    >     ds.begin(ReadWrite.WRITE);
    >     FileManager.get().readModel(model, fileName);
    >     ds.commit();
    >     ds.end();
    >     return true;
     > }
    
          ds.begin(ReadWrite.WRITE);
          Model model = ds.getNamedModel(graphName);
          RDFDataMgr.read(model, fileName);
          ds.commit();
          ds.end();
    
    
    or even:
    
             Txn.executeWrite(ds, ()->{
                 Model model = ds.getNamedModel(graphName);
                 RDFDataMgr.read(model, fileName);
             });
    
    http://jena.apache.org/documentation/txn/
    
    
    > }
    >
    >
    >
    > At start, after everything is read and data set is committed, I’m printing out the graph names and their sizes, to check, if everything was loaded:
    >
    > 2017-04-10 13:50:50 INFO  Ontology:50 - Named graph aaa - 7855 triples
    > 2017-04-10 13:50:50 INFO  Ontology:50 - Named graph bbb - 26 triples
    > 2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ccc - 4 triples
    > 2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ddd - 20000 triples
    > …
    >
    > After that I’m trying to query some data from a named graph:
    >
    > SELECT count ($s)
    > FROM NAMED <aaa>
    > {
    >     { ?s ?p ?o }
    > }
    >
    > or trying to query it without specifying graph:
    >
    > SELECT count ($s)
    > {
    >     { ?s ?p ?o }
    > }
    >
    > The result is empty:
    >
    > {
    >   "head": {
    >     "vars": [ ".1" ]
    >   } ,
    >   "results": {
    >     "bindings": [
    >       {
    >         ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
    >       }
    >     ]
    >   }
    > }
    >
    > What am I doing wrong?
    >
    > S.
    >
    


Re: When using named graphs, can't query the data

Posted by Andy Seaborne <an...@apache.org>.

On 10/04/17 22:06, Dimov, Stefan wrote:
> Hi,
>
> I\u2019m using in-mem base and loading multiple named graphs in one data set, iterating thru :
>
> private static boolean loadGraphT(Dataset ds) {
>     \u2026
>     String filename = \u2026
>     String graphName = \u2026
>    \u2026
>     Model model = ds.getNamedModel(graphName);
Put this inside the transaction

>     ds.begin(ReadWrite.WRITE);
>     FileManager.get().readModel(model, fileName);
>     ds.commit();
>     ds.end();
>     return true;
 > }

      ds.begin(ReadWrite.WRITE);
      Model model = ds.getNamedModel(graphName);
      RDFDataMgr.read(model, fileName);
      ds.commit();
      ds.end();


or even:

         Txn.executeWrite(ds, ()->{
             Model model = ds.getNamedModel(graphName);
             RDFDataMgr.read(model, fileName);
         });

http://jena.apache.org/documentation/txn/


> }
>
>
>
> At start, after everything is read and data set is committed, I\u2019m printing out the graph names and their sizes, to check, if everything was loaded:
>
> 2017-04-10 13:50:50 INFO  Ontology:50 - Named graph aaa - 7855 triples
> 2017-04-10 13:50:50 INFO  Ontology:50 - Named graph bbb - 26 triples
> 2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ccc - 4 triples
> 2017-04-10 13:50:50 INFO  Ontology:50 - Named graph ddd - 20000 triples
> \u2026
>
> After that I\u2019m trying to query some data from a named graph:
>
> SELECT count ($s)
> FROM NAMED <aaa>
> {
>     { ?s ?p ?o }
> }
>
> or trying to query it without specifying graph:
>
> SELECT count ($s)
> {
>     { ?s ?p ?o }
> }
>
> The result is empty:
>
> {
>   "head": {
>     "vars": [ ".1" ]
>   } ,
>   "results": {
>     "bindings": [
>       {
>         ".1": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "0" }
>       }
>     ]
>   }
> }
>
> What am I doing wrong?
>
> S.
>