From f9cf2fa3f225da034e4f84750ae45b63fd101bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr> Date: Wed, 20 Apr 2011 13:19:02 +0000 Subject: [PATCH] - Added autoselecting BasicOntology.load() --- html/relnotes.html | 1 + .../exmo/ontowrap/BasicOntology.java | 23 +++++++++- .../exmo/ontowrap/OntologyFactory.java | 42 ++++++++++++++++++- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/html/relnotes.html b/html/relnotes.html index b7bbe9dd..df285fe7 100644 --- a/html/relnotes.html +++ b/html/relnotes.html @@ -65,6 +65,7 @@ The development of 4 versions continues. <li>Added <tt>WeightedPRecEvaluator</tt> weighting confidences (eval)</li> <li>Added <tt>toURIAlignment</tt> and <tt>toEDOALAlignment</tt> for <tt>EDOALAlignment</tt> (edoal)</li> <li>Added matching test generator facility (gen)</li> +<li>Added autoselecting <tt>BasicOntology.load()</tt> (ontowrap)</li> <li>Suppressed <tt>EDOALRelation</tt>: EDOAL uses <tt>BasicRelation</tt> (edoal)</li> <li>EDOAL default printout now uses pretty relations, i.e., <, >, =, % (edoal)</li> <li>Changed order of display to precision/F-measure/recall (util)</li> diff --git a/src/fr/inrialpes/exmo/ontowrap/BasicOntology.java b/src/fr/inrialpes/exmo/ontowrap/BasicOntology.java index 027f30d8..0a062f55 100644 --- a/src/fr/inrialpes/exmo/ontowrap/BasicOntology.java +++ b/src/fr/inrialpes/exmo/ontowrap/BasicOntology.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2007-2008, 2010 + * Copyright (C) INRIA, 2007-2008, 2010-2011 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -60,4 +60,25 @@ public class BasicOntology<O> implements Ontology<O> { } return result; } + + public LoadedOntology load() throws OntowrapException { + OntowrapException ex = null; + // Try to use the default factory + try { + return OntologyFactory.getFactory().loadOntology( file ); + } catch ( OntowrapException owex ) { + ex = new OntowrapException( "Cannot load ontology "+file, owex ); + } + // Otherwise try the possible ones + for ( String className : OntologyFactory.getFactories( formalismURI ) ) { + try { + return OntologyFactory.newInstance( className ).loadOntology( file ); + } catch ( OntowrapException owex ) { + if ( ex == null ) + ex = new OntowrapException( "Cannot load ontology "+file, owex ); + } + } + throw ex; + } + } diff --git a/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java b/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java index 57b10d2d..701e79b8 100644 --- a/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java +++ b/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2008, 2010 + * Copyright (C) INRIA, 2008, 2010-2011 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -21,7 +21,12 @@ package fr.inrialpes.exmo.ontowrap; import java.net.URI; +import java.net.URISyntaxException; import java.util.Hashtable; +import java.util.Set; +import java.util.HashSet; +import java.util.Map; +import java.util.HashMap; import java.lang.reflect.InvocationTargetException; @@ -41,10 +46,43 @@ public abstract class OntologyFactory { public static final int MENTIONNED = 11; public static final int ALL = 12; + private static Map<URI,Set<String>> factories = null; + protected static Hashtable<String,OntologyFactory> instances = null; private static String API_NAME="fr.inrialpes.exmo.ontowrap.owlapi30.OWLAPI3OntologyFactory"; + public static Set<String> getFactories( URI formalism ) { + if ( factories == null ){ + factories = new HashMap<URI, Set<String>>(); + try { + HashSet<String> owl = new HashSet<String>(); + factories.put( new URI("http://www.w3.org/2002/07/owl#"), owl ); + owl.add( "fr.inrialpes.exmo.ontowrap.jena25.JENAOntologyFactory" ); + owl.add( "fr.inrialpes.exmo.ontowrap.owlapi30.OWLAPI3OntologyFactory" ); + owl.add( "fr.inrialpes.exmo.ontowrap.owlapi10.OWLAPIOntologyFactory" ); + + HashSet<String> rdfs = new HashSet<String>(); + factories.put( new URI("http://www.w3.org/2000/01/rdf-schema#"), rdfs ); + rdfs.add( "fr.inrialpes.exmo.ontowrap.jena25.JENAOntologyFactory" ); + + //HashSet<String> owl2 = new HashSet<String>(); + //factories.put( new URI("http://www.w3.org/2002/07/owl#"), owl2 ); + //owl2.add( "fr.inrialpes.exmo.ontowrap.jena25.JENAOntologyFactory" ); + //owl2.add( "fr.inrialpes.exmo.ontowrap.owlapi30.OWLAPI3OntologyFactory" ); + + HashSet<String> skos = new HashSet<String>(); + factories.put( new URI("http://www.w3.org/2004/02/skos/core#"), skos ); + skos.add( "fr.inrialpes.exmo.ontowrap.skoslite.SKOSLiteOntologyFactory" ); + skos.add( "fr.inrialpes.exmo.ontowrap.skosapi.SKOSOntologyFactory" ); + + } catch ( URISyntaxException uriex ) { + uriex.printStackTrace(); // should never occur + } + } + return factories.get( formalism ); + } + public static String getDefaultFactory(){ return API_NAME; } @@ -57,7 +95,7 @@ public abstract class OntologyFactory { return newInstance(API_NAME); } - private static OntologyFactory newInstance( String apiName ) { + protected static OntologyFactory newInstance( String apiName ) { if ( instances == null ) instances = new Hashtable<String,OntologyFactory>(); OntologyFactory of = instances.get( apiName ); if ( of != null ) return of; -- GitLab