private OntClass createJenaClass(Class mobiClass) { OntClass jenaClasse = this.jena.createClass(this.ontologyPrefix + mobiClass.getUri()); if (mobiClass.getComment() != null) { jenaClasse.setComment(mobiClass.getComment(), null); } return jenaClasse; }
public void exportInstances() { for (Instance instance : this.mobi.getAllInstances().values()) { for (Class mobiClass : this.mobi.getInstanceClasses(instance)) { OntClass ontClassA = this.createJenaClass(mobiClass); Class mobiBaseClass = instance.getBaseClass(); Individual instanceJena = this.jena.getIndividual(this.ontologyPrefix + instance.getUri()); if (mobiBaseClass != null) { OntClass ontBaseClass = this.createJenaClass(mobiBaseClass); if (!mobiBaseClass.getUri().equals(mobiClass.getUri())) ontBaseClass.addSubClass(ontClassA); if (instanceJena == null) { instanceJena = this.jena.createIndividual(this.ontologyPrefix + instance.getUri(), ontBaseClass); instanceJena.addOntClass(ontClassA); } else { instanceJena.addOntClass(ontBaseClass); instanceJena.addOntClass(ontClassA); } } else { if (instanceJena == null) instanceJena = this.jena.createIndividual(this.ontologyPrefix + instance.getUri(), ontClassA); else instanceJena.addOntClass(ontClassA); } } } }
public static void LeDominio(String path) { try { Mobi2OWL mobiOWL = new Mobi2OWL(); mobiOWL.importForMobiOfOWL(path); Mobi mobi = mobiOWL.getMobi(); for (Class mobiClass : mobi.getAllClasses().values()) { System.out.println( "==================Reading Class: " + mobiClass.getUri().toUpperCase() + "=================="); System.out.println(">>>Instances Belonging to Class"); for (Instance instance : mobi.getClassInstances(mobiClass.getUri())) { System.out.println(instance.getUri()); } System.out.println( "==================End of Class: " + mobiClass.getUri().toUpperCase() + "=================="); } for (InheritanceRelation inheritance : mobi.getAllInheritanceRelations().values()) { System.out.println("==================Reading Relation Inheritance=================="); System.out.println("SUPER CLASS: " + inheritance.getClassA().getUri()); System.out.println("SUB CLASS: " + inheritance.getClassB().getUri()); System.out.println("NAME: " + inheritance.getUri()); System.out.println("Reading Relations between instances"); for (InstanceRelation instanceRelation : inheritance.getInstanceRelationMapA().values()) { System.out.println( "Instance " + instanceRelation.getInstance().getUri().toUpperCase() + " has values: "); for (Instance instance : instanceRelation.getAllInstances().values()) System.out.println(instance.getUri().toUpperCase()); } System.out.println("==================End of Relation=================="); } for (EquivalenceRelation equivalence : mobi.getAllEquivalenceRelations().values()) { System.out.println("==================Reading Relation=================="); System.out.println("CLASS A: " + equivalence.getClassA().getUri()); System.out.println("CLASS B: " + equivalence.getClassB().getUri()); System.out.println("NAME: " + equivalence.getUri()); System.out.println("Reading Relations between instances"); for (InstanceRelation instanceRelation : equivalence.getInstanceRelationMapA().values()) { System.out.println( "Instance " + instanceRelation.getInstance().getUri().toUpperCase() + " has values: "); for (Instance instance : instanceRelation.getAllInstances().values()) System.out.println(instance.getUri().toUpperCase()); } System.out.println("==================End of Relation=================="); } for (CompositionRelation composition : mobi.getAllCompositionRelations().values()) { System.out.println("==================Reading Relation Composition=================="); System.out.println("NAME A: " + composition.getNameA()); System.out.println("NAME B: " + composition.getNameB()); System.out.println("DOMAIN: " + composition.getClassA().getUri()); System.out.println("RANGE: " + composition.getClassB().getUri()); System.out.println("Reading Relations between instances"); for (InstanceRelation instanceRelation : composition.getInstanceRelationMapA().values()) { System.out.println( "Instance " + instanceRelation.getInstance().getUri().toUpperCase() + " has values: "); for (Instance instance : instanceRelation.getAllInstances().values()) System.out.println(instance.getUri().toUpperCase()); } System.out.println("==================End of Relation=================="); } } catch (Exception e) { e.printStackTrace(); } }
private void ImportRelationsInheritanceOrEquivalence(int typeRelation) throws Exception { List<OntClass> classes = this.jena.listClasses().toList(); for (OntClass jenaClass : classes) { Class mobiClass = new Class(jenaClass.getLocalName()); // this.mobi.getClass(jenaClass.getLocalName()); if (mobiClass != null) { List<OntClass> subClasses = null; if (typeRelation == Relation.INHERITANCE) subClasses = this.OntClassInheritanceChain(jenaClass.listSubClasses().toList()); else if (typeRelation == Relation.EQUIVALENCE) subClasses = jenaClass.listEquivalentClasses().toList(); for (OntClass jenaSubClass : subClasses) { if (jenaSubClass != null && !jenaSubClass.getLocalName().equals(mobiClass.getUri()) && jenaSubClass.listInstances().hasNext()) { // this.mobi.addConcept(mobiClass); Class mobiSubClass = new Class(jenaSubClass.getLocalName()); Relation relation = null; if (typeRelation == Relation.INHERITANCE) relation = this.mobi.createInheritanceRelation("isSuper"); else if (typeRelation == Relation.EQUIVALENCE) relation = this.mobi.createEquivalenceRelation("equals"); relation.setClassA(mobiClass); relation.setClassB(mobiSubClass); List<? extends OntResource> individualsClassA = jenaClass.listInstances().toList(); List<? extends OntResource> individualsClassB = jenaSubClass.listInstances().toList(); for (OntResource resourceA : individualsClassA) { Individual individualA = resourceA.asIndividual(); Instance instanceA = new Instance(individualA.getLocalName()); // this.mobi.getInstance(individualA.getLocalName()); for (OntResource resourceB : individualsClassB) { Individual individualB = resourceB.asIndividual(); Instance instanceB = new Instance(individualB.getLocalName()); // this.mobi.getInstance(individualB.getLocalName()); if (instanceB != null && instanceA.getUri().equals(instanceB.getUri())) { this.mobi.addConcept(mobiClass); this.mobi.addConcept(mobiSubClass); this.mobi.addConcept(instanceA); this.mobi.addConcept(instanceB); try { this.mobi.isOneOf(instanceA, mobiClass); this.mobi.isOneOf(instanceB, mobiSubClass); } catch (ExceptionURI e) { } this.mobi.addConcept(instanceB); relation.addInstanceRelation(instanceA, instanceB); } } } relation.processCardinality(); if (relation.getInstanceRelationMapA().size() > 0) this.mobi.addConcept(relation); } } } } }