- 更新日時:
- 2014/11/18 14:16:47 (10 年 前)
- パス:
- SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder
- ファイル:
-
- 5 変更
凡例:
- 変更なし
- 追加
- 削除
-
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/OWL/OWLClassGraph.java
r205 r206 10 10 */ 11 11 import java.util.*; 12 //import java.util.LinkedList;13 //import java.util.List;14 //import java.util.ListIterator;15 12 16 13 public class OWLClassGraph extends LabeledMultiDigraph{ … … 26 23 ClassLink classLink; 27 24 List<ClassLink> path; 25 Set<String> classURIs; // apearing class URIs in the path 28 26 //boolean converge; 29 27 … … 40 38 //this.converge = converge; 41 39 } 42 } 43 40 41 public LinkAndPath(ClassLink classLink, List<ClassLink> path, String originalClassURI, Set<String> classURIs){ 42 this.classLink = classLink; 43 this.path = path; 44 this.originalClassURI = originalClassURI; 45 this.classURIs = classURIs; 46 //this.converge = converge; 47 } 48 } 49 44 50 public OWLClassGraph(String startClass, String endClass){ 45 51 super(); … … 52 58 nsteps = 3; 53 59 limit = 1000; 54 prunecut = 100; 60 prunecut = 100; 61 th = 5; 62 } 63 64 public OWLClassGraph(String startClass, String endClass, int th){ 65 super(); 66 67 // start & end 68 this.startClass = startClass; 69 this.endClass = endClass; 70 // th of instances 71 this.th = th; 72 73 // parameters 74 nsteps = 3; 75 limit = 1000; 76 prunecut = 100; 55 77 } 56 78 57 79 public Path[] getPaths(RDFSchemaAnalyzer rdfsa, boolean countLink){ 58 80 List<List<ClassLink>> paths = null; 59 paths = searchPaths(rdfsa, countLink); 81 //paths = searchPaths(rdfsa, countLink); 82 paths = searchPathsbyVisitingNodes(rdfsa, countLink); 60 83 NavigableSet<Path> sortedpath = new TreeSet<Path>(); 61 84 ListIterator<List<ClassLink>> pit = paths.listIterator(); … … 114 137 crrlp.classLink.getDirection() != classLinks[j].getDirection() && 115 138 crrlp.originalClassURI.equals( classLinks[j].getLinkedClassURI()) ){ 116 //System.out.println("P1");117 continue;118 }119 if ( checkPruning(crrlp.classLink, classLinks[j]) ){120 //System.out.println("P2");121 139 continue; 122 140 } … … 133 151 } 134 152 135 //private 136 137 /* 153 private List<List<ClassLink>> searchPathsbyVisitingNodes(RDFSchemaAnalyzer rdfsa, boolean countLinks){ 154 List<List<ClassLink>> paths = new ArrayList<>(); 155 List<LinkAndPath> lp = new LinkedList<>(); 156 Set<String> urls = new HashSet<String>(); 157 urls.add(startClass); 158 lp.add(new LinkAndPath(new ClassLink("",startClass,null,Direction.both,0,0,0,0,0,false,false), 159 new LinkedList<ClassLink>(), startClass, urls)); 160 try{ 161 for ( int i = 0; i < nsteps; i++ ){ 162 ListIterator<LinkAndPath> lit = lp.listIterator(); 163 List<LinkAndPath> nextlp = new LinkedList<>(); 164 while ( lit.hasNext() ){ 165 LinkAndPath crrlp = lit.next(); 166 ClassLink[] classLinks = rdfsa.getNextClass(null, crrlp.classLink.getLinkedClassURI(), limit, countLinks); 167 // limit 168 for ( int j = 0 ; j < classLinks.length; j++ ){ 169 if (crrlp.classURIs.contains(classLinks[j].getLinkedClassURI()) ){ 170 continue; // visited 171 } 172 List<ClassLink> crrpath = new LinkedList<>(crrlp.path); 173 crrpath.add(classLinks[j]); 174 Set<String> crrurls = new HashSet<String>(crrlp.classURIs); 175 crrurls.add(classLinks[j].getLinkedClassURI()); 176 if ( classLinks[j].getLinkedClassURI() == null ){ continue; } 177 if ( classLinks[j].getNumOfLinks() <= th){ 178 continue; 179 } 180 if ( classLinks[j].getLinkedClassURI().equals(endClass) ){ 181 paths.add(new LinkedList<>(crrpath)); 182 continue; 183 } 184 //crrlp.classURIs.add() 185 nextlp.add(new LinkAndPath(classLinks[j], crrpath, crrlp.classLink.getLinkedClassURI(),crrurls)); 186 } 187 } 188 lp = nextlp; 189 } 190 }catch(Exception e){ 191 System.err.println(e); 192 } 193 return paths; 194 } 195 196 /* 138 197 private List<List<ClassLink>> searchPathsWithCut(OWLQueryBuilderImpl qb){ 139 198 List<List<ClassLink>> paths = new ArrayList<>(); … … 261 320 } 262 321 263 322 /* 323 public Path[] getPathsByWholeGraph(RDFSchemaAnalyzer rdfsa){ 324 setWholeGraph(rdfsa); 325 List<List<ClassLink>> paths = null; 326 //paths = searchPaths(rdfsa, countLink); 327 paths = searchPathsbyVisitingNodes(rdfsa, countLink); 328 NavigableSet<Path> sortedpath = new TreeSet<Path>(); 329 ListIterator<List<ClassLink>> pit = paths.listIterator(); 330 int j = 0; 331 while ( pit.hasNext() ){ 332 Path path = new Path(); 333 path.setStartClass(startClass); 334 List<ClassLink> crrpath = pit.next(); 335 path.setClassLinks(crrpath); 336 ListIterator<ClassLink> cit = crrpath.listIterator(); 337 int min = Integer.MAX_VALUE; 338 while ( cit.hasNext() ){ 339 ClassLink cl = cit.next(); 340 if ( cl.getNumOfLinks() < min ){ 341 min = cl.getNumOfLinks(); 342 } 343 } 344 path.setWidth(min); 345 sortedpath.add(path); 346 j++; 347 } 348 Path[] patharray = new Path[paths.size()]; 349 Iterator<Path> pait = sortedpath.descendingIterator(); 350 int i = 0; 351 while ( pait.hasNext() ){ 352 patharray[i] = pait.next(); 353 i++; 354 } 355 return patharray; 356 } 357 */ 264 358 } -
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 -
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/www/EPServlet.java
r205 r206 68 68 throws ServletException, IOException { 69 69 HttpSession session = request.getSession(); 70 // Initialize the session 70 71 session.removeAttribute("qpg"); 72 session.removeAttribute("graph"); 71 73 QueryPathGenerator qpg = new QueryPathGenerator(); 72 74 -
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/www/PLServlet.java
r205 r206 94 94 } 95 95 jsonstr += "]}"; 96 System.out.println("JSON:");97 System.out.println(jsonstr);96 //System.out.println("JSON:"); 97 //System.out.println(jsonstr); 98 98 out.print(jsonstr); 99 //List<Path>100 //session.setAttribute("pathlist", pathlist);101 99 } 102 100 -
SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/www/SPServlet.java
r204 r206 84 84 PrintWriter out = response.getWriter(); 85 85 String jpath = request.getParameter("jsonpath"); 86 System.out.println("JsonPath"); 87 System.out.println(jpath); 86 88 Path path = null; 87 89 try {