チェンジセット 36 : BH13SPARQLBuilder/src

差分発生行の前後
無視リスト:
更新日時:
2014/01/31 11:17:26 (11 年 前)
更新者:
nori
ログメッセージ:

SPARQLクエリの整形

パス:
BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL
ファイル:
2 変更

凡例:

変更なし
追加
削除
  • BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/OWLQueryBuilder.java

    r32 r36  
    8282 
    8383        public Path[] getPaths(String startClass, String endClass, int mode, boolean countLinks) throws Exception; 
     84 
    8485        public String createSPARQL(Path path) throws Exception; 
    8586 
     
    103104 InstanceLink[] getNextInstancesViaInstanceLink(String[] graphURIs, String originInstance, 
    104105                        int limit) throws Exception; 
    105         public LabelMap[] getLabels(String[] graphURIs, String[] resourceURIs, String language) throws Exception; 
    106         public ClassLink[] countLinks(String[] graphURIs, String startClassURI, 
     106 
     107 public LabelMap[] getLabels(String[] graphURIs, String[] resourceURIs, String language) throws Exception; 
     108 
     109 public ClassLink[] countLinks(String[] graphURIs, String startClassURI, 
    107110                        ClassLink[] classLinks) throws Exception; 
    108111 
  • BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/OWLQueryBuilderImpl.java

    r32 r36  
    5252         */ 
    5353        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"; 
    5858                String[] graphURIs = new String[0]; 
     59 
     60                keyword = null; 
    5961 
    6062                OWLQueryBuilder builder = new OWLQueryBuilderImpl(sparqlEndpoint); 
     
    6769                        System.out.println(cls); 
    6870                } 
    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, 
    7575                                false); 
    7676                if (cls != null) { 
     
    7878                                System.out.println(cl.toString()); 
    7979                        } 
    80                         cls = builder.countLinks(null, clz[1].getClassURI(), cls); 
     80                        cls = builder.countLinks(null, clz[0].getClassURI(), cls); 
    8181                        for (ClassLink cl : cls) { 
    8282                                System.out.println(cl.toString()); 
    8383                        } 
    8484                } 
    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 
    86103                /* 
    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                  *  
    97104                 * System.out.println("INS-INS"); ins = builder.getInstances(null, 
    98105                 * "\"A.C. Reed\"@en"); InstanceLink[] iLinks = 
     
    100107                 * ins[0].getInstanceURI(), 100); 
    101108                 *  
    102                  *  
    103                  *  
    104                  * if( iLinks != null ){ for( InstanceLink in: iLinks){ 
     109                 * if (iLinks != null) { for (InstanceLink in : iLinks) { 
    105110                 * System.out.println(in.toString()); } } 
    106111                 */ 
     
    142147 
    143148                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"); 
    147157                if (countInstances) { 
    148158                        queryStr.append("      ?i rdf:type ?c.\n"); 
     
    156166                        queryStr.append(keyword); 
    157167                        queryStr.append("\" , \"i\" )\n"); 
    158                         queryStr.append("  )"); 
     168                        queryStr.append("  )\n"); 
    159169                } 
    160170                if (countInstances) { 
    161                         queryStr.append("\n}  GROUP BY ?c ?pLabel"); 
     171                        queryStr.append("}  GROUP BY ?c ?pLabel"); 
    162172                } else { 
    163                         queryStr.append("\n}"); 
     173                        queryStr.append("}"); 
    164174                } 
    165175                System.out.println(queryStr.toString()); 
     
    177187                                String uri = res.getURI(); 
    178188                                int numOfInstances = 0; 
    179                                 if( countInstances ){ 
     189                                if (countInstances) { 
    180190                                        numOfInstances = sol.getLiteral("numOfInstances").getInt(); 
    181191                                } 
     
    493503        } 
    494504 
    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 { 
    496507                OWLClassGraph graph = new OWLClassGraph(startClass, endClass); 
    497508                return graph.getPaths(this, mode, countLinks); 
     
    748759        } 
    749760 
    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) { 
    752764                        return new SClass[0]; 
    753765                } 
    754766                HashMap<String, SClass> classMap = new HashMap<String, SClass>(); 
    755                 for(SClass sc: classes){ 
     767                for (SClass sc : classes) { 
    756768                        classMap.put(sc.getClassURI(), sc); 
    757769                } 
     
    803815                } 
    804816                qexec.close(); 
    805          
     817 
    806818                return classes; 
    807819        }