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