チェンジセット 28 : BH13SPARQLBuilder
- 更新日時:
- 2014/01/31 09:38:51 (11 年 前)
- パス:
- BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL
- ファイル:
-
- 2 変更
凡例:
- 変更なし
- 追加
- 削除
-
BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/OWLQueryBuilder.java
r26 r28 20 20 * @param graphURIs縲讀懃エ「蟇セ雎。縺ョgraph縺ョURI驟榊� (null繧�聞縺�縺ョ驟榊�繧ょ庄) 21 21 * @param keyword ��ull繧�ゥコ譁�ュ励�荳榊庄�� 22 * @param countInstances 繧ッ繝ゥ繧ケ縺ォ螻槭@縺ヲ縺�k繧、繝ウ繧ケ繧ソ繝ウ繧ケ縺ョ謨ー繧呈焚縺医k蝣エ蜷医�true繧剃ク弱∴繧� 22 23 * @return 繧ッ繝ゥ繧ケURI縺ョ驟榊� 23 24 * @throws Exception 24 25 * @since 28.01.2014 25 26 */ 26 public SClass[] getOWLClasses(String[] graphURIs, String keyword ) throws Exception;27 public SClass[] getOWLClasses(String[] graphURIs, String keyword, boolean countInstances) throws Exception; 27 28 28 29 /** -
BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/OWLQueryBuilderImpl.java
r27 r28 53 53 public static void main(String[] args) throws Exception { 54 54 String sparqlEndpoint = "http://dbpedia.org/sparql"; 55 //String sparqlEndpoint = "http://lsd.dbcls.jp/sparql";55 // String sparqlEndpoint = "http://lsd.dbcls.jp/sparql"; 56 56 String keyword = "artiste"; 57 //String keyword = "Agent";57 // String keyword = "Agent"; 58 58 String[] graphURIs = new String[0]; 59 59 60 60 OWLQueryBuilder builder = new OWLQueryBuilderImpl(sparqlEndpoint); 61 SClass[] clz = builder.getOWLClasses(graphURIs, keyword );61 SClass[] clz = builder.getOWLClasses(graphURIs, keyword, false); 62 62 for (SClass cls : clz) { 63 63 System.out.println(cls); … … 76 76 } 77 77 } 78 79 78 80 79 /* 81 80 * System.out.println("CLS-INS"); cls = … … 115 114 * @since 28.01.2014 116 115 */ 117 public SClass[] getOWLClasses(String[] graphURIs, String keyword )118 throws Exception {116 public SClass[] getOWLClasses(String[] graphURIs, String keyword, 117 boolean countInstances) throws Exception { 119 118 StringBuffer queryStr = new StringBuffer(); 120 119 queryStr.append("PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"); 121 120 queryStr.append("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"); 122 121 queryStr.append("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"); 123 queryStr.append("SELECT DISTINCT ?c ?pLabel (COUNT(?i) AS ?numOfInstances)\n"); 122 if (countInstances) { 123 queryStr.append("SELECT DISTINCT ?c ?pLabel (COUNT(?i) AS ?numOfInstances)\n"); 124 } else { 125 queryStr.append("SELECT DISTINCT ?c ?pLabel \n"); 126 } 124 127 if (graphURIs != null) { 125 128 for (String graphURI : graphURIs) { … … 135 138 queryStr.append(" ?c rdfs:label ?label.\n"); 136 139 queryStr.append(" ?c rdfs:label ?pLabel.\n"); 137 queryStr.append(" ?i rdf:type ?c.\n"); 138 140 if (countInstances) { 141 queryStr.append(" ?i rdf:type ?c.\n"); 142 } 139 143 // queryStr.append(" ?c rdfs:label "); 140 144 // queryStr.append(keyword); 141 145 // queryStr.append("."); 142 143 queryStr.append(" FILTER (\n"); 144 queryStr.append(" REGEX( ?label , \""); 145 queryStr.append(keyword); 146 queryStr.append("\" , \"i\" )\n"); 147 queryStr.append(" )"); 148 queryStr.append("\n} GROUP BY ?c ?pLabel"); 149 146 if (keyword != null && keyword.length() != 0) { 147 queryStr.append(" FILTER (\n"); 148 queryStr.append(" REGEX( ?label , \""); 149 queryStr.append(keyword); 150 queryStr.append("\" , \"i\" )\n"); 151 queryStr.append(" )"); 152 } 153 if (countInstances) { 154 queryStr.append("\n} GROUP BY ?c ?pLabel"); 155 } else { 156 queryStr.append("\n}"); 157 } 150 158 System.out.println(queryStr.toString()); 151 159 … … 295 303 } 296 304 queryStr.append("WHERE{\n"); 297 //queryStr.append(" { ?c rdf:type rdfs:Class. }\n UNION\n { ?c rdf:type owl:Class. }\n");305 // queryStr.append(" { ?c rdf:type rdfs:Class. }\n UNION\n { ?c rdf:type owl:Class. }\n"); 298 306 queryStr.append(" { ?p rdfs:domain <"); 299 307 queryStr.append(originClass); 300 308 queryStr.append(">.\n ?p rdfs:range ?c.\n"); 301 309 302 303 310 if (countLinks) { 304 311 queryStr.append(" ?o ?p ?s."); 305 } else{312 } else { 306 313 queryStr.append("filter(exists{\n"); 307 314 queryStr.append(" ?o rdf:type ?c.\n"); … … 320 327 if (countLinks) { 321 328 queryStr.append(" ?s ?p ?o."); 322 } else{329 } else { 323 330 queryStr.append("filter(exists{\n"); 324 331 queryStr.append(" ?s rdf:type ?c.\n");