Jena gang: I'm trying to use the Jena-Text stuff to do text searches in SPARQL and am running into a problem. I am indexing two triples, with an rdfs:label property, then doing a search using text:query that should match 0 triples. But I still get back two results when I run my query (the two triples I previously indexed, even though they don't contain the query string).
I'm sure I'm probably just doing something wrong, but so far I'm having no luck figuring out what it is. If somebody could look at this code and give me a pointer, it would be much appreciated. class JenaTextMain1 { static main(args) { // Base dataset Dataset dataset = TDBFactory.createDataset("jenastore"); EntityDefinition entDef = new EntityDefinition("uri", "text", RDFS.label) ; // Lucene, in memory. Directory dir = new RAMDirectory(); // Join together into a dataset Dataset ds = TextDatasetFactory.createLucene(dataset, dir, entDef); ds.begin(ReadWrite.WRITE); Model m = ds.defaultModel; Resource rSubject = m.createResource( "http://ontology.fogbeam.com/example/TestResource1" ); Resource rSubject2 = m.createResource( "http://ontology.fogbeam.com/example/TestResource2" ); try { Statement s = m.createStatement(rSubject, RDFS.label, "This is a TEST Resource" ); m.add( s ); Statement s2 = m.createStatement(rSubject2, RDFS.label, "Bratwurst" ); m.add( s2 ); ds.commit(); String baseQueryString = "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " + "PREFIX dc: <http://purl.org/dc/elements/1.1/> " + "PREFIX dcterm: <http://purl.org/dc/terms/> " + "PREFIX owl: <http://www.w3.org/2002/07/owl#> " + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX text: <http://jena.apache.org/text#>"; /* Do a SPARQL query using Jena-Text here... */ String queryString = baseQueryString + "SELECT ?s { ?s text:query ('Flibble') ; rdfs:label ?label ; }"; ds.begin(ReadWrite.READ); Query query = QueryFactory.create(queryString) ; Reasoner reasoner = ReasonerRegistry.getOWLMiniReasoner(); InfModel inf = ModelFactory.createInfModel(reasoner, m); QueryExecution qexec = QueryExecutionFactory.create(query, inf); try { ResultSet solutions = qexec.execSelect(); for ( ; solutions.hasNext() ; ) { QuerySolution soln = solutions.nextSolution(); println "solution: ${soln}"; Iterator iter = soln.varNames(); } ds.commit(); } finally { qexec.close(); } } finally { if( ds != null ) { ds.end(); } } println "done"; } } Running this results in this output: solution: ( ?s = <http://ontology.fogbeam.com/example/TestResource1> ) solution: ( ?s = <http://ontology.fogbeam.com/example/TestResource2> ) done Any and all help is greatly appreciated. Also, on a related note... the page here: https://jena.apache.org/documentation/query/text-query.html has the following link listed as "example code here" but the link is no longer valid. https://svn.apache.org/repos/asf/jena/trunk/jena-text/src/main/java/examples/ Thanks, Phil This message optimized for indexing by NSA PRISM