チェンジセット 22 : BH13SPARQLBuilder/src/org/biohackathon
- 更新日時:
- 2014/01/30 15:43:23 (11 年 前)
- ファイル:
-
- 1 変更
凡例:
- 変更なし
- 追加
- 削除
-
BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/OWLQueryBuilderImpl.java
r20 r22 6 6 import java.util.HashSet; 7 7 import java.util.Set; 8 9 8 10 9 import com.hp.hpl.jena.query.Query; … … 19 18 /** 20 19 * 繧ッ繧ィ繝ェ繧堤函謌舌☆繧九◆繧√�讖溯�繧呈署萓帙☆繧区ク繧ッ繝ゥ繧ケ 20 * 21 21 * @author Norio KOBAYASHI 22 22 * @since 28.01.2014 … … 28 28 private String endpointURI = null; 29 29 30 31 30 /** 32 31 * 繧「繧ッ繧サ繧ケ縺吶kSPARQL endpoint縺ョURI繧呈欠螳壹☆繧区ァ区�蟄� 33 32 * 34 * @param endpointURI縲繧「繧ッ繧サ繧ケ縺吶kSPARQL endpoint縺ョURI 33 * @param endpointURI 34 * 縲繧「繧ッ繧サ繧ケ縺吶kSPARQL endpoint縺ョURI 35 35 * @throws Exception 36 36 * @since 28.01.2014 … … 45 45 * 繧ッ繧ィ繝ェ繝薙Ν繝繝シ縺ョ譛ャ逡ェ繝励Ο繧ー繝ゥ繝縺ァ縺ッ縺薙�繝。繧ス繝�ラ縺ッ菴ソ逕ィ縺励↑縺� 46 46 * </p> 47 * @param args 菴ソ逕ィ縺励↑縺� 47 * 48 * @param args 49 * 菴ソ逕ィ縺励↑縺� 48 50 * @throws Exception 49 51 * @since 28.01.2014 50 52 */ 51 53 public static void main(String[] args) throws Exception { 52 String sparqlEndpoint = "http://dbpedia.org/sparql"; 53 String keyword = "artiste"; 54 // String sparqlEndpoint = "http://dbpedia.org/sparql"; 55 String sparqlEndpoint = "http://lsd.dbcls.jp/sparql"; 56 // String keyword = "artiste"; 57 String keyword = "Agent"; 54 58 String[] graphURIs = new String[0]; 55 59 56 60 OWLQueryBuilder builder = new OWLQueryBuilderImpl(sparqlEndpoint); 57 61 SClass[] clz = builder.getOWLClasses(graphURIs, keyword); 58 for (SClass cls: clz){62 for (SClass cls : clz) { 59 63 System.out.println(cls); 60 64 } 61 65 62 System.out.println("CLS"); 63 ClassLink[] cls = builder.getNextClass(null, clz[0].getClassURI(), 0, false); 64 if( cls != null ){ 65 for( ClassLink cl: cls){ 66 System.out.println(cl.toString()); 67 } 68 } 69 70 System.out.println("CLS-INS"); 71 cls = builder.getNextClassViaInstanceLink(null, clz[0].getClassURI(), 100); 72 if( cls != null ){ 73 for( ClassLink cl: cls){ 74 System.out.println(cl.toString()); 75 } 76 } 77 78 System.out.println("Instances"); 79 Instance[] ins = builder.getInstances(null, "\"A.C. Reed\"@en"); 80 if( ins != null ){ 81 for( Instance in: ins){ 82 System.out.println(in.toString()); 83 } 84 } 85 86 87 System.out.println("INS-INS"); 88 ins = builder.getInstances(null, "\"A.C. Reed\"@en"); 89 InstanceLink[] iLinks = builder.getNextInstancesViaInstanceLink(null, ins[0].getInstanceURI(), 100); 90 91 92 93 if( iLinks != null ){ 94 for( InstanceLink in: iLinks){ 95 System.out.println(in.toString()); 96 } 97 } 98 99 100 } 101 102 66 /* 67 * System.out.println("CLS"); ClassLink[] cls = 68 * builder.getNextClass(null, clz[0].getClassURI(), 0, false); if( cls 69 * != null ){ for( ClassLink cl: cls){ 70 * System.out.println(cl.toString()); } } 71 * 72 * System.out.println("CLS-INS"); cls = 73 * builder.getNextClassViaInstanceLink(null, clz[0].getClassURI(), 100); 74 * if( cls != null ){ for( ClassLink cl: cls){ 75 * System.out.println(cl.toString()); } } 76 * 77 * System.out.println("Instances"); Instance[] ins = 78 * builder.getInstances(null, "\"A.C. Reed\"@en"); if( ins != null ){ 79 * for( Instance in: ins){ System.out.println(in.toString()); } } 80 * 81 * 82 * System.out.println("INS-INS"); ins = builder.getInstances(null, 83 * "\"A.C. Reed\"@en"); InstanceLink[] iLinks = 84 * builder.getNextInstancesViaInstanceLink(null, 85 * ins[0].getInstanceURI(), 100); 86 * 87 * 88 * 89 * if( iLinks != null ){ for( InstanceLink in: iLinks){ 90 * System.out.println(in.toString()); } } 91 */ 92 } 93 103 94 /** 104 95 * 譏守、コ逧�↓RDF縺ァ譖ク縺九l縺ヲ縺�k繧ッ繝ゥ繧ケ繧貞叙蠕励☆繧� 105 96 * <p> 106 * 謖�ョ壹&繧後◆graphURIs縺ョ荳ュ縺九i縲√く繝シ繝ッ繝シ繝峨↓繝偵ャ繝医☆繧九Λ繝吶Ν繧呈戟縺、繧ッ繝ゥ繧ケ��dfs:Class�峨r縺吶∋縺ヲ霑斐☆ 107 * <br> 97 * 謖�ョ壹&繧後◆graphURIs縺ョ荳ュ縺九i縲√く繝シ繝ッ繝シ繝峨↓繝偵ャ繝医☆繧九Λ繝吶Ν繧呈戟縺、繧ッ繝ゥ繧ケ��dfs:Class�峨r縺吶∋縺ヲ霑斐☆ <br> 108 98 * </p> 109 99 * 110 * @param graphURIs縲讀懃エ「蟇セ雎。縺ョgraph縺ョURI驟榊� (null繧�聞縺�縺ョ驟榊�繧ょ庄) 111 * @param keyword ��ull繧�ゥコ譁�ュ励�荳榊庄�� 100 * @param graphURIs 101 * 縲讀懃エ「蟇セ雎。縺ョgraph縺ョURI驟榊� (null繧�聞縺�縺ョ驟榊�繧ょ庄) 102 * @param keyword 103 * ��ull繧�ゥコ譁�ュ励�荳榊庄�� 112 104 * @return 繧ッ繝ゥ繧ケURI縺ョ驟榊� 113 105 * @throws Exception … … 129 121 } 130 122 queryStr.append("WHERE{\n"); 131 123 132 124 queryStr.append(" {?c rdf:type rdfs:Class} UNION {?c rdf:type owl:Class}\n"); 133 125 … … 136 128 queryStr.append(" ?i rdf:type ?c.\n"); 137 129 138 //queryStr.append(" ?c rdfs:label ");139 //queryStr.append(keyword);140 //queryStr.append(".");141 142 queryStr.append(" FILTER (\n"); 130 // queryStr.append(" ?c rdfs:label "); 131 // queryStr.append(keyword); 132 // queryStr.append("."); 133 134 queryStr.append(" FILTER (\n"); 143 135 queryStr.append(" REGEX( ?label , \""); 144 136 queryStr.append(keyword); 145 137 queryStr.append("\" , \"i\" )\n"); 146 queryStr.append(" )"); 138 queryStr.append(" )"); 147 139 queryStr.append("\n} GROUP BY ?c ?pLabel"); 148 140 149 //System.out.println(queryStr.toString());150 141 System.out.println(queryStr.toString()); 142 151 143 Query query = QueryFactory.create(queryStr.toString()); 152 144 QueryExecution qexec = QueryExecutionFactory.sparqlService(endpointURI, … … 154 146 155 147 ResultSet results = qexec.execSelect(); 156 HashMap<String, SClass> classMap = new HashMap<String,SClass>();148 HashMap<String, SClass> classMap = new HashMap<String, SClass>(); 157 149 for (; results.hasNext();) { 158 150 QuerySolution sol = results.next(); 159 151 Resource res = sol.getResource("c"); 160 String uri = res.getURI();161 int numOfInstances = sol.getLiteral("numOfInstances").getInt();162 //System.out.println(numOfInstances);163 Literal labelLiteral = sol.getLiteral("pLabel");164 SClass sClass = null;165 if( classMap.containsKey(uri)){166 sClass = classMap.get(uri);167 }168 else{152 if (res != null) { 153 String uri = res.getURI(); 154 int numOfInstances = sol.getLiteral("numOfInstances").getInt(); 155 // System.out.println(numOfInstances); 156 Literal labelLiteral = sol.getLiteral("pLabel"); 157 SClass sClass = null; 158 if (classMap.containsKey(uri)) { 159 sClass = classMap.get(uri); 160 } else { 169 161 sClass = new SClass(uri, null, numOfInstances); 170 162 classMap.put(uri, sClass); 171 }172 if ( labelLiteral != null ){163 } 164 if (labelLiteral != null) { 173 165 String label = labelLiteral.getString(); 174 166 String lang = labelLiteral.getLanguage(); 175 167 sClass.addLabel(new Label(label, lang)); 176 168 } 169 } 177 170 } 178 171 qexec.close(); … … 180 173 } 181 174 182 183 175 /** 184 * 縲繧、繝ウ繧ケ繧ソ繝ウ繧ケ繧貞叙蠕励☆繧�176 * 縲繧、繝ウ繧ケ繧ソ繝ウ繧ケ繧貞叙蠕励☆繧� 185 177 * <p> 186 * 謖�ョ壹&繧後◆graphURIs縺ョ荳ュ縺九i縲√く繝シ繝ッ繝シ繝峨↓繝偵ャ繝医☆繧九Λ繝吶Ν繧呈戟縺、繧、繝ウ繧ケ繧ソ繝ウ繧ケ繧偵☆縺ケ縺ヲ霑斐☆ 187 * <br> 188 * 縺薙%縺ァ繧、繝ウ繧ケ繧ソ繝ウ繧ケ縺ィ縺ッ縲〉df:type縺ョ荳サ隱槭→縺励※險倩ソー縺輔l縺ヲ縺�k繧ゅ�繧偵>縺� 189 * <br> 178 * 謖�ョ壹&繧後◆graphURIs縺ョ荳ュ縺九i縲√く繝シ繝ッ繝シ繝峨↓繝偵ャ繝医☆繧九Λ繝吶Ν繧呈戟縺、繧、繝ウ繧ケ繧ソ繝ウ繧ケ繧偵☆縺ケ縺ヲ霑斐☆ <br> 179 * 縺薙%縺ァ繧、繝ウ繧ケ繧ソ繝ウ繧ケ縺ィ縺ッ縲〉df:type縺ョ荳サ隱槭→縺励※險倩ソー縺輔l縺ヲ縺�k繧ゅ�繧偵>縺�<br> 190 180 * </p> 191 181 * 192 * @param graphURIs縲讀懃エ「蟇セ雎。縺ョgraph縺ョURI驟榊� (null繧�聞縺�縺ョ驟榊�繧ょ庄) 193 * @param keyword ��ull繧�ゥコ譁�ュ励�荳榊庄�� 182 * @param graphURIs 183 * 縲讀懃エ「蟇セ雎。縺ョgraph縺ョURI驟榊� (null繧�聞縺�縺ョ驟榊�繧ょ庄) 184 * @param keyword 185 * ��ull繧�ゥコ譁�ュ励�荳榊庄�� 194 186 * @return 繧ッ繝ゥ繧ケURI縺ョ驟榊� 195 187 * @throws Exception … … 211 203 } 212 204 queryStr.append("WHERE{\n"); 213 // queryStr.append(" {?c rdf:type rdfs:Class} UNION {?c rdf:type owl:Class}\n"); 214 215 205 // queryStr.append(" {?c rdf:type rdfs:Class} UNION {?c rdf:type owl:Class}\n"); 206 216 207 queryStr.append(" ?ins rdf:type ?c.\n"); 217 208 queryStr.append(" ?ins rdfs:label "); … … 220 211 queryStr.append(" FILTER (?c != rdf:Property)"); 221 212 queryStr.append("}"); 222 223 // System.out.println(queryStr.toString());224 213 214 // System.out.println(queryStr.toString()); 215 225 216 Query query = QueryFactory.create(queryStr.toString()); 226 217 QueryExecution qexec = QueryExecutionFactory.sparqlService(endpointURI, … … 235 226 String clsURI = cls.getURI(); 236 227 String insURI = ins.getURI(); 237 if ( instanceMap.containsKey(insURI)){228 if (instanceMap.containsKey(insURI)) { 238 229 HashSet<String> classes = instanceMap.get(insURI); 239 230 classes.add(clsURI); 240 } else{231 } else { 241 232 HashSet<String> classes = new HashSet<String>(); 242 233 instanceMap.put(insURI, classes); … … 247 238 Set<String> keySet = instanceMap.keySet(); 248 239 ArrayList<Instance> instanceList = new ArrayList<Instance>(); 249 for(String key: keySet){ 250 Instance ins = new Instance(key, instanceMap.get(key).toArray(new String[0])); 240 for (String key : keySet) { 241 Instance ins = new Instance(key, instanceMap.get(key).toArray( 242 new String[0])); 251 243 instanceList.add(ins); 252 244 } … … 254 246 } 255 247 256 257 248 /** 258 * 縲謖�ョ壹&繧後◆繧ッ繝ゥ繧ケ繧定オキ轤ケ縺ィ縺励∵�遉コ逧�↓險倩ソー縺輔l縺ヲ縺�kOWL縺ョproperty蛻カ邏�r隱ソ縺ケ縲√◎縺ョproperty蛻カ邏�〒249 * 縲謖�ョ壹&繧後◆繧ッ繝ゥ繧ケ繧定オキ轤ケ縺ィ縺励∵�遉コ逧�↓險倩ソー縺輔l縺ヲ縺�kOWL縺ョproperty蛻カ邏�r隱ソ縺ケ縲√◎縺ョproperty蛻カ邏�〒 259 250 * 髢「騾」縺・縺代i繧後※縺�k繧ッ繝ゥ繧ケ繧堤カイ鄒�噪縺ォ蜿門セ励☆繧� 260 251 * <p> 261 * 蜃ヲ逅�ッセ雎。繝��繧ソ繧暖raphURIs縺ァ謖�ョ壹☆繧九%縺ィ縺後〒縺阪k 262 * <br> 252 * 蜃ヲ逅�ッセ雎。繝��繧ソ繧暖raphURIs縺ァ謖�ョ壹☆繧九%縺ィ縺後〒縺阪k <br> 263 253 * <br> 264 254 * </p> 265 255 * 266 * @param graphURIs縲讀懃エ「蟇セ雎。縺ョgraph縺ョURI驟榊� 縲(null繧�聞縺�縺ョ驟榊�繧ょ庄) 267 * @param originClass 襍キ轤ケ縺ィ縺ェ繧九け繝ゥ繧ケ縺ョURI縲��ull荳榊庄�� 268 * @param limit 隗」縺ィ縺励※霑斐&繧後kClassLink驟榊�縺ョ髟キ縺輔�荳企剞蛟、繧呈欠螳壹☆繧九�荳企剞蛟、繧定ィュ螳壹@縺ェ縺�エ蜷医�0莉・荳九�蛟、繧呈欠螳壹☆繧� 256 * @param graphURIs 257 * 縲讀懃エ「蟇セ雎。縺ョgraph縺ョURI驟榊� 縲(null繧�聞縺�縺ョ驟榊�繧ょ庄) 258 * @param originClass 259 * 襍キ轤ケ縺ィ縺ェ繧九け繝ゥ繧ケ縺ョURI縲��ull荳榊庄�� 260 * @param limit 261 * 隗」縺ィ縺励※霑斐&繧後kClassLink驟榊�縺ョ髟キ縺輔�荳企剞蛟、繧呈欠螳壹☆繧九�荳企剞蛟、繧定ィュ螳壹@縺ェ縺�エ蜷医�0莉・荳九�蛟、繧呈欠螳壹☆繧� 269 262 * @return ClassLink縺ョ驟榊�縲ゅ%縺薙↓縺ッ縲∝叙蠕励&繧後◆繧ッ繝ゥ繧ケ縺ィ髢「菫ゅ▼縺代i繧後※縺�k繝励Ο繝代ユ繧」縲�未菫ゅ�蜷代″縺悟性縺セ繧後k縲� 270 263 * @throws Exception … … 279 272 280 273 // SELECT 281 if( countLinks ){ 282 queryStr.append("SELECT DISTINCT ?p ?pDirection ?c (COUNT(?s) AS ?numOfLinks) \n"); 283 } 284 else{ 274 if (countLinks) { 275 queryStr.append("SELECT DISTINCT ?p ?pDirection ?c (COUNT(?s) AS ?numOfLinks) \n"); 276 } else { 285 277 queryStr.append("SELECT DISTINCT ?p ?pDirection ?c \n"); 286 278 } 287 279 288 280 if (graphURIs != null) { 289 281 for (String graphURI : graphURIs) { … … 299 291 queryStr.append(">.\n ?p rdfs:range ?c.\n"); 300 292 301 if ( countLinks ){302 303 } 304 293 if (countLinks) { 294 queryStr.append(" ?o ?p ?s."); 295 } 296 305 297 queryStr.append("}\n UNION\n"); 306 298 queryStr.append(" { ?p rdfs:range <"); … … 309 301 queryStr.append(" ?p rdfs:domain ?c.\n"); 310 302 311 if ( countLinks ){312 313 } 314 303 if (countLinks) { 304 queryStr.append(" ?s ?p ?o."); 305 } 306 315 307 queryStr.append("}\n"); 316 308 317 309 queryStr.append(" ?p ?pDirection ?c.\n"); 318 310 319 320 311 queryStr.append(" ?s rdf:type ?c.\n"); 321 312 322 if ( countLinks){313 if (countLinks) { 323 314 queryStr.append(" ?o rdf:type <"); 324 315 queryStr.append(originClass); 325 316 queryStr.append(">.\n"); 326 317 queryStr.append("}\nGROUP BY ?p ?pDirection ?c\n"); 327 } 328 else{ 318 } else { 329 319 queryStr.append("}\n"); 330 320 } … … 334 324 queryStr.append("\n"); 335 325 } 336 337 System.out.println(queryStr.toString()); 338 326 327 System.out.println(queryStr.toString()); 328 339 329 Query query = QueryFactory.create(queryStr.toString()); 340 330 QueryExecution qexec = QueryExecutionFactory.sparqlService(endpointURI, … … 346 336 QuerySolution sol = results.next(); 347 337 Resource pro = sol.getResource("p"); 348 Resource cls = sol.getResource("c"); 349 Resource dir = sol.getResource("pDirection"); 350 String proURI = pro.getURI(); 351 String clsURI = cls.getURI(); 352 String dirURI = dir.getURI(); 353 354 // System.out.println(pro.getURI() + " " + cls.getURI() + " " + dir.getURI()); 355 356 357 Direction direction = null; 358 if( dirURI.equals("http://www.w3.org/2000/01/rdf-schema#domain") || dirURI.equals("rdfs:domain")){ 359 direction = Direction.reverse; 360 } 361 if( dirURI.equals("http://www.w3.org/2000/01/rdf-schema#range") || dirURI.equals("rdfs:range")){ 362 if( direction != null ){ 363 direction = Direction.both; 364 }else{ 365 direction = Direction.forward; 338 if (pro != null) { 339 Resource cls = sol.getResource("c"); 340 Resource dir = sol.getResource("pDirection"); 341 String proURI = pro.getURI(); 342 String clsURI = cls.getURI(); 343 String dirURI = dir.getURI(); 344 345 // System.out.println(pro.getURI() + " " + cls.getURI() + " " + 346 // dir.getURI()); 347 348 Direction direction = null; 349 if (dirURI 350 .equals("http://www.w3.org/2000/01/rdf-schema#domain") 351 || dirURI.equals("rdfs:domain")) { 352 direction = Direction.reverse; 366 353 } 367 } 368 // System.out.println(direction); 369 int numOfLinks = sol.getLiteral("numOfLinks").getInt(); 370 ClassLink cl = new ClassLink(proURI, clsURI, direction, numOfLinks); 371 solCLs.add(cl); 354 if (dirURI.equals("http://www.w3.org/2000/01/rdf-schema#range") 355 || dirURI.equals("rdfs:range")) { 356 if (direction != null) { 357 direction = Direction.both; 358 } else { 359 direction = Direction.forward; 360 } 361 } 362 // System.out.println(direction); 363 int numOfLinks = sol.getLiteral("numOfLinks").getInt(); 364 ClassLink cl = new ClassLink(proURI, clsURI, direction, 365 numOfLinks); 366 solCLs.add(cl); 367 } 372 368 } 373 369 qexec.close(); 374 370 return solCLs.toArray(new ClassLink[0]); 375 371 } 376 377 372 378 373 /** 379 *縲謖�ョ壹&繧後◆繧ッ繝ゥ繧ケ繧定オキ轤ケ縺ィ縺励√◎縺ョ繧ッ繝ゥ繧ケ縺ォ螻槭@縺ヲ縺�k繧、繝ウ繧ケ繧ソ繝ウ繧ケ縺ィ繝ェ繝ウ繧ッ縺悟シオ繧峨l縺ヲ縺�k繧、繝ウ繧ケ繧ソ繝ウ繧ケ縺ョ髮�粋繧貞叙蠕励@縲∝叙蠕励@縺溘う繝ウ繧ケ繧ソ繝ウ繧ケ縺ョ繧ッ繝ゥ繧ケ繧堤カイ鄒�噪縺ォ蜿門セ励☆繧� 374 * 縲謖�ョ壹&繧後◆繧ッ繝ゥ繧ケ繧定オキ轤ケ縺ィ縺励√◎縺ョ繧ッ繝ゥ繧ケ縺ォ螻槭@縺ヲ縺�k繧、繝ウ繧ケ繧ソ繝ウ繧ケ縺ィ繝ェ繝ウ繧ッ縺悟シオ繧峨l縺ヲ縺�k繧、繝ウ繧ケ繧ソ繝ウ繧ケ縺ョ髮�粋繧貞叙蠕励@縲� 375 * 蜿門セ励@縺溘う繝ウ繧ケ繧ソ繝ウ繧ケ縺ョ繧ッ繝ゥ繧ケ繧堤カイ鄒�噪縺ォ蜿門セ励☆繧� 380 376 * <p> 381 * 縺薙%縺ァ繧、繝ウ繧ケ繧ソ繝ウ繧ケ縺ィ縺ッ縲〉df:type縺ョ荳サ隱槭→縺励※險倩ソー縺輔l縺ヲ縺�k繧ゅ�繧偵>縺� 382 * <br> 383 * 蜃ヲ逅�ッセ雎。繝��繧ソ繧暖raphURIs縺ァ謖�ョ壹☆繧九%縺ィ縺後〒縺阪k 384 * <br> 377 * 縺薙%縺ァ繧、繝ウ繧ケ繧ソ繝ウ繧ケ縺ィ縺ッ縲〉df:type縺ョ荳サ隱槭→縺励※險倩ソー縺輔l縺ヲ縺�k繧ゅ�繧偵>縺�<br> 378 * 蜃ヲ逅�ッセ雎。繝��繧ソ繧暖raphURIs縺ァ謖�ョ壹☆繧九%縺ィ縺後〒縺阪k <br> 385 379 * </p> 386 380 * 387 * @param graphURIs縲讀懃エ「蟇セ雎。縺ョgraph縺ョURI驟榊� 縲(null繧�聞縺�縺ョ驟榊�繧ょ庄) 388 * @param originClass 襍キ轤ケ縺ィ縺ェ繧九け繝ゥ繧ケ縺ョURI縲��ull荳榊庄�� 389 * @param limit 隗」縺ィ縺励※霑斐&繧後kClassLink驟榊�縺ョ髟キ縺輔�荳企剞蛟、繧呈欠螳壹☆繧九�荳企剞蛟、繧定ィュ螳壹@縺ェ縺�エ蜷医�0莉・荳九�蛟、繧呈欠螳壹☆繧� 381 * @param graphURIs 382 * 縲讀懃エ「蟇セ雎。縺ョgraph縺ョURI驟榊� 縲(null繧�聞縺�縺ョ驟榊�繧ょ庄) 383 * @param originClass 384 * 襍キ轤ケ縺ィ縺ェ繧九け繝ゥ繧ケ縺ョURI縲��ull荳榊庄�� 385 * @param limit 386 * 隗」縺ィ縺励※霑斐&繧後kClassLink驟榊�縺ョ髟キ縺輔�荳企剞蛟、繧呈欠螳壹☆繧九�荳企剞蛟、繧定ィュ螳壹@縺ェ縺�エ蜷医�0莉・荳九�蛟、繧呈欠螳壹☆繧� 390 387 * @return ClassLink縺ョ驟榊�縲ゅ%縺薙↓縺ッ縲∝叙蠕励&繧後◆繧ッ繝ゥ繧ケ縺ィ髢「菫ゅ▼縺代i繧後※縺�k繝励Ο繝代ユ繧」縲�未菫ゅ�蜷代″縺悟性縺セ繧後k縲� 391 388 * @throws Exception 392 389 * @since 28.01.2014 393 390 */ 394 public ClassLink[] getNextClassViaInstanceLink(String[] graphURIs, String originClass,395 int limit) throws Exception {391 public ClassLink[] getNextClassViaInstanceLink(String[] graphURIs, 392 String originClass, int limit) throws Exception { 396 393 StringBuffer queryStr = new StringBuffer(); 397 394 queryStr.append("PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"); … … 418 415 queryStr.append("\n"); 419 416 } 420 421 // System.out.println(queryStr.toString()); 422 417 418 // System.out.println(queryStr.toString()); 419 423 420 Query query = QueryFactory.create(queryStr.toString()); 424 421 QueryExecution qexec = QueryExecutionFactory.sparqlService(endpointURI, … … 434 431 Direction direction = null; 435 432 String propURI = null; 436 if ( proForward != null ){437 if ( proReverse != null ){433 if (proForward != null) { 434 if (proReverse != null) { 438 435 direction = Direction.both; 439 } else{436 } else { 440 437 direction = Direction.forward; 441 438 } 442 439 propURI = proForward.getURI(); 443 } else{440 } else { 444 441 direction = Direction.reverse; 445 442 propURI = proReverse.getURI(); 446 443 } 447 444 String clsURI = cls.getURI(); 448 //System.out.println(propURI + " " + clsURI + " " + direction);449 445 // System.out.println(propURI + " " + clsURI + " " + direction); 446 450 447 ClassLink cl = new ClassLink(propURI, clsURI, direction, 0); 451 448 solCLs.add(cl); … … 455 452 } 456 453 457 458 459 454 public Path[] getPaths(String startClass, String endClass) throws Exception { 460 455 OWLClassGraph graph = new OWLClassGraph(startClass, endClass); … … 466 461 } 467 462 468 469 470 471 /* 472 private String executeSelect(String sparqlQuery) throws Exception { 473 HttpClient client = HttpClientBuilder.create().build(); 474 HttpPost httppost = new HttpPost(endpointURI); 475 httppost.setHeader("Content-Type", "application/x-www-form-urlencoded"); 476 httppost.setHeader("Accept", "application/sparql-results+xml"); 477 List<NameValuePair> nvpList = new ArrayList<NameValuePair>(); 478 nvpList.add(new BasicNameValuePair("query", sparqlQuery)); 479 // nvpList.add(new BasicNameValuePair("format", 480 // outputFormat.getMime())); 481 httppost.setEntity(new UrlEncodedFormEntity(nvpList, Charset 482 .forName("UTF-8"))); 483 HttpResponse response = client.execute(httppost); 484 // System.out.println("[StatusLine] " + response.getStatusLine()); 485 HttpEntity entity = response.getEntity(); 486 String entityString = EntityUtils.toString(entity, "UTF-8"); 487 return entityString; 488 } 489 */ 490 463 /* 464 * private String executeSelect(String sparqlQuery) throws Exception { 465 * HttpClient client = HttpClientBuilder.create().build(); HttpPost httppost 466 * = new HttpPost(endpointURI); httppost.setHeader("Content-Type", 467 * "application/x-www-form-urlencoded"); httppost.setHeader("Accept", 468 * "application/sparql-results+xml"); List<NameValuePair> nvpList = new 469 * ArrayList<NameValuePair>(); nvpList.add(new BasicNameValuePair("query", 470 * sparqlQuery)); // nvpList.add(new BasicNameValuePair("format", // 471 * outputFormat.getMime())); httppost.setEntity(new 472 * UrlEncodedFormEntity(nvpList, Charset .forName("UTF-8"))); HttpResponse 473 * response = client.execute(httppost); // 474 * System.out.println("[StatusLine] " + response.getStatusLine()); 475 * HttpEntity entity = response.getEntity(); String entityString = 476 * EntityUtils.toString(entity, "UTF-8"); return entityString; } 477 */ 478 491 479 /** 492 * 縲謖�ョ壹&繧後◆繧、繝ウ繧ケ繧ソ繝ウ繧ケ繧定オキ轤ケ縺ィ縺励√◎縺ョ繧、繝ウ繧ケ繧ソ繝ウ繧ケ縺ォ繝ェ繝ウ繧ッ縺悟シオ繧峨l縺ヲ縺�k繧、繝ウ繧ケ繧ソ繝ウ繧ケ縺ョ髮�粋繧貞叙蠕励☆繧九�493 * 縲蜿門セ励&繧後◆蜷�う繝ウ繧ケ繧ソ繝ウ繧ケ縺ョ繧ッ繝ゥ繧ケ繧らカイ鄒�噪縺ォ蜿門セ励☆繧�480 * 縲謖�ョ壹&繧後◆繧、繝ウ繧ケ繧ソ繝ウ繧ケ繧定オキ轤ケ縺ィ縺励√◎縺ョ繧、繝ウ繧ケ繧ソ繝ウ繧ケ縺ォ繝ェ繝ウ繧ッ縺悟シオ繧峨l縺ヲ縺�k繧、繝ウ繧ケ繧ソ繝ウ繧ケ縺ョ髮�粋繧貞叙蠕励☆繧九� 481 * 縲蜿門セ励&繧後◆蜷�う繝ウ繧ケ繧ソ繝ウ繧ケ縺ョ繧ッ繝ゥ繧ケ繧らカイ鄒�噪縺ォ蜿門セ励☆繧� 494 482 * <p> 495 * 縺薙%縺ァ繧、繝ウ繧ケ繧ソ繝ウ繧ケ縺ィ縺ッ縲〉df:type縺ョ荳サ隱槭→縺励※險倩ソー縺輔l縺ヲ縺�k繧ゅ�繧偵>縺� 496 * <br> 497 * 蜃ヲ逅�ッセ雎。繝��繧ソ繧暖raphURIs縺ァ謖�ョ壹☆繧九%縺ィ縺後〒縺阪k 498 * <br> 483 * 縺薙%縺ァ繧、繝ウ繧ケ繧ソ繝ウ繧ケ縺ィ縺ッ縲〉df:type縺ョ荳サ隱槭→縺励※險倩ソー縺輔l縺ヲ縺�k繧ゅ�繧偵>縺�<br> 484 * 蜃ヲ逅�ッセ雎。繝��繧ソ繧暖raphURIs縺ァ謖�ョ壹☆繧九%縺ィ縺後〒縺阪k <br> 499 485 * </p> 500 486 * 501 * @param graphURIs縲讀懃エ「蟇セ雎。縺ョgraph縺ョURI驟榊� 縲(null繧�聞縺�縺ョ驟榊�繧ょ庄) 502 * @param originInstance 襍キ轤ケ縺ィ縺ェ繧九う繝ウ繧ケ繧ソ繝ウ繧ケ縺ョURI縲��ull荳榊庄�� 503 * @param limit 隗」縺ィ縺励※霑斐&繧後kInstanceLink驟榊�縺ョ髟キ縺輔�荳企剞蛟、繧呈欠螳壹☆繧九�荳企剞蛟、繧定ィュ螳壹@縺ェ縺�エ蜷医�0莉・荳九�蛟、繧呈欠螳壹☆繧� 487 * @param graphURIs 488 * 縲讀懃エ「蟇セ雎。縺ョgraph縺ョURI驟榊� 縲(null繧�聞縺�縺ョ驟榊�繧ょ庄) 489 * @param originInstance 490 * 襍キ轤ケ縺ィ縺ェ繧九う繝ウ繧ケ繧ソ繝ウ繧ケ縺ョURI縲��ull荳榊庄�� 491 * @param limit 492 * 隗」縺ィ縺励※霑斐&繧後kInstanceLink驟榊�縺ョ髟キ縺輔�荳企剞蛟、繧呈欠螳壹☆繧九�荳企剞蛟、繧定ィュ螳壹@縺ェ縺�エ蜷医�0莉・荳九�蛟、繧呈欠螳壹☆繧� 504 493 * @return InstanceLink縺ョ驟榊�縲ゅ%縺薙↓縺ッ縲∝叙蠕励&繧後◆繧ッ繝ゥ繧ケ縺ィ髢「菫ゅ▼縺代i繧後※縺�k繝励Ο繝代ユ繧」縲�未菫ゅ�蜷代″縺悟性縺セ繧後k縲� 505 494 * @throws Exception 506 495 * @since 28.01.2014 507 496 */ 508 public InstanceLink[] getNextInstancesViaInstanceLink(String[] graphURIs, String originInstance,509 int limit) throws Exception {497 public InstanceLink[] getNextInstancesViaInstanceLink(String[] graphURIs, 498 String originInstance, int limit) throws Exception { 510 499 StringBuffer queryStr = new StringBuffer(); 511 500 queryStr.append("PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"); … … 521 510 } 522 511 queryStr.append("WHERE{\n"); 523 //queryStr.append(" { ?c rdf:type rdfs:Class. }\n UNION\n { ?c rdf:type owl:Class. }\n");512 // queryStr.append(" { ?c rdf:type rdfs:Class. }\n UNION\n { ?c rdf:type owl:Class. }\n"); 524 513 queryStr.append(" ?ins rdf:type ?c.\n"); 525 514 queryStr.append(" { ?ins ?pr <"); … … 537 526 queryStr.append("\n"); 538 527 } 539 540 // System.out.println(queryStr.toString()); 541 528 529 // System.out.println(queryStr.toString()); 530 542 531 Query query = QueryFactory.create(queryStr.toString()); 543 532 QueryExecution qexec = QueryExecutionFactory.sparqlService(endpointURI, … … 554 543 Direction direction = null; 555 544 String propURI = null; 556 if ( proForward != null ){557 if ( proReverse != null ){545 if (proForward != null) { 546 if (proReverse != null) { 558 547 direction = Direction.both; 559 } else{548 } else { 560 549 direction = Direction.forward; 561 550 } 562 551 propURI = proForward.getURI(); 563 } else{552 } else { 564 553 direction = Direction.reverse; 565 554 propURI = proReverse.getURI(); … … 568 557 String insURI = ins.getURI(); 569 558 String key = propURI + "\t" + insURI + "\t" + direction; 570 if ( insLinkMap.containsKey(key)){559 if (insLinkMap.containsKey(key)) { 571 560 InstanceLink insLink = insLinkMap.get(key); 572 561 insLink.addLinkedClassURI(clsURI); 573 }else{ 574 InstanceLink insLink = new InstanceLink(propURI, insURI, new String[]{clsURI}, direction); 562 } else { 563 InstanceLink insLink = new InstanceLink(propURI, insURI, 564 new String[] { clsURI }, direction); 575 565 insLinkMap.put(key, insLink); 576 566 } … … 581 571 } 582 572 583 584 public LabelMap[] getLabels(String[] graphURIs, String[] resourceURIs, String language) throws Exception{585 if ( resourceURIs == null || resourceURIs.length == 0 ){573 public LabelMap[] getLabels(String[] graphURIs, String[] resourceURIs, 574 String language) throws Exception { 575 if (resourceURIs == null || resourceURIs.length == 0) { 586 576 return new LabelMap[0]; 587 577 } … … 602 592 queryStr.append(" FILTER(?res IN ("); 603 593 boolean f = false; 604 for ( String resourceURI: resourceURIs ){605 if (f){594 for (String resourceURI : resourceURIs) { 595 if (f) { 606 596 queryStr.append(", "); 607 597 } … … 613 603 queryStr.append("))\n"); 614 604 queryStr.append("}"); 615 616 System.out.println(queryStr.toString()); 617 605 606 System.out.println(queryStr.toString()); 607 618 608 Query query = QueryFactory.create(queryStr.toString()); 619 609 QueryExecution qexec = QueryExecutionFactory.sparqlService(endpointURI, … … 626 616 String uri = sol.getResource("res").getURI(); 627 617 Literal literal = sol.getLiteral("label"); 628 if ( literal != null ){618 if (literal != null) { 629 619 String label = literal.getString(); 630 620 String lang = literal.getLanguage(); 631 if ( language != null && language.equals(lang)){621 if (language != null && language.equals(lang)) { 632 622 Label lbl = new Label(label, lang); 633 if ( lMap.containsKey(uri)){623 if (lMap.containsKey(uri)) { 634 624 LabelMap lm = lMap.get(uri); 635 625 lm.addLabel(lbl); 636 } else{637 LabelMap lm = new LabelMap(uri, new Label[] {lbl});626 } else { 627 LabelMap lm = new LabelMap(uri, new Label[] { lbl }); 638 628 lMap.put(uri, lm); 639 629 } … … 643 633 return lMap.values().toArray(new LabelMap[0]); 644 634 } 645 635 646 636 }