- 更新日時:
- 2014/09/25 15:42:35 (10 年 前)
- パス:
- BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/endpointMetadata
- ファイル:
-
- 2 変更
凡例:
- 変更なし
- 追加
- 削除
-
BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/endpointMetadata/MetadataFile.java
r158 r160 2 2 3 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; 4 18 5 19 public class MetadataFile { 6 20 21 Model model = null; 22 String endpointURI = null; 23 Calendar startDateTime = null; 24 Calendar endDateTime = null; 7 25 8 26 public MetadataFile(File file) throws Exception{ … … 10 28 } 11 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 12 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 } 13 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 14 91 } 15 92 -
BH13SPARQLBuilder/src/org/biohackathon/SPARQLBuilder/endpointMetadata/MetadataManager.java
r158 r160 2 2 3 3 import java.io.File; 4 import java.util.ArrayList; 4 import java.util.HashMap; 5 import java.util.Set; 5 6 6 7 public class MetadataManager { 7 8 9 HashMap<String,MetadataFile> metadataTable = null; 10 11 12 public static void main(String[] args) throws Exception{ 13 String dirStr = "c:\\temp\\crawl"; 14 MetadataManager manager = new MetadataManager(dirStr); 15 String[] uris = manager.getURIList(); 16 for(String uri: uris){ 17 System.out.println(uri); 18 MetadataFile mFile = manager.getMetadataFile(uri); 19 System.out.println(mFile.getStartDateTime().getTime().toString()); 20 System.out.println(mFile.getEndDateTime().getTime().toString()); 21 } 22 } 8 23 9 MetadataFile[] metadataFiles = null; 24 public MetadataFile getMetadataFile(String uri){ 25 return metadataTable.get(uri); 26 } 27 28 public String[] getURIList(){ 29 Set<String> keySet = metadataTable.keySet(); 30 return keySet.toArray(new String[0]); 31 } 32 10 33 11 34 public MetadataManager(String metadataDirStr) throws Exception { … … 15 38 16 39 public void init(String metadataDirStr) throws Exception{ 40 metadataTable = new HashMap<String,MetadataFile>(); 17 41 File metadataDir = new File(metadataDirStr); 18 42 File[] files = null; … … 30 54 throw new Exception("File/Directory not found: " + metadataDirStr); 31 55 } 32 ArrayList<MetadataFile> aList = new ArrayList<MetadataFile>();33 56 for(File file: files){ 34 57 MetadataFile metadataFile = null; 35 58 try{ 36 59 metadataFile = new MetadataFile(file); 37 aList.add(metadataFile); 60 String uri = metadataFile.getEndpointURI(); 61 if( uri != null ){ 62 metadataTable.put(uri, metadataFile); 63 } 38 64 }catch(Exception ex){ 39 65 // WARNING 40 66 System.out.println("Invalid metadata file: " + file.getAbsolutePath()); 67 ex.printStackTrace(); 41 68 } 42 69 } 43 metadataFiles = aList.toArray(new MetadataFile[0]);44 70 } 45 71