- 更新日時:
- 2014/01/31 11:17:26 (11 年 前)
- ファイル:
-
- 1 変更
凡例:
- 変更なし
- 追加
- 削除
-
BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/OWLQueryBuilderImpl.java
r32 r36 52 52 */ 53 53 public static void main(String[] args) throws Exception { 54 String sparqlEndpoint = "http://dbpedia.org/sparql";55 //String sparqlEndpoint = "http://lsd.dbcls.jp/sparql";56 String keyword = "artiste";57 // String keyword = "Agent";54 // String sparqlEndpoint = "http://dbpedia.org/sparql"; 55 String sparqlEndpoint = "http://lsd.dbcls.jp/sparql"; 56 // String keyword = "artiste"; 57 String keyword = "EnglishCode"; 58 58 String[] graphURIs = new String[0]; 59 60 keyword = null; 59 61 60 62 OWLQueryBuilder builder = new OWLQueryBuilderImpl(sparqlEndpoint); … … 67 69 System.out.println(cls); 68 70 } 69 70 71 /* 72 System.out.println("CLS"); 73 74 ClassLink[] cls = builder.getNextClass(null, clz[1].getClassURI(), 100, 71 72 System.out.println("CLS"); 73 74 ClassLink[] cls = builder.getNextClass(null, clz[0].getClassURI(), 100, 75 75 false); 76 76 if (cls != null) { … … 78 78 System.out.println(cl.toString()); 79 79 } 80 cls = builder.countLinks(null, clz[ 1].getClassURI(), cls);80 cls = builder.countLinks(null, clz[0].getClassURI(), cls); 81 81 for (ClassLink cl : cls) { 82 82 System.out.println(cl.toString()); 83 83 } 84 84 } 85 */ 85 86 System.out.println("CLS-INS"); 87 cls = builder.getNextClassViaInstanceLink(null, clz[0].getClassURI(), 88 100); 89 if (cls != null) { 90 for (ClassLink cl : cls) { 91 System.out.println(cl.toString()); 92 } 93 } 94 95 System.out.println("Instances"); 96 Instance[] ins = builder.getInstances(null, "\"A.C. Reed\"@en"); 97 if (ins != null) { 98 for (Instance in : ins) { 99 System.out.println(in.toString()); 100 } 101 } 102 86 103 /* 87 * System.out.println("CLS-INS"); cls =88 * builder.getNextClassViaInstanceLink(null, clz[0].getClassURI(), 100);89 * if( cls != null ){ for( ClassLink cl: cls){90 * System.out.println(cl.toString()); } }91 *92 * System.out.println("Instances"); Instance[] ins =93 * builder.getInstances(null, "\"A.C. Reed\"@en"); if( ins != null ){94 * for( Instance in: ins){ System.out.println(in.toString()); } }95 *96 *97 104 * System.out.println("INS-INS"); ins = builder.getInstances(null, 98 105 * "\"A.C. Reed\"@en"); InstanceLink[] iLinks = … … 100 107 * ins[0].getInstanceURI(), 100); 101 108 * 102 * 103 * 104 * if( iLinks != null ){ for( InstanceLink in: iLinks){ 109 * if (iLinks != null) { for (InstanceLink in : iLinks) { 105 110 * System.out.println(in.toString()); } } 106 111 */ … … 142 147 143 148 queryStr.append(" {?c rdf:type rdfs:Class} UNION {?c rdf:type owl:Class}\n"); 144 145 queryStr.append(" ?c rdfs:label ?label.\n"); 146 queryStr.append(" ?c rdfs:label ?pLabel.\n"); 149 // queryStr.append(" ?i rdf:type ?c.\n"); 150 151 152 153 if (countInstances) { 154 queryStr.append(" ?c rdfs:label ?label.\n"); 155 } 156 queryStr.append(" ?c rdfs:label ?pLabel.\n"); 147 157 if (countInstances) { 148 158 queryStr.append(" ?i rdf:type ?c.\n"); … … 156 166 queryStr.append(keyword); 157 167 queryStr.append("\" , \"i\" )\n"); 158 queryStr.append(" ) ");168 queryStr.append(" )\n"); 159 169 } 160 170 if (countInstances) { 161 queryStr.append(" \n} GROUP BY ?c ?pLabel");171 queryStr.append("} GROUP BY ?c ?pLabel"); 162 172 } else { 163 queryStr.append(" \n}");173 queryStr.append("}"); 164 174 } 165 175 System.out.println(queryStr.toString()); … … 177 187 String uri = res.getURI(); 178 188 int numOfInstances = 0; 179 if ( countInstances ){189 if (countInstances) { 180 190 numOfInstances = sol.getLiteral("numOfInstances").getInt(); 181 191 } … … 493 503 } 494 504 495 public Path[] getPaths(String startClass, String endClass, int mode, boolean countLinks) throws Exception { 505 public Path[] getPaths(String startClass, String endClass, int mode, 506 boolean countLinks) throws Exception { 496 507 OWLClassGraph graph = new OWLClassGraph(startClass, endClass); 497 508 return graph.getPaths(this, mode, countLinks); … … 748 759 } 749 760 750 public SClass[] countInstances(String[] graphURIs, SClass[] classes) throws Exception{ 751 if( classes == null || classes.length == 0 ){ 761 public SClass[] countInstances(String[] graphURIs, SClass[] classes) 762 throws Exception { 763 if (classes == null || classes.length == 0) { 752 764 return new SClass[0]; 753 765 } 754 766 HashMap<String, SClass> classMap = new HashMap<String, SClass>(); 755 for (SClass sc: classes){767 for (SClass sc : classes) { 756 768 classMap.put(sc.getClassURI(), sc); 757 769 } … … 803 815 } 804 816 qexec.close(); 805 817 806 818 return classes; 807 819 }