- 更新日時:
- 2014/01/30 15:15:33 (11 年 前)
- パス:
- BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL
- ファイル:
-
- 2 変更
凡例:
- 変更なし
- 追加
- 削除
-
BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/OWLQueryBuilder.java
r10 r20 59 59 * @since 28.01.2014 60 60 */ 61 public ClassLink[] getNextClass(String[] graphURIs, String originClass, int limit ) throws Exception;61 public ClassLink[] getNextClass(String[] graphURIs, String originClass, int limit, boolean countLinks) throws Exception; 62 62 63 63 /** … … 73 73 * @param originClass 襍キ轤ケ縺ィ縺ェ繧九け繝ゥ繧ケ縺ョURI縲��ull荳榊庄�� 74 74 * @param limit 隗」縺ィ縺励※霑斐&繧後kClassLink驟榊�縺ョ髟キ縺輔�荳企剞蛟、繧呈欠螳壹☆繧九�荳企剞蛟、繧定ィュ螳壹@縺ェ縺�エ蜷医�0莉・荳九�蛟、繧呈欠螳壹☆繧� 75 * @param countLinks 繧、繝ウ繧ケ繧ソ繝ウ繧ケ髢薙�繝ェ繝ウ繧ッ縺ョ謨ー�医ヨ繝ェ繝励Ν謨ー�峨r霑斐@縺溘>縺ィ縺阪�true繧呈欠螳壹☆繧� 75 76 * @return ClassLink縺ョ驟榊�縲ゅ%縺薙↓縺ッ縲∝叙蠕励&繧後◆繧ッ繝ゥ繧ケ縺ィ髢「菫ゅ▼縺代i繧後※縺�k繝励Ο繝代ユ繧」縲�未菫ゅ�蜷代″縺悟性縺セ繧後k縲� 76 77 * @throws Exception … … 101 102 InstanceLink[] getNextInstancesViaInstanceLink(String[] graphURIs, String originInstance, 102 103 int limit) throws Exception; 104 public LabelMap[] getLabels(String[] graphURIs, String[] resourceURIs, String language) throws Exception; 105 103 106 } -
BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/OWLQueryBuilderImpl.java
r19 r20 61 61 62 62 System.out.println("CLS"); 63 ClassLink[] cls = builder.getNextClass(null, clz[0].getClassURI(), 0 );63 ClassLink[] cls = builder.getNextClass(null, clz[0].getClassURI(), 0, false); 64 64 if( cls != null ){ 65 65 for( ClassLink cl: cls){ … … 272 272 */ 273 273 public ClassLink[] getNextClass(String[] graphURIs, String originClass, 274 int limit ) throws Exception {274 int limit, boolean countLinks) throws Exception { 275 275 StringBuffer queryStr = new StringBuffer(); 276 276 queryStr.append("PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"); 277 277 queryStr.append("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"); 278 278 queryStr.append("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"); 279 // queryStr.append("SELECT DISTINCT ?p ?pDirection ?c (COUNT(?s) AS ?numOfLinks) \n"); 280 queryStr.append("SELECT DISTINCT ?p ?pDirection ?c \n"); 279 280 // SELECT 281 if( countLinks ){ 282 queryStr.append("SELECT DISTINCT ?p ?pDirection ?c (COUNT(?s) AS ?numOfLinks) \n"); 283 } 284 else{ 285 queryStr.append("SELECT DISTINCT ?p ?pDirection ?c \n"); 286 } 287 281 288 if (graphURIs != null) { 282 289 for (String graphURI : graphURIs) { … … 291 298 queryStr.append(originClass); 292 299 queryStr.append(">.\n ?p rdfs:range ?c.\n"); 293 // queryStr.append(" ?o ?p ?s."); 300 301 if( countLinks ){ 302 queryStr.append(" ?o ?p ?s."); 303 } 304 294 305 queryStr.append("}\n UNION\n"); 295 306 queryStr.append(" { ?p rdfs:range <"); … … 297 308 queryStr.append(">.\n"); 298 309 queryStr.append(" ?p rdfs:domain ?c.\n"); 299 // queryStr.append(" ?s ?p ?o."); 310 311 if( countLinks ){ 312 queryStr.append(" ?s ?p ?o."); 313 } 314 300 315 queryStr.append("}\n"); 301 316 … … 304 319 305 320 queryStr.append(" ?s rdf:type ?c.\n"); 306 // queryStr.append(" ?o rdf:type <"); 307 // queryStr.append(originClass); 308 // queryStr.append(">.\n"); 309 queryStr.append("}\n"); 310 // queryStr.append("GROUP BY ?p ?pDirection ?c\n"); 321 322 if( countLinks){ 323 queryStr.append(" ?o rdf:type <"); 324 queryStr.append(originClass); 325 queryStr.append(">.\n"); 326 queryStr.append("}\nGROUP BY ?p ?pDirection ?c\n"); 327 } 328 else{ 329 queryStr.append("}\n"); 330 } 311 331 if (limit > 0) { 312 332 queryStr.append("limit "); … … 602 622 ResultSet results = qexec.execSelect(); 603 623 HashMap<String, LabelMap> lMap = new HashMap<String, LabelMap>(); 604 HashMap<String, InstanceLink> insLinkMap = new HashMap<String, InstanceLink>();605 624 for (; results.hasNext();) { 606 625 QuerySolution sol = results.next(); … … 623 642 } 624 643 return lMap.values().toArray(new LabelMap[0]); 625 626 627 644 } 628 645