Reputation: 13666
I'm trying to make the official example for Apache Jena Text to work with an rdf file. The official example is given here.
Honestly, I think that there is too less documentation and the example is too generic. It does not provide a real rdf file to be given as example and there are a lot of things to configure. I'm trying to analyze this RDF file.
--UPDATE--
I found the files used in the official example as mentioned in a comment to this question.
Thus, I defined the following ttl file by mixing the original example with the foaf.rdf file. Now I have the file foaf.ttl
:
@prefix : <http://localhost/jena_example/#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix con: <http://www.w3.org/2000/10/swap/pim/contact#> .
@prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix s: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix cc: <http://creativecommons.org/ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
:T1 rdfs:label "X0 X1 X2" .
:T2 rdfs:label "X10 X11 X12" .
:B1 rdfs:label "X1" .
:B2 foaf:name "X1" .
:B3 foaf:name "Sean" .
:Sean
a foaf:Person ;
foaf:name "Sean Palmer" .
:Tim_Bray
a foaf:Person ;
foaf:name "X1" .
:me
foaf:name "Oshani Seneviratne" .
:John_Gage
a foaf:Person ;
foaf:img <http://upload.wikimedia.org/wikipedia/commons/d/de/John_Gage.jpg> ;
foaf:name "John Gage" .
Thus, with respect to the original Java file mentioned so far, I set in the main:
public static void main(String [] args){
TextQuery.init();
Dataset ds = createCode();
//Dataset ds = createAssembler() ;
loadData(ds, "foaf.ttl") ;
queryData(ds) ;
}
In the queryData
method I have:
String pre = StrUtils.strjoinNL
( "PREFIX : <http://localhost/jena_example/#>"
, "PREFIX dc: <http://purl.org/dc/elements/1.1/>"
, "PREFIX con: <http://www.w3.org/2000/10/swap/pim/contact#>"
, "PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>"
, "PREFIX foaf: <http://xmlns.com/foaf/0.1/>"
, "PREFIX s: <http://www.w3.org/2000/01/rdf-schema#>"
, "PREFIX owl: <http://www.w3.org/2002/07/owl#>"
, "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
, "PREFIX cc: <http://creativecommons.org/ns#>"
, "PREFIX text: <http://jena.apache.org/text#>"
, "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>") ;
String qs = StrUtils.strjoinNL
( "SELECT * "
, " { ?res text:query ('X*' 10) ;"
, " rdfs:label ?label"
, " }") ;
And in createCode()
I have:
// Define the index mapping
EntityDefinition entDef = new EntityDefinition("uri", "text", RDFS.label.asNode()) ;
The result is:
-----------------------
| res | label |
=======================
| :T1 | "X0 X1 X2" |
| :T2 | "X10 X11 X12" |
| :B1 | "X1" |
-----------------------
However, I report that X1 was included also in triple:
:B2 foaf:name "X1" .
but B2
is not in the result set. One may say: "You have to define an index". Well, the very strange thing is that if I set in createCode()
:
// Define the index mapping
EntityDefinition entDef = new EntityDefinition("blablabla", "blablabla", RDFS.label.asNode()) ;
the result doesn't change!
So, what is the role of EntityDefinition
?
What am I doing wrong?
Upvotes: 2
Views: 740
Reputation: 28646
Your problem is primarily down to your entity definition AFAICT, I'm fairly sure with the entity definition you've used your text index will be empty. If you've used a disk based Lucene index you can use a tool like Luke to confirm this.
Your entity definition is as follows:
EntityDefinition entDef = new EntityDefinition("rdf:about", "rdf:resource", RDFS.label.asNode()) ;
Which is problematic in a couple of ways:
entityField
(the first parameter), you need to use a full URIrdf:about
is not a real URI, it is a syntax detail of RDF/XML so indexing this will always index nothingIt is also important to note that what you've shown is incomplete code and it only pertains to accessing an existing text index. There is nothing to show if and how you've actually indexed the text in your RDF.
Upvotes: 1