チェンジセット 94 : BH13SPARQLBuilder
- 更新日時:
- 2014/07/03 14:59:43 (10 年 前)
- パス:
- BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL
- ファイル:
-
- 3 変更
凡例:
- 変更なし
- 追加
- 削除
-
BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/AcquiredStructureAnalyzer.java
r93 r94 14 14 import com.hp.hpl.jena.rdf.model.Literal; 15 15 import com.hp.hpl.jena.rdf.model.Model; 16 import com.hp.hpl.jena.rdf.model.Property; 16 17 import com.hp.hpl.jena.rdf.model.Resource; 17 18 … … 33 34 34 35 public static void main(String[] args) throws Exception{ 35 JenaModelGenerator jmGene = new JenaModelGenerator("c:\\temp\\ allie.ttl");36 JenaModelGenerator jmGene = new JenaModelGenerator("c:\\temp\\dberdf.ttl"); 36 37 AcquiredStructureAnalyzer impl 37 38 = new AcquiredStructureAnalyzer(jmGene.getEndpointURI(), jmGene.getGraphURIs(), jmGene.getModel()); 39 System.out.println("--------------------------"); 38 40 SClass[] scs = impl.getOWLClasses(null, null, null, true); 41 System.out.println("list classes:---------------"); 39 42 for(SClass sc: scs){ 40 43 System.out.println(sc.toString()); 41 44 } 42 ClassLink[] cls = impl.getNextClass(null,"http://purl.org/goodrelations/v1#Offering",100,true ); 45 System.out.println("--------------------------"); 46 47 ClassLink[] cls = impl.getNextClass(null,"http://purl.org/allie/ontology/201108#EachPair",100,true ); 43 48 for(ClassLink cl: cls){ 44 49 System.out.println(cl.toString()); 45 50 } 51 System.out.println("--------------------------"); 46 52 47 53 } … … 75 81 queryStr.append("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"); 76 82 queryStr.append("SELECT DISTINCT ?c ?pLabel ?numOfInstances\n"); 77 if (targetGraphURIs != null) {78 for (String graphURI : targetGraphURIs) {79 queryStr.append("FROM <");80 queryStr.append(graphURI);81 queryStr.append(">\n");82 }83 }83 // if (targetGraphURIs != null) { 84 // for (String graphURI : targetGraphURIs) { 85 // queryStr.append("FROM <"); 86 // queryStr.append(graphURI); 87 // queryStr.append(">\n"); 88 // } 89 // } 84 90 queryStr.append("WHERE{\n"); 85 86 //87 91 queryStr.append(" ?c rdf:type rdfs:Class. \n"); 88 92 queryStr.append(" ?c <http://sparqlbuilder.org/numberOfInstances> ?numOfInstances. \n"); … … 96 100 queryStr.append("\') && \n ("); 97 101 98 // (LANG(?keywords) = 'en') &&99 100 102 for (int i = 0; i < keywords.length; i++) { 101 103 if (i > 0) … … 119 121 ResultSet results = null; 120 122 try { 121 long start = System.currentTimeMillis();123 // long start = System.currentTimeMillis(); 122 124 qexec = QueryExecutionFactory.create(query, model); 123 125 results = qexec.execSelect(); 124 long end = System.currentTimeMillis();125 System.out.println("EXEC TIME: " + (end - start));126 // long end = System.currentTimeMillis(); 127 // System.out.println("EXEC TIME: " + (end - start)); 126 128 } catch (Exception ex) { 127 129 ex.printStackTrace(); … … 133 135 QuerySolution sol = results.next(); 134 136 Resource res = sol.getResource("c"); 135 if (res != null ) {137 if (res != null && res.getURI() != null) { 136 138 String uri = res.getURI(); 137 139 int numOfInstances = 0; … … 156 158 qexec.close(); 157 159 return classMap.values().toArray(new SClass[0]); 158 159 160 } 160 161 … … 174 175 175 176 // SELECT 176 queryStr.append("SELECT DISTINCT ? c ?d ?p ?numInsStart ?numInsEnd ?numTriples\n");177 178 if (targetGraphURIs != null) {179 for (String graphURI : targetGraphURIs) {180 queryStr.append("FROM <");181 queryStr.append(graphURI);182 queryStr.append(">\n");183 }184 }177 queryStr.append("SELECT DISTINCT ?indPropCat ?c ?d ?p ?numLnkInsStart ?numLnkInsEnd ?numInsDom ?numInsRan ?numTriples ?isStartClsLim ?isEndClsLim\n"); 178 179 // if (targetGraphURIs != null) { 180 // for (String graphURI : targetGraphURIs) { 181 // queryStr.append("FROM <"); 182 // queryStr.append(graphURI); 183 // queryStr.append(">\n"); 184 // } 185 // } 185 186 186 187 queryStr.append("WHERE{\n"); 187 188 queryStr.append(" ?cr rdf:type <http://sparqlbuilder.org/ClassRelation>. \n"); 188 queryStr.append(" <" + originClass + "> <http://sparqlbuilder.org/numberOfInstances> ?numInsStart. \n");189 // queryStr.append(" <" + originClass + "> <http://sparqlbuilder.org/numberOfInstances> ?numInsStart. \n"); 189 190 queryStr.append(" {"); 190 191 queryStr.append(" ?cr <http://sparqlbuilder.org/startClass> <" + originClass + ">. \n"); … … 192 193 queryStr.append(" ?cr <http://sparqlbuilder.org/property> ?p. \n"); 193 194 queryStr.append(" ?cr <http://sparqlbuilder.org/numberOfTriples> ?numTriples. \n"); 194 queryStr.append(" ?c <http://sparqlbuilder.org/numberOfInstances> ?numInsEnd. \n"); 195 queryStr.append(" ?cr <http://sparqlbuilder.org/numberOfInstancesOfStartClass> ?numLnkInsStart. \n"); 196 queryStr.append(" ?cr <http://sparqlbuilder.org/numberOfInstancesOfEndClass> ?numLnkInsEnd. \n"); 197 queryStr.append(" ?cr <http://sparqlbuilder.org/startClassLimitedQ> ?isStartClsLim. \n"); 198 queryStr.append(" ?cr <http://sparqlbuilder.org/endClassLimitedQ> ?isEndClsLim. \n"); 195 199 queryStr.append("}\n"); 196 200 queryStr.append(" UNION\n"); … … 200 204 queryStr.append(" ?cr <http://sparqlbuilder.org/property> ?p. \n"); 201 205 queryStr.append(" ?cr <http://sparqlbuilder.org/numberOfTriples> ?numTriples.\n"); 202 queryStr.append(" ?d <http://sparqlbuilder.org/numberOfInstances> ?numInsEnd. \n"); 206 queryStr.append(" ?cr <http://sparqlbuilder.org/numberOfInstancesOfStartClass> ?numLnkInsEnd. \n"); 207 queryStr.append(" ?cr <http://sparqlbuilder.org/numberOfInstancesOfEndClass> ?numLnkInsStart. \n"); 208 queryStr.append(" ?cr <http://sparqlbuilder.org/startClassLimitedQ> ?isEndClsLim. \n"); 209 queryStr.append(" ?cr <http://sparqlbuilder.org/endClassLimitedQ> ?isStartClsLim. \n"); 203 210 queryStr.append("}\n"); 211 212 queryStr.append(" ?pp rdf:type <http://sparqlbuilder.org/PropertyProfile>. \n"); 213 queryStr.append(" ?pp <http://sparqlbuilder.org/property> ?p. \n"); 214 queryStr.append(" ?pp <http://sparqlbuilder.org/individualPropertyCategory> ?indPropCat. \n"); 215 queryStr.append(" ?pp <http://sparqlbuilder.org/numberOfInstancesOfDomainClass> ?numInsDom. \n"); 216 queryStr.append(" ?pp <http://sparqlbuilder.org/numberOfInstancesOfRangeClass> ?numInsRan \n"); 217 218 204 219 queryStr.append("}\n"); 205 220 … … 212 227 213 228 // System.out.println("getNextClasses SPARQL Query: "); 214 //System.out.println(queryStr.toString());229 System.out.println(queryStr.toString()); 215 230 216 231 Query query = QueryFactory.create(queryStr.toString()); … … 234 249 String clsURI = null; 235 250 if (pro != null) { 251 int indPropCat = 4; 252 Literal indPropCatLit = sol.getLiteral("indPropCat"); 253 if( indPropCatLit != null ){ 254 indPropCat = indPropCatLit.getInt(); 255 } 256 if( indPropCat < 4 ) { 236 257 String proURI = pro.getURI(); 237 258 Resource ccls = sol.getResource("c"); … … 248 269 } 249 270 } 271 272 250 273 int numTriples = 0; 251 274 Literal numTriplesLit = sol.getLiteral("numTriples"); … … 253 276 numTriples = numTriplesLit.getInt(); 254 277 } 255 int numInsStart = 0; 256 Literal numInsStartLit = sol.getLiteral("numInsStart"); 278 279 int numLnkInsStart = 0; 280 Literal numInsStartLit = sol.getLiteral("numLnkInsStart"); 257 281 if( numInsStartLit != null ){ 258 num InsStart = numInsStartLit.getInt();259 } 260 int num InsEnd = 0;261 Literal numInsEndLit = sol.getLiteral("num InsEnd");282 numLnkInsStart = numInsStartLit.getInt(); 283 } 284 int numLnkInsEnd = 0; 285 Literal numInsEndLit = sol.getLiteral("numLnkInsEnd"); 262 286 if( numInsEndLit != null ){ 263 numInsEnd = numInsEndLit.getInt(); 264 } 287 numLnkInsEnd = numInsEndLit.getInt(); 288 } 289 290 int numInsDom = 0; 291 Literal numInsDomLit = sol.getLiteral("numInsDom"); 292 if( numInsDomLit != null ){ 293 numInsDom = numInsDomLit.getInt(); 294 } 295 int numInsRan = 0; 296 Literal numInsRanLit = sol.getLiteral("numInsRan"); 297 if( numInsRanLit != null ){ 298 numInsRan = numInsRanLit.getInt(); 299 } 300 301 boolean isStartClsLim = false; 302 Literal isStartClsLimLit = sol.getLiteral("isStartClsLim"); 303 if( isStartClsLimLit != null ){ 304 isStartClsLim = isStartClsLimLit.getBoolean(); 305 } 306 boolean isEndClsLim = false; 307 Literal isEndClsLimLit = sol.getLiteral("isEndClsLim"); 308 if( isEndClsLimLit != null ){ 309 isEndClsLim = isEndClsLimLit.getBoolean(); 310 } 311 265 312 ClassLink cl = new ClassLink(proURI, clsURI, direction, 266 numTriples, 0, 0, numInsEnd, numInsStart);313 numTriples, numInsDom, numInsRan, numLnkInsStart, numLnkInsEnd, isStartClsLim, isEndClsLim); 267 314 solCLs.add(cl); 268 } 269 } 270 qexec.close(); 315 316 } 317 } 318 } 319 qexec.close(); 271 320 return solCLs.toArray(new ClassLink[0]); 272 321 } … … 347 396 return lMap.values().toArray(new LabelMap[0]); 348 397 } 398 349 399 /* 350 public ClassLink[] countLinks(String[] graphURIs, String startClassURI, 351 ClassLink[] classLinks) throws Exception; 352 400 public ClassLink[] countLinks(String[] graphURIs, String startClassURI, ClassLink[] classLinks) throws Exception; 353 401 public SClass[] countInstances(String[] graphURIs, SClass[] classes) throws Exception; 354 402 355 356 403 */ 404 357 405 } -
BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/ClassLink.java
r76 r94 20 20 private int numOfOriginClassInstances = 0; 21 21 private int numOfLinkedClassInstances = 0; 22 private boolean domainClassLimitedQ = false; 23 private boolean rangeClassLimitedQ = false; 24 22 25 23 26 /** … … 33 36 public ClassLink(String propertyURI, String linkedClassURI, Direction direction, 34 37 int numLinks, int numOfOriginInstances, int numOfLinkedInstances, 35 int numOfOriginClassInstances, int numofLinkedClassInstances){ 38 int numOfOriginClassInstances, int numofLinkedClassInstances, 39 boolean domainClassLimitedQ, boolean rangeClassLimitedQ){ 36 40 this.propertyURI = propertyURI; 37 41 this.linkedClassURI = linkedClassURI; … … 42 46 this.numOfOriginClassInstances = numOfOriginClassInstances; 43 47 this.numOfLinkedClassInstances = numofLinkedClassInstances; 48 this.domainClassLimitedQ = domainClassLimitedQ; 49 this.rangeClassLimitedQ = rangeClassLimitedQ; 44 50 } 45 51 … … 122 128 sb.append(linkedClassURI); 123 129 sb.append(" ["); 130 sb.append(numOfOriginClassInstances); 131 sb.append("/"); 124 132 sb.append(numOfOriginInstances); 125 sb.append("/");126 sb.append(numOfOriginClassInstances);127 133 sb.append("]縲---"); 128 134 … … 133 139 134 140 sb.append(" ["); 141 sb.append(numOfLinkedClassInstances); 142 sb.append("/"); 135 143 sb.append(numOfLinkedInstances); 136 sb.append("/");137 sb.append(numOfLinkedClassInstances);138 144 sb.append("]"); 139 145 return sb.toString(); … … 168 174 169 175 176 177 178 public final boolean isDomainClassLimitedQ() { 179 return domainClassLimitedQ; 180 } 181 182 183 public final boolean isRangeClassLimitedQ() { 184 return rangeClassLimitedQ; 185 } 186 187 170 188 public final int getNumOfOriginInstances() { 171 189 return numOfOriginInstances; -
BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/Label.java
r19 r94 56 56 } 57 57 sb.append("\""); 58 if (language != null ) {58 if (language != null && !language.equals("")) { 59 59 sb.append("@"); 60 60 sb.append(language);