From 541a5ee21e07796b08413bd47f383fdab063a09f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20David?= <Jerome.David@univ-grenoble-alpes.fr> Date: Fri, 16 Jul 2010 07:59:56 +0000 Subject: [PATCH] The SkosLiteOntologyFactory --- .../skoslite/SKOSLiteOntologyFactory.java | 66 +++++++++++++++++++ .../ontowrap/skoslite/SKOSLiteThesaurus.java | 4 ++ 2 files changed, 70 insertions(+) create mode 100644 src/fr/inrialpes/exmo/ontowrap/skoslite/SKOSLiteOntologyFactory.java diff --git a/src/fr/inrialpes/exmo/ontowrap/skoslite/SKOSLiteOntologyFactory.java b/src/fr/inrialpes/exmo/ontowrap/skoslite/SKOSLiteOntologyFactory.java new file mode 100644 index 00000000..fdb3c7fa --- /dev/null +++ b/src/fr/inrialpes/exmo/ontowrap/skoslite/SKOSLiteOntologyFactory.java @@ -0,0 +1,66 @@ +package fr.inrialpes.exmo.ontowrap.skoslite; + +import java.net.URI; +import java.net.URISyntaxException; + +import com.hp.hpl.jena.rdf.model.Model; + +import fr.inrialpes.exmo.ontowrap.OntologyCache; +import fr.inrialpes.exmo.ontowrap.OntologyFactory; +import fr.inrialpes.exmo.ontowrap.OntowrapException; + +public class SKOSLiteOntologyFactory extends OntologyFactory { + + private URI formalismUri; + private final static String formalismId = "SKOS1.0"; + private final static OntologyCache<SKOSLiteThesaurus> cache = new OntologyCache<SKOSLiteThesaurus>(); + + public SKOSLiteOntologyFactory() { + try { + formalismUri = new URI("http://www.w3.org/2004/02/skos/core#"); + } catch (URISyntaxException e) { + + e.printStackTrace(); + } + } + + @Override + public void clearCache() throws OntowrapException { + cache.clear(); + } + + @Override + public SKOSLiteThesaurus loadOntology(URI uri) throws OntowrapException { + SKOSLiteThesaurus onto = cache.getOntologyFromURI( uri ); + if ( onto != null ) return onto; + onto = cache.getOntology( uri ); + if ( onto != null ) return onto; + onto = new SKOSLiteThesaurus(uri); + onto.setFormalism( formalismId ); + onto.setFormURI( formalismUri ); + + // TODO find the URI of a skos thesaurus + //onto.setURI( dataset.getURI() ); + //cache.recordOntology( uri, onto ); + + return onto; + } + + @Override + public SKOSLiteThesaurus newOntology(Object m) throws OntowrapException { + if ( m instanceof Model ) { + SKOSLiteThesaurus onto = new SKOSLiteThesaurus((Model) m); + onto.setFormalism( formalismId ); + onto.setFormURI( formalismUri ); + //TODO Find the URI of a skos thesaurus ? + // This is the URI of the corresponding OWL API Ontology + //URI uri = ((SKOSDataset)ontology).getURI(); + //onto.setURI( uri ); + //cache.recordOntology( uri, onto ); + return onto; + } else { + throw new OntowrapException( "Argument is not an Jena Model: "+m ); + } + } + +} diff --git a/src/fr/inrialpes/exmo/ontowrap/skoslite/SKOSLiteThesaurus.java b/src/fr/inrialpes/exmo/ontowrap/skoslite/SKOSLiteThesaurus.java index 8bb927ae..21effdae 100644 --- a/src/fr/inrialpes/exmo/ontowrap/skoslite/SKOSLiteThesaurus.java +++ b/src/fr/inrialpes/exmo/ontowrap/skoslite/SKOSLiteThesaurus.java @@ -41,6 +41,10 @@ public class SKOSLiteThesaurus implements HeavyLoadedOntology<Model> { public SKOSLiteThesaurus(URI file) { setFile(file); } + + public SKOSLiteThesaurus(Model onto) { + this.setOntology(onto); + } @Override public boolean getCapabilities(int Direct, int Asserted, int Named) throws OntowrapException { -- GitLab