I want to get the Job ID passed as parameter and check the id with the id in the owl file and then, match the job skill of that job id to the skill of the candidates (candidates also contain skills). I am getting the url parameter and storing in a variable.
String jobID = request.getParameter("JobID");
String query =
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
"PREFIX owl: <http://www.w3.org/2002/07/owl#> " +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " +
"PREFIX ns0: <http://www.Jobsurveillance.com/CV#> " +
"SELECT (str(?object) as ?label) " +
"(str(?object2) as ?label2) " +
"(str (?phoneNumobj) as ?label3) " +
"(str (?degreeobj) as ?label4) " +
"(str (?jobcatObj) as ?label5) " +
"(str (?candidateSkill) as ?label8) " +
"(str (?jobAdID) as ?label6) " +
"(str (?jobSkill) as ?label7) WHERE { " +
" ?person ns0:Full_Name ?object ." +
" ?person ns0:Email_Id ?object2 ." +
" ?person ns0:Phone_Number ?phoneNumobj ." +
" ?person ns0:Degree ?degreeobj ." +
" ?person ns0:Job_Category ?jobcatObj ." +
" ?person ns0:Skills ?candidateSkill ." +
" ?job ns0:JobID ?jobAdID ." +
" ?job ns0:JobSkills ?jobSkill ." +
" filter (regex(?jobAdID, \"" + jobID + "\") ." +
" filter (?jobSkill = ?candidateSkill)) ." +
"}";
When I run i get an error like below:
com.hp.hpl.jena.query.QueryParseException: Encountered " "." ". "" at line 1,
column 756.
Was expecting one of:
"not" ...
"in" ...
<INTEGER_POSITIVE> ...
<DECIMAL_POSITIVE> ...
<DOUBLE_POSITIVE> ...
<INTEGER_NEGATIVE> ...
<DECIMAL_NEGATIVE> ...
<DOUBLE_NEGATIVE> ...
")" ...
"=" ...
"!=" ...
">" ...
"<" ...
"<=" ...
">=" ...
"||" ...
"&&" ...
"+" ...
"-" ...
"*" ...
"/" ...
My Dataset is as follows
<owl:NamedIndividual rdf:about="http://www.Jobsurveillance.com/CV#Candidate6">
<rdf:type>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.Jobsurveillance.com/CV#includes"/>
<owl:someValuesFrom rdf:resource="http://www.Jobsurveillance.com/CV#CV"/>
</owl:Restriction>
</rdf:type>
<ns0:Address rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Colombo 15</ns0:Address>
<ns0:Company rdf:datatype="http://www.w3.org/2001/XMLSchema#string">TechOrin</ns0:Company>
<ns0:Degree rdf:datatype="http://www.w3.org/2001/XMLSchema#string">B.Sc (Hons), Information Technology</ns0:Degree>
<ns0:Email_Id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">yashmitha#gmail.com</ns0:Email_Id>
<ns0:Skills rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Java</ns0:Skills>
<ns0:Job_Category rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Marketing</ns0:Job_Category>
<ns0:Full_Name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Yashmitha</ns0:Full_Name>
<ns0:Phone_Number rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">0723679017</ns0:Phone_Number>
</owl:NamedIndividual>
This is my SPARQL query. Am I implementing the filter in the correct way. Could anyone pl help me with this. Thanks!
ISSUE SOLVED. The query below helped me get the exact output which I needed
String query =
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
"PREFIX owl: <http://www.w3.org/2002/07/owl#> " +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " +
"PREFIX ns0: <http://www.Jobsurveillance.com/CV#> " +
"SELECT (str(?object) as ?label) " +
"(str(?object2) as ?label2) " +
"(str (?phoneNumobj) as ?label3) " +
"(str (?degreeobj) as ?label4) " +
"(str (?jobcatObj) as ?label5) " +
"(str (?candidateSkill) as ?label8) " +
"(str (?jobSkill) as ?label7) WHERE { " +
" ?person ns0:Full_Name ?object ." +
" ?person ns0:Email_Id ?object2 ." +
" ?person ns0:Phone_Number ?phoneNumobj ." +
" ?person ns0:Degree ?degreeobj ." +
" ?person ns0:Job_Category ?jobcatObj ." +
" ?person ns0:Skills ?candidateSkill ." +
" ?job ns0:JobID \"" + jobID + "\"." +
" ?job ns0:JobSkills ?jobSkill ." +
" filter (?jobSkill = ?candidateSkill)" +
"}";
In the above code the below line which was
filter (?jobSkill = ?candidateSkill))
is corrected as
filter (?jobSkill = ?candidateSkill)
Related
Data
<ns0:Address rdf:datatype="http://www.w3.org/2001/XMLSchema#string">s block, kotahena</ns0:Address>
SPARQL Query:
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
"PREFIX owl: <http://www.w3.org/2002/07/owl#> " +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " +
"PREFIX ns0: <http://www.Jobsurveillance.com/CV#> " +
"SELECT (str(?object) as ?label) WHERE { " +
" ?subject rdf:Full_Name ?object ." +
"}"
Error during Run
Exception error occurs when running the program.
Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Encountered "(" at line 1, column 212.
Was expecting one of:
<VAR1> ...
<VAR2> ...
"distinct" ...
"reduced" ...
"*" ...
I am running the Virtuoso SPARQL endpoint for executing the query. but while I am executing the query my execution stuck.
QueryExecution qexec = null;
try {
System.out.println("now inside");
String queryString = "PREFIX ns: <http://example.org/ns#>" +
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\r\n" +
"SELECT ?title ?price" +
" {" +
" ?x ns:price ?p ." +
" ?x ns:discount ?discount ." +
" ?x <http://purl.org/dc/elements/1.1/title> ?title . " +
" BIND ('12'^^xsd:integer AS ?price)" +
" FILTER( ?price < 20 )" +
" }";
System.out.println(queryString);
System.out.println("inside the sparql just before call");
qexec = QueryExecutionFactory.sparqlService("http://192.168.99.100:8890/sparql", queryString);
ResultSet results = qexec.execSelect();
System.out.println("inside the sparql just after call");
// write to a ByteArrayOutputStream
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ResultSetFormatter.outputAsJSON(outputStream, results);
String json = outputStream.toString();
System.out.println(json);
return json;
} catch (Exception e) {
e.printStackTrace();
}finally {
qexec.close();
}
return "Error";
sample data
#prefix dc: <http://purl.org/dc/elements/1.1/> .
#prefix : <http://example.org/book/> .
#prefix ns: <http://example.org/ns#> .
:book1 dc:title "SPARQL Tutorial" .
:book1 ns:price 42 .
:book1 ns:discount 0.2 .
:book2 dc:title "The Semantic Web" .
:book2 ns:price 23 .
:book2 ns:discount 0.25 .
While executing qexec.execSelect() it shouldn't give any error nor output result. But it will happen occasionally.
As while tracing it will print all the details up to below statement
System.out.println("inside the sparql just before call");
but not after that.
How do I trace it? How do I figure out what causes the issue?
Note: My query is very small so there is no time issue.
Also, I notice that after updating the new updated version of Jena 3.7.0 I am getting this issue
If I read the comments correctly, I think that the issue was resolved by changing --
qexec = QueryExecutionFactory.sparqlService("http://192.168.99.100:8890/sparql", queryString);
-- to --
QueryEngineHTTP qexec = new QueryEngineHTTP ("http://192.168.99.100:8890/sparql", queryString);
-- which is a workaround that doesn't reveal the cause of the original problem, but nonetheless got past it successfully.
When i run this query on dbpedia.org
SELECT DISTINCT ?resource ?label ?location
WHERE
{
<http://dbpedia.org/resource/New_York_City> geo:geometry ?sourcegeo .
?resource geo:geometry ?location ;
rdfs:label ?label .
FILTER( bif:st_intersects( ?location, ?sourcegeo, 20 ) ) .
FILTER( lang( ?label ) = "en" )
}
it is producing results fine but same query gives me error when using java jena api.
String s2 = "SELECT DISTINCT ?resource ?label ?location \r\n" +
"WHERE \r\n" +
" { \r\n" +
" <http://dbpedia.org/resource/New_York_City> geo:geometry ?sourcegeo . \r\n" +
" ?resource geo:geometry ?location ; \r\n" +
" rdfs:label ?label . \r\n" +
" FILTER( bif:st_intersects( ?location, ?sourcegeo, 20 ) ) . \r\n" +
" FILTER( lang( ?label ) = \"en\" ) \r\n" +
" }\r\n" +
"";
Query query = QueryFactory.create(s2); //s2 = the query above
QueryExecution qExe = QueryExecutionFactory.sparqlService( "http://dbpedia.org/sparql", query );
ResultSet results = qExe.execSelect();
ResultSetFormatter.out(System.out, results, query) ;
it gives me the following errors
Exception in thread "main" org.apache.jena.query.QueryParseException: Line 4, column 49: Unresolved prefixed name: geo:geometry
at org.apache.jena.sparql.lang.ParserBase.throwParseException(ParserBase.java:521)
at org.apache.jena.sparql.lang.ParserBase.resolvePName(ParserBase.java:286)
at org.apache.jena.sparql.lang.sparql_11.SPARQLParser11.PrefixedName(SPARQLParser11.java:4857)
at org.apache.jena.sparql.lang.sparql_11.SPARQLParser11.iri(SPARQLParser11.java:4841) and it goes on
DBPedia has a number of Predefined Namespace Prefixes, which includes
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>,
which Jena does not have. Hence you have to specify it for use Jena before your SELECT. I.e.
String s2 = "PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>\r\n" +
"SELECT DISTINCT ?resource ?label ?location \r\n" +
... etc
Below SPARQL execdescribe query giving me only two prefixes as output while running with Jena query but when I run this query on virtuoso SPARQL endpoint it's giving perfect output.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX db: <http://dbpedia.org/ontology/>
PREFIX prop: <http://dbpedia.org/property/>
DESCRIBE ?movie ?author ?genre
WHERE {
?movie rdf:type db:Film ;
prop:author ?author ;
prop:genre ?genre .
}
LIMIT 2
OFFSET 0
When I run with Jena I am getting only two line output like this,
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
Below is my code which I am using but with some query its working fine,
String queryString = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
"PREFIX db: <http://dbpedia.org/ontology/> " +
"PREFIX prop: <http://dbpedia.org/property/>" +
"DESCRIBE ?movie ?author ?genre" +
"WHERE { " +
"?movie rdf:type db:Film ;" +
"prop:author ?author ;" +
"prop:genre ?genre ." +
"}" +
"LIMIT 2" +
"OFFSET 0";
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://localhost:8890/sparql", queryString);
Model results = qexec.execDescribe();
results.write(System.out,"TTL");
Its perfectly giving me output on virtuoso SPARQL end point.
below is screen shot,
As suggested in comments by #AKSW, There is a space issue in the query. So after edited my query, it will perfectly work fine.
I'm tring to find informations about a place (ex : New York http://dbpedia.org/page/New_York). I' try to get informations suchs as nearestCity , museum)...
My request returns nothing...
String name = "New_York";
String s4 = "PREFIX g: <http://www.w3.org/2003/01/geo/wgs84_pos#>\n" +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
"PREFIX onto: <http://dbpedia.org/ontology/>\n" +
"PREFIX dbpedia: <http://dbpedia.org/resource/>PREFIX dcterms: <http://purl.org/dc/terms/>\n"+
"PREFIX dp: <http://dbpedia.org/resource/>\n"+
"PREFIX dbprop: <http://dbpedia.org/property/>\n" +
"PREFIX grs: <http://www.georss.org/georss/>\n"+
"PREFIX dbpedia-oll: <http://dbpedia.org/ontology/> \n"+
"PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>PREFIX category: <http://dbpedia.org/resource/Category:>\n"+
"\n" +
"SELECT ?nearestCity \n" +
"WHERE\n" +
"{ OPTIONAL{onto:"+name+" grs:nearestCity ?nearestCity .}\n"+
" }\n" +
"LIMIT 300\n" +
"";
There are a couple problems with the query you are doing:
1) Some namespaces are wrong: the resource New_York has the URI: http://dbpedia.org/resource/New_York. In your query that would translate to "dbpedia:"+name instead of "onto:"+name.
2) The properties that you are looking for point to the resource New_York, not the other way around. For example, for the nearest city one, this is the query that works (note the namespaces again for the property):
SELECT ?nearestCity where {
?nearestCity <http://dbpedia.org/property/nearestCity> <http://dbpedia.org/resource/New_York>.
}LIMIT 300
(See results)
And for museum:
SELECT ?m where {
?m <http://dbpedia.org/ontology/museum> <http://dbpedia.org/resource/New_York>.
}LIMIT 300
(See results)