001/** 002 * Copyright (C) 2007 - 2016, Jens Lehmann 003 * 004 * This file is part of DL-Learner. 005 * 006 * DL-Learner is free software; you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation; either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * DL-Learner is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package org.dllearner.kb.repository.oxford; 020 021import java.net.URI; 022import java.text.DecimalFormat; 023import java.util.ArrayList; 024import java.util.Collection; 025import java.util.Collections; 026import java.util.List; 027 028import org.apache.log4j.Logger; 029import org.dllearner.kb.repository.OntologyRepository; 030import org.dllearner.kb.repository.OntologyRepositoryEntry; 031import org.semanticweb.owlapi.model.IRI; 032import org.semanticweb.owlapi.model.OWLOntology; 033import org.semanticweb.owlapi.util.OntologyIRIShortFormProvider; 034 035public class OxfordRepository implements OntologyRepository{ 036 037 private static final Logger log = Logger.getLogger(OxfordRepository.class); 038 039 private final String repositoryName = "Oxford"; 040 041 private final URI repositoryLocation = URI.create("http://www.cs.ox.ac.uk/isg/ontologies/UID/"); 042 043 private List<RepositoryEntry> entries; 044 045 int numberOfEntries = 797; 046 047 DecimalFormat df = new DecimalFormat("00000"); 048 049 public OxfordRepository() { 050 entries = new ArrayList<>(); 051 } 052 053 @Override 054 public void initialize() { 055 refresh(); 056 } 057 058 @Override 059 public String getName() { 060 return repositoryName; 061 } 062 063 @Override 064 public String getLocation() { 065 return repositoryLocation.toString(); 066 } 067 068 @Override 069 public void refresh() { 070 fillRepository(); 071 } 072 073 @Override 074 public Collection<OntologyRepositoryEntry> getEntries() { 075 List<OntologyRepositoryEntry> ret = new ArrayList<>(); 076 ret.addAll(entries); 077 return ret; 078 } 079 080 @Override 081 public List<Object> getMetaDataKeys() { 082 return Collections.emptyList(); 083 } 084 085 @Override 086 public OWLOntology getOntology(OntologyRepositoryEntry entry) { 087 return null; 088 } 089 090 public void dispose() { 091 } 092 093 ///////////////////////////////////////////////////////////////////////////////////////////////// 094 // 095 // Implementation details 096 097 private void fillRepository() { 098 entries.clear(); 099 for(int i = 1; i <= numberOfEntries; i++){ 100 entries.add(new RepositoryEntry(URI.create(repositoryLocation + df.format(i) + ".owl"))); 101 } 102 log.info("Loaded " + entries.size() + " ontology entries from Oxford."); 103 } 104 105 private class RepositoryEntry implements OntologyRepositoryEntry { 106 107 private String shortName; 108 109 private URI ontologyURI; 110 111 private URI physicalURI; 112 113 public RepositoryEntry(URI ontologyIRI) { 114 this.ontologyURI = ontologyIRI; 115 OntologyIRIShortFormProvider sfp = new OntologyIRIShortFormProvider(); 116 shortName = sfp.getShortForm(IRI.create(ontologyIRI)); 117 physicalURI = ontologyIRI; 118 } 119 120 @Override 121 public String getOntologyShortName() { 122 return shortName; 123 } 124 125 @Override 126 public URI getOntologyURI() { 127 return ontologyURI; 128 } 129 130 @Override 131 public URI getPhysicalURI() { 132 return physicalURI; 133 } 134 135 @Override 136 public String getMetaData(Object key) { 137 return null; 138 } 139 140 } 141 142 public static void main(String[] args) throws Exception { 143 new OxfordRepository().fillRepository(); 144 } 145 146}