You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by al...@apache.org on 2011/07/15 18:56:14 UTC
svn commit: r1147236 [1/2] - in
/incubator/stanbol/trunk/ontologymanager/ontonet/src:
main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/
main/java/org/apache/stanbol/ontologymanager/ontonet/api/registry/
main/java/org/apache/stanbol/ontologym...
Author: alexdma
Date: Fri Jul 15 16:56:12 2011
New Revision: 1147236
URL: http://svn.apache.org/viewvc?rev=1147236&view=rev
Log:
STANBOL-285 :
- Added bind methods to AbstractOntologyInputSource, and calling them in its subclasses.
- Added loader method and input source for single ontology libraries
Added:
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/registry/io/LibrarySource.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/Locations.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/registry/TestOntologyLibrary.java
Removed:
incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/Namespace.java
Modified:
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractOntologyInputSource.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/BlankOntologySource.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/ParentPathInputSource.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/RootOntologyIRISource.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/RootOntologySource.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/ScopeOntologySource.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/registry/RegistryLoader.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/registry/io/OntologyRegistryIRISource.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/impl/RegistryLoaderImpl.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/registry/TestRegistry.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/registry/krestest.owl
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractOntologyInputSource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractOntologyInputSource.java?rev=1147236&r1=1147235&r2=1147236&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractOntologyInputSource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractOntologyInputSource.java Fri Jul 15 16:56:12 2011
@@ -1,19 +1,19 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.stanbol.ontologymanager.ontonet.api.io;
import java.util.Set;
@@ -23,9 +23,9 @@ import org.semanticweb.owlapi.model.OWLO
/**
* Abstract implementation of {@link OntologyInputSource} with the basic methods for obtaining root ontologies
- * and their physical IRIs where applicable.
- *
- * @author alessandro
+ * and their physical IRIs where applicable.<br/>
+ * </br> Implementations should either invoke abstract methods {@link #bindPhysicalIri(IRI)} and
+ * {@link #bindRootOntology(OWLOntology)} in their constructors, or override them.
*
*/
public abstract class AbstractOntologyInputSource implements OntologyInputSource {
@@ -34,6 +34,32 @@ public abstract class AbstractOntologyIn
protected OWLOntology rootOntology = null;
+ /**
+ * This method is used to remind developers to bind a physical IRI to the {@link OntologyInputSource} if
+ * intending to do so.
+ *
+ * Implementation should assign a value to {@link #physicalIri}.
+ *
+ * @param iri
+ * the physical ontology IRI.
+ */
+ protected void bindPhysicalIri(IRI iri) {
+ this.physicalIri = iri;
+ }
+
+ /**
+ * This method is used to remind developers to bind a root ontology to the {@link OntologyInputSource} if
+ * intending to do so.
+ *
+ * Implementation should assign a value to {@link #rootOntology}.
+ *
+ * @param ontology
+ * the root ontology.
+ */
+ protected void bindRootOntology(OWLOntology ontology) {
+ this.rootOntology = ontology;
+ }
+
/*
* (non-Javadoc)
*
@@ -47,6 +73,11 @@ public abstract class AbstractOntologyIn
&& this.rootOntology.equals(src.getRootOntology());
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource#getClosure()
+ */
@Override
public Set<OWLOntology> getClosure() {
return rootOntology.getOWLOntologyManager().getImportsClosure(rootOntology);
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/BlankOntologySource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/BlankOntologySource.java?rev=1147236&r1=1147235&r2=1147236&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/BlankOntologySource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/BlankOntologySource.java Fri Jul 15 16:56:12 2011
@@ -1,19 +1,19 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.stanbol.ontologymanager.ontonet.api.io;
import org.semanticweb.owlapi.apibinding.OWLManager;
@@ -30,13 +30,17 @@ import org.semanticweb.owlapi.model.OWLO
*/
public class BlankOntologySource extends AbstractOntologyInputSource {
+ /**
+ * Creates a new input source with an unnamed, empty ontology.
+ */
public BlankOntologySource() {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
try {
- this.rootOntology = manager.createOntology();
+ bindRootOntology(manager.createOntology());
} catch (OWLOntologyCreationException e) {
- this.rootOntology = null;
+ bindRootOntology(null);
}
+ bindPhysicalIri(null);
}
@Override
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/ParentPathInputSource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/ParentPathInputSource.java?rev=1147236&r1=1147235&r2=1147236&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/ParentPathInputSource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/ParentPathInputSource.java Fri Jul 15 16:56:12 2011
@@ -1,19 +1,19 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.stanbol.ontologymanager.ontonet.api.io;
import java.io.File;
@@ -75,9 +75,9 @@ public class ParentPathInputSource exten
+ " is a directory. Only regular files are allowed.");
AutoIRIMapper mapper = new AutoIRIMapper(rootFile.getParentFile(), true);
mgr.addIRIMapper(mapper);
- rootOntology = mgr.loadOntologyFromOntologyDocument(rootFile);
+ bindRootOntology(mgr.loadOntologyFromOntologyDocument(rootFile));
// TODO : do we really want this to happen?
- physicalIri = IRI.create(rootFile);
+ bindPhysicalIri(IRI.create(rootFile));
}
@Override
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/RootOntologyIRISource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/RootOntologyIRISource.java?rev=1147236&r1=1147235&r2=1147236&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/RootOntologyIRISource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/RootOntologyIRISource.java Fri Jul 15 16:56:12 2011
@@ -1,19 +1,19 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.stanbol.ontologymanager.ontonet.api.io;
import org.semanticweb.owlapi.apibinding.OWLManager;
@@ -37,8 +37,8 @@ public class RootOntologyIRISource exten
}
public RootOntologyIRISource(IRI rootPhysicalIri, OWLOntologyManager manager) throws OWLOntologyCreationException {
- physicalIri = rootPhysicalIri;
- rootOntology = manager.loadOntologyFromOntologyDocument(rootPhysicalIri);
+ bindPhysicalIri(rootPhysicalIri);
+ bindRootOntology(manager.loadOntologyFromOntologyDocument(rootPhysicalIri));
}
/*
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/RootOntologySource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/RootOntologySource.java?rev=1147236&r1=1147235&r2=1147236&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/RootOntologySource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/RootOntologySource.java Fri Jul 15 16:56:12 2011
@@ -1,57 +1,61 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.stanbol.ontologymanager.ontonet.api.io;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
/**
- * An input source that provides the supplied OWL ontology straight away. The
- * physical IRI is either obtained from the default document IRI in the
- * ontology, or supplied manually using the appropriate constructor (e.g.
+ * An input source that provides the supplied OWL ontology straight away. The physical IRI is either obtained
+ * from the default document IRI in the ontology, or supplied manually using the appropriate constructor (e.g.
* retrieved from the ontology manager that actually loaded the ontology).
- *
- * @author alessandro
- *
*/
public class RootOntologySource extends AbstractOntologyInputSource {
- public RootOntologySource(OWLOntology rootOntology) {
- this.rootOntology = rootOntology;
- try {
- physicalIri = rootOntology.getOntologyID().getDefaultDocumentIRI();
- } catch (Exception e) {
- // Ontology might be anonymous, no physical IRI then...
- }
-
- }
-
- public RootOntologySource(OWLOntology rootOntology, IRI phyicalIRI) {
- this.rootOntology = rootOntology;
- this.physicalIri = phyicalIRI;
- }
-
- /*
- * (non-Javadoc)
- * @see eu.iksproject.kres.manager.io.AbstractOntologyInputSource#toString()
- */
- @Override
- public String toString() {
- return "ROOT_ONT<" + rootOntology.getOntologyID() + ">";
- }
+ public RootOntologySource(OWLOntology rootOntology) {
+ bindRootOntology(rootOntology);
+ try {
+ bindPhysicalIri(rootOntology.getOntologyID().getDefaultDocumentIRI());
+ } catch (Exception e) {
+ // Ontology might be anonymous, no physical IRI then...
+ bindPhysicalIri(null);
+ }
+
+ }
+
+ /**
+ * This constructor can be used to hijack ontologies using a physical IRI other than their default one.
+ *
+ * @param rootOntology
+ * @param phyicalIRI
+ */
+ public RootOntologySource(OWLOntology rootOntology, IRI phyicalIRI) {
+ this(rootOntology);
+ bindPhysicalIri(phyicalIRI);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.iksproject.kres.manager.io.AbstractOntologyInputSource#toString()
+ */
+ @Override
+ public String toString() {
+ return "ROOT_ONT<" + rootOntology.getOntologyID() + ">";
+ }
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/ScopeOntologySource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/ScopeOntologySource.java?rev=1147236&r1=1147235&r2=1147236&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/ScopeOntologySource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/ScopeOntologySource.java Fri Jul 15 16:56:12 2011
@@ -1,19 +1,19 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.stanbol.ontologymanager.ontonet.api.io;
import org.semanticweb.owlapi.model.IRI;
@@ -30,12 +30,12 @@ import org.slf4j.LoggerFactory;
public class ScopeOntologySource extends AbstractOntologyInputSource {
public ScopeOntologySource(IRI scopeIri, OWLOntology ontology, IRI origin) {
- rootOntology = ontology;
+ bindRootOntology(ontology);
LoggerFactory.getLogger(ScopeOntologySource.class).debug("Rewriting {} to {}/{}",
new IRI[] {origin, scopeIri, ontology.getOntologyID().getOntologyIRI()});
- physicalIri = !ontology.isAnonymous() ? IRI.create(scopeIri + "/"
- + ontology.getOntologyID().getOntologyIRI())
- : origin;
+ IRI iri = !ontology.isAnonymous() ? IRI.create(scopeIri + "/"
+ + ontology.getOntologyID().getOntologyIRI()) : origin;
+ bindPhysicalIri(iri);
}
@Override
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/registry/RegistryLoader.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/registry/RegistryLoader.java?rev=1147236&r1=1147235&r2=1147236&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/registry/RegistryLoader.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/registry/RegistryLoader.java Fri Jul 15 16:56:12 2011
@@ -1,19 +1,19 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.stanbol.ontologymanager.ontonet.api.registry;
import java.util.Set;
@@ -30,9 +30,6 @@ import org.semanticweb.owlapi.model.OWLO
/**
* A registry loader is a toolkit for loading all ontologies indexed by an ontology registry, or those
* referenced by one of the libraries within a registry.
- *
- * @author alessandro
- *
*/
public interface RegistryLoader {
@@ -48,10 +45,20 @@ public interface RegistryLoader {
boolean hasLibrary(Registry reg, IRI libraryID);
+ /**
+ * Only extract the ontologies belonging to the library specified, if found in the registry at the
+ * supplied location.
+ *
+ * @param registryPhysicalRIRI
+ * @param libraryID
+ * @return
+ */
+ Registry loadLibraryEager(IRI registryPhysicalIRI, IRI libraryID);
+
void loadLocations() throws RegistryContentException;
/**
- * The ontology at <code>physicalIRI</code> may in turn include more than one registry.
+ * The ontology at <code>physicalIRI</code> may in turn include more than one library.
*
* @param physicalIRI
* @return
Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/registry/io/LibrarySource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/registry/io/LibrarySource.java?rev=1147236&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/registry/io/LibrarySource.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/registry/io/LibrarySource.java Fri Jul 15 16:56:12 2011
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.ontologymanager.ontonet.api.registry.io;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.stanbol.ontologymanager.ontonet.api.io.AbstractOntologyInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.registry.RegistryLoader;
+import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.Registry;
+import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.RegistryItem;
+import org.apache.stanbol.ontologymanager.ontonet.impl.util.OntologyUtils;
+import org.apache.stanbol.owl.util.URIUtils;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException;
+import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LibrarySource extends AbstractOntologyInputSource {
+
+ private IRI libraryID;
+
+ private Logger log = LoggerFactory.getLogger(getClass());
+
+ public LibrarySource(IRI libraryID) {
+ this(libraryID, URIUtils.upOne(libraryID));
+ }
+
+ public LibrarySource(IRI libraryID, IRI registryLocation) {
+ this(libraryID, registryLocation, null);
+ }
+
+ public LibrarySource(IRI libraryID,
+ IRI registryLocation,
+ OWLOntologyManager ontologyManager,
+ RegistryLoader loader) {
+ this(libraryID, registryLocation, ontologyManager, loader, null);
+ }
+
+ /**
+ * The most complete constructor
+ *
+ * @param libraryID
+ * @param registryLocation
+ * @param ontologyManager
+ * @param loader
+ * @param parentSrc
+ */
+ public LibrarySource(IRI libraryID,
+ IRI registryLocation,
+ OWLOntologyManager ontologyManager,
+ RegistryLoader loader,
+ OntologyInputSource parentSrc) {
+ this.libraryID = libraryID;
+
+ // The ontology that imports the whole network is created in-memory, therefore it has no physical IRI.
+ bindPhysicalIri(null);
+
+ Set<OWLOntology> subtrees = new HashSet<OWLOntology>();
+ Registry reg = loader.loadLibraryEager(registryLocation, libraryID);
+ for (RegistryItem ri : reg.getChildren()) {
+ if (ri.isLibrary()) try {
+ Set<OWLOntology> adds = loader.gatherOntologies(ri, ontologyManager, true);
+ subtrees.addAll(adds);
+ } catch (OWLOntologyAlreadyExistsException e) {
+ // Chettefreca
+ continue;
+ } catch (OWLOntologyCreationException e) {
+ log.warn("Failed to load ontology library " + ri.getName() + ". Skipping.", e);
+ // If we can't load this library at all, scrap it.
+ // TODO : not entirely convinced of this step.
+ continue;
+ }
+ }
+
+ // We always construct a new root now, even if there's just one subtree.
+
+ // Set<OWLOntology> subtrees = mgr.getOntologies();
+ // if (subtrees.size() == 1)
+ // rootOntology = subtrees.iterator().next();
+ // else
+ try {
+ if (parentSrc != null) bindRootOntology(OntologyUtils.buildImportTree(parentSrc, subtrees,
+ ontologyManager));
+ else bindRootOntology(OntologyUtils.buildImportTree(subtrees, ontologyManager));
+ } catch (OWLOntologyCreationException e) {
+ log.error("Failed to build import tree for registry source " + registryLocation, e);
+ }
+ }
+
+ public LibrarySource(IRI libraryID, IRI registryLocation, RegistryLoader loader) {
+ this(libraryID, registryLocation, OWLManager.createOWLOntologyManager(), loader);
+ }
+
+ public LibrarySource(IRI libraryID,
+ IRI registryLocation,
+ RegistryLoader loader,
+ OntologyInputSource parentSrc) {
+ this(libraryID, registryLocation, OWLManager.createOWLOntologyManager(), loader, parentSrc);
+ }
+
+ public LibrarySource(IRI libraryID, OWLOntologyManager ontologyManager, RegistryLoader loader) {
+ this(libraryID, URIUtils.upOne(libraryID), ontologyManager, loader);
+ }
+
+ public LibrarySource(IRI libraryID,
+ OWLOntologyManager ontologyManager,
+ RegistryLoader loader,
+ OntologyInputSource parentSrc) {
+ this(libraryID, URIUtils.upOne(libraryID), ontologyManager, loader, parentSrc);
+ }
+
+ public LibrarySource(IRI libraryID, RegistryLoader loader) {
+ this(libraryID, URIUtils.upOne(libraryID), loader);
+ }
+
+ public LibrarySource(IRI libraryID, RegistryLoader loader, OntologyInputSource parentSrc) {
+ this(libraryID, URIUtils.upOne(libraryID), OWLManager.createOWLOntologyManager(), loader, parentSrc);
+ }
+
+ @Override
+ public String toString() {
+ return "LIBRARY<" + libraryID + ">";
+ }
+
+}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/registry/io/OntologyRegistryIRISource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/registry/io/OntologyRegistryIRISource.java?rev=1147236&r1=1147235&r2=1147236&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/registry/io/OntologyRegistryIRISource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/registry/io/OntologyRegistryIRISource.java Fri Jul 15 16:56:12 2011
@@ -1,19 +1,19 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.stanbol.ontologymanager.ontonet.api.registry.io;
import java.util.HashSet;
@@ -25,6 +25,7 @@ import org.apache.stanbol.ontologymanage
import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.Registry;
import org.apache.stanbol.ontologymanager.ontonet.api.registry.models.RegistryItem;
import org.apache.stanbol.ontologymanager.ontonet.impl.util.OntologyUtils;
+import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException;
@@ -33,106 +34,92 @@ import org.semanticweb.owlapi.model.OWLO
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
- * An input source that provides a single ontology that imports all the imported
- * ontology libraries found in the ontology registry obtained by dereferencing a
- * supplied IRI.
- *
- * @author alessandro
+ * An input source that provides a single ontology that imports all the imported ontology libraries found in
+ * the ontology registry obtained by dereferencing a supplied IRI.
*
*/
public class OntologyRegistryIRISource extends AbstractOntologyInputSource {
- protected IRI registryIRI = null;
+ private Logger log = LoggerFactory.getLogger(getClass());
+
+ protected IRI registryIRI = null;
- public OntologyRegistryIRISource(IRI registryIRI,
- OWLOntologyManager ontologyManager, RegistryLoader loader) {
- this(registryIRI, ontologyManager, loader, null);
- }
-
- /**
- * Creates a new ontology input source by providing a new root ontology that
- * imports the entire network addressed by the ontology registry at the
- * supplied IRI.
- *
- * @param registryIRI
- */
- public OntologyRegistryIRISource(IRI registryIRI,
- OWLOntologyManager ontologyManager, RegistryLoader loader,
- OntologyInputSource parentSrc) {
-
- this.registryIRI = registryIRI;
-
- Logger log = LoggerFactory.getLogger(getClass());
-
- Set<OWLOntology> subtrees = new HashSet<OWLOntology>();
- for (Registry reg : loader.loadRegistriesEager(registryIRI)) {
- for (RegistryItem ri : reg.getChildren()) {
- if (ri.isLibrary())
- try {
- Set<OWLOntology> adds = loader.gatherOntologies(ri,
- ontologyManager, true);
- subtrees.addAll(adds);
- } catch (OWLOntologyAlreadyExistsException e) {
- // Chettefreca
- continue;
- } catch (OWLOntologyCreationException e) {
- log.warn(
- "KReS : [NONFATAL] Failed to load ontology library "
- + ri.getName() + ". Skipping.", e);
- // If we can't load this library at all, scrap it.
- // TODO : not entirely convinced of this step.
- continue;
- }
- }
- }
- // We always construct a new root now, even if there's just one subtree.
-
- // Set<OWLOntology> subtrees = mgr.getOntologies();
- // if (subtrees.size() == 1)
- // rootOntology = subtrees.iterator().next();
- // else
- try {
- if (parentSrc != null)
- rootOntology = OntologyUtils.buildImportTree(parentSrc,
- subtrees, ontologyManager);
- else
- rootOntology = OntologyUtils.buildImportTree(subtrees,
- ontologyManager);
- } catch (OWLOntologyCreationException e) {
- log.error(
- "KReS :: Failed to build import tree for registry source "
- + registryIRI, e);
- }
- }
-
- /**
- * This method always return null. The ontology that imports the whole
- * network is created in-memory, therefore it has no physical IRI.
- */
- @Override
- public IRI getPhysicalIRI() {
- return null;
- }
-
- /**
- * This method always return false. The ontology that imports the whole
- * network is created in-memory, therefore it has no physical IRI.
- */
- @Override
- public boolean hasPhysicalIRI() {
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see eu.iksproject.kres.manager.io.AbstractOntologyInputSource#toString()
- */
- @Override
- public String toString() {
- return "REGISTRY_IRI<" + registryIRI + ">";
- }
+ /**
+ * @param registryIRI
+ * @param ontologyManager
+ * @param loader
+ */
+ public OntologyRegistryIRISource(IRI registryIRI,
+ OWLOntologyManager ontologyManager,
+ RegistryLoader loader) {
+ this(registryIRI, ontologyManager, loader, null);
+ }
+
+ /**
+ * Creates a new ontology input source by providing a new root ontology that imports the entire network
+ * addressed by the ontology registry at the supplied IRI.
+ *
+ * @param registryIRI
+ */
+ public OntologyRegistryIRISource(IRI registryIRI,
+ OWLOntologyManager ontologyManager,
+ RegistryLoader loader,
+ OntologyInputSource parentSrc) {
+
+ this.registryIRI = registryIRI;
+
+ // The ontology that imports the whole network is created in-memory, therefore it has no physical IRI.
+ bindPhysicalIri(null);
+
+ Set<OWLOntology> subtrees = new HashSet<OWLOntology>();
+ for (Registry reg : loader.loadRegistriesEager(registryIRI)) {
+ for (RegistryItem ri : reg.getChildren()) {
+ if (ri.isLibrary()) try {
+ Set<OWLOntology> adds = loader.gatherOntologies(ri, ontologyManager, true);
+ subtrees.addAll(adds);
+ } catch (OWLOntologyAlreadyExistsException e) {
+ // Chettefreca
+ continue;
+ } catch (OWLOntologyCreationException e) {
+ log.warn("Failed to load ontology library " + ri.getName() + ". Skipping.", e);
+ // If we can't load this library at all, scrap it.
+ // TODO : not entirely convinced of this step.
+ continue;
+ }
+ }
+ }
+ // We always construct a new root now, even if there's just one subtree.
+
+ // Set<OWLOntology> subtrees = mgr.getOntologies();
+ // if (subtrees.size() == 1)
+ // rootOntology = subtrees.iterator().next();
+ // else
+ try {
+ if (parentSrc != null) bindRootOntology(OntologyUtils.buildImportTree(parentSrc, subtrees,
+ ontologyManager));
+ else bindRootOntology(OntologyUtils.buildImportTree(subtrees, ontologyManager));
+ } catch (OWLOntologyCreationException e) {
+ log.error("Failed to build import tree for registry source " + registryIRI, e);
+ }
+ }
+
+ public OntologyRegistryIRISource(IRI registryIRI, RegistryLoader loader) {
+ this(registryIRI, OWLManager.createOWLOntologyManager(), loader, null);
+ }
+
+ public OntologyRegistryIRISource(IRI registryIRI, RegistryLoader loader, OntologyInputSource parentSrc) {
+ this(registryIRI, OWLManager.createOWLOntologyManager(), loader, parentSrc);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.stanbol.ontologymanager.ontonet.api.io.AbstractOntologyInputSource#toString()
+ */
+ @Override
+ public String toString() {
+ return "REGISTRY_IRI<" + registryIRI + ">";
+ }
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java?rev=1147236&r1=1147235&r2=1147236&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java Fri Jul 15 16:56:12 2011
@@ -1,19 +1,19 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.stanbol.ontologymanager.ontonet.impl;
import java.io.File;
@@ -79,11 +79,10 @@ import org.slf4j.LoggerFactory;
* The running context of a Stanbol Ontology Network Manager instance. From this object it is possible to obtain
* factories, indices, registries and what have you.
*
- * @author alessandro
* @see ONManager
*
*/
-@Component(immediate = true, metatype = true)
+@Component(immediate = true)
@Service(ONManager.class)
public class ONManagerImpl implements ONManager {
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/impl/RegistryLoaderImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/impl/RegistryLoaderImpl.java?rev=1147236&r1=1147235&r2=1147236&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/impl/RegistryLoaderImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/registry/model/impl/RegistryLoaderImpl.java Fri Jul 15 16:56:12 2011
@@ -1,19 +1,19 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.stanbol.ontologymanager.ontonet.impl.registry.model.impl;
import java.io.UnsupportedEncodingException;
@@ -58,6 +58,7 @@ import org.semanticweb.owlapi.model.OWLO
import org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException;
import org.semanticweb.owlapi.model.OWLOntologyChangeException;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.semanticweb.owlapi.model.OWLOntologyDocumentAlreadyExistsException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLOntologySetProvider;
import org.semanticweb.owlapi.util.OWLAxiomFilter;
@@ -68,513 +69,472 @@ import org.slf4j.LoggerFactory;
public class RegistryLoaderImpl implements RegistryLoader {
- private final OWLClass cRegistryLibrary;
+ private final OWLClass cRegistryLibrary;
- private final OWLObjectProperty isPartOf, isOntologyOf;
+ private final OWLObjectProperty isPartOf, isOntologyOf;
- private Logger log = LoggerFactory.getLogger(getClass());
+ private Logger log = LoggerFactory.getLogger(getClass());
- private final IRI mergedOntologyIRI = IRI
- .create(CODOVocabulary.REPOSITORY_MERGED_ONTOLOGY);
+ private final IRI mergedOntologyIRI = IRI.create(CODOVocabulary.REPOSITORY_MERGED_ONTOLOGY);
- private ONManager onm;
+ private ONManager onm;
- private Map<URI, OWLOntology> registryOntologiesCache = new HashMap<URI, OWLOntology>();
+ private Map<URI,OWLOntology> registryOntologiesCache = new HashMap<URI,OWLOntology>();
- /**
+ /**
*/
- public RegistryLoaderImpl(ONManager onm) {
- this.onm = onm;
- OWLDataFactory factory = OWLManager.getOWLDataFactory();
- cRegistryLibrary = factory.getOWLClass(IRI
- .create(CODOVocabulary.CODD_OntologyLibrary));
- isPartOf = factory.getOWLObjectProperty(IRI
- .create(CODOVocabulary.PARTOF_IsPartOf));
- isOntologyOf = factory.getOWLObjectProperty(IRI
- .create(CODOVocabulary.ODPM_IsOntologyOf));
- }
+ public RegistryLoaderImpl(ONManager onm) {
+ this.onm = onm;
+ OWLDataFactory factory = OWLManager.getOWLDataFactory();
+ cRegistryLibrary = factory.getOWLClass(IRI.create(CODOVocabulary.CODD_OntologyLibrary));
+ isPartOf = factory.getOWLObjectProperty(IRI.create(CODOVocabulary.PARTOF_IsPartOf));
+ isOntologyOf = factory.getOWLObjectProperty(IRI.create(CODOVocabulary.ODPM_IsOntologyOf));
+ }
- public Set<OWLOntology> gatherOntologies(RegistryItem registryItem,
+ public Set<OWLOntology> gatherOntologies(RegistryItem registryItem,
OWLOntologyManager manager,
boolean recurseRegistries) throws OWLOntologyCreationException {
-
-
Set<OWLOntology> result = new HashSet<OWLOntology>();
- if (registryItem instanceof Registry){
- for (RegistryItem item : ((Registry) registryItem)
- .getChildren())
+ if (registryItem instanceof Registry) {
+ for (RegistryItem item : ((Registry) registryItem).getChildren())
+ try {
+ result.addAll(gatherOntologies(item, manager, recurseRegistries));
+ } catch (OWLOntologyCreationException e) {
+ log.warn("Could not gather ontologies for registry " + registryItem.getName()
+ + ". Skipping.", e);
+ continue;
+ }
+ } else if (registryItem.isOntology()) {
+ IRI locationIri = null;
try {
+ locationIri = IRI.create(((RegistryOntology) registryItem).getURL());
+ result.add(manager.loadOntology(locationIri));
+ } catch (OWLOntologyAlreadyExistsException ex) {
+ // We are trying to oad an alread existing ontology,
+ // we take it from the manager directly
+ result.add(manager.getOntology(ex.getOntologyID()));
+
+ } catch (OWLOntologyCreationIOException ex) {
+ log.error("Cannot load ontology from " + locationIri);
+ } catch (URISyntaxException e) {
+ log.warn("Malformed URI for ontology " + registryItem.getName() + ". Skipping.", e);
+ }
+ } else if (registryItem.isLibrary()) {
+ for (RegistryItem item : ((RegistryLibrary) registryItem).getChildren()) {
result.addAll(gatherOntologies(item, manager, recurseRegistries));
- } catch (OWLOntologyCreationException e) {
- log.warn(
- "[NONFATAL] Could not gather ontologies for registry " + registryItem.getName()
- + ". Skipping.", e);
+ }
+ }
+ return result;
+ }
+
+ public RegistryLibrary getLibrary(Registry reg, IRI libraryID) {
+ for (RegistryItem child : reg.getChildren()) {
+ try {
+ if (child.isLibrary() && IRI.create(child.getURL()).equals(libraryID)) return (RegistryLibrary) child;
+ } catch (URISyntaxException e) {
+ // If some URL is not well-formed here and there, sticazzi
continue;
}
}
- else if (registryItem.isOntology()){
- IRI locationIri = null;
- try {
- locationIri = IRI.create(((RegistryOntology) registryItem)
- .getURL());
- result.add(manager.loadOntology(locationIri));
- } catch (OWLOntologyAlreadyExistsException ex) {
- // We are trying to oad an alread existing ontology,
- // we take it from the manager directly
- result.add(manager.getOntology(ex.getOntologyID()));
-
- } catch (OWLOntologyCreationIOException ex) {
- // FIXME Log error here
- log.error("[NONFATAL] Cannot load ontology from "+locationIri);
- } catch (URISyntaxException e) {
- log.warn("[NONFATAL] Malformed URI for ontology " + registryItem.getName()
- + ". Skipping.", e);
- }
- } else if (registryItem.isLibrary()){
- for (RegistryItem item : ((RegistryLibrary) registryItem).getChildren()) {
- result.addAll(gatherOntologies(item, manager, recurseRegistries));
- }
+ return null;
+ }
+
+ private OWLOntology getMergedOntology(IRI registryLocation) throws RegistryContentException {
+ try {
+ return getMergedOntology(registryLocation.toURI().toURL());
+ } catch (MalformedURLException e) {
+ log.warn("Malformed URI for merged ontology from registry " + registryLocation, e);
+ return null;
}
- return result;
}
- public RegistryLibrary getLibrary(Registry reg, IRI libraryID) {
- for (RegistryItem child : reg.getChildren()) {
- try {
- if (child.isLibrary()
- && IRI.create(child.getURL()).equals(libraryID))
- return (RegistryLibrary) child;
- } catch (URISyntaxException e) {
- // If some URL is not well-formed here and there, sticazzi
- continue;
- }
- }
- return null;
- }
-
- private OWLOntology getMergedOntology(IRI registryLocation)
- throws RegistryContentException {
- try {
- return getMergedOntology(registryLocation.toURI().toURL());
- } catch (MalformedURLException e) {
- log.warn(
- "KReS :: [NONFATAL] Malformed URI for merged ontology from registry "
- + registryLocation, e);
- return null;
- }
- }
-
- private OWLOntology getMergedOntology(URL registryLocation)
- throws RegistryContentException {
- OWLOntology ontology = null;
-
- try {
- IRI mergedOntology = mergedOntologyIRI.resolve("#"
- + URLEncoder.encode(registryLocation.toString(), "UTF-8"));
- if (!ODPRegistryCacheManager.registryContains(mergedOntology
- .toURI())) {
-
- // final OWLOntology ont =
- // getOntologyForRegistryLocation(registryLocation
- // .toURI());
-
- final OWLOntology ont = getOntologyForRegistryLocationNoCached(registryLocation
- .toURI());
- if (ont == null)
- throw new RegistryContentException(
- new NullPointerException("Registry unavailable: "
- + registryLocation.toURI()));
-
- OWLOntologySetProvider provider = new OWLOntologySetProvider() {
- public Set<OWLOntology> getOntologies() {
- return ODPRegistryCacheManager.getManager()
- .getImportsClosure(ont);
- }
- };
- final OWLDataFactory factory = ODPRegistryCacheManager
- .getManager().getOWLDataFactory();
-
- // We filter only interesting axioms
- OWLAxiomFilter filter = new OWLAxiomFilter() {
- public boolean passes(OWLAxiom arg0) {
- if (arg0.getSignature()
- .contains(
- factory.getOWLClass(IRI
- .create(CODOVocabulary.CODD_OntologyLibrary)))
- || arg0.getSignature()
- .contains(
- factory.getOWLClass(IRI
- .create(CODOVocabulary.CODK_Ontology)))
- || arg0.getSignature()
- .contains(
- factory.getOWLObjectProperty(IRI
- .create(CODOVocabulary.ODPM_IsOntologyOf)))
- || arg0.getSignature()
- .contains(
- factory.getOWLObjectProperty(IRI
- .create(CODOVocabulary.PARTOF_IsPartOf)))
- || arg0.getSignature()
- .contains(
- factory.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL
- .getIRI()))) {
- return true;
- }
- return false;
- }
- };
-
- OWLOntologyMerger merger = new OWLOntologyMerger(provider,
- filter);
- OWLOntology merged = merger.createMergedOntology(
- ODPRegistryCacheManager.getManager(), mergedOntology);
- ODPRegistryCacheManager.addResource(merged,
- mergedOntology.toURI());
- ontology = merged;
- } else {
- ontology = ODPRegistryCacheManager.getOntology(mergedOntology
- .toURI());
- }
- } catch (URIUnresolvableException e) {
- throw new RegistryContentException(e);
- } catch (OWLOntologyCreationException e) {
- throw new RegistryContentException(e);
- } catch (OWLOntologyChangeException e) {
- throw new RegistryContentException(e);
- } catch (ODPRegistryCacheException e) {
- throw new RegistryContentException(e);
- } catch (UnsupportedEncodingException e) {
- throw new RegistryContentException(e);
- } catch (URISyntaxException e) {
- throw new RegistryContentException(e);
- }
- return ontology;
- }
-
- private OWLOntology getOntologyForRegistryLocation(URI location) {
- return registryOntologiesCache.get(location);
- }
-
- private OWLOntology getOntologyForRegistryLocationNoCached(URI location) {
- OWLOntologyManagerFactoryImpl factory = onm.getOntologyManagerFactory();
- IRI iri = IRI.create(location);
- try {
- if (factory != null)
- return factory.createOntologyManager(true)
- .loadOntologyFromOntologyDocument(iri);
- else
- return OWLManager.createOWLOntologyManager()
- .loadOntologyFromOntologyDocument(iri);
- } catch (OWLOntologyCreationException e) {
- log.error("KReS :: Registry loader failed to load ontology at "
- + location, e);
- return null;
- }
- }
-
- public Object getParent(Object child) {
- if (child instanceof AbstractRegistryItem) {
- return ((RegistryItem) child).getParent();
- }
- return null;
- }
-
- private Set<OWLIndividual> getParentContainer(OWLNamedIndividual child,
- OWLOntology ontology) {
-
- if (child.getObjectPropertyValues(ontology).containsKey(isPartOf)
- || child.getObjectPropertyValues(ontology).containsKey(
- isOntologyOf)) {
- Set<OWLIndividual> partOfSet = child.getObjectPropertyValues(
- ontology).get(isPartOf);
- Set<OWLIndividual> ontologyOfSet = child.getObjectPropertyValues(
- ontology).get(isOntologyOf);
-
- Set<OWLIndividual> mergedSet = new HashSet<OWLIndividual>();
- if (partOfSet != null)
- mergedSet.addAll(partOfSet);
- if (ontologyOfSet != null)
- mergedSet.addAll(ontologyOfSet);
- return mergedSet;
- } else
- return new HashSet<OWLIndividual>();
- }
-
- private Set<OWLNamedIndividual> getParts(OWLIndividual parent,
- OWLOntology ontology) {
- Set<OWLNamedIndividual> indies = ontology.getIndividualsInSignature();
- Iterator<OWLNamedIndividual> iter = indies.iterator();
- Set<OWLNamedIndividual> tor = new HashSet<OWLNamedIndividual>();
- // For each individual in this ontology
- while (iter.hasNext()) {
- OWLNamedIndividual n = iter.next();
- // Get its parent wrt to isPartOf or isOntologyOf relationships
- for (OWLIndividual i : this.getParentContainer(n, ontology)) {
- if (i.equals(parent)) {
- tor.add(n);
- break;
- }
- }
- }
- return tor;
- }
-
- private List<Registry> getRegistries() {
- List<Registry> registries = new ArrayList<Registry>();
- // String storedStringValue = XDRegistryPlugin.getDefault()
- // .getPreferenceStore().getString(
- // PreferenceConstants.P_ODP_REGISTRIES);
- String[] regs = new String[] {}/*
- * URLListEditor
- * .parsePreferenceStoreValue
- * (storedStringValue)
- */;
-
- for (int i = 0; i < regs.length; i++) {
- Registry registry1 = null;
- try {
- // TODO Find a way to obtain registry names
- String registryName = ""/*
- * URLListEditor
- * .parseNameValueString(regs[i])[0]
- */;
- // TODO Find a way to obtain registry locations
- String registryLocation = ""/*
- * URLListEditor
- * .parseNameValueString(regs[i])[1]
- */;
- registry1 = new Registry(registryName);
- registry1.setURL(new URL(registryLocation));
- } catch (Exception e) {
- if (registry1 != null) {
- registry1.setError(e.getLocalizedMessage());
- log.error(
- "KReS :: Error on ODP registry: "
- + registry1.getName(), e);
- }
- }
- if (registry1 != null)
- registries.add(registry1);
- else
- log.error("KReS :: Cannot load ODP registry: " + regs[i]);
- }
- return registries;
- }
-
- private List<Registry> getRegistries(XDRegistrySource source) {
-
- List<Registry> registries = new ArrayList<Registry>();
-
- if (source.getPhysicalIRI() != null) {
-
- } else if (source.isInputStreamAvailable()) {
-
- } else if (source.isReaderAvailable()) {
-
- }
-
- return registries;
- }
-
- private RegistryLibrary getTree(OWLNamedIndividual i, OWLOntology ontology) {
-
- RegistryLibrary to = new RegistryLibrary(new RDFSLabelGetter(ontology,
- i.getIRI(), false).getPreferred());
- try {
- Set<OWLNamedIndividual> children = this.getParts(i, ontology);
- if (children.size() == 0)
- return to;
- for (OWLNamedIndividual childIndividual : children) {
- if (isLibrary(childIndividual, ontology)) {
- RegistryLibrary t = this.getTree(childIndividual, ontology);
- to.addChild(t);
- } else if (isOntology(childIndividual, ontology)) {
- RegistryOntology t = new RegistryOntology(
- new RDFSLabelGetter(ontology, childIndividual
- .getIRI(), false).getPreferred());
- t.setURL(childIndividual.getIRI().toURI().toURL());
- to.addChild(t);
- }
- }
- } catch (MalformedURLException e) {
- log.error(
- "KReS :: MalformedURLException caught while getting tree for "
- + i.getIRI(), e);
-
- }
- return to;
- }
-
- public boolean hasChildren(Object parent) {
- if (parent instanceof RegistryLibrary)
- return ((RegistryLibrary) parent).hasChildren();
- return false;
- }
-
- public boolean hasLibrary(Registry reg, IRI libraryID) {
- for (RegistryItem child : reg.getChildren()) {
- try {
- if (child.isLibrary()
- && IRI.create(child.getURL()).equals(libraryID))
- return true;
- } catch (URISyntaxException e) {
- // If some URL is not well-formed here and there, sticazzi
- continue;
- }
- }
- return false;
- }
-
- private boolean isLibrary(OWLIndividual indy, OWLOntology ontology) {
- OWLClass folderClass = OWLManager.getOWLDataFactory().getOWLClass(
- IRI.create(CODOVocabulary.CODD_OntologyLibrary));
- return (folderClass.getIndividuals(ontology).contains(indy));
- }
-
- private boolean isOntology(OWLIndividual indy, OWLOntology ontology) {
- OWLClass ontologyClass = OWLManager.getOWLDataFactory().getOWLClass(
- IRI.create(CODOVocabulary.CODK_Ontology));
- return (ontologyClass.getIndividuals(ontology).contains(indy));
- }
-
- public void loadLocations() throws RegistryContentException {
-
- try {
-
- registryOntologiesCache.clear();
- List<Registry> registries = getRegistries();
-
- int regsize = registries.size();
- int c = 0;
- for (Registry current : registries) {
- c++;
- log.debug("Loading " + current.toString() + " [" + c + "/"
- + regsize + "]");
- if (!ODPRegistryCacheManager.registryContains(current.getURL()
- .toURI())) {
- try {
- log.debug("Fetching: " + current.getURL().toURI());
- registryOntologiesCache.put(current.getURL().toURI(),
- ODPRegistryCacheManager.getOntology(current
- .getURL().toURI()));
- } catch (URIUnresolvableException e) {
- log.error("KReS :: could not resolve URI "
- + current.getURL().toURI(), e);
- registryOntologiesCache.put(current.getURL().toURI(),
- null);
- } catch (ODPRegistryCacheException e) {
- log.error("KReS :: failed to cache ontology "
- + current.getURL().toURI(), e);
- registryOntologiesCache.put(current.getURL().toURI(),
- null);
- }
- }
- }
- c = 0;
- for (Registry registry : registries) {
- c++;
- try {
- registry = setupRegistry(registry);
- } catch (RegistryContentException e) {
- registry.setError(" [Unable to load from location "
- + registry.getURL().toString() + "]");
- }
- }
- } catch (Throwable th) {
- log.error(
- "KreS :: Exception occurred while trying to get registry locations.",
- th);
- }
- }
-
- /**
- * The ontology at <code>physicalIRI</code> may in turn include more than
- * one registry.
- *
- * @param physicalIRI
- * @return
- */
- public Set<Registry> loadRegistriesEager(IRI physicalIRI) {
+ private OWLOntology getMergedOntology(URL registryLocation) throws RegistryContentException {
+ OWLOntology ontology = null;
+
+ try {
+ IRI mergedOntology = mergedOntologyIRI.resolve("#"
+ + URLEncoder.encode(registryLocation.toString(),
+ "UTF-8"));
+ if (!ODPRegistryCacheManager.registryContains(mergedOntology.toURI())) {
+
+ // final OWLOntology ont =
+ // getOntologyForRegistryLocation(registryLocation
+ // .toURI());
+
+ final OWLOntology ont = getOntologyForRegistryLocationNoCached(registryLocation.toURI());
+ if (ont == null) throw new RegistryContentException(new NullPointerException(
+ "Registry unavailable: " + registryLocation.toURI()));
+
+ OWLOntologySetProvider provider = new OWLOntologySetProvider() {
+ public Set<OWLOntology> getOntologies() {
+ return ODPRegistryCacheManager.getManager().getImportsClosure(ont);
+ }
+ };
+ final OWLDataFactory factory = ODPRegistryCacheManager.getManager().getOWLDataFactory();
+
+ // We filter only interesting axioms
+ OWLAxiomFilter filter = new OWLAxiomFilter() {
+ public boolean passes(OWLAxiom arg0) {
+ if (arg0.getSignature().contains(
+ factory.getOWLClass(IRI.create(CODOVocabulary.CODD_OntologyLibrary)))
+ || arg0.getSignature().contains(
+ factory.getOWLClass(IRI.create(CODOVocabulary.CODK_Ontology)))
+ || arg0.getSignature().contains(
+ factory.getOWLObjectProperty(IRI.create(CODOVocabulary.ODPM_IsOntologyOf)))
+ || arg0.getSignature().contains(
+ factory.getOWLObjectProperty(IRI.create(CODOVocabulary.PARTOF_IsPartOf)))
+ || arg0.getSignature().contains(
+ factory.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()))) {
+ return true;
+ }
+ return false;
+ }
+ };
+
+ OWLOntologyMerger merger = new OWLOntologyMerger(provider, filter);
+ OWLOntology merged = merger.createMergedOntology(ODPRegistryCacheManager.getManager(),
+ mergedOntology);
+ ODPRegistryCacheManager.addResource(merged, mergedOntology.toURI());
+ ontology = merged;
+ } else {
+ ontology = ODPRegistryCacheManager.getOntology(mergedOntology.toURI());
+ }
+ } catch (URIUnresolvableException e) {
+ throw new RegistryContentException(e);
+ } catch (OWLOntologyCreationException e) {
+ throw new RegistryContentException(e);
+ } catch (OWLOntologyChangeException e) {
+ throw new RegistryContentException(e);
+ } catch (ODPRegistryCacheException e) {
+ throw new RegistryContentException(e);
+ } catch (UnsupportedEncodingException e) {
+ throw new RegistryContentException(e);
+ } catch (URISyntaxException e) {
+ throw new RegistryContentException(e);
+ }
+ return ontology;
+ }
- Set<Registry> results = new HashSet<Registry>();
- OWLOntologyManager mgr = onm.getOwlCacheManager();// getManager();
+ private OWLOntology getOntologyForRegistryLocation(URI location) {
+ return registryOntologiesCache.get(location);
+ }
- try {
- OWLOntology ontology = mgr.loadOntology(physicalIRI);
- for (OWLIndividual ind : cRegistryLibrary.getIndividuals(ontology))
- if (ind.isNamed()) {
- OWLNamedIndividual nind = ind.asOWLNamedIndividual();
- IRI regiri = nind.getIRI();
- Registry registry = new Registry(regiri.getFragment());
- try {
- // TODO: avoid using toURL crap
- registry.setURL(regiri.toURI().toURL());
- } catch (MalformedURLException e) {
- // Why should a well-formed IRI be a malformed URL
- // anyway ?
- log.warn("KReS :: ontology document IRI " + physicalIRI
- + " matches a malformed URI pattern.", e);
- }
- // Find the ontologies in this registry
- // If this is individual is not "ontology of" or "part of",
- // then proceed.
- if (!nind.getObjectPropertyValues(ontology).containsKey(
- isPartOf)
- && !nind.getObjectPropertyValues(ontology)
- .containsKey(isOntologyOf)) {
- registry.addChild(this.getTree(
- (OWLNamedIndividual) nind, ontology));
- }
- results.add(registry);
- }
- } catch (OWLOntologyAlreadyExistsException e) {
- log.warn("KReS :: ontology " + e.getOntologyID()
- + " exists and will not be reloaded.", e);
- // Do nothing. Existing ontologies are fine.
- } catch (OWLOntologyCreationException e) {
- log.error("KReS :: Could not load ontology " + physicalIRI + " .",
- e);
- } finally {
- }
- return results;
- }
-
- /**
- * Requires that Registry objects are created earlier. Problem is, we might
- * not know their names a priori.
- *
- * @param registry
- * @return
- * @throws RegistryContentException
- */
- private Registry setupRegistry(Registry registry)
- throws RegistryContentException {
+ private OWLOntology getOntologyForRegistryLocationNoCached(URI location) {
+ OWLOntologyManagerFactoryImpl factory = onm.getOntologyManagerFactory();
+ IRI iri = IRI.create(location);
+ try {
+ if (factory != null) return factory.createOntologyManager(true).loadOntologyFromOntologyDocument(
+ iri);
+ else return OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(iri);
+ } catch (OWLOntologyCreationException e) {
+ log.error("KReS :: Registry loader failed to load ontology at " + location, e);
+ return null;
+ }
+ }
+
+ public Object getParent(Object child) {
+ if (child instanceof AbstractRegistryItem) {
+ return ((RegistryItem) child).getParent();
+ }
+ return null;
+ }
+
+ private Set<OWLIndividual> getParentContainer(OWLNamedIndividual child, OWLOntology ontology) {
+
+ if (child.getObjectPropertyValues(ontology).containsKey(isPartOf)
+ || child.getObjectPropertyValues(ontology).containsKey(isOntologyOf)) {
+ Set<OWLIndividual> partOfSet = child.getObjectPropertyValues(ontology).get(isPartOf);
+ Set<OWLIndividual> ontologyOfSet = child.getObjectPropertyValues(ontology).get(isOntologyOf);
+
+ Set<OWLIndividual> mergedSet = new HashSet<OWLIndividual>();
+ if (partOfSet != null) mergedSet.addAll(partOfSet);
+ if (ontologyOfSet != null) mergedSet.addAll(ontologyOfSet);
+ return mergedSet;
+ } else return new HashSet<OWLIndividual>();
+ }
+
+ private Set<OWLNamedIndividual> getParts(OWLIndividual parent, OWLOntology ontology) {
+ Set<OWLNamedIndividual> indies = ontology.getIndividualsInSignature();
+ Iterator<OWLNamedIndividual> iter = indies.iterator();
+ Set<OWLNamedIndividual> tor = new HashSet<OWLNamedIndividual>();
+ // For each individual in this ontology
+ while (iter.hasNext()) {
+ OWLNamedIndividual n = iter.next();
+ // Get its parent wrt to isPartOf or isOntologyOf relationships
+ for (OWLIndividual i : this.getParentContainer(n, ontology)) {
+ if (i.equals(parent)) {
+ tor.add(n);
+ break;
+ }
+ }
+ }
+ return tor;
+ }
+
+ private List<Registry> getRegistries() {
+ List<Registry> registries = new ArrayList<Registry>();
+ // String storedStringValue = XDRegistryPlugin.getDefault()
+ // .getPreferenceStore().getString(
+ // PreferenceConstants.P_ODP_REGISTRIES);
+ String[] regs = new String[] {}/*
+ * URLListEditor .parsePreferenceStoreValue (storedStringValue)
+ */;
+
+ for (int i = 0; i < regs.length; i++) {
+ Registry registry1 = null;
+ try {
+ // TODO Find a way to obtain registry names
+ String registryName = ""/*
+ * URLListEditor .parseNameValueString(regs[i])[0]
+ */;
+ // TODO Find a way to obtain registry locations
+ String registryLocation = ""/*
+ * URLListEditor .parseNameValueString(regs[i])[1]
+ */;
+ registry1 = new Registry(registryName);
+ registry1.setURL(new URL(registryLocation));
+ } catch (Exception e) {
+ if (registry1 != null) {
+ registry1.setError(e.getLocalizedMessage());
+ log.error("KReS :: Error on ODP registry: " + registry1.getName(), e);
+ }
+ }
+ if (registry1 != null) registries.add(registry1);
+ else log.error("KReS :: Cannot load ODP registry: " + regs[i]);
+ }
+ return registries;
+ }
+
+ private List<Registry> getRegistries(XDRegistrySource source) {
+
+ List<Registry> registries = new ArrayList<Registry>();
+
+ if (source.getPhysicalIRI() != null) {
- // For each registry:
- registry.removeChildren();
- OWLOntology ontology = getMergedOntology(registry.getURL());
-
- // TODO: Restore ODP cache manager.
- // setManager(ODPRegistryCacheManager.getManager());
- Set<OWLIndividual> folderSet = cRegistryLibrary
- .getIndividuals(ontology);
-
- // Look for first level elements;
- Iterator<OWLIndividual> iter = folderSet.iterator();
- while (iter.hasNext()) {
- OWLIndividual i = iter.next();
- if (i instanceof OWLNamedIndividual) {
- if (!i.getObjectPropertyValues(ontology).containsKey(isPartOf)
- && !i.getObjectPropertyValues(ontology).containsKey(
- isOntologyOf)) {
- registry.addChild(this.getTree((OWLNamedIndividual) i,
- ontology));
- }
- }
- }
+ } else if (source.isInputStreamAvailable()) {
- return registry;
- }
+ } else if (source.isReaderAvailable()) {
+
+ }
+
+ return registries;
+ }
+
+ private RegistryLibrary getTree(OWLNamedIndividual i, OWLOntology ontology) {
+
+ RegistryLibrary to = new RegistryLibrary(
+ new RDFSLabelGetter(ontology, i.getIRI(), false).getPreferred());
+ try {
+ Set<OWLNamedIndividual> children = this.getParts(i, ontology);
+ if (children.size() == 0) return to;
+ for (OWLNamedIndividual childIndividual : children) {
+ if (isLibrary(childIndividual, ontology)) {
+ RegistryLibrary t = this.getTree(childIndividual, ontology);
+ t.setURL(childIndividual.getIRI().toURI().toURL());
+ to.addChild(t);
+ } else if (isOntology(childIndividual, ontology)) {
+ RegistryOntology t = new RegistryOntology(new RDFSLabelGetter(ontology,
+ childIndividual.getIRI(), false).getPreferred());
+ t.setURL(childIndividual.getIRI().toURI().toURL());
+ to.addChild(t);
+ }
+ }
+ } catch (MalformedURLException e) {
+ log.error("KReS :: MalformedURLException caught while getting tree for " + i.getIRI(), e);
+
+ }
+ return to;
+ }
+
+ public boolean hasChildren(Object parent) {
+ if (parent instanceof RegistryLibrary) return ((RegistryLibrary) parent).hasChildren();
+ return false;
+ }
+
+ public boolean hasLibrary(Registry reg, IRI libraryID) {
+ for (RegistryItem child : reg.getChildren()) {
+ try {
+ if (child.isLibrary() && IRI.create(child.getURL()).equals(libraryID)) return true;
+ } catch (URISyntaxException e) {
+ // If some URL is not well-formed here and there, sticazzi
+ continue;
+ }
+ }
+ return false;
+ }
+
+ private boolean isLibrary(OWLIndividual indy, OWLOntology ontology) {
+ OWLClass folderClass = OWLManager.getOWLDataFactory().getOWLClass(
+ IRI.create(CODOVocabulary.CODD_OntologyLibrary));
+ return (folderClass.getIndividuals(ontology).contains(indy));
+ }
+
+ private boolean isOntology(OWLIndividual indy, OWLOntology ontology) {
+ OWLClass ontologyClass = OWLManager.getOWLDataFactory().getOWLClass(
+ IRI.create(CODOVocabulary.CODK_Ontology));
+ return (ontologyClass.getIndividuals(ontology).contains(indy));
+ }
+
+ @Override
+ public Registry loadLibraryEager(IRI registryPhysicalIRI, IRI libraryID) {
+ Registry registry = null;
+ OWLOntologyManager mgr = onm.getOwlCacheManager();// getManager();
+
+ try {
+ OWLOntology ontology = mgr.loadOntology(registryPhysicalIRI);
+ for (OWLIndividual ind : cRegistryLibrary.getIndividuals(ontology))
+ if (ind.isNamed()) {
+ OWLNamedIndividual nind = ind.asOWLNamedIndividual();
+ IRI regiri = nind.getIRI();
+ if (!regiri.equals(libraryID)) continue;
+ registry = new Registry(regiri.getFragment());
+ try {
+ // TODO: avoid using toURL crap
+ registry.setURL(regiri.toURI().toURL());
+ } catch (MalformedURLException e) {
+ // Why should a well-formed IRI be a malformed URL anyway ?
+ log.warn("Ontology document IRI " + registryPhysicalIRI
+ + " matches a malformed URI pattern.", e);
+ }
+ // Find the ontologies in this registry. If this is individual is not "ontology of" or
+ // "part of", then proceed.
+ if (!nind.getObjectPropertyValues(ontology).containsKey(isPartOf)
+ && !nind.getObjectPropertyValues(ontology).containsKey(isOntologyOf)) {
+ registry.addChild(this.getTree((OWLNamedIndividual) nind, ontology));
+ }
+ }
+ } catch (OWLOntologyDocumentAlreadyExistsException e) {
+ log.warn("Ontology document at " + e.getOntologyDocumentIRI()
+ + " exists and will not be reloaded.", e);
+ } catch (OWLOntologyAlreadyExistsException e) {
+ log.warn("KReS :: ontology " + e.getOntologyID() + " exists and will not be reloaded.", e);
+ // Do nothing. Existing ontologies are fine.
+ } catch (OWLOntologyCreationException e) {
+ log.error("KReS :: Could not load ontology " + registryPhysicalIRI + " .", e);
+ } finally {}
+ return registry;
+ }
+
+ public void loadLocations() throws RegistryContentException {
+
+ try {
+
+ registryOntologiesCache.clear();
+ List<Registry> registries = getRegistries();
+
+ int regsize = registries.size();
+ int c = 0;
+ for (Registry current : registries) {
+ c++;
+ log.debug("Loading " + current.toString() + " [" + c + "/" + regsize + "]");
+ if (!ODPRegistryCacheManager.registryContains(current.getURL().toURI())) {
+ try {
+ log.debug("Fetching: " + current.getURL().toURI());
+ registryOntologiesCache.put(current.getURL().toURI(),
+ ODPRegistryCacheManager.getOntology(current.getURL().toURI()));
+ } catch (URIUnresolvableException e) {
+ log.error("KReS :: could not resolve URI " + current.getURL().toURI(), e);
+ registryOntologiesCache.put(current.getURL().toURI(), null);
+ } catch (ODPRegistryCacheException e) {
+ log.error("KReS :: failed to cache ontology " + current.getURL().toURI(), e);
+ registryOntologiesCache.put(current.getURL().toURI(), null);
+ }
+ }
+ }
+ c = 0;
+ for (Registry registry : registries) {
+ c++;
+ try {
+ registry = setupRegistry(registry);
+ } catch (RegistryContentException e) {
+ registry.setError(" [Unable to load from location " + registry.getURL().toString() + "]");
+ }
+ }
+ } catch (Throwable th) {
+ log.error("KreS :: Exception occurred while trying to get registry locations.", th);
+ }
+ }
+
+ /**
+ * The ontology at <code>physicalIRI</code> may in turn include more than one registry.
+ *
+ * @param physicalIRI
+ * @return
+ */
+ public Set<Registry> loadRegistriesEager(IRI physicalIRI) {
+
+ Set<Registry> results = new HashSet<Registry>();
+ OWLOntologyManager mgr = onm.getOwlCacheManager();// getManager();
+
+ try {
+ OWLOntology ontology = mgr.loadOntology(physicalIRI);
+ for (OWLIndividual ind : cRegistryLibrary.getIndividuals(ontology))
+ if (ind.isNamed()) {
+ OWLNamedIndividual nind = ind.asOWLNamedIndividual();
+ IRI regiri = nind.getIRI();
+ Registry registry = new Registry(regiri.getFragment());
+ try {
+ // TODO: avoid using toURL crap
+ registry.setURL(regiri.toURI().toURL());
+ } catch (MalformedURLException e) {
+ // Why should a well-formed IRI be a malformed URL
+ // anyway ?
+ log.warn("KReS :: ontology document IRI " + physicalIRI
+ + " matches a malformed URI pattern.", e);
+ }
+ // Find the ontologies in this registry
+ // If this is individual is not "ontology of" or "part of",
+ // then proceed.
+ if (!nind.getObjectPropertyValues(ontology).containsKey(isPartOf)
+ && !nind.getObjectPropertyValues(ontology).containsKey(isOntologyOf)) {
+ registry.addChild(this.getTree((OWLNamedIndividual) nind, ontology));
+ }
+ results.add(registry);
+ }
+ } catch (OWLOntologyDocumentAlreadyExistsException e) {
+ log.warn("Ontology document at" + e.getOntologyDocumentIRI()
+ + " exists and will not be reloaded.", e);
+ } catch (OWLOntologyAlreadyExistsException e) {
+ log.warn("KReS :: ontology " + e.getOntologyID() + " exists and will not be reloaded.", e);
+ // Do nothing. Existing ontologies are fine.
+ } catch (OWLOntologyCreationException e) {
+ log.error("KReS :: Could not load ontology " + physicalIRI + " .", e);
+ } finally {}
+ return results;
+ }
+
+ /**
+ * Requires that Registry objects are created earlier. Problem is, we might not know their names a priori.
+ *
+ * @param registry
+ * @return
+ * @throws RegistryContentException
+ */
+ private Registry setupRegistry(Registry registry) throws RegistryContentException {
+
+ // For each registry:
+ registry.removeChildren();
+ OWLOntology ontology = getMergedOntology(registry.getURL());
+
+ // TODO: Restore ODP cache manager.
+ // setManager(ODPRegistryCacheManager.getManager());
+ Set<OWLIndividual> folderSet = cRegistryLibrary.getIndividuals(ontology);
+
+ // Look for first level elements;
+ Iterator<OWLIndividual> iter = folderSet.iterator();
+ while (iter.hasNext()) {
+ OWLIndividual i = iter.next();
+ if (i instanceof OWLNamedIndividual) {
+ if (!i.getObjectPropertyValues(ontology).containsKey(isPartOf)
+ && !i.getObjectPropertyValues(ontology).containsKey(isOntologyOf)) {
+ registry.addChild(this.getTree((OWLNamedIndividual) i, ontology));
+ }
+ }
+ }
+
+ return registry;
+ }
}