root/BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/OWL/StructureCrawler.java @ 85

リビジョン 85, 3.2 KB (コミッタ: nori, 10 年 前)

StructureCrawlerクラス導入

  • 属性 svn:mime-type の設定値 text/plain
行番号 
1package org.biohackathon.SPARQLBuilder.OWL;
2
3import java.io.File;
4import java.util.HashMap;
5import java.util.Map;
6import java.util.Set;
7
8import jp.riken.accc.db.rdf.crawler.dataStructure.SchemaCategory;
9import jp.riken.accc.db.rdf.crawler.dataStructure.sparql.JenaModelGenerator;
10import jp.riken.accc.db.rdf.crawler.dataStructure.sparql.RDFsCrawlerImpl;
11
12public class StructureCrawler {
13
14        private File dataDir = null;
15
16        public static void main(String[] args) throws Exception{
17                StructureCrawler sc = new StructureCrawler(new File("c:\\temp"));
18                sc.crawl("http://data.allie.dbcls.jp/sparql", "allie.ttl");
19               
20                Map<String,String> acTable = sc.getAcquiredStructureFiles();
21                Set<String> keySet = acTable.keySet();
22                for(String key: keySet){
23                        String val = acTable.get(key);
24                        System.out.println("File: " + key + " --- " + val);
25                }
26        }
27       
28       
29       
30        public Map<String, String> getAcquiredStructureFiles(){
31                Map<String, String> table = new HashMap<String, String>();
32                if( dataDir.isDirectory() ){
33                        // read files
34                        File[] files = dataDir.listFiles();
35                        for(File file: files){
36                                String uri = null;
37                                try{
38                                        JenaModelGenerator jmGene = new JenaModelGenerator(file.getAbsolutePath());
39                                        uri = jmGene.getEndpointURI();
40                                }catch(Exception ex){
41                                        //
42                                }
43                                if( uri != null ){
44                                        table.put(uri, file.getAbsolutePath());
45                                }
46                        }
47                }else{
48                        if( dataDir.isFile() ){
49                                String uri = null;
50                                try{
51                                        JenaModelGenerator jmGene = new JenaModelGenerator(dataDir.getAbsolutePath());
52                                        uri = jmGene.getEndpointURI();
53                                }catch(Exception ex){
54                                        //
55                                }
56                                if( uri != null ){
57                                        table.put(uri, dataDir.getAbsolutePath());
58                                }
59                        }
60                }
61                return table;
62        }
63       
64       
65       
66        public StructureCrawler(File dataDir) throws Exception {
67                this.dataDir = dataDir;
68        }
69
70        public void crawl(String endPURI, String outFileName) throws Exception {
71                RDFsCrawlerImpl impl = new RDFsCrawlerImpl(endPURI);
72                // Resource[] res = impl.getRDFProperties();
73                // Resource[] res = impl.getInferedRDFsClassesFromInstances();
74                // Resource[] res = impl.getDomainRangeDeclaredRDFProperties();
75                // Resource[] res = impl.getDeclaredRDFsClasses();
76                // for(Resource r: res){
77                // System.out.println(r.getURI().toString());
78                // }
79                // Model model = impl.getProperiesFromDomainRangeDecls();
80                // Model model = impl.getPropertiesFromInstanceDecls();
81                // RDFWriter writer = model.getWriter("N3");
82                // writer.setProperty("showXMLDeclaration","true");
83                // writer.write(model,System.out,"");
84                // model.close();
85
86                SchemaCategory sc = impl.determineSchemaCategory();
87
88                // RDF/XML, RDF/XML-ABBREV, N-TRIPLE, N3
89                String tFileName = null;
90                if (outFileName == null) {
91                        if (endPURI.lastIndexOf("/", endPURI.length() - 2) > 0) {
92                                tFileName = endPURI.substring(
93                                                endPURI.lastIndexOf("/", endPURI.length() - 2) + 1,
94                                                endPURI.length());
95                        } else {
96                                tFileName = endPURI;
97                        }
98                } else {
99                        tFileName = outFileName;
100                        File outFile = new File(dataDir, tFileName);
101                        if (outFile.exists()) {
102                                outFile = File.createTempFile(tFileName, "", dataDir);
103                        }
104                        sc.write2File(outFile.getAbsolutePath(), "Turtle");
105                        // System.out.println("Category:" + sc.getCategory());
106                }
107
108        }
109
110}
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。