Multiple individuals retrieved from sparql query

60 views Asked by At

I have an owl file classes and individuals are in the same file. Complaint and User (classes). I create users' complaints as individuals. An complaint class has dataProperties (id, num of read, title, tags, content etc. ) I wrote a sparql query with jena on eclipse swing project;

String queryRetrieveAll = "SELECT * WHERE \n { "
+ "?Complaint skyt:numOfRead ?Num . "
+ " FILTER (?Num >= 1) " 
+ ".}\n";

and retrive all complaints in my owl file. for example;

-------------------------------
| Complaint            | Num |
===============================
| skyt:apple           | 484  |
| skyt:toshiba         | 202  |
| skyt:niluferturizm   | 43   |
| skyt:kamilkoc        | 42   |
| skyt:eceElektronik   | 254  |
| skyt:celebi          | 112  |

THAT's OKAY but. I want to retrieve owner of complaint from query, too. and i add a row query above.

String queryRetrieveAll = "SELECT * WHERE \n { "
+ "?Complaint skyt:numOfRead ?Num . "
+ " FILTER (?Num >= 1) " 
+ "?Complaint skyt:Owner ?owner . "// or "?Complaint skyt:sId ?ID . "
+ ".}\n";

Results of this query, individuals are retrieved repeatedly,

 ----------------------------------------------- 
| Complaint            | Num | Owner
 =============================================== 
| skyt:apple           | 484  | skyt:huseyinG | 
| skyt:apple           | 484  | skyt:kaanY   | 
| skyt:apple           | 484  | skyt:ramazanÇ | 
| skyt:apple           | 484  | skyt:mertM    | 
| skyt:apple           | 484  | skyt:burakÇ  |
| skyt:apple           | 484  | skyt:merveE   | 
| skyt:apple           | 484  | skyt:ertuncE  | 
| skyt:toshiba         | 202  | skyt:sahinT  |
| skyt:niluferturizm   | 43   | skyt:yasinT   | 
| skyt:kamilkoc        | 42   | skyt:hanifeC  | 
| skyt:kamilkoc        | 42   | skyt:HasanH   |
| skyt:kamilkoc        | 42   | skyt:semihA   | 
| skyt:eceElektronik   | 254  | skyt:sonerD   | 
| skyt:celebi          | 112  | skyt:gayeB   | 
| skyt:polypadSarj     | 265  | skyt:serefG   | 
| skyt:polypadSarj     | 265  | skyt:metinY   | 
| skyt:polypadSarj     | 265  | skyt:simayS  
| skyt:apple           | 871  | skyt:huseyinG | 
| skyt:apple           | 871  | skyt:kaanY    | 
| skyt:apple           | 871  | skyt:ramazanÇ | 
| skyt:apple           | 871  | skyt:mertM    | 
| skyt:apple           | 871  | skyt:burakÇ   | 
| skyt:apple           | 871  | skyt:merveE  |
| skyt:apple           | 871  | skyt:ertuncE  |

How i fix it? I want to retrieve all complaints with owner,id,numOfread, vs.

1

There are 1 answers

0
babeyh On BEST ANSWER

I solve the problem. In owl file some of the individual are same name by my mistake. For example complaint about apple, i have given this individual name as "apple". For this reason, they sometimes retrieve multiple. I give distinct name all individuals and change my query below. Then it works. :)

String queryExtractAll = 
"SELECT DISTINCT ?Num ?Owner ?Title ?Content WHERE \n { " 
+ "?Complaint skyt:numofRead ?Num;" 
+ "skyt:owner ?Owner;" 
+ "skyt:title ?Title;" 
+ "skyt:content ?Content"
+ " FILTER (?Num >= 1) " + ".}\n"
+ " ORDER BY DESC (?Num) ";