On 7/31/2014 14:45, Jorge Gastaldi wrote:
This is basically what I'm doing. "query" is the SPARQL query string. I will turn it into a Model, modify it and then, I want to rebuild it.


SPINModuleRegistry.get().init();
// Create an empty OntModel importing SP
Model model = ModelFactory.createDefaultModel();
model.setNsPrefix("rdf", RDF.getURI());
model.setNsPrefix("dbpedia", "http://dbpedia.org/resource/";);
Query arqQuery = ARQFactory.get().createQuery(model, query);
ARQ2SPIN arq2SPIN = new ARQ2SPIN(model);
Select spinQuery = (Select) arq2SPIN.createQuery(arqQuery, null);


    // Then I add some rules to the model
Model modeloReglas = ModelFactory.createDefaultModel();
modeloReglas.read("reglas.ttl");
modeloConsulta.add(modeloReglas);


    // And run the inferences (following another example from SPIN-API)
OntModel ontModel = JenaUtil.createOntologyModel(OntModelSpec.OWL_MEM, modeloConsulta);
Model newTriples = ModelFactory.createDefaultModel();
ontModel.addSubModel(newTriples);
SPINInferences.run(ontModel, newTriples, null, null, false, null);

At this stage I assume you want to execute rules that add triples to the existing Select? If that is the case then you should do

    ontModel.addSubModel(model);

before running the inferences to make sure that the rules also "see" that existing Select. The Jena resource of that Select would still be the same, only that you need to redirect it into the ontModel so that it also "sees" the inferred triples:

    spinQuery = (Select) SPINFactory.asQuery(spinQuery.inModel(ontModel));

If you then want to convert this Select back into a valid SPARQL string, make sure that you had switched off the cache of the ARQFactory beforehand - otherwise it may believe that it has seen this query before and used a cached copy of the string:

    ARQFactory.get().clearCaches();

But again, I am not sure if we are talking about the same problem. Maybe your rules are in fact producing a completely new instance of sp:Select? In that case, find it via Jena using

Resource newSelect = newTriples.listSubjectsWithProperty(RDF.type, SP.Select).next();

which should give you the first (and only) instance of sp:Select in the inferences, and then you can use SPINFactory to turn it into a Select instance etc.

HTH
Holger

The inference rules add valid (I hope) triples to the SPIN SPARQL query.
At this point I have a model that has both a SPARQL Query (the original with aditional parts) and some SPIN rules. I want to get the query from the model (i can remove the rules from the model, if necesary). There is a similar question in the mailing list, but in that case the query was the body of a template, so it's easy to get the Resource. Here the query it's something like this:

[ a  <http://spinrdf.org/sp#Select> ;
  <http://spinrdf.org/sp#resultVariables>
          ( [ <http://spinrdf.org/sp#varName>
"a"^^<http://www.w3.org/2001/XMLSchema#string> ] [ <http://spinrdf.org/sp#varName> "b"^^<http://www.w3.org/2001/XMLSchema#string> ] [ <http://spinrdf.org/sp#varName>
"c"^^<http://www.w3.org/2001/XMLSchema#string> ] ) ;
<http://spinrdf.org/sp#where> ( [ <http://spinrdf.org/sp#object> [ <http://spinrdf.org/sp#varName>
 "c"^^<http://www.w3.org/2001/XMLSchema#string> ] ;
 <http://spinrdf.org/sp#predicate>
[ <http://spinrdf.org/sp#varName>
 "b"^^<http://www.w3.org/2001/XMLSchema#string> ] ;
 <http://spinrdf.org/sp#subject>
[ <http://spinrdf.org/sp#varName>
 "a"^^<http://www.w3.org/2001/XMLSchema#string> ]
                                   ] )
] .
      As I say early, probably the answer is trivial.

Thanks for your patience,
Jorge




On Wednesday, July 30, 2014 4:21:18 AM UTC-3, Holger Knublauch wrote:

    On 7/30/2014 15:42, Jorge Gastaldi wrote:
    >
    > Thanks for your answer!
    >
    >
    > I think that the problem is that I don't know how to create the
    Select
    > object ("spinQuery" in the example) without refering to the
    query string.
    >
    > From the example:
    > Select spinQuery = (Select) arq2SPIN.createQuery(arqQuery, null);
    >
    > arqQuery was created using the query String. I only have the
    Jena Model.
    >
    >
    > This is problably something trivial, but I'm quite at loss here.

    So is your starting point a Jena Resource instance? To convert
    that into
    a Select, use SPINFactory.asQuery(resource)

    If this doesn't help, I need to see a source code snippet where
    you are
    stuck.

    HTH
    Holger

--
-- You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary Network (EVN), TopBraid Composer, TopBraid Live, TopBraid Insight, SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en
---
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.

--
-- You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary 
Network (EVN), TopBraid Composer, TopBraid Live, TopBraid Insight, SPARQLMotion, SPARQL 
Web Pages and SPIN.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en
--- You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to