チェンジセット 10 : BH13SPARQLBuilder/src/org
- 更新日時:
- 2014/01/30 11:47:45 (11 年 前)
- パス:
- BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL
- ファイル:
-
- 1 追加
- 3 変更
凡例:
- 変更なし
- 追加
- 削除
-
BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/Label.java
r2 r10 32 32 } 33 33 34 34 public String toString(){ 35 StringBuffer sb = new StringBuffer(); 36 sb.append("\""); 37 if( label != null ){ 38 sb.append(label); 39 } 40 sb.append("\""); 41 if( language != null ){ 42 sb.append("@"); 43 sb.append(language); 44 } 45 return sb.toString(); 46 } 35 47 36 48 } -
BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/OWLQueryBuilder.java
r2 r10 24 24 * @since 28.01.2014 25 25 */ 26 public S tring[] getOWLClasses(String[] graphURIs, String keyword) throws Exception;26 public SClass[] getOWLClasses(String[] graphURIs, String keyword) throws Exception; 27 27 28 28 /** … … 37 37 * @param graphURIs縲讀懃エ「蟇セ雎。縺ョgraph縺ョURI驟榊� (null繧�聞縺�縺ョ驟榊�繧ょ庄) 38 38 * @param keyword ��ull繧�ゥコ譁�ュ励�荳榊庄�� 39 * @return 繧ッ繝ゥ繧ケ URI縺ョ驟榊�39 * @return 繧ッ繝ゥ繧ケ縺ョ驟榊� 40 40 * @throws Exception 41 41 * @since 28.01.2014 -
BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/OWLQueryBuilderImpl.java
r5 r10 25 25 import com.hp.hpl.jena.query.QuerySolution; 26 26 import com.hp.hpl.jena.query.ResultSet; 27 import com.hp.hpl.jena.rdf.model.Literal; 27 28 import com.hp.hpl.jena.rdf.model.Resource; 28 29 … … 65 66 66 67 OWLQueryBuilder builder = new OWLQueryBuilderImpl(sparqlEndpoint); 67 S tring[] clsURIs= builder.getOWLClasses(graphURIs, keyword);68 for(S tring cls: clsURIs){68 SClass[] clz = builder.getOWLClasses(graphURIs, keyword); 69 for(SClass cls: clz){ 69 70 System.out.println(cls); 70 71 } 71 72 72 73 System.out.println("CLS"); 73 ClassLink[] cls = builder.getNextClass(null, cl sURIs[0], 0);74 ClassLink[] cls = builder.getNextClass(null, clz[0].getClassURI(), 0); 74 75 if( cls != null ){ 75 76 for( ClassLink cl: cls){ … … 79 80 80 81 System.out.println("CLS-INS"); 81 cls = builder.getNextClassViaInstanceLink(null, cl sURIs[0], 100);82 cls = builder.getNextClassViaInstanceLink(null, clz[0].getClassURI(), 100); 82 83 if( cls != null ){ 83 84 for( ClassLink cl: cls){ … … 124 125 * @since 28.01.2014 125 126 */ 126 public S tring[] getOWLClasses(String[] graphURIs, String keyword)127 public SClass[] getOWLClasses(String[] graphURIs, String keyword) 127 128 throws Exception { 128 129 StringBuffer queryStr = new StringBuffer(); … … 130 131 queryStr.append("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"); 131 132 queryStr.append("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"); 132 queryStr.append("SELECT DISTINCT ?c \n");133 queryStr.append("SELECT DISTINCT ?c ?pLabel (COUNT(?i) AS ?numOfInstances)\n"); 133 134 if (graphURIs != null) { 134 135 for (String graphURI : graphURIs) { … … 143 144 144 145 queryStr.append(" ?c rdfs:label ?label.\n"); 146 queryStr.append(" ?c rdfs:label ?pLabel.\n"); 147 queryStr.append(" ?i rdf:type ?c.\n"); 145 148 146 149 // queryStr.append(" ?c rdfs:label "); … … 153 156 queryStr.append("\" , \"i\" )\n"); 154 157 queryStr.append(" )"); 155 queryStr.append("\n} ");158 queryStr.append("\n} GROUP BY ?c ?pLabel"); 156 159 157 160 System.out.println(queryStr.toString()); … … 162 165 163 166 ResultSet results = qexec.execSelect(); 164 ArrayList<String> solStrings = new ArrayList<String>();167 HashMap<String,SClass> classMap = new HashMap<String,SClass>(); 165 168 for (; results.hasNext();) { 166 169 QuerySolution sol = results.next(); 167 170 Resource res = sol.getResource("c"); 168 171 String uri = res.getURI(); 169 solStrings.add(uri); 172 int numOfInstances = sol.getLiteral("numOfInstances").getInt(); 173 //System.out.println(numOfInstances); 174 Literal labelLiteral = sol.getLiteral("pLabel"); 175 SClass sClass = null; 176 if( classMap.containsKey(uri)){ 177 sClass = classMap.get(uri); 178 } 179 else{ 180 sClass = new SClass(uri, null, numOfInstances); 181 classMap.put(uri, sClass); 182 } 183 if( labelLiteral != null ){ 184 String label = labelLiteral.getString(); 185 String lang = labelLiteral.getLanguage(); 186 sClass.addLabel(new Label(label, lang)); 187 } 170 188 } 171 189 qexec.close(); 172 return solStrings.toArray(new String[0]);190 return classMap.values().toArray(new SClass[0]); 173 191 } 174 192