Hi Dhaval,
The "...lexical..." errors you are getting is coming from the Jena
SPARQL parser being invoked when using the QueryFactory.create method,
if you by pass this method and execute the query directly with the
VirtuosoQueryExecutionFactory.create method it should then work.
I was able to recreate the error you report using the sample inference
rule set in our documentation at:
http://docs.openlinksw.com/virtuoso/rdfsparqlrule.html#rdfsparqlruleexamples
Amended the code as follows then enabled me to successfully run the
inference query from Jena:
import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.rdf.model.RDFNode;
import virtuoso.jena.driver.*;
public class VirtuosoSPARQLExample10 {
/**
* Executes a SPARQL query against a virtuoso url and prints results.
*/
public static void main(String[] args) {
VirtGraph set = new VirtGraph ("gr", "jdbc:virtuoso://localhost:
1111", "dba", "dba");
String query = "define input:inference 'http://localhost:8890/schema/
property_rules1' select ?s from <http://localhost:8890/test> where {?s
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/sioc/ns#Space
> }";
VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create
(query, set);
ResultSet results = vqe.execSelect();
while (results.hasNext()) {
QuerySolution result = results.nextSolution();
RDFNode graph = result.get("graph");
RDFNode s = result.get("s");
RDFNode p = result.get("p");
RDFNode o = result.get("o");
System.out.println(graph + " { " + s + " " + p + " " + o +
" . }");
}
}
}
VIRTMAIN@hugh-williams-computer-2323:~/binsrc/jena$ /usr/bin/javac -
classpath "lib/arq.jar:lib/iri.jar:lib/jena.jar:../../libsrc/
JDBCDriverType4/virtjdbc3.jar:./virt_jena.jar:./virtuoso_driver:."
VirtuosoSPARQLExample10.java
VIRTMAIN@hugh-williams-computer-2323:~/binsrc/jena$ /usr/bin/java -
classpath "lib/arq.jar:lib/iri.jar:lib/jena.jar:lib/icu4j_3_4.jar:lib/
xercesImpl.jar:lib/commons-logging-1.1.1.jar:lib/axis.jar:../../libsrc/
JDBCDriverType4/virtjdbc3.jar:./virt_jena.jar:." VirtuosoSPARQLExample10
gr { http://localhost:8890/dataspace/discussion/oWiki-test1Wiki null
null . }
gr { http://localhost:8890/dataspace/test2/weblog/test2tWeblog null
null . }
gr { http://localhost:8890/dataspace null null . }
Having successfully run the same query from isql and the sparql
endpoint:
hugh-williams-computer-2323:~ hughwilliams $ /usr/local/virtuoso-
opensource/bin/isql
OpenLink Interactive SQL (Virtuoso), version 0.9849b.
Type HELP; for help and EXIT; to exit.
SQL> shutdown();
Connected to OpenLink Virtuoso
Driver: 05.11.3039 OpenLink Virtuoso ODBC Driver
hugh-williams-computer-2323:~ hughwilliams$ /usr/local/virtuoso-
opensource/bin/isql
OpenLink Interactive SQL (Virtuoso), version 0.9849b.
Type HELP; for help and EXIT; to exit.
SQL> sparql define input:inference 'http://localhost:8890/schema/
property_rules1' select ?s from <http://localhost:8890/test> where {?s
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/sioc/ns#Space
> };
s
VARCHAR
_______________________________________________________________________________
http://localhost:8890/dataspace/discussion/oWiki-test1Wiki
http://localhost:8890/dataspace/test2/weblog/test2tWeblog
http://localhost:8890/dataspace
3 Rows. -- 39 msec.
SQL>
Thus amending your sample likewise should enable you query to run
also ...
Best Regards
Hugh Williams
Professional Services
OpenLink Software
Web: http://www.openlinksw.com
Support: http://support.openlinksw.com
Forums: http://boards.openlinksw.com/support
On 7 Sep 2009, at 18:11, Dhaval Thakker wrote:
Dear List members,
I am still hanging on this problem and though would send you another
email. Here is what i have done so far:
1. Let's say I have an ontology which I have loaded with TTLP
function as graph "http://myontology.org". This ontology contains
atleast this: (baseuri: http://Entity.owl)
Person a owl:Class
Actor a owl:Class
Actor rdfs:subclassOf Person
2. And I have data that refers to the elements from the above
ontology and is loaded again with TTLP as graph "http://mydata.org"
a sample data is:
Don a Actor
3. Now I create a ruleset from the ontology in 1 using RDFS_Ruleset
function such as:
rdfs_rule_set ('http://inference.org', 'http://myontology.org');
4. As I am interested in checking the subclass relationship: here is
what I do at my local sparql endpoint interface:
define input:inference 'http://inference.org' select ?s where {?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type
> <http://Entity.owl#Person>}
I successfully get Don as answer.
However when I do the same with the API as follows I get nothing:
///code start
String url;
if(args.length == 0)
url = "jdbc:virtuoso://localhost:
1111/charset=UTF-8/log_enable=2";
else
url = args[0];
VirtGraph set = new VirtGraph (url, "dba", "dba");
Query sparql = QueryFactory.create("define input:inference 'http://
inference.org' select ?s where {?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type
> <http://Entity.owl#Person>}");
VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create
(sparql, set);
ResultSet results = vqe.execSelect();
while (results.hasNext())
{
com.hp.hpl.jena.query.QuerySolution result = results.nextSolution();
RDFNode s = result.get("s");
System.out.println("{ " + " " + s + " }");
}
///code end
due to define:inference in the above it gives me lexical error (as
obviously not being a standard sparql syntax) and when I remove it
and try it again it returns nothing. When I try it with
select ?s where {?s <http://www.w3.org/1999/02/22-rdf-syntax-
ns#type> <http://Entity.owl#Actor>}
It works fine with Don again as an answer.
Any hints?
Thanks for your help
Dhaval
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and
focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.
http://p.sf.net/sfu/bobj-july_______________________________________________
Virtuoso-users mailing list
Virtuoso-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/virtuoso-users