差分発生行の前後
無視リスト:
更新日時:
2015/04/08 17:05:11 (9 年 前)
更新者:
atsuko
ログメッセージ:

コスト関数導入

ファイル:
1 変更

凡例:

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

    r248 r251  
    77package org.biohackathon.SPARQLBuilder.OWL; 
    88 
     9import java.io.*; 
     10import java.util.*; 
    911 
    1012/** 
     
    2123     
    2224    private static final String CDIR = "cdata"; 
    23      
    24     /* 
     25         
    2526    public static void main(String[] args){ 
    26         // For Test 
    27         //String sp = "http://data.allie.dbcls.jp/sparql"; 
    28         //String sc = "http://purl.org/allie/ontology/201108#ShortForm"; 
    29         //String ec = "http://purl.org/allie/ontology/201108#LongForm"; 
    30  
    31         String sp = "http://www.ebi.ac.uk/rdf/services/chembl/sparql"; 
    32         String sc = "http://rdf.ebi.ac.uk/terms/chembl#Enzyme"; 
    33         String ec = "http://rdf.ebi.ac.uk/terms/chembl#Activity"; 
    34  
    35         //String sp = "http://www.ebi.ac.uk/rdf/services/biosamples/sparql"; 
    36         //String sc = "http://rdf.ebi.ac.uk/terms/biosd/Sample"; 
    37         //String ec = "http://purl.obolibrary.org/obo/NCBITaxon_7955"; 
    38         //String sp = "http://www.ebi.ac.uk/rdf/services/biosamples/sparql"; 
    39         //String sc = "http://rdf.ebi.ac.uk/terms/biosd/Sample"; 
    40         //String ec = "http://purl.obolibrary.org/obo/NCBITaxon_7955"; 
    41         //String sp = "http://lsd.dbcls.jp/sparql"; 
    42         //String sc = "http://purl.jp/bio/10/lsd/ontology/201209#EnglishCode"; 
    43         //String ec = "http://purl.jp/bio/10/lsd/ontology/201209#JapaneseCode"; 
    44         //QueryPathGenerator qpg = new QueryPathGenerator(sp, "c:\\cdata"); 
    45         QueryPathGenerator qpg1 = new QueryPathGenerator(sp, "cdata/"); 
    46         //qpg1.testOWLClassGraph(); 
    47         //SClass[] cl = qpg.getClasses(null); 
    48     }*/ 
     27        QueryPathGenerator qpg = new QueryPathGenerator(); 
     28        //String[] elist = qpg.getFactory().getEndpointURIList(); 
     29        List<String> elist = new LinkedList<String>(); 
     30        File file0 = new File("eplist.txt"); 
     31        try{ 
     32            BufferedReader br = new BufferedReader(new FileReader(file0)); 
     33            String buf = null; 
     34            while( (buf = br.readLine()) != null){ 
     35                elist.add(buf); 
     36            } 
     37        }catch(IOException e){ 
     38            System.err.println(e); 
     39        } 
     40         
     41        ListIterator<String> eit = elist.listIterator(); 
     42        int i = 0; 
     43        while(eit.hasNext()){ 
     44            String ep = eit.next(); 
     45            qpg.setSPARQLendpoint(ep); 
     46            qpg.graph = new OWLClassGraph(qpg.analyzer); 
     47            SClass[] classes = qpg.getClasses(null); 
     48            File file1 = new File("path".concat(Integer.toString(i)).concat(".txt")); 
     49            File file2 = new File("ptable".concat(Integer.toString(i)).concat(".txt")); 
     50            try{ 
     51                BufferedWriter bw1 = new BufferedWriter(new FileWriter(file1)); 
     52                BufferedWriter bw2 = new BufferedWriter(new FileWriter(file2)); 
     53                String jsonstr = "["; 
     54                int m = 0; 
     55                for ( int j = 0 ; j < classes.length; j ++ ){ 
     56                    SClass start = classes[j]; 
     57                    for ( int k = j + 1 ; k < classes.length; k++ ){ 
     58                        SClass end = classes[k]; 
     59                        Path[] paths = qpg.getPaths(start.getClassURI(), end.getClassURI(), false);                         
     60                        for( int l = 0; l < paths.length; l++ ){ 
     61                            if ( paths[l] == null ){ 
     62                                continue; 
     63                            } 
     64                            if (m > 0 ){ 
     65                                jsonstr += ","; 
     66                            } 
     67                            double cost = paths[l].computeCost();                                                         
     68                            bw2.write(Double.toString(cost)); 
     69                            bw2.write(","); 
     70                            bw2.write(Boolean.toString(EndpointAccess.checkPath(paths[l], ep))); 
     71                            bw2.newLine(); 
     72                            jsonstr += paths[i].toJSONString3(classes); 
     73                            m++; 
     74                        } 
     75                    } 
     76                } 
     77                jsonstr += "]"; 
     78                bw1.write(jsonstr); 
     79                bw1.newLine(); 
     80                 
     81                bw1.close(); 
     82                bw2.close(); 
     83            }catch(IOException e){ 
     84                System.err.println(e); 
     85            } 
     86            i++; 
     87        } 
     88    } 
    4989     
    5090    public QueryPathGenerator(){ 
     
    5898     
    5999    public void setOWLClassGraph(String startClass){ 
    60         graph = new OWLClassGraph(analyzer, sparqlEndpoint, startClass, askcheck); 
     100        //graph = new OWLClassGraph(analyzer, sparqlEndpoint, startClass, askcheck); 
     101        graph = new OWLClassGraph(analyzer, sparqlEndpoint, startClass, true); 
    61102    } 
    62      
    63 /* 
    64     public QueryPathGenerator(String sparqlEndpoint, String crawlFileName){ 
    65         factory = new RDFSchemaAnalyzerFactory(crawlFileName); 
    66         setSPARQLendpoint(sparqlEndpoint); 
    67         setOWLClassGraph(); 
    68     } 
    69     */ 
    70103     
    71104    public SClass[] getClasses(String keyword){ 
     
    86119     
    87120    public Path[] getPaths(String startClass, String endClass, boolean askcheck){ 
    88         this.askcheck = askcheck; 
    89121        if ( graph == null ){ 
    90122            //System.err.println("Class graph is null.");  
    91123            setOWLClassGraph(startClass); 
    92124        } 
     125        graph.askcheck = askcheck; 
    93126        return graph.getPaths(startClass, endClass); 
    94127    } 
     
    139172        return label; 
    140173    } 
    141      
    142     /* 
    143     private void setOWLClassGraph(){ 
    144         //graph = new OWLClassGraph(analyzer); 
    145         graph = new OWLClassGraph(); 
    146     }*/ 
    147      
     174         
    148175    public OWLClassGraph getOWLClassGraph(){ 
    149176        /*if ( graph == null ){