Problem with "datatype" function in a SPARQL query
Hi all, Maybe this question has been already answered or is in the documentation, but I can't find an answer. I have a code to perform a set of SPARQL queries against a concrete dataset. My problem is that, the SPARQL query is making use of datatype() function, and it seems that Jena is not recognizing this function (and therefore return me an error). The query that I want to perform is the following: *SELECT distinct datatype(?o) as ?datatype* *FROM <@NAMED_GRAPH>* *WHERE {* * ?s a <@SUBJECT_TYPE> .* *?s <@PREDICATE_TYPE> ?o . * * FILTER isLiteral(?o)* *}* *group by ?o* Originally it was "SELECT distinct(datatype(?o)) as ?datatype" but I saw that distinct should be used without parenthesis. (I also try with "SELECT distinct datatype ?o as..." with no positive result). An example of the query: SELECT distinct datatype(?o) as ?datatype FROM <http://bio2rdf.org/bio2rdf.dataset:bio2rdf-affymetrix-20131220> WHERE { ?s a <http://bio2rdf.org/affymetrix_vocabulary:Genechip-Array> . ?s <http://bio2rdf.org/affymetrix_vocabulary:x-unigene> ?o . FILTER isLiteral(?o) } group by ?o If I perform the query against the endpoint ( http://s4.semanticscience.org:14001/sparql), it runs fine (in this case is not returning any result, but no errors are thrown): http://s4.semanticscience.org:14001/sparql?default-graph-uri=&query=SELECT+distinct+datatype%28%3Fo%29+as+%3Fdatatype%0D%0AFROM+%3Chttp%3A%2F%2Fbio2rdf.org%2Fbio2rdf.dataset%3Abio2rdf-affymetrix-20131220%3E%0D%0AWHERE+%7B%0D%0A+%3Fs+a+%3Chttp%3A%2F%2Fbio2rdf.org%2Faffymetrix_vocabulary%3AGenechip-Array%3E+.%0D%0A%3Fs+%3Chttp%3A%2F%2Fbio2rdf.org%2Faffymetrix_vocabulary%3Ax-unigene%3E+%3Fo+.+++%0D%0A+FILTER+isLiteral%28%3Fo%29%0D%0A%7D%0D%0Agroup+by+%3Fo&format=text%2Fhtml&timeout=0&debug=on However, when I use my code (which generates the query ok, I check it printing the query), it returns the following exception: http://pastebin.com/qhzyxJKn The code which performs the query is here (the method which throws the exception is the QueryFactory.create(..): http://pastebin.com/2VVgKyZT I guess that it is a problem "calling" datatype function, but not sure how to solve it. Thanks! -- Dr. Alejandro Rodríguez González - PhD Bioinformatics at Centre for Plant Biotechnology and Genomics UPM-INIA Polytechnic University of Madrid http://www.alejandrorg.com Phone: +34 914524900 . Ext: 25550 *Once the game is over, the king and the pawn go back in the same box. - Italian proverb*
Problem with "datatype" function in a SPARQL query
Hi all, Maybe this question has been already answered or is in the documentation, but I can't find an answer. I have a code to perform a set of SPARQL queries against a concrete dataset. My problem is that, the SPARQL query is making use of datatype() function, and it seems that Jena is not recognizing this function (and therefore return me an error). The query that I want to perform is the following: *SELECT distinct datatype(?o) as ?datatype* *FROM <@NAMED_GRAPH>* *WHERE {* * ?s a <@SUBJECT_TYPE> .* *?s <@PREDICATE_TYPE> ?o . * * FILTER isLiteral(?o)* *}* *group by ?o* Originally it was "SELECT distinct(datatype(?o)) as ?datatype" but I saw that distinct should be used without parenthesis. (I also try with "SELECT distinct datatype ?o as..." with no positive result). An example of the query: SELECT distinct datatype(?o) as ?datatype FROM <http://bio2rdf.org/bio2rdf.dataset:bio2rdf-affymetrix-20131220> WHERE { ?s a <http://bio2rdf.org/affymetrix_vocabulary:Genechip-Array> . ?s <http://bio2rdf.org/affymetrix_vocabulary:x-unigene> ?o . FILTER isLiteral(?o) } group by ?o If I perform the query against the endpoint ( http://s4.semanticscience.org:14001/sparql), it runs fine (in this case is not returning any result, but no errors are thrown): http://s4.semanticscience.org:14001/sparql?default-graph-uri=&query=SELECT+distinct+datatype%28%3Fo%29+as+%3Fdatatype%0D%0AFROM+%3Chttp%3A%2F%2Fbio2rdf.org%2Fbio2rdf.dataset%3Abio2rdf-affymetrix-20131220%3E%0D%0AWHERE+%7B%0D%0A+%3Fs+a+%3Chttp%3A%2F%2Fbio2rdf.org%2Faffymetrix_vocabulary%3AGenechip-Array%3E+.%0D%0A%3Fs+%3Chttp%3A%2F%2Fbio2rdf.org%2Faffymetrix_vocabulary%3Ax-unigene%3E+%3Fo+.+++%0D%0A+FILTER+isLiteral%28%3Fo%29%0D%0A%7D%0D%0Agroup+by+%3Fo&format=text%2Fhtml&timeout=0&debug=on However, when I use my code (which generates the query ok, I check it printing the query), it returns the following exception: http://pastebin.com/qhzyxJKn The code which performs the query is here (the method which throws the exception is the QueryFactory.create(..): http://pastebin.com/2VVgKyZT I guess that it is a problem "calling" datatype function, but not sure how to solve it. Thanks! -- Dr. Alejandro Rodríguez González - PhD Bioinformatics at Centre for Plant Biotechnology and Genomics UPM-INIA Polytechnic University of Madrid http://www.alejandrorg.com Phone: +34 914524900 . Ext: 25550 *Once the game is over, the king and the pawn go back in the same box. - Italian proverb*
Retrieving a data type in a SPARQL query
Hi! Sorry if this question has been already answered. Based on a previous query to this list ( http://goo.gl/kfKMqP ) now I have a small problem. I have the same query and the following code (see query and code here: http://pastebin.com/16B6MPmz ). My problem is that, if I execute this query manually against the endpoint (see: http://goo.gl/RVWuSi ) I can get correctly the desired result (a datatype). However, doing this by code, I got the QuerySolution object (which contains the variable name (dt) and the datatype (xml:string)), but I can't get the datatype from the QuerySolution object. If I try calling getResource(variable) method, it returns null. If I do the same with the getLiteral(variable) or get(variable) to get a RDFNode, always it returns a null value. Now, I'm getting the value parsing the toString() value of the QuerySolution object, but I'm wondering if it is an easier way to do that, or maybe I'm not using the correct classes/methods. Thanks! -- Dr. Alejandro Rodríguez González - PhD Bioinformatics at Centre for Plant Biotechnology and Genomics UPM-INIA Polytechnic University of Madrid http://www.alejandrorg.com Phone: +34 914524900 . Ext: 25550 *Once the game is over, the king and the pawn go back in the same box. - Italian proverb*
Re: Problem with "datatype" function in a SPARQL query
Hi! Thanks for your answer both! Yep, the problem was in the parenthesis. Sorry if the message arrive twice to the mailing list, I had some problems with the email! Cheers On 11 May 2014 18:27, Andy Seaborne wrote: > On 9 May 2014 11:38, Alejandro Rodríguez González > wrote: > > Hi all, > > > > Maybe this question has been already answered or is in the documentation, > > but I can't find an answer. > > > > I have a code to perform a set of SPARQL queries against a concrete > > dataset. My problem is that, the SPARQL query is making use of datatype() > > function, and it seems that Jena is not recognizing this function (and > > therefore return me an error). > > > > The query that I want to perform is the following: > > > > *SELECT distinct datatype(?o) as ?datatype* > > The syntax is: > > SELECT distinct (datatype(?o) as ?datatype) > > The () are not to do with DISTINCT, they come from the AS part: > > (expression AS ?variable) > > > *FROM <@NAMED_GRAPH>* > > *WHERE {* > > * ?s a <@SUBJECT_TYPE> .* > > *?s <@PREDICATE_TYPE> ?o . * > > * FILTER isLiteral(?o)* > > *}* > > *group by ?o* > > > > > > Originally it was "SELECT distinct(datatype(?o)) as ?datatype" but I saw > > that distinct should be used without parenthesis. (I also try with > "SELECT > > distinct datatype ?o as..." with no positive result). > > > > An example of the query: > > > > SELECT distinct datatype(?o) as ?datatype > > FROM <http://bio2rdf.org/bio2rdf.dataset:bio2rdf-affymetrix-20131220> > > WHERE { > > ?s a <http://bio2rdf.org/affymetrix_vocabulary:Genechip-Array> . > > ?s <http://bio2rdf.org/affymetrix_vocabulary:x-unigene> ?o . > > FILTER isLiteral(?o) > > } > > group by ?o > > > > If I perform the query against the endpoint ( > > http://s4.semanticscience.org:14001/sparql), it runs fine (in this case > is > > not returning any result, but no errors are thrown): > > > > > http://s4.semanticscience.org:14001/sparql?default-graph-uri=&query=SELECT+distinct+datatype%28%3Fo%29+as+%3Fdatatype%0D%0AFROM+%3Chttp%3A%2F%2Fbio2rdf.org%2Fbio2rdf.dataset%3Abio2rdf-affymetrix-20131220%3E%0D%0AWHERE+%7B%0D%0A+%3Fs+a+%3Chttp%3A%2F%2Fbio2rdf.org%2Faffymetrix_vocabulary%3AGenechip-Array%3E+.%0D%0A%3Fs+%3Chttp%3A%2F%2Fbio2rdf.org%2Faffymetrix_vocabulary%3Ax-unigene%3E+%3Fo+.+++%0D%0A+FILTER+isLiteral%28%3Fo%29%0D%0A%7D%0D%0Agroup+by+%3Fo&format=text%2Fhtml&timeout=0&debug=on > > > > However, when I use my code (which generates the query ok, I check it > > printing the query), it returns the following exception: > > http://pastebin.com/qhzyxJKn > > > > The code which performs the query is here (the method which throws the > > exception is the QueryFactory.create(..): http://pastebin.com/2VVgKyZT > > > > I guess that it is a problem "calling" datatype function, but not sure > how > > to solve it. > > > > Thanks! > > > > -- > > Dr. Alejandro Rodríguez González - PhD > > > > Bioinformatics at Centre for Plant Biotechnology and Genomics UPM-INIA > > Polytechnic University of Madrid > > http://www.alejandrorg.com > > Phone: +34 914524900 . Ext: 25550 > > > > > > *Once the game is over, the king and the pawn go back in the same box. - > > Italian proverb* > On 11 May 2014 18:20, james anderson wrote: > good evening dr rodriguez; > > On 11 May 2014, at 01:12, Alejandro Rodríguez González < > alejandro.rod@gmail.com> wrote: > > SELECT distinct datatype(?o) as ?datatype > FROM <http://bio2rdf.org/bio2rdf.dataset:bio2rdf-affymetrix-20131220> > WHERE { > ?s a <http://bio2rdf.org/affymetrix_vocabulary:Genechip-Array> . > ?s <http://bio2rdf.org/affymetrix_vocabulary:x-unigene> ?o . > FILTER isLiteral(?o) > } > group by ?o > > > > note that, where you have indicated the “group by ?o”, you have specified > an aggregation. > of this aggregation, strictly speaking, the ?o in the projection clause > should be used with the“sample” operator before it can be supplied to > ‘datatype’. > although, perhaps jena makes an exception here... > > best regards, from berlin, > > > > --- > james anderson | ja...@dydra.com | http://dydra.com > -- Dr. Alejandro Rodríguez González - PhD Bioinformatics at Centre for Plant Biotechnology and Genomics UPM-INIA Polytechnic University of Madrid http://www.alejandrorg.com Phone: +34 914524900 . Ext: 25550 *Once the game is over, the king and the pawn go back in the same box. - Italian proverb*
Problem with "datatype" function in a SPARQL query
Hi all, Maybe this question has been already answered or is in the documentation, but I can't find an answer. I have a code to perform a set of SPARQL queries against a concrete dataset. My problem is that, the SPARQL query is making use of datatype() function, and it seems that Jena is not recognizing this function (and therefore return me an error). The query that I want to perform is the following: *SELECT distinct datatype(?o) as ?datatype* *FROM <@NAMED_GRAPH>* *WHERE {* * ?s a <@SUBJECT_TYPE> .* *?s <@PREDICATE_TYPE> ?o . * * FILTER isLiteral(?o)* *}* *group by ?o* Originally it was "SELECT distinct(datatype(?o)) as ?datatype" but I saw that distinct should be used without parenthesis. (I also try with "SELECT distinct datatype ?o as..." with no positive result). An example of the query: SELECT distinct datatype(?o) as ?datatype FROM <http://bio2rdf.org/bio2rdf.dataset:bio2rdf-affymetrix-20131220> WHERE { ?s a <http://bio2rdf.org/affymetrix_vocabulary:Genechip-Array> . ?s <http://bio2rdf.org/affymetrix_vocabulary:x-unigene> ?o . FILTER isLiteral(?o) } group by ?o If I perform the query against the endpoint ( http://s4.semanticscience.org:14001/sparql), it runs fine (in this case is not returning any result, but no errors are thrown): http://s4.semanticscience.org:14001/sparql?default-graph-uri=&query=SELECT+distinct+datatype%28%3Fo%29+as+%3Fdatatype%0D%0AFROM+%3Chttp%3A%2F%2Fbio2rdf.org%2Fbio2rdf.dataset%3Abio2rdf-affymetrix-20131220%3E%0D%0AWHERE+%7B%0D%0A+%3Fs+a+%3Chttp%3A%2F%2Fbio2rdf.org%2Faffymetrix_vocabulary%3AGenechip-Array%3E+.%0D%0A%3Fs+%3Chttp%3A%2F%2Fbio2rdf.org%2Faffymetrix_vocabulary%3Ax-unigene%3E+%3Fo+.+++%0D%0A+FILTER+isLiteral%28%3Fo%29%0D%0A%7D%0D%0Agroup+by+%3Fo&format=text%2Fhtml&timeout=0&debug=on However, when I use my code (which generates the query ok, I check it printing the query), it returns the following exception: http://pastebin.com/qhzyxJKn The code which performs the query is here (the method which throws the exception is the QueryFactory.create(..): http://pastebin.com/2VVgKyZT I guess that it is a problem "calling" datatype function, but not sure how to solve it. Thanks! -- Dr. Alejandro Rodríguez González - PhD Bioinformatics at Centre for Plant Biotechnology and Genomics UPM-INIA Polytechnic University of Madrid http://www.alejandrorg.com Phone: +34 914524900 . Ext: 25550 *Once the game is over, the king and the pawn go back in the same box. - Italian proverb*
Re: Working with quads. Some questions
Hi Rob, Thanks for your reply. I saw the errors with the uri/literal creation. Completely true! And about the Nquad specification, yep, I think I understand my problem! Thanks! On 2 October 2013 14:13, Alejandro Rodríguez González < alejandro.rod@gmail.com> wrote: > Hi all, > > I'm trying to create a small program which convert an RDF file into quads > adding context. > > I've been looking at the examples in the API and some information on > Google, but I don't know exactly what I'm doing wrong. > > I create my quads in the following way: > > ArrayList quads = new ArrayList(); > quads.add(new Quad(this.assertionNode, this.rdfTypeNode, > this.nanoPubSchemaAssertionNode, this.nanoPubNode)); > quads.add(new Quad(this.nanoPubNode, this.purlCoverageNode, > getNodeFromString(coverageContent), this.provenanceNode)); > > The "nodes" are created using NodeFactory. Just an example with the nodes > used in the example presented before: > > this.assertionNode = NodeFactory.createLiteral(" > http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/assertion/6bfba5c26cedaa3caf460d36d25ceef0 > "); > > this.nanoPubNode = NodeFactory.createLiteral(" > http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0 > "); > > this.provenanceNode = NodeFactory.createLiteral(" > http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/provenance/1380725119158 > "); > > etc. > > Once I've created all my structure, I try to print it on screen and store > it on a .nq file using this code: > > Dataset ds = TDBFactory.createDataset(); > DatasetGraph dsg = ds.asDatasetGraph(); > for (int i = 0; i < quads.size(); i++) { > dsg.add(quads.get(i)); > } > RDFDataMgr.write(new FileOutputStream(new File("output/nquad2.nq")), > dsg, RDFFormat.NQUADS); > System.out.println(dsg.toString()); > > The output that I get in the console is the following: > > (dataset > (graph) > (graph " > http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/assertion/6bfba5c26cedaa3caf460d36d25ceef0 > " > (triple "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; " > http://www.nanopub.org/nschema#Assertion"; " > http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0 > ") > ) > (graph " > http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0 > " > (triple "http://purl.org/dc/elements/1.1/description"; "\"Output from > SADI Service\"@en" " > http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/provenance/1380725119158 > ") > )) > > > Which, it is the one that "I desire". However, in the file, I've the > following: > > "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; " > http://www.nanopub.org/nschema#Assertion"; " > http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0"; > " > http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/assertion/6bfba5c26cedaa3caf460d36d25ceef0"; > . > "http://purl.org/dc/elements/1.1/description"; "\"Output from SADI > Service\"@en" " > http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/provenance/1380725119158"; > " > http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0"; > . > > My questions are: > > 1) Why is the order of the nodes different? I mean, I expect to have: > context, s, p, o (like when it is printed) > 2) Why, even using RDFFormat.NQUADS the serialization is between " " and > not between <> ? > > Probably I'm missing something ... > > Thanks for your time. > > Cheers, > > Alejandro > > -- > Dr. Alejandro Rodríguez González - PhD > > Bioinformatics at Centre for Plant Biotechnology and Genomics UPM-INIA > Polytechnic University of Madrid > http://www.alejandrorg.com > Phone: +34 914524900 . Ext: 25550 > > > *Once the game is over, the king and the pawn go back in the same box. - > Italian proverb* > -- Dr. Alejandro Rodríguez González - PhD Bioinformatics at Centre for Plant Biotechnology and Genomics UPM-INIA Polytechnic University of Madrid http://www.alejandrorg.com Phone: +34 914524900 . Ext: 25550 *Once the game is over, the king and the pawn go back in the same box. - Italian proverb*
Working with quads. Some questions
Hi all, I'm trying to create a small program which convert an RDF file into quads adding context. I've been looking at the examples in the API and some information on Google, but I don't know exactly what I'm doing wrong. I create my quads in the following way: ArrayList quads = new ArrayList(); quads.add(new Quad(this.assertionNode, this.rdfTypeNode, this.nanoPubSchemaAssertionNode, this.nanoPubNode)); quads.add(new Quad(this.nanoPubNode, this.purlCoverageNode, getNodeFromString(coverageContent), this.provenanceNode)); The "nodes" are created using NodeFactory. Just an example with the nodes used in the example presented before: this.assertionNode = NodeFactory.createLiteral(" http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/assertion/6bfba5c26cedaa3caf460d36d25ceef0 "); this.nanoPubNode = NodeFactory.createLiteral(" http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0 "); this.provenanceNode = NodeFactory.createLiteral(" http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/provenance/1380725119158 "); etc. Once I've created all my structure, I try to print it on screen and store it on a .nq file using this code: Dataset ds = TDBFactory.createDataset(); DatasetGraph dsg = ds.asDatasetGraph(); for (int i = 0; i < quads.size(); i++) { dsg.add(quads.get(i)); } RDFDataMgr.write(new FileOutputStream(new File("output/nquad2.nq")), dsg, RDFFormat.NQUADS); System.out.println(dsg.toString()); The output that I get in the console is the following: (dataset (graph) (graph " http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/assertion/6bfba5c26cedaa3caf460d36d25ceef0 " (triple "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; " http://www.nanopub.org/nschema#Assertion"; " http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0 ") ) (graph " http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0 " (triple "http://purl.org/dc/elements/1.1/description"; "\"Output from SADI Service\"@en" " http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/provenance/1380725119158 ") )) Which, it is the one that "I desire". However, in the file, I've the following: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; " http://www.nanopub.org/nschema#Assertion"; " http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0"; " http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/assertion/6bfba5c26cedaa3caf460d36d25ceef0"; . "http://purl.org/dc/elements/1.1/description"; "\"Output from SADI Service\"@en" " http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/provenance/1380725119158"; " http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0"; . My questions are: 1) Why is the order of the nodes different? I mean, I expect to have: context, s, p, o (like when it is printed) 2) Why, even using RDFFormat.NQUADS the serialization is between " " and not between <> ? Probably I'm missing something ... Thanks for your time. Cheers, Alejandro -- Dr. Alejandro Rodríguez González - PhD Bioinformatics at Centre for Plant Biotechnology and Genomics UPM-INIA Polytechnic University of Madrid http://www.alejandrorg.com Phone: +34 914524900 . Ext: 25550 *Once the game is over, the king and the pawn go back in the same box. - Italian proverb*
Re: Empty derivation files
Hi Dave, I see that it is complex, right.. just to finish: Do you have any example about creating a customized rule syntax to translate it into Jena Rules (and how is this process)? Thanks
Re: Empty derivation files
Hi Dave, Why? The correct, standard way to do disjunctions in rule systems is to have multiple rules. Stick with that approach. Yep, I understand, but the problem is that the number of rules will get quite high with this approach depending on the configuration of the disease modeled. The only rule that that initializes the counter is: rule_dX_NOT_REST_SIGNS which (a) only fires if there is a finding other than sA to sE and (b) asserts your ont:dX_NOT_SIGNS flag. So the only situation in which there is a zero counter to get the counting started is one where you have some other finding and even then those counting rules will never fire because they are guarded by: noValue(?i, ont:hasNegSign ont:dX_NOT_SIGNS) If they did fire than be aware that the counting rules you have do not remove the older counts (the painful bit of counting in JenaRules) so you'll end up with all the count values not a single total value. I saw.. I've been working on this, and I've modified the rules. From my POV are correct, but probably I'm missing something since the new approach is not working: http://pastebin.com/EGB2s2YK I've created a rule to init the counter when a sign is received and the counter doesn't have any value (I'm using value 4 as an example, but I have also tried with noValue builtin), but it doesn't work. I've also modified the rule where the counter is increased, not checking the flag dX_NOT_SIGNS (only is checked in diagnosis). The workflow should be (if I'm not wrong): 1. Check if there is any forbidden sign (allowed: sA to sE). If there is any forbidden sign, set flat dX_NOT_SIGNS 2. Init the counter when: you received a sign & counter != 4 3. Increase counter when you receive sC 4. Return dX as diagnosis: we have as input sA & sB & counter >= 1 & dX_NOT_SIGNS flag is not set
Re: Empty derivation files
Hi Dave, Thanks, this makes my task harder :-) Let me then ask you a question about the rules that I have. Maybe you can help me with this. Based on the same example that we were talking I want to create a rules that are executed when "I have sign A, B (compulsory) and one of the following: C, D, E). For this, I already have a solution creating several combinations such as A,B,C; A,B,D; etc.. but I want other design. I've then some rules where, first of all, I close the world using noValue and specifying only A,B,C,D, and E as valid signs. Then, I've created a rule that should be fired (with diagnosis result) only if I have A, B (compulsory) and a counter with a value greater or equal to 1. Then, I've developed also three more rules (one per remaining sign: C,D,E), that increases this counter. However it seems to not be working. Here are the rules: http://pastebin.com/LeWY7Ndq PD: The counter doesn't exist in my current ontology. It is created in the same way than hasNegSign. Thanks! ___ Sorry no. There are sophisticated rule systems that can tell you why a rule wasn't fired but there's no support for that in JenaRules. Dave
Re: Empty derivation files
Hi Dave, It seems that the problem was precisely this line because after remove it now the files are not empty (except one, but because the rules were not fired). I don't remember why I introduced this line.. :-? Just another question: It is possible to see a more detailed debug of the derivations? For example, I want to know why some rules are not being fired, something that will help me to know what I'm doing wrong. Thanks! _ There's no problem creating an InfModel over another model the problem is that you have lines like: this.model.add(this.inferenceModel); Where this.model is the model which is underneath this.inferenceModel, thus adding the data back into itself. This is probably not harmful on its own but makes it hard to trace what you are trying to do. You can in fact just create an OntModel with the reasoner attached. So a simple example might be:
Re: Empty derivation files
Hi Dave, Sorry, I thought that this was minimal enough :-) Just one question: how can I create an inference model without feed the model with the original model? All the examples that I saw use a Model object to load the ontology and feed the InfModel (with the reasoner also). Thanks! __ That's not a *minimal* example! It's quite hard to see what you are trying to do with model and inferenceModel. The inferenceModel is created over the top of model and yet you also add inferenceModel back into model at various stages. Very circular and probably not what you mean. You seem to set derivation logging on model, rather than inferenceModel during createConsult and then set derivation logging on inferenceModel only at the start of executeInference. At least for the first cycle this will be after inference is complete and so there's no derivations left to make and nothing will be logged for that iteration. Can I suggest that you start with a simpler test case. Just create a single InfModel over your rules. No fiddling with the base model. Set derivation logging on at creation time. Then add a data sample and check that derivations are logged. If you try that and it works then you know the Jena machinery works the way you are using it and you can incrementally extend your code to do what you want it to do. If if doesn't work then you have a test case we can take a look at without having work out the rest of your code :) Cheers, Dave
Re: Empty derivation files
Hi Dave, Thanks. I've created a small ontology and set of rules which are fired (I print the results and I saw that is making the inference correctly). I checked if derivation is switched on (I've executed setDerivationLogging to true)) and the files continue empty..!! This is the full code that I'm using: OWLInferenceManager: http://pastebin.com/trQVtv1s Consult: http://pastebin.com/nCnT0nBa Main: http://pastebin.com/UduJ2nXY The ontology: http://pastebin.com/1QkrknMr The rules: http://pastebin.com/JPT3UZSi And the output (that confirms that rules are fired, but no derivation is logged): http://pastebin.com/HA06pYmX Thanks for your help! Hi, > > Nothing leaps out as wrong with the piece of the code that you have shown > so the next step would be for you to start debugging. Check whether any > derivations are being found, if so check whether they can be serialized to > the console. > > If no derviations are being found then maybe your haven't switched on > derivation logging or maybe your rules are not being fired. > > If you really get stuck then create a complete minimum test case you can > post. In your case that would mean creating a minimum data sample and rule > set as well as the code to run it. You might well find that in the process > of creating that minimal test case you find the problem :) > > Dave
Re: Empty derivation files
Hi Dave, Thanks. I've created a small ontology and set of rules which are fired (I print the results and I saw that is making the inference correctly). I checked if derivation is switched on (I've executed setDerivationLogging to true)) and the files continue empty..!! This is the full code that I'm using: OWLInferenceManager: http://pastebin.com/trQVtv1s Consult: http://pastebin.com/nCnT0nBa Main: http://pastebin.com/UduJ2nXY The ontology: http://pastebin.com/1QkrknMr The rules: http://pastebin.com/JPT3UZSi And the output (that confirms that rules are fired, but no derivation is logged): http://pastebin.com/HA06pYmX Thanks for your help! Hi, > > Nothing leaps out as wrong with the piece of the code that you have shown > so the next step would be for you to start debugging. Check whether any > derivations are being found, if so check whether they can be serialized to > the console. > > If no derviations are being found then maybe your haven't switched on > derivation logging or maybe your rules are not being fired. > > If you really get stuck then create a complete minimum test case you can > post. In your case that would mean creating a minimum data sample and rule > set as well as the code to run it. You might well find that in the process > of creating that minimal test case you find the problem :) > > Dave > > >
Re: Empty derivation files
Hi, I continue with the problem that I've posted on jena-dev @ yahoo. I change the code to close the stream out of the loop. This is the new code: http://pastebin.com/GhQXe2tg The problem is that the generated files continue empty :-/ Thanks, Alejandro --- In jena-...@yahoogroups.com, "jalo_rg" wrote: > > Silly mistake! > > Thanks Dave! And sorry for posting here, I saw the deprecation just after send the email. > > Thanks! > > --- In jena-...@yahoogroups.com, Dave Reynolds wrote: > > > > This list is deprecated, jena support has moved to Apache, see: > > http://jena.apache.org/help_and_support/index.html > > > > Your problem is that you are closing the output stream within the loop: > > > >while (sti.hasNext()) { > > Statement st = (Statement) sti.next(); > > for (Iterator id = this.inferenceModel.getDerivation(st); id > > .hasNext();) { > > Derivation deriv = (Derivation) id.next(); > > deriv.printTrace(out, true); > >} > >... > >out.flush(); > >out.close(); > >} > > > > So after the first iteration out is closed. If the first statement in > > the iterator happens to be a fact with no derivation then the first > > iteration doesn't generate any output and you end up with an empty file. > > > > Don't know why you aren't seeing IOExceptions. > > > > Dave > > > > On 16/07/12 16:56, Alejandro Rodríguez González wrote: > > > Hello to all, > > > > > > > > > I'm trying to see the derivation of some rules that I developing but the > > > derivation files that the code creates always are empty. > > > > > > I don't know if it is a problem with my code or maybe some bug. > > > > > > Here is the code: > > > > > > http://pastebin.com/P8EqXcXP > > > > > > The files are created correctly (explc1.txt - explc4.txt) but they have > > > no content. If I change the PrintWriter to print in screen (System.out) > > > and it seems to crash. The normal output (writing to file), returns the > > > following: > > > > > > http://pastebin.com/0u8TSATb > > > > > > If I change the PrintWriter to System.out it "cuts" (finish) and only > > > shows this (but without errors or exceptions): > > > > > > http://pastebin.com/PA5KFmmk > > > > > > I also have some doubts with my rules since they are not working as I > > > expected, but maybe I can fix it if I can access to the derivation (to > > > see what is going wrong). > > > > > > Thanks! > > > -- Dr. Alejandro Rodríguez González - PhD Bioinformatics at Centre for Plant Biotechnology and Genomics UPM-INIA Polytechnic University of Madrid http://www.alejandrorg.com Phone: +34 914524900 . Ext: 25550 *Once the game is over, the king and the pawn go back in the same box. - Italian proverb*