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 HashMap<String, Class> getMobiRangesObjectProperty( String nameJenaObjectProperty, boolean isCompositionRelation) { HashMap<String, Class> hashRanges = new HashMap<String, Class>(); if (isCompositionRelation) { for (CompositionRelation c : this.mobi.getAllCompositionRelations().values()) { if (this.mobi .getPropertyName(c.getNameA(), c.getClassA(), c.getClassB()) .equals(nameJenaObjectProperty) && !hashRanges.containsKey(c.getClassB().getUri())) hashRanges.put(c.getClassB().getUri(), c.getClassB()); if (c.getNameB() != null && this.mobi .getPropertyName(c.getNameB(), c.getClassB(), c.getClassA()) .equals(nameJenaObjectProperty) && !hashRanges.containsKey(c.getClassA().getUri())) hashRanges.put(c.getClassA().getUri(), c.getClassA()); } } else { for (SymmetricRelation s : this.mobi.getAllSymmetricRelations().values()) { if (this.mobi .getPropertyName(s.getName(), s.getClassA(), s.getClassB()) .equals(nameJenaObjectProperty) && !hashRanges.containsKey(s.getClassB().getUri())) hashRanges.put(s.getClassB().getUri(), s.getClassB()); } } return hashRanges; }
public void exportSymmetricRelations() throws ExceptionSymmetricRelation { HashMap<String, HashMap<String, HashMap<String, Integer>>> relationsPropertys = new HashMap<String, HashMap<String, HashMap<String, Integer>>>(); HashMap<String, HashMap<String, HashMap<String, Class>>> listRestrictions = new HashMap<String, HashMap<String, HashMap<String, Class>>>(); for (SymmetricRelation symmetricRelation : this.mobi.getAllSymmetricRelations().values()) { String nameJenaObjectProperty = this.mobi.getPropertyName( symmetricRelation.getName(), symmetricRelation.getClassA(), symmetricRelation.getClassB()); for (CompositionRelation cr : this.mobi.getAllCompositionRelations().values()) { if ((this.mobi .getPropertyName(cr.getNameA(), cr.getClassA(), cr.getClassB()) .equals(nameJenaObjectProperty)) || (cr.getNameB() != null && this.mobi .getPropertyName(cr.getNameB(), cr.getClassB(), cr.getClassA()) .equals(nameJenaObjectProperty))) throw new ExceptionSymmetricRelation( "Could not create OWL file. There is another composition relation with the name: " + nameJenaObjectProperty + " for this symmetric relation."); } OntClass classeA = this.createJenaClass(symmetricRelation.getClassA()); OntClass classeB = this.createJenaClass(symmetricRelation.getClassB()); if (!relationsPropertys.containsKey(nameJenaObjectProperty)) relationsPropertys.put( nameJenaObjectProperty, new HashMap<String, HashMap<String, Integer>>()); if (!((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectProperty)) .containsKey(symmetricRelation.getClassA().getUri())) ((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectProperty)) .put(symmetricRelation.getClassA().getUri(), new HashMap<String, Integer>()); if (!((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectProperty)) .containsKey(symmetricRelation.getClassB().getUri())) ((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectProperty)) .put(symmetricRelation.getClassB().getUri(), new HashMap<String, Integer>()); if (!listRestrictions.containsKey(nameJenaObjectProperty)) listRestrictions.put(nameJenaObjectProperty, new HashMap<String, HashMap<String, Class>>()); if (!listRestrictions .get(nameJenaObjectProperty) .containsKey(symmetricRelation.getClassA().getUri())) listRestrictions .get(nameJenaObjectProperty) .put(symmetricRelation.getClassA().getUri(), new HashMap<String, Class>()); if (!listRestrictions .get(nameJenaObjectProperty) .get(symmetricRelation.getClassA().getUri()) .containsKey(symmetricRelation.getClassB().getUri())) listRestrictions .get(nameJenaObjectProperty) .get(symmetricRelation.getClassA().getUri()) .put(symmetricRelation.getClassB().getUri(), symmetricRelation.getClassB()); if (!listRestrictions .get(nameJenaObjectProperty) .containsKey(symmetricRelation.getClassB().getUri())) listRestrictions .get(nameJenaObjectProperty) .put(symmetricRelation.getClassB().getUri(), new HashMap<String, Class>()); if (!listRestrictions .get(nameJenaObjectProperty) .get(symmetricRelation.getClassB().getUri()) .containsKey(symmetricRelation.getClassA().getUri())) listRestrictions .get(nameJenaObjectProperty) .get(symmetricRelation.getClassB().getUri()) .put(symmetricRelation.getClassA().getUri(), symmetricRelation.getClassA()); ObjectProperty objectProperty = this.jena.createObjectProperty(this.ontologyPrefix + nameJenaObjectProperty); SymmetricProperty p = objectProperty.convertToSymmetricProperty(); p.setInverseOf(p); p.setDomain(this.getJenaDomainsObjectProperty(nameJenaObjectProperty, false)); p.setRange(this.getJenaRangesObjectProperty(nameJenaObjectProperty, false)); for (InstanceRelation instanceRelation : symmetricRelation.getInstanceRelationMapA().values()) { Individual individual = this.jena.createIndividual( this.ontologyPrefix + instanceRelation.getInstance().getUri(), classeA); for (Instance instance : instanceRelation.getAllInstances().values()) { Individual individualv1 = this.jena.createIndividual(this.ontologyPrefix + instance.getUri(), classeB); individualv1.addProperty(objectProperty, individual); individual.addProperty(objectProperty, individualv1); if (!((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectProperty)) .get(symmetricRelation.getClassA().getUri()) .containsKey(instanceRelation.getInstance().getUri())) ((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectProperty)) .get(symmetricRelation.getClassA().getUri()) .put(instanceRelation.getInstance().getUri(), 1); else { Integer count = ((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectProperty)) .get(symmetricRelation.getClassA().getUri()) .get(instanceRelation.getInstance().getUri()); ((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectProperty)) .get(symmetricRelation.getClassA().getUri()) .put(instanceRelation.getInstance().getUri(), count + 1); } } } for (InstanceRelation instanceRelation : symmetricRelation.getInstanceRelationMapB().values()) { Individual individual = this.jena.createIndividual( this.ontologyPrefix + instanceRelation.getInstance().getUri(), classeB); for (Instance instance : instanceRelation.getAllInstances().values()) { Individual individualv1 = this.jena.createIndividual(this.ontologyPrefix + instance.getUri(), classeA); individual.addProperty(objectProperty, individualv1); individualv1.addProperty(objectProperty, individual); } } } Set<String> keysRestrictions = listRestrictions.keySet(); for (String keyRestriction : keysRestrictions) { HashMap<String, HashMap<String, Class>> listRestrictions2 = listRestrictions.get(keyRestriction); Set<String> keysRestrictions2 = listRestrictions2.keySet(); for (String keyRestriction2 : keysRestrictions2) { this.createJenaRestriction( this.jena.createObjectProperty(this.ontologyPrefix + keyRestriction), this.jena.createClass(this.ontologyPrefix + keyRestriction2), this.createUnionJenaClassFromMobiClass(listRestrictions2.get(keyRestriction2)), Mobi2OWL.RESTRICTION_ALLVALUES); } } this.convertToFunctionalOrInverseFunctionalProperty(relationsPropertys, false); }
public void exportCompositionRelations() throws ExceptionInverseRelation, ExceptionSymmetricRelation { HashMap<String, HashMap<String, HashMap<String, Integer>>> relationsPropertys = new HashMap<String, HashMap<String, HashMap<String, Integer>>>(); HashMap<String, HashMap<String, HashMap<String, Class>>> listRestrictions = new HashMap<String, HashMap<String, HashMap<String, Class>>>(); for (CompositionRelation cr : this.mobi.getAllCompositionRelations().values()) { for (SymmetricRelation sr : this.mobi.getAllSymmetricRelations().values()) { if (this.mobi .getPropertyName(sr.getName(), sr.getClassA(), sr.getClassB()) .equals(this.mobi.getPropertyName(cr.getNameA(), cr.getClassA(), cr.getClassB()))) throw new ExceptionSymmetricRelation( "Unable to generate the OWL file, as it has a symmetrical relationship with the name: " + this.mobi.getPropertyName(cr.getNameA(), cr.getClassA(), cr.getClassB()) + " for this relationship composition."); if (cr.getNameB() != null && this.mobi .getPropertyName(cr.getNameB(), cr.getClassB(), cr.getClassA()) .equals(this.mobi.getPropertyName(sr.getName(), sr.getClassA(), sr.getClassB()))) throw new ExceptionSymmetricRelation( "Unable to generate the OWL file, as it has a symmetrical relationship with the name:" + this.mobi.getPropertyName(cr.getNameB(), cr.getClassB(), cr.getClassA()) + " for this relationship composition."); } OntClass classA = this.createJenaClass(cr.getClassA()); OntClass classB = this.createJenaClass(cr.getClassB()); ObjectProperty objectPropertyA = null, objectPropertyB = null; String nameJenaObjectPropertyA = null, nameJenaObjectPropertyB = null; if (cr.getNameA() != null) { nameJenaObjectPropertyA = this.mobi.getPropertyName(cr.getNameA(), cr.getClassA(), cr.getClassB()); objectPropertyA = this.jena.createObjectProperty(this.ontologyPrefix + nameJenaObjectPropertyA, false); objectPropertyA.setDomain(this.getJenaDomainsObjectProperty(nameJenaObjectPropertyA, true)); objectPropertyA.setRange(this.getJenaRangesObjectProperty(nameJenaObjectPropertyA, true)); if (!relationsPropertys.containsKey(nameJenaObjectPropertyA)) relationsPropertys.put( nameJenaObjectPropertyA, new HashMap<String, HashMap<String, Integer>>()); if (!((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectPropertyA)) .containsKey(cr.getClassA().getUri())) ((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectPropertyA)) .put(cr.getClassA().getUri(), new HashMap<String, Integer>()); if (this.getMobiDomainsObjectProperty(nameJenaObjectPropertyA, true).size() > 1) { if (!listRestrictions.containsKey(nameJenaObjectPropertyA)) listRestrictions.put( nameJenaObjectPropertyA, new HashMap<String, HashMap<String, Class>>()); if (!listRestrictions.get(nameJenaObjectPropertyA).containsKey(cr.getClassA().getUri())) listRestrictions .get(nameJenaObjectPropertyA) .put(cr.getClassA().getUri(), new HashMap<String, Class>()); if (!listRestrictions .get(nameJenaObjectPropertyA) .get(cr.getClassA().getUri()) .containsKey(cr.getClassB().getUri())) listRestrictions .get(nameJenaObjectPropertyA) .get(cr.getClassA().getUri()) .put(cr.getClassB().getUri(), cr.getClassB()); } } if (cr.getNameB() != null) { nameJenaObjectPropertyB = this.mobi.getPropertyName(cr.getNameB(), cr.getClassB(), cr.getClassA()); String nameInversePropertyA = this.mobi.getInversePropertyName(nameJenaObjectPropertyB); String nameInversePropertyB = this.mobi.getInversePropertyName(nameJenaObjectPropertyA); if (!nameInversePropertyA.equals(nameJenaObjectPropertyA)) throw new ExceptionInverseRelation( "Unable to generate the OWL file, as the inverse of the" + nameJenaObjectPropertyB + " is the property" + nameInversePropertyA + ". Thus, the property" + nameJenaObjectPropertyA + " can not be attributed to the reverse of the latter."); if (!nameInversePropertyB.equals(nameJenaObjectPropertyB)) throw new ExceptionInverseRelation( "Unable to generate the OWL file, as the inverse of the" + nameJenaObjectPropertyA + " is the property " + nameInversePropertyB + ". Thus, the property" + nameJenaObjectPropertyB + " can not be attributed to the reverse of the latter."); if (nameInversePropertyA.equals(nameInversePropertyB)) throw new ExceptionInverseRelation( "Unable to generate the OWL file as a composition of two-way relationship with the names of the inverse and direct the same to be characterized as a symmetrical relationship."); objectPropertyB = this.jena.createObjectProperty(this.ontologyPrefix + nameJenaObjectPropertyB, false); objectPropertyB.setDomain(this.getJenaDomainsObjectProperty(nameJenaObjectPropertyB, true)); objectPropertyB.setRange(this.getJenaRangesObjectProperty(nameJenaObjectPropertyB, true)); if (!relationsPropertys.containsKey(nameJenaObjectPropertyB)) relationsPropertys.put( nameJenaObjectPropertyB, new HashMap<String, HashMap<String, Integer>>()); if (!((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectPropertyB)) .containsKey(cr.getClassB().getUri())) ((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectPropertyB)) .put(cr.getClassB().getUri(), new HashMap<String, Integer>()); if (this.getMobiDomainsObjectProperty(nameJenaObjectPropertyB, true).size() > 1) { if (!listRestrictions.containsKey(nameJenaObjectPropertyB)) listRestrictions.put( nameJenaObjectPropertyB, new HashMap<String, HashMap<String, Class>>()); if (!listRestrictions.get(nameJenaObjectPropertyB).containsKey(cr.getClassB().getUri())) listRestrictions .get(nameJenaObjectPropertyB) .put(cr.getClassB().getUri(), new HashMap<String, Class>()); if (!listRestrictions .get(nameJenaObjectPropertyB) .get(cr.getClassB().getUri()) .containsKey(cr.getClassA().getUri())) listRestrictions .get(nameJenaObjectPropertyB) .get(cr.getClassB().getUri()) .put(cr.getClassA().getUri(), cr.getClassA()); } } if ((cr.getNameA() != null) && (cr.getNameB() != null)) { objectPropertyA.setInverseOf(objectPropertyB); objectPropertyB.setInverseOf(objectPropertyA); } for (InstanceRelation instanceRelation : cr.getInstanceRelationMapA().values()) { Individual individualA = this.jena.createIndividual( this.ontologyPrefix + instanceRelation.getInstance().getUri(), classA); for (Instance instance : instanceRelation.getAllInstances().values()) { Individual individualB = jena.createIndividual(this.ontologyPrefix + instance.getUri(), classB); if (cr.getNameA() != null) { individualA.addProperty(objectPropertyA, individualB); if (!((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectPropertyA)) .get(cr.getClassA().getUri()) .containsKey(instanceRelation.getInstance().getUri())) ((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectPropertyA)) .get(cr.getClassA().getUri()) .put(instanceRelation.getInstance().getUri(), 1); else { Integer count = ((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectPropertyA)) .get(cr.getClassA().getUri()) .get(instanceRelation.getInstance().getUri()); ((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectPropertyA)) .get(cr.getClassA().getUri()) .put(instanceRelation.getInstance().getUri(), count + 1); } } if (cr.getNameB() != null) { individualB.addProperty(objectPropertyB, individualA); if (!((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectPropertyB)) .get(cr.getClassB().getUri()) .containsKey(instance.getUri())) ((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectPropertyB)) .get(cr.getClassB().getUri()) .put(instance.getUri(), 1); else { Integer count = ((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectPropertyB)) .get(cr.getClassB().getUri()) .get(instance.getUri()); ((HashMap<String, HashMap<String, Integer>>) relationsPropertys.get(nameJenaObjectPropertyB)) .get(cr.getClassB().getUri()) .put(instance.getUri(), count + 1); } } } } } Set<String> keysRestrictions1 = listRestrictions.keySet(); for (String keyRestriction1 : keysRestrictions1) { HashMap<String, HashMap<String, Class>> listRestrictions2 = listRestrictions.get(keyRestriction1); Set<String> keysRestrictions2 = listRestrictions2.keySet(); for (String keyRestriction2 : keysRestrictions2) { this.createJenaRestriction( this.jena.createObjectProperty(this.ontologyPrefix + keyRestriction1), this.jena.createClass(this.ontologyPrefix + keyRestriction2), this.createUnionJenaClassFromMobiClass(listRestrictions2.get(keyRestriction2)), RESTRICTION_ALLVALUES); } } this.convertToFunctionalOrInverseFunctionalProperty(relationsPropertys, true); }