1 | package org.biohackathon.SPARQLBuilder.endpointMetadata;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.util.Calendar;
|
---|
5 | import java.util.Date;
|
---|
6 | import java.util.HashSet;
|
---|
7 |
|
---|
8 | import jp.riken.accc.db.rdf.crawler.dataStructure.sparql.URICollection;
|
---|
9 |
|
---|
10 | import org.apache.jena.riot.RDFDataMgr;
|
---|
11 |
|
---|
12 | import com.hp.hpl.jena.rdf.model.Literal;
|
---|
13 | import com.hp.hpl.jena.rdf.model.Model;
|
---|
14 | import com.hp.hpl.jena.rdf.model.NodeIterator;
|
---|
15 | import com.hp.hpl.jena.rdf.model.Property;
|
---|
16 | import com.hp.hpl.jena.rdf.model.RDFNode;
|
---|
17 | import com.hp.hpl.jena.rdf.model.Resource;
|
---|
18 |
|
---|
19 | public class MetadataFile {
|
---|
20 |
|
---|
21 | Model model = null;
|
---|
22 | String endpointURI = null;
|
---|
23 | Calendar startDateTime = null;
|
---|
24 | Calendar endDateTime = null;
|
---|
25 |
|
---|
26 | public MetadataFile(File file) throws Exception{
|
---|
27 | readFile(file);
|
---|
28 | }
|
---|
29 |
|
---|
30 | public String getEndpointURI(){
|
---|
31 | return endpointURI;
|
---|
32 | }
|
---|
33 |
|
---|
34 | public Calendar getStartDateTime(){
|
---|
35 | return startDateTime;
|
---|
36 | }
|
---|
37 |
|
---|
38 | public Calendar getEndDateTime(){
|
---|
39 | return endDateTime;
|
---|
40 | }
|
---|
41 |
|
---|
42 |
|
---|
43 | private void readFile(File file) throws Exception{
|
---|
44 | model = RDFDataMgr.loadModel(file.getAbsolutePath());
|
---|
45 | Property sd_endpoint = model.getProperty(URICollection.PROPERTY_SD_ENDPOINT);
|
---|
46 | NodeIterator nit = model.listObjectsOfProperty(sd_endpoint);
|
---|
47 | Resource endPointRes = null;
|
---|
48 | endpointURI = null;
|
---|
49 | if( nit.hasNext() ){
|
---|
50 | RDFNode endPointNode = nit.next();
|
---|
51 | endPointRes = endPointNode.asResource();
|
---|
52 | endpointURI = endPointRes.getURI();
|
---|
53 | }
|
---|
54 |
|
---|
55 | Property sd_default_dataset = model.getProperty(URICollection.PROPERTY_SD_DEFAULT_DATA_SET);
|
---|
56 | nit = model.listObjectsOfProperty(sd_default_dataset);
|
---|
57 | Resource defaultDataSet = null;
|
---|
58 | if( nit.hasNext() ){
|
---|
59 | RDFNode node = nit.next();
|
---|
60 | defaultDataSet = node.asResource();
|
---|
61 | }
|
---|
62 | // log
|
---|
63 | Property sbm_crawlLog = model.getProperty(URICollection.PROPERTY_SB_CRAWL_LOG);
|
---|
64 | nit = model.listObjectsOfProperty(sbm_crawlLog);
|
---|
65 | Resource crawlLogBlankNode = null;
|
---|
66 | if( nit.hasNext() ){
|
---|
67 | RDFNode node = nit.next();
|
---|
68 | crawlLogBlankNode = node.asResource();
|
---|
69 | }
|
---|
70 | // start
|
---|
71 | Property sbm_startTime = model.getProperty(URICollection.PROPERTY_SB_CRAWL_START_TIME);
|
---|
72 | nit = model.listObjectsOfProperty(sbm_startTime);
|
---|
73 | startDateTime = null;
|
---|
74 | if( nit.hasNext() ){
|
---|
75 | Literal startTimeLit = null;
|
---|
76 | RDFNode node = nit.next();
|
---|
77 | startTimeLit = node.asLiteral();
|
---|
78 | startDateTime = ((com.hp.hpl.jena.datatypes.xsd.XSDDateTime)(startTimeLit.getValue())).asCalendar();
|
---|
79 | }
|
---|
80 | // end
|
---|
81 | Property sbm_endTime = model.getProperty(URICollection.PROPERTY_SB_CRAWL_END_TIME);
|
---|
82 | nit = model.listObjectsOfProperty(sbm_endTime);
|
---|
83 | endDateTime = null;
|
---|
84 | if( nit.hasNext() ){
|
---|
85 | Literal endTimeLit = null;
|
---|
86 | RDFNode node = nit.next();
|
---|
87 | endTimeLit = node.asLiteral();
|
---|
88 | endDateTime = ((com.hp.hpl.jena.datatypes.xsd.XSDDateTime)(endTimeLit.getValue())).asCalendar();
|
---|
89 | }
|
---|
90 |
|
---|
91 | }
|
---|
92 |
|
---|
93 | }
|
---|