Menu

A possible bug

Help
Jotomicron
2012-11-06
2013-04-23
  • Jotomicron

    Jotomicron - 2012-11-06

    Hello.

    I'm trying to use two OWLDB databases to manage my ontologies. They both refer to the same classes, but each contains a specific type of axioms. Currently, this is what I'm doing:

    import java.util.Set;
    import org.hibernate.PropertyAccessException;
    import org.semanticweb.owlapi.apibinding.OWLManager;
    import org.semanticweb.owlapi.model.AxiomType;
    import org.semanticweb.owlapi.model.IRI;
    import org.semanticweb.owlapi.model.OWLAnnotation;
    import org.semanticweb.owlapi.model.OWLAnnotationProperty;
    import org.semanticweb.owlapi.model.OWLAnnotationValue;
    import org.semanticweb.owlapi.model.OWLClass;
    import org.semanticweb.owlapi.model.OWLDataFactory;
    import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom;
    import org.semanticweb.owlapi.model.OWLLiteral;
    import org.semanticweb.owlapi.model.OWLOntology;
    import org.semanticweb.owlapi.model.OWLOntologyCreationException;
    import org.semanticweb.owlapi.model.OWLOntologyManager;
    import de.fraunhofer.iitb.owldb.OWLDBManager;
    import de.fraunhofer.iitb.owldb.OWLDBOntologyManager;
    public class DisjointFetcher {
        
        private static OWLOntologyManager    ontologyManager;
        private static OWLDataFactory        dataFactory;
        private static OWLOntology           mainOntology;
        private static OWLOntology           disjointsOntology;
        
        private static OWLAnnotationProperty rdfsLabel;
        private static IRI mainOntologyIRI;
        private static IRI disjointsOntologyIRI;
        
        public static void main(String[] args) throws OWLOntologyCreationException {
            mainOntologyIRI = IRI.create("jdbc:mysql://localhost/main_owldb");
            disjointsOntologyIRI = IRI.create("jdbc:mysql://localhost/disjoints_owldb");
            
            dataFactory = OWLManager.getOWLDataFactory();
            ontologyManager = OWLDBManager.createOWLOntologyManager(dataFactory);
            rdfsLabel = dataFactory.getRDFSLabel();
            
            mainOntology = ((OWLDBOntologyManager) ontologyManager).loadOntology(mainOntologyIRI);
            disjointsOntology = ((OWLDBOntologyManager) ontologyManager).loadOntology(disjointsOntologyIRI);
            
            for (OWLDisjointClassesAxiom axiom : disjointsOntology.getAxioms(AxiomType.DISJOINT_CLASSES)) {
                System.out.println("Pairwaise disjoint:");
                for (OWLClass owlClass : axiom.getClassesInSignature()) {
                    System.out.printf("    %s\t\"%s\"\n", getLabel(owlClass), name);
                }
                System.out.println();
            }
        }
        
        private static String getLabel(OWLClass owlClass) {
            try {
                Set<OWLAnnotation> annotations = owlClass.getAnnotations(mainOntology, rdfsLabel);
                for (OWLAnnotation owlAnnotation : annotations) {
                    OWLAnnotationValue value = owlAnnotation.getValue();
                    if (value instanceof OWLLiteral)
                        return ((OWLLiteral) value).getLiteral();
                }
            }
            catch (PropertyAccessException ex) {
                System.out.println(owlClass);
                throw ex;
            }
            return null;
        }
    }
    

    This class results in this error:

    org.hibernate.PropertyAccessException: could not set a field value by reflection setter of uk.ac.manchester.cs.owl.owlapi.OWLLiteralImpl.datatype
       ...
    Caused by: java.lang.IllegalArgumentException: Can not set org.semanticweb.owlapi.model.OWLDatatype field uk.ac.manchester.cs.owl.owlapi.OWLLiteralImpl.datatype to uk.ac.manchester.cs.owl.owlapi.OWLClassImpl
       ...
    

    I'm not entirely sure this is a bug in owldb, hibernate or if it's an error on my code (or even an error on the .owl file, but since the ontology was successfully imported into the database I don't think it can be a problem of that kind).

    Could this be caused by accessing two different ontologies at the same time?
    Can you think of any hint that can help me solve this issue?

    Thank you very much.

     
  • Jürgen Moßgraber

    We noticed this problem in a project as well but could not track it down. It seems to be related to how the owlapi classes work which seems to conflict somehow with Hibernate.

     

Log in to post a comment.

MongoDB Logo MongoDB