Re: Dynamic graph/model inference within a select.

2013-06-21 Thread Andy Seaborne

On 19/06/13 20:11, Dick Murray wrote:

Hi sorry PICNIC moment...

I get the following results which is what I need. Against the dataset I get
2 results for each graph. Against the datasetgraphmap with override I get 2
results for g2 but 4 results for g1 because of the RDFS.




Problem with the 2 phase approach is that the phase 1 query isn't easy and
then there's the issue whether it's atomic. Ideally it needs to be dynamic
as the triples/quads are iterated


Atomicity is guaranteed inside a single transaction which can be several 
queries/updates.   Transactions are related to threads.




Are you saying that optimization might cause the getGraph not to be called?


Yes


Being called more than once for the same graph I can get around i.e. keep a
cache for the duration of the query.


You could update via the RDFS view of the dataset.  Maybe that way, you 
only have to build it once.




Thanks again.

Dick.


Andy



Re: Dynamic graph/model inference within a select.

2013-06-19 Thread Dick Murray
Hi sorry PICNIC moment...

I get the following results which is what I need. Against the dataset I get
2 results for each graph. Against the datasetgraphmap with override I get 2
results for g2 but 4 results for g1 because of the RDFS.

select * where {{ ?g a http://example.org/graph#Graph }. graph ?g {
http://example.org/trek/Triton ?p ?o}}
---
| g  | p
  | o  |
===
| http://example.org/graphs/g1 | 
http://www.w3.org/1999/02/22-rdf-syntax-ns#type | 
http://example.org/bikes#SingleSpeed |
| http://example.org/graphs/g1 | 
http://www.w3.org/2000/01/rdf-schema#label  | Triton
  |
| http://example.org/graphs/g2 | 
http://www.w3.org/1999/02/22-rdf-syntax-ns#type | 
http://example.org/bikes#SingleSpeed |
| http://example.org/graphs/g2 | 
http://www.w3.org/2000/01/rdf-schema#label  | Triton
  |
---

select * where {{ ?g a http://example.org/graph#Graph }. graph ?g {
http://example.org/trek/Triton ?p ?o}}
---
| g  | p
  | o  |
===
| http://example.org/graphs/g1 | 
http://www.w3.org/1999/02/22-rdf-syntax-ns#type | 
http://example.org/bikes#SingleSpeed |
| http://example.org/graphs/g1 | 
http://www.w3.org/2000/01/rdf-schema#label  | Triton
  |
| http://example.org/graphs/g1 | 
http://www.w3.org/1999/02/22-rdf-syntax-ns#type | 
http://example.org/bikes#Road|
| http://example.org/graphs/g1 | 
http://www.w3.org/1999/02/22-rdf-syntax-ns#type | 
http://example.org/bikes#Bike|
| http://example.org/graphs/g2 | 
http://www.w3.org/1999/02/22-rdf-syntax-ns#type | 
http://example.org/bikes#SingleSpeed |
| http://example.org/graphs/g2 | 
http://www.w3.org/2000/01/rdf-schema#label  | Triton
  |
---


Problem with the 2 phase approach is that the phase 1 query isn't easy and
then there's the issue whether it's atomic. Ideally it needs to be dynamic
as the triples/quads are iterated

Are you saying that optimization might cause the getGraph not to be called?
Being called more than once for the same graph I can get around i.e. keep a
cache for the duration of the query.

Thanks again.

Dick.



On 19 June 2013 12:20, Andy Seaborne a...@apache.org wrote:

 On 18/06/13 18:22, Dick Murray wrote:

 I'm looking for dynamic inference based on the select. Given a dataset
 with
 multiple named graphs I would like the ability to wrap specific named
 graphs based on some form of filter when the select is processed.


 The dataset being queried can not be manipulated during the query.

 Whether getGraph is called is evaluator dependent (it's not in TDB which
 works on quads).

 There is no guarantee a query is executed in a particular order.  It coudl
 do the GRAPH bit before the dft graph access.  Currently, that unlikely,
 but there is no guarantee.  Oh - and it may happen twice for rewritten
 queries (equality optimizations like to generate multiple more grounded
 accesses).


  Given the dataset D which contains the named graphs G1, G2, G3 I would
 like
 G2 to be returned with RDFS inference if it is queried in a select. I have
 achieved this by wrapping the graph as an InfModel and using a
 DatasetGraphMap but this requires that the graph be known before the
 select
 is executed. What I'm trying to find (if it exists) is the point during
 the
 select processing when the graph is identified and used? Does this exist
 in
 a TDB Dataset or is it just a set of quads?


 Such a point exists (OpExecutor.execute(OpGraph)) but because of
 optimization and/or converting to quads.

 A TDB datsegraph is a set of triples (dft graph) + a set of quads (named
 graphs).Full quad based optimization isn't really done currently but it
 will be in future so any internal approach is going to be vulnerable to
 changes.

 I think you need a 2-phase approach.

 Phase-1 is setup - query the data and determine which graphs to add
 inference to.

 Phase-2 : Build a new datasetgraph and then query that for the real
 answers.

 Maybe that's what you are doing.  If you query dgm I'd expect to see the
 RDFS inferences but it does not show where you issue the query. Complete,
 minimal example?

 Andy


 

Re: Dynamic graph/model inference within a select.

2013-06-18 Thread Dick Murray
I'm looking for dynamic inference based on the select. Given a dataset with
multiple named graphs I would like the ability to wrap specific named
graphs based on some form of filter when the select is processed.

Given the dataset D which contains the named graphs G1, G2, G3 I would like
G2 to be returned with RDFS inference if it is queried in a select. I have
achieved this by wrapping the graph as an InfModel and using a
DatasetGraphMap but this requires that the graph be known before the select
is executed. What I'm trying to find (if it exists) is the point during the
select processing when the graph is identified and used? Does this exist in
a TDB Dataset or is it just a set of quads?

Dick.


On 18 June 2013 16:01, Andy Seaborne a...@apache.org wrote:

 Dick,

 I'm not completely sure what you're trying to do - a complete minimal
 example showing how they bits and pieces fit together would be good.  It
 seems to be querying the dataset without the inference graph.  I don't see
 where you query the dataset (and which one)

  if (graphNode.getURI().equals(**types.getURI())) {

 if (graphNode.equals(types.**asNode())  {



 On 18/06/13 14:22, Dick Murray wrote:

 Hi.

 Is it possible to get at the graph i.e. the ?g (specifically the returned
 nodes) when the following query is executed?


 Yes - getGraph / getNamedModel depending on which level your working at.


  SELECT  *
 WHERE
{ { ?g 
 http://www.w3.org/1999/02/22-**rdf-syntax-ns#typehttp://www.w3.org/1999/02/22-rdf-syntax-ns#type
 
 http://www.unit4.com/daas/**graph#Graphhttp://www.unit4.com/daas/graph#Graph
 }
  GRAPH ?g
{ ?s ?p ?o }
}

 When the result is instantiated I want to return the ?g as an RDFS
 infmodel. Ideally I want to decide what to return based on the ?g. I've
 traced the execSelect() and the ResultSetMem() but drew a blank as to
 where
 I can get at the ?g's!


 ResultSet.next().getResource(**g) ;
or
 ResultSet.nextBinding().get(**Var.alloc(g)) ;




 The following allows me to wrap the returned graph but this is static i.e.
 I need to know the ?g's to generate the dgm to pass to the
 QueryExecutionFactory.

 dataset.begin(ReadWrite.READ);
 DatasetGraphMap dgm = new DatasetGraphMap(dataset.**asDatasetGraph()) {

 @Override
 public Graph getGraph(Node graphNode) {
 Graph g = super.getGraph(graphNode);
 if (graphNode.getURI().equals(**types.getURI())) {
 g = asRDFS(g);
 }
 return g;
 }
   public Graph asRDFS(Graph g) {
 return
 ModelFactory.createRDFSModel(**ModelFactory.**createModelForGraph(g)).**
 getGraph();
 }
   };
 Graph g = dgm.getGraph(types.asNode());
 info(g.size());
 dataset.end();

 For the following triples loaded in the default graph;

 @prefix rdf: 
 http://www.w3.org/1999/02/22-**rdf-syntax-ns#http://www.w3.org/1999/02/22-rdf-syntax-ns#
 .
 @prefix rdfs: 
 http://www.w3.org/2000/01/**rdf-schema#http://www.w3.org/2000/01/rdf-schema#
 .

 @prefix graph: 
 http://www.unit4.com/daas/**graph#http://www.unit4.com/daas/graph#
 .

 @prefix graphs: 
 http://www.unit4.com/daas/**graphs/http://www.unit4.com/daas/graphs/
 .

 graph:Graph
 rdf:type rdfs:Class.
 graphs:g1
 rdf:type graph:Graph.

 and these loaded in a named graph 
 http://www.unit4.com/daas/**graphs/g1http://www.unit4.com/daas/graphs/g1
 ;

 @prefix rdf: 
 http://www.w3.org/1999/02/22-**rdf-syntax-ns#http://www.w3.org/1999/02/22-rdf-syntax-ns#
 .
 @prefix rdfs: 
 http://www.w3.org/2000/01/**rdf-schema#http://www.w3.org/2000/01/rdf-schema#
 .

 @prefix graph: 
 http://www.unit4.com/daas/**graph#http://www.unit4.com/daas/graph#
 .

 @prefix graphs: 
 http://www.unit4.com/daas/**graphs/http://www.unit4.com/daas/graphs/
 .

 graphs:g1
 rdfs:label Graph 1.

 A select returns;

 select * where {{ ?g a 
 http://www.unit4.com/daas/**graph#Graphhttp://www.unit4.com/daas/graph#Graph
 }. graph ?g
 {?s ?p ?o}}
 --**--**
 --**--**
 
 | g | s
  | p| o |
 ==**==**
 ==**==**
 
 | 
 http://www.unit4.com/daas/**graphs/g1http://www.unit4.com/daas/graphs/g1
 | 
 http://www.unit4.com/daas/**graphs/g1http://www.unit4.com/daas/graphs/g1
 | 
 http://www.w3.org/2000/01/rdf-**schema#labelhttp://www.w3.org/2000/01/rdf-schema#label
 | Graph 1 |
 --**--**
 --**--**
 

 What I want is for it to return about 40 more... :-)