- 更新日時:
- 2014/11/18 14:16:47 (10 年 前)
- ファイル:
-
- 1 変更
凡例:
- 変更なし
- 追加
- 削除
-
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/www/CLServlet.java
r204 r206 10 10 import java.io.PrintWriter; 11 11 import java.math.BigDecimal; 12 //import java.math.BigDecimal;12 import java.util.*; 13 13 import javax.json.*; 14 14 import javax.servlet.ServletException; … … 80 80 qpg = new QueryPathGenerator(); 81 81 } 82 SortedSet<String> sortedClasses = new TreeSet<String>(); // display + url 82 83 qpg.setSPARQLendpoint(ep); 83 84 SClass[] classes = qpg.getClasses(null); 84 JsonBuilderFactory jbfactory = Json.createBuilderFactory(null);85 JsonArrayBuilder jab = jbfactory.createArrayBuilder();86 85 for (int i = 0 ; i < classes.length; i++ ){ 87 JsonObjectBuilder job = jbfactory.createObjectBuilder();88 86 String uri = classes[i].getClassURI(); 89 job.add("uri", uri);90 87 Label[] labels = classes[i].getLabels(); 91 88 String label = null; … … 103 100 label = tmplabel2[tmplabel2.length-1]; 104 101 } 105 106 StringBuilder displaybuilder = new StringBuilder(label); 107 displaybuilder.append(" ("); 108 displaybuilder.append(classes[i].getNumOfInstances()); 109 displaybuilder.append(")"); 110 job.add("display", displaybuilder.toString()); 102 StringBuilder classbuilder = new StringBuilder(label); 103 classbuilder.append(" ("); 104 classbuilder.append(classes[i].getNumOfInstances()); 105 classbuilder.append(") "); 106 classbuilder.append(uri); 107 sortedClasses.add(classbuilder.toString()); 108 } 109 JsonBuilderFactory jbfactory = Json.createBuilderFactory(null); 110 JsonArrayBuilder jab = jbfactory.createArrayBuilder(); 111 Iterator<String> cit = sortedClasses.iterator(); 112 while( cit.hasNext() ){ 113 JsonObjectBuilder job = jbfactory.createObjectBuilder(); 114 String classinfo = cit.next(); 115 String[] data = classinfo.split(" "); 116 if (data.length != 2 ){ 117 System.out.println("data is wrong?"); 118 } 119 job.add("uri", data[1]); 120 job.add("display", data[0]); 111 121 jab.add(job); 112 122 } 113 123 JsonArray ja = jab.build(); 114 124 out.print(ja); 125 // 126 115 127 } 116 128