チェンジセット 269 : SPARQLBuilderWWW2016/src/java/org/biohackathon/SPARQLBuilder/OWL/AcquiredStructureAnalyzer.java
- 更新日時:
- 2016/03/14 20:01:59 (9 年 前)
- ファイル:
-
- 1 変更
凡例:
- 変更なし
- 追加
- 削除
-
SPARQLBuilderWWW2016/src/java/org/biohackathon/SPARQLBuilder/OWL/AcquiredStructureAnalyzer.java
r267 r269 3 3 import java.util.*; 4 4 5 import jp.riken.accc.db.rdf.crawler.dataStructure.sparql.JenaModelGenerator; 6 import jp.riken.accc.db.rdf.crawler.dataStructure.sparql.URICollection; 5 import jp.riken.accc.db.sparqlBuilderMetadata.crawler.dataStructure.sparql.JenaModelGenerator; 6 import jp.riken.accc.db.sparqlBuilderMetadata.crawler.dataStructure.sparql.URICollection; 7 import jp.riken.accc.db.sparqlBuilderMetadata.crawler.dataStructure.sparql.crawler.CrawledMetadata; 8 import jp.riken.accc.db.sparqlBuilderMetadata.crawler.dataStructure.sparql.crawler.Dataset; 7 9 8 10 import com.hp.hpl.jena.query.Query; … … 20 22 public class AcquiredStructureAnalyzer implements RDFSchemaAnalyzer { 21 23 22 private Model model = null; 23 private String endpointURI = null; 24 private String[] graphURIs = null; 24 private CrawledMetadata crawledMetadata = null; 25 25 26 26 public String getEndpointURI(){ 27 return endpointURI;27 return crawledMetadata.getEndpointURI(); 28 28 } 29 29 30 30 public String[] getGraphURIs(){ 31 return graphURIs;31 return crawledMetadata.getGraphURIs(); 32 32 } 33 33 … … 57 57 */ 58 58 59 public AcquiredStructureAnalyzer(String endpointURI, String[] graphURIs, Model model){ 60 this.model = model; 61 this.endpointURI = endpointURI; 62 this.graphURIs = graphURIs; 63 } 64 65 private String[] filterGraphURIs(String[] orgGraphURIs){ 59 public AcquiredStructureAnalyzer(CrawledMetadata crawledMetadata){ 60 this.crawledMetadata = crawledMetadata; 61 } 62 63 private String filterGraphURIs(String orgGraphURIs){ 66 64 // TODO 67 return graphURIs; 68 } 69 70 71 public SClass[] listClasses(String[] graphURIs, boolean countInstances) throws Exception{ 72 return getOWLClasses(graphURIs, null, null, countInstances); 73 } 74 75 76 77 78 public SClass[] getOWLClasses(String[] graphURIs, String[] keywords, String language, boolean countInstances) throws Exception{ 79 return getOWLClassList(graphURIs, keywords, language, countInstances).toArray(new SClass[0]); 80 } 81 82 public List<SClass> getOWLClassList(String[] graphURIs, String[] keywords, String language, boolean countInstances) throws Exception{ 83 String[] targetGraphURIs = filterGraphURIs(graphURIs); 84 65 return orgGraphURIs; 66 } 67 68 69 public SClass[] listClasses(String graphURI, boolean countInstances) throws Exception{ 70 return getOWLClasses(graphURI, null, null, countInstances); 71 } 72 73 74 75 76 public SClass[] getOWLClasses(String graphURI, String[] keywords, String language, boolean countInstances) throws Exception{ 77 return getOWLClassList(graphURI, keywords, language, countInstances).toArray(new SClass[0]); 78 } 79 80 public List<SClass> getOWLClassList(String graphURI, String[] keywords, String language, boolean countInstances) throws Exception{ 81 String targetGraphURI = filterGraphURIs(graphURI); 82 83 Dataset dataset = crawledMetadata.getDataset(targetGraphURI); 84 85 85 86 StringBuffer queryStr = new StringBuffer(); 86 87 queryStr.append("PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"); … … 88 89 queryStr.append("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"); 89 90 queryStr.append("SELECT DISTINCT ?c ?pLabel ?entities\n"); 90 // if (targetGraphURIs != null) { 91 // for (String graphURI : targetGraphURIs) { 92 // queryStr.append("FROM <"); 93 // queryStr.append(graphURI); 94 // queryStr.append(">\n"); 95 // } 96 // } 91 if (targetGraphURI != null) { 92 queryStr.append("FROM <"); 93 queryStr.append(targetGraphURI); 94 queryStr.append(">\n"); 95 } 97 96 queryStr.append("WHERE{\n"); 98 97 queryStr.append(" ?cp <").append(URICollection.PROPERTY_VOID_CLASS).append("> ?c. \n"); … … 133 132 try { 134 133 // long start = System.currentTimeMillis(); 135 qexec = QueryExecutionFactory.create(query, model);134 qexec = QueryExecutionFactory.create(query, dataset.getModel()); 136 135 results = qexec.execSelect(); 137 136 // long end = System.currentTimeMillis(); … … 177 176 178 177 179 public ClassLink[] getNextClass(String[] graphURIs, String originClass, int limit, boolean countLinks) throws Exception{ 180 String[] targetGraphURIs = filterGraphURIs(graphURIs); 181 178 public ClassLink[] getNextClass(String graphURI, String originClass, int limit, boolean countLinks) throws Exception{ 179 String targetGraphURI = filterGraphURIs(graphURI); 180 Dataset dataset = crawledMetadata.getDataset(targetGraphURI); 181 182 182 183 StringBuffer queryStr = new StringBuffer(); 183 184 queryStr.append("PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"); … … 188 189 queryStr.append("SELECT DISTINCT ?indPropCat ?c ?dat ?d ?p ?numLnkInsStart ?numLnkInsEnd ?numInsDom ?numInsRan ?numTriples\n"); 189 190 190 // if (targetGraphURIs != null) { 191 // for (String graphURI : targetGraphURIs) { 192 // queryStr.append("FROM <"); 193 // queryStr.append(graphURI); 194 // queryStr.append(">\n"); 195 // } 196 // } 191 if (targetGraphURI != null) { 192 queryStr.append("FROM <"); 193 queryStr.append(targetGraphURI); 194 queryStr.append(">\n"); 195 } 197 196 198 197 queryStr.append("WHERE{\n"); … … 254 253 try { 255 254 long start = System.currentTimeMillis(); 256 qexec = QueryExecutionFactory.create(query, model);255 qexec = QueryExecutionFactory.create(query, dataset.getModel()); 257 256 results = qexec.execSelect(); 258 257 long end = System.currentTimeMillis(); … … 363 362 */ 364 363 365 public LabelMap[] getLabels(String [] graphURIs, String[] resourceURIs,364 public LabelMap[] getLabels(String graphURI, String[] resourceURIs, 366 365 String language) throws Exception { 367 if (resourceURIs == null || resourceURIs.length == 0) { 368 return new LabelMap[0]; 369 } 366 // if (resourceURI == null || resourceURIs.length == 0) { 367 // return new LabelMap[0]; 368 // } 369 370 String targetGraphURI = filterGraphURIs(graphURI); 371 Dataset dataset = crawledMetadata.getDataset(targetGraphURI); 372 373 370 374 StringBuffer queryStr = new StringBuffer(); 371 375 queryStr.append("PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"); … … 373 377 queryStr.append("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"); 374 378 queryStr.append("SELECT DISTINCT ?res ?label \n"); 375 if (graphURIs != null) { 376 for (String graphURI : graphURIs) { 379 if (targetGraphURI != null) { 377 380 queryStr.append("FROM <"); 378 queryStr.append( graphURI);381 queryStr.append(targetGraphURI); 379 382 queryStr.append(">\n"); 380 }381 383 } 382 384 queryStr.append("WHERE{\n"); … … 399 401 400 402 Query query = QueryFactory.create(queryStr.toString()); 401 QueryExecution qexec = QueryExecutionFactory.create(query, model);403 QueryExecution qexec = QueryExecutionFactory.create(query, dataset.getModel()); 402 404 403 405 ResultSet results = qexec.execSelect();