- 更新日時:
- 2014/08/19 20:56:13 (10 年 前)
- ファイル:
-
- 1 変更
凡例:
- 変更なし
- 追加
- 削除
-
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/www/SPServlet.java
r136 r142 9 9 import java.io.IOException; 10 10 import java.io.PrintWriter; 11 import java.util.ArrayList; 12 import java.util.Arrays; 11 13 import java.util.Iterator; 12 14 import java.util.List; … … 78 80 PrintWriter out = response.getWriter(); 79 81 String jpath = request.getParameter("jsonpath"); 80 Pathpath = null;82 List<String> path = null; 81 83 try { 82 84 path = convertJ2Path(jpath); … … 119 121 }// </editor-fold> 120 122 121 private PathconvertJ2Path(String jpath) throws JSONException{123 private List<String> convertJ2Path(String jpath) throws JSONException{ 122 124 123 JSONObject object = new JSONObject(jpath); 125 126 JSONArray classLinks=new JSONArray(jpath); 127 128 String string; 129 List <String> list = null; 130 for (int i=0;i<classLinks.length();i++) 131 { 132 string = classLinks.getJSONObject(i).toString(); 133 if (string.contains(",")) { 134 list =Arrays.asList(string.split(",")); 135 136 } else 137 throw new IllegalArgumentException("path error"); 138 139 } 140 141 return list; 142 143 /* JSONObject object = new JSONObject(jpath); 124 144 String startClass = object.getJSONObject("startClassURI").toString(); 125 145 int width = Integer.parseInt(object.getJSONObject("width").toString()); … … 146 166 list.add(classLink); 147 167 } 148 Path path = new Path(startClass, list, width);168 Path path = new Path(startClass, list, width); 149 169 return path; 170 */ 171 172 150 173 } 151 174 152 private String convertPath2SPARQL( Pathpath) throws Exception{175 private String convertPath2SPARQL(List<String> path) throws Exception{ 153 176 if( path == null ){ 154 177 throw new Exception("Path is null."); 155 178 } 156 String startClass = path.getStartClass(); 157 List<ClassLink> classLinks = path.getClassLinks(); 179 180 181 //List<String> classLinks = path.getClassLinks(); 158 182 159 183 StringBuffer queryStr = new StringBuffer(); … … 161 185 StringBuffer whereStr = new StringBuffer(); 162 186 // if(num==0){ 163 int num = classLinks.size();187 // int num = classLinks.size(); 164 188 // } 165 189 … … 176 200 int i = 0; 177 201 int k = 0; 178 for (ClassLink link :classLinks ) 202 203 String startClass = path.get(path.size()-1); 204 List<String> classLinks = null; 205 // ArrayList<String> array= (String[])path.toArray(); 206 207 // classLinks.add(path.get(i)); 208 209 int num =(path.size()-1)/2; 210 211 for(int j=path.size()-2;j>0;j=j-2) 179 212 { 180 properties = link.getPropertyURI(); 181 objectClasses = link.getLinkedClassURI(); 182 direction = link.getDirection(); 213 // properties = link.getPropertyURI(); 214 // objectClasses = link.getLinkedClassURI(); 215 // direction = link.getDirection(); 216 properties = path.get(j); 217 objectClasses = path.get(j-1); 218 direction = Direction.forward; 183 219 184 220 if (i==0)