I wrote the following jena query in Eclipse which produces a URI and description of a medical disorder pertaining to the inner ear.
public static void main(String[] args) {
String FOAF = "http://http://xmlns.com/foaf/0.1/";
String NS = "http://philshields.altervista.org/owl/_";
String rdf= "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
String owl= "http://www.w3.org/2002/07/owl#" ;
String xsd= "http://www.w3.org/2001/XMLSchema#";
String rdfs= "http://www.w3.org/2000/01/rdf-schema#";
String dc= "http://purl.org/dc/elements/1.1/";
Model model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
//model = FileManager.get().loadModel("c:/Ontologies/ICD-10 ontologies/2017_10_26_ICD10_AM_Code Order.owl");
model = FileManager.get().loadModel("c:/jena/ICD.owl");
String resultsAsString;
String queryString = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\r\n" +
"PREFIX owl: <http://www.w3.org/2002/07/owl#>\r\n" +
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\r\n" +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\r\n" +
"PREFIX dc: <http://purl.org/dc/elements/1.1/>\r\n" +
"SELECT (str(?subject) AS ?string) ?object\r\n" +
" WHERE {?subject dc:title ?object \r\n" +
"FILTER regex(?object,\"inner ear\",\"i\")}\r\n" +
"" ;
Query query = QueryFactory.create(queryString) ;
try (QueryExecution qexec = QueryExecutionFactory.create(query, model)) {
ResultSet results = qexec.execSelect() ;
for ( ; results.hasNext() ; )
{
//QuerySolution soln = results.nextSolution() ;
ResultSetFormatter.out(System.out, results, query) ;
}
}
}
It produces the correct results shown here:
-------------------------------------------------------------------------------------------------------------------------------------
| string | object |
=====================================================================================================================================
| "http://www.semanticweb.org/philshields/ontologies/2017/8/untitled-ontology-341#H83.3" | "Noise effects on inner ear" |
| "http://www.semanticweb.org/philshields/ontologies/2017/8/untitled-ontology-341#S01.38" | "Open wound of inner ear" |
| "http://www.semanticweb.org/philshields/ontologies/2017/8/untitled-ontology-341#H83.8" | "Other specified diseases of inner ear" |
| "http://www.semanticweb.org/philshields/ontologies/2017/8/untitled-ontology-341#H83.9" | "Disease of inner ear, unspecified" |
I am trying to discard all of the URI and keep the fragment value which is the code number of the disorder after the hash.
I tried using SELECT (str(?subject) AS ?string) ?object
, but it does not work.