Search code examples
sparqlrdfjenaowl

Using multiple filters in SPARQL query


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">[email protected]</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!


Solution

  • 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)