チェンジセット 274 : SPARQLBuilderWWW/src/java
- 更新日時:
- 2016/03/16 17:26:17 (9 年 前)
- ファイル:
-
- 1 変更
凡例:
- 変更なし
- 追加
- 削除
-
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/www/CLServlet.java
r260 r274 85 85 if ( ep == null ){ 86 86 JsonBuilderFactory jbfactory = Json.createBuilderFactory(null); 87 JsonObjectBuilder job = jbfactory.createObjectBuilder();88 87 89 88 String[] eplist = qpg.getFactory().getEndpointURIList(); 89 TreeSet<String> classes = new TreeSet<String>(); 90 90 for ( int i = 0; i < eplist.length; i++ ){ 91 91 try{ 92 92 qpg.setSPARQLendpoint(eplist[i]); 93 SClass[] classes = qpg.getClasses(null); 94 sortedClasses = qpg.getSortedClasses(classes); 95 JsonArray ja = getJsonArrayFromSortedClasses(jbfactory, sortedClasses); 96 job.add(eplist[i], ja); 93 SClass[] cls = qpg.getClasses(null); 94 qpg.setClassLabels(cls); // HENKO TODO 95 for (int j = 0; j < cls.length; j++ ){ 96 classes.add(qpg.getClassLabel(cls[j].getClassURI()).concat("\t") 97 .concat(cls[j].getClassURI()).concat("\t") 98 .concat(new Integer(cls[j].getNumOfInstances()).toString()) 99 .concat("\t").concat(eplist[i])); 100 } 97 101 }catch(Exception e){ 102 e.printStackTrace(); 98 103 System.err.println(e); 99 104 } 100 105 } 101 Json Object jo = job.build();102 out.print(j o);106 JsonArray ja = getJsonArrayFromClasses(jbfactory, classes); 107 out.print(ja); 103 108 return; 104 109 } … … 115 120 116 121 JsonBuilderFactory jbfactory = Json.createBuilderFactory(null); 117 JsonArray ja = getJsonArrayFromSortedClasses(jbfactory, sortedClasses );122 JsonArray ja = getJsonArrayFromSortedClasses(jbfactory, sortedClasses, ep); 118 123 out.print(ja); 119 124 } … … 143 148 }// </editor-fold> 144 149 145 private JsonArray getJsonArrayFromSortedClasses(JsonBuilderFactory jbfactory, SortedSet<String> sortedClasses){ 150 151 private JsonArray getJsonArrayFromSortedClasses(JsonBuilderFactory jbfactory, 152 SortedSet<String> sortedClasses, String ep){ 146 153 JsonArrayBuilder jab = jbfactory.createArrayBuilder(); 147 154 Iterator<String> cit = sortedClasses.iterator(); … … 150 157 while( cit.hasNext() ){ 151 158 String classinfo = cit.next(); 152 String[] data = classinfo.split(" 159 String[] data = classinfo.split("\t"); 153 160 if (data.length != 3 ){ 154 161 System.out.println("data is wrong?"); … … 157 164 tmpclasses.add(classinfo); 158 165 }else{ 166 job.add("ep", ep); 159 167 job.add("uri", data[2]); 160 168 job.add("label", data[0]); … … 166 174 while( cit.hasNext() ){ 167 175 String classinfo = cit.next(); 168 String[] data = classinfo.split(" 176 String[] data = classinfo.split("\t"); 169 177 if (data.length != 3 ){ 170 178 System.out.println("data is wrong?"); 171 179 } 180 job.add("ep", ep); 172 181 job.add("uri", data[2]); 173 182 job.add("label", data[0]); … … 178 187 return ja; 179 188 } 189 190 private JsonArray getJsonArrayFromClasses(JsonBuilderFactory jbfactory, TreeSet<String> cl){ 191 JsonArrayBuilder jab = jbfactory.createArrayBuilder(); 192 JsonObjectBuilder job = jbfactory.createObjectBuilder(); 193 Iterator<String> cit = cl.iterator(); 194 195 while( cit.hasNext() ){ 196 String classinfo = cit.next(); 197 String[] data = classinfo.split("\t"); 198 if (data.length != 4 ){ 199 System.out.println("data is wrong?"); // KOKO 200 }else{ 201 job.add("ep", data[3]); 202 job.add("uri", data[1]); 203 job.add("label", data[0]); 204 job.add("number", data[2]); 205 jab.add(job); 206 } 207 } 208 JsonArray ja = jab.build(); 209 return ja; 210 } 180 211 } 212