public void retrieveRoomsMap() { // this method retrieves the rooms to be insserted in the two rooms lists. // it deposits the retrieved data in a map where the key is the room name (String) and the value // is the corresponding entity IRI. // the above data structure will be used in passing the entity IRIs in the jess working memory // when constructing the facts // when the respective room name (String) is selected in the rooms list combo box. for (OWLSubClassOfAxiom scoAx : topIxOnt.getSubClassAxiomsForSuperClass( OWLFactory.getOWLClass( IRI.create( "http://www.semanticweb.org/ontologies/ptyxiaki_v0.6/2011/5/Ontology1308067064597.owl#Room")))) { String tmpS = scoAx.getSubClass().toString(); Set<OWLAnnotationAssertionAxiom> tmpAnnSet = topIxOnt.getAnnotationAssertionAxioms( IRI.create(tmpS.substring(tmpS.indexOf('<') + 1, tmpS.indexOf('>')))); for (OWLAnnotationAssertionAxiom aaAx : tmpAnnSet) { if (aaAx.getProperty() .toString() .equals( "<http://www.semanticweb.org/ontologies/ptyxiaki_v0.6/2011/5/Ontology1308067064597.owl#classID>")) { roomToIRI.put( aaAx.getValue().toString().substring(1, aaAx.getValue().toString().indexOf('^') - 1), tmpS.substring(tmpS.indexOf('<') + 1, tmpS.indexOf('>'))); } } } }
public Map<String, OWLIndividual> returnSitesInOntology() { // map that contains the correspondance between the names of the sites // and their OWLIndividual representations. Map<String, OWLIndividual> returnMap = new HashMap<>(); List<OWLIndividual> returnList = new ArrayList<>(); OWLAnnotationProperty hasNameAnnotationProperty = OWLFactory.getOWLAnnotationProperty(":individualName", topIxPrefixManager); OWLClassExpression tempSiteClassExpression = OWLFactory.getOWLClass(":Site", topIxPrefixManager); for (OWLClassAssertionAxiom tempClassAssAx : topIxOnt.getClassAssertionAxioms(tempSiteClassExpression)) { returnList.add(tempClassAssAx.getIndividual()); Set<OWLAnnotationAssertionAxiom> tempSiteAnnotationsSet = topIxOnt.getAnnotationAssertionAxioms( tempClassAssAx.getIndividual().asOWLNamedIndividual().getIRI()); for (OWLAnnotationAssertionAxiom tempAnnotationAssertionAxiom : tempSiteAnnotationsSet) { if (tempAnnotationAssertionAxiom.getProperty().equals(hasNameAnnotationProperty)) { String tempString = tempAnnotationAssertionAxiom.getValue().toString(); logger.info(tempString); tempString = tempString.substring(tempString.indexOf('"') + 1, tempString.indexOf('^') - 1); logger.info(tempString); logger.info(tempClassAssAx.getIndividual().toString()); returnMap.put(tempString, tempClassAssAx.getIndividual()); } } } return returnMap; }
//////////////////////////////// // INDIVIDUAL ASSERTION METHODS// //////////////////////////////// public boolean assertSiteIndividual(String siteNameHash, String siteNameAnnotation) { OWLClassExpression tmpCE = OWLFactory.getOWLClass(":Site", topIxPrefixManager); OWLIndividual tmpInd = OWLFactory.getOWLNamedIndividual(':' + siteNameHash, topIxPrefixManager); manager.addAxiom(topIxOnt, OWLFactory.getOWLClassAssertionAxiom(tmpCE, tmpInd)); manager.addAxiom( topIxOnt, OWLFactory.getOWLAnnotationAssertionAxiom( OWLFactory.getOWLAnnotationProperty( IRI.create( topIxOnt.getOntologyID().getOntologyIRI().toString() + '#' + "individualName")), IRI.create(topIxOnt.getOntologyID().getOntologyIRI().toString() + '#' + siteNameHash), OWLFactory.getOWLLiteral(siteNameAnnotation))); return true; }
public boolean assertHouseIndividual(String houseEntryHash, String houseEntryAnnotation) { OWLClassExpression tempClassExpression = OWLFactory.getOWLClass(":House", topIxPrefixManager); OWLIndividual tempIndividual = OWLFactory.getOWLNamedIndividual(':' + houseEntryHash, topIxPrefixManager); manager.addAxiom( topIxOnt, OWLFactory.getOWLClassAssertionAxiom(tempClassExpression, tempIndividual)); manager.addAxiom( topIxOnt, OWLFactory.getOWLAnnotationAssertionAxiom( OWLFactory.getOWLAnnotationProperty( IRI.create( topIxOnt.getOntologyID().getOntologyIRI().toString() + '#' + "individualName")), IRI.create(topIxOnt.getOntologyID().getOntologyIRI().toString() + '#' + houseEntryHash), OWLFactory.getOWLLiteral(houseEntryAnnotation))); return true; }
public boolean assertRoomIndividual( String roomName, String roomIndividualHash, String roomIndividualAnnotation) { OWLClassExpression tempClassExpression = OWLFactory.getOWLClass( IRI.create( roomToIRI.get( roomName))); // retrieves the Room Class IRI fron the roomToIRI map, using // roomID as a key. OWLIndividual tempIndividual = OWLFactory.getOWLNamedIndividual(':' + roomIndividualHash, topIxPrefixManager); manager.addAxiom( topIxOnt, OWLFactory.getOWLClassAssertionAxiom(tempClassExpression, tempIndividual)); manager.addAxiom( topIxOnt, OWLFactory.getOWLAnnotationAssertionAxiom( OWLFactory.getOWLAnnotationProperty( IRI.create( topIxOnt.getOntologyID().getOntologyIRI().toString() + '#' + "individualName")), IRI.create( topIxOnt.getOntologyID().getOntologyIRI().toString() + '#' + roomIndividualHash), OWLFactory.getOWLLiteral(String.format(roomIndividualAnnotation)))); return true; }
public boolean retrieveSolutions(String siteNameHash) { // use the siteNameHash to access a certain Site individual in the ontology // retrieve each Solution individual of this site and use it to re-initialise the Solutions List OwlSolution tempSolution; OwlSolvedHouse tempSolvedHouse; OwlSolvedRoom tempSolvedRoom; // first clear the Solution List contents... this.solutionsList.clear(); OWLIndividual tempSiteIndividual = OWLFactory.getOWLNamedIndividual(":" + siteNameHash, topIxPrefixManager); OWLClassExpression tempSolutionClassExpression = OWLFactory.getOWLClass(":Solution", topIxPrefixManager); Set<OWLObjectPropertyAssertionAxiom> tempSitePropertyAxioms = topIxOnt.getObjectPropertyAssertionAxioms(tempSiteIndividual); Set<OWLIndividual> tempSolutionIndividuals = new HashSet<>(); // Solution individuals for this particular site. will be filled below... Set<OWLIndividual> tempSolvedHouseIndividuals = new HashSet<>(); Set<OWLIndividual> tempSolvedRoomIndividuals = new HashSet<>(); // populate the tempSolutionIndividuals Set<OWLIndividual> // with the Solution individuals that are solutions of the current Site // this block runs through the set of all the object property axioms // that have this site as their subject // and filters out the ones that are of type "hasSolution" for (OWLObjectPropertyAssertionAxiom tempObjPropAssAx : tempSitePropertyAxioms) { OWLObjectProperty tempHasSolutionObjectProperty = OWLFactory.getOWLObjectProperty( IRI.create(topIxOnt.getOntologyID().getOntologyIRI() + "#hasSolution")); if (tempObjPropAssAx.getProperty() == tempHasSolutionObjectProperty) { tempSolutionIndividuals.add(tempObjPropAssAx.getObject()); } } // retrieving the site dimensions for this solution set // (the site remains the same throughout the plethos of solutions). int tempSiteLength = 0; int tempSiteWidth = 0; OWLDataProperty siteHasLengthProp = OWLFactory.getOWLDataProperty(":hasX", topIxPrefixManager); OWLDataProperty siteHasWidthProp = OWLFactory.getOWLDataProperty(":hasY", topIxPrefixManager); Set<OWLDataPropertyAssertionAxiom> tempSiteDataProperties = new HashSet<>(); tempSiteDataProperties = topIxOnt.getDataPropertyAssertionAxioms(tempSiteIndividual); for (OWLDataPropertyAssertionAxiom tempSiteDataProperty : tempSiteDataProperties) { if (tempSiteDataProperty.getProperty() == siteHasLengthProp) { tempSiteLength = tempSiteDataProperty.getObject().parseInteger(); } if (tempSiteDataProperty.getProperty() == siteHasWidthProp) { tempSiteWidth = tempSiteDataProperty.getObject().parseInteger(); } } logger.info(tempSolutionIndividuals.size()); // running every solution individual for/of that particular site in order // to extract the solvedHouse's and the solvedRoom's // via the hasSolvedHouse and hasSolvedRoom properties. int solutionCounter = 0; for (OWLIndividual tempSolutionIndividual : tempSolutionIndividuals) { tempSolution = new OwlSolution(); tempSolution.setSolutionID(new Integer(++solutionCounter)); tempSolution.setSiteLength(new Integer(tempSiteLength)); tempSolution.setSiteWidth(new Integer(tempSiteWidth)); // clearing the contents of these two structuresin order to accommodate the solved entities of // the next solution. tempSolvedHouseIndividuals.clear(); tempSolvedRoomIndividuals.clear(); for (OWLObjectPropertyAssertionAxiom tempObjPropAssAx : topIxOnt.getObjectPropertyAssertionAxioms(tempSolutionIndividual)) { OWLObjectProperty tempHasSolvedHouseObjectProperty = OWLFactory.getOWLObjectProperty( IRI.create(topIxOnt.getOntologyID().getOntologyIRI() + "#hasSolvedHouse")); OWLObjectProperty tempHasSolvedRoomObjectProperty = OWLFactory.getOWLObjectProperty( IRI.create(topIxOnt.getOntologyID().getOntologyIRI() + "#hasSolvedRoom")); if (tempObjPropAssAx.getProperty() == tempHasSolvedHouseObjectProperty) { tempSolvedHouseIndividuals.add(tempObjPropAssAx.getObject()); } else if (tempObjPropAssAx.getProperty() == tempHasSolvedRoomObjectProperty) { tempSolvedRoomIndividuals.add(tempObjPropAssAx.getObject()); } } for (OWLIndividual tempSolvedHouseIndividual : tempSolvedHouseIndividuals) { tempSolvedHouse = new OwlSolvedHouse(); for (OWLDataPropertyAssertionAxiom tempDatPropAssAx : topIxOnt.getDataPropertyAssertionAxioms(tempSolvedHouseIndividual)) { if (tempDatPropAssAx.getProperty() == (OWLFactory.getOWLDataProperty(":hasL", topIxPrefixManager))) { // logger.info(tempDatPropAssAx.getObject().parseInteger()); tempSolvedHouse.setSolvedHouseLength(tempDatPropAssAx.getObject().parseInteger()); } else if (tempDatPropAssAx.getProperty() == (OWLFactory.getOWLDataProperty(":hasW", topIxPrefixManager))) { tempSolvedHouse.setSolvedHouseWidth(tempDatPropAssAx.getObject().parseInteger()); } else if (tempDatPropAssAx.getProperty() == (OWLFactory.getOWLDataProperty(":hasX", topIxPrefixManager))) { tempSolvedHouse.setSolvedHouseX(tempDatPropAssAx.getObject().parseInteger()); } else if (tempDatPropAssAx.getProperty() == (OWLFactory.getOWLDataProperty(":hasY", topIxPrefixManager))) { tempSolvedHouse.setSolvedHouseY(tempDatPropAssAx.getObject().parseInteger()); } else if (tempDatPropAssAx.getProperty() == (OWLFactory.getOWLDataProperty(":hasLiteral", topIxPrefixManager))) { tempSolvedHouse.setSolvedHouseLiteral(tempDatPropAssAx.getObject().getLiteral()); } } // logger.info(tempSolvedHouse.getSolvedHouseX()+" "+tempSolvedHouse.getSolvedHouseY()); tempSolution.getSolvedHouses().add(tempSolvedHouse); } for (OWLIndividual tempSolvedRoomIndividual : tempSolvedRoomIndividuals) { tempSolvedRoom = new OwlSolvedRoom(); for (OWLDataPropertyAssertionAxiom tempDatPropAssAx : topIxOnt.getDataPropertyAssertionAxioms(tempSolvedRoomIndividual)) { if (tempDatPropAssAx.getProperty() == (OWLFactory.getOWLDataProperty(":hasL", topIxPrefixManager))) { tempSolvedRoom.setSolvedRoomLength(tempDatPropAssAx.getObject().parseInteger()); } else if (tempDatPropAssAx.getProperty() == (OWLFactory.getOWLDataProperty(":hasW", topIxPrefixManager))) { tempSolvedRoom.setSolvedRoomWidth(tempDatPropAssAx.getObject().parseInteger()); } else if (tempDatPropAssAx.getProperty() == (OWLFactory.getOWLDataProperty(":hasH", topIxPrefixManager))) { tempSolvedRoom.setSolvedRoomHeight(tempDatPropAssAx.getObject().parseInteger()); } else if (tempDatPropAssAx.getProperty() == (OWLFactory.getOWLDataProperty(":hasX", topIxPrefixManager))) { tempSolvedRoom.setSolvedRoomX(tempDatPropAssAx.getObject().parseInteger()); } else if (tempDatPropAssAx.getProperty() == (OWLFactory.getOWLDataProperty(":hasY", topIxPrefixManager))) { tempSolvedRoom.setSolvedRoomY(tempDatPropAssAx.getObject().parseInteger()); } else if (tempDatPropAssAx.getProperty() == (OWLFactory.getOWLDataProperty(":hasZ", topIxPrefixManager))) { tempSolvedRoom.setSolvedRoomZ(tempDatPropAssAx.getObject().parseInteger()); } else if (tempDatPropAssAx.getProperty() == (OWLFactory.getOWLDataProperty(":hasLiteral", topIxPrefixManager))) { tempSolvedRoom.setSolvedRoomLiteral(tempDatPropAssAx.getObject().getLiteral()); } } tempSolution.getSolvedRooms().add(tempSolvedRoom); } this.solutionsList.add(tempSolution); } return true; }
public boolean storeSolutions(String siteNameHash) { for (OwlSolution tempSolution : solutionsList) { // assert Solution individual and assert Site->hasSolution OWLClassExpression solutionClassExpression = OWLFactory.getOWLClass(":Solution", topIxPrefixManager); String tempSolutionID = String.format(siteNameHash + "_S_%1$02d", tempSolution.getSolutionID().intValue()); OWLIndividual tempSolutionIndividual = OWLFactory.getOWLNamedIndividual(":" + tempSolutionID, topIxPrefixManager); OWLClassAssertionAxiom tempClassAssertionAxiom = OWLFactory.getOWLClassAssertionAxiom(solutionClassExpression, tempSolutionIndividual); manager.addAxiom(topIxOnt, tempClassAssertionAxiom); OWLObjectProperty tempSolutionObjectProperty = OWLFactory.getOWLObjectProperty(":hasSolution", topIxPrefixManager); OWLIndividual tempSiteIndividual = OWLFactory.getOWLNamedIndividual(":" + siteNameHash, topIxPrefixManager); OWLObjectPropertyAssertionAxiom tempObjPropAssAxiom = OWLFactory.getOWLObjectPropertyAssertionAxiom( tempSolutionObjectProperty, tempSiteIndividual, tempSolutionIndividual); manager.addAxiom(topIxOnt, tempObjPropAssAxiom); // assert SolvedHouse individuals and assert Solution->hasSolvedHouse objProperty. also assert // the DATA PROPERTIES for each solvedHouse indvidual for (OwlSolvedHouse tempSolvedHouse : tempSolution.getSolvedHouses()) { // logger.info("373"); // logger.info(tempSolution.getSolvedHouses().toString()); OWLClassExpression solvedHouseClassExpression = OWLFactory.getOWLClass(":SolvedHouse", topIxPrefixManager); OWLIndividual tempSolvedHouseIndividual = OWLFactory.getOWLNamedIndividual( ":" + tempSolutionID + "_SH_" + tempSolvedHouse.getSolvedHouseHash(), topIxPrefixManager); OWLClassAssertionAxiom tempClassAssAx = OWLFactory.getOWLClassAssertionAxiom( solvedHouseClassExpression, tempSolvedHouseIndividual); manager.addAxiom(topIxOnt, tempClassAssAx); OWLObjectProperty tempSolvedHouseObjectProperty = OWLFactory.getOWLObjectProperty(":hasSolvedHouse", topIxPrefixManager); OWLObjectPropertyAssertionAxiom tempHouseObjPropAssAx = OWLFactory.getOWLObjectPropertyAssertionAxiom( tempSolvedHouseObjectProperty, tempSolutionIndividual, tempSolvedHouseIndividual); manager.addAxiom(topIxOnt, tempHouseObjPropAssAx); OWLDataProperty tempDataProperty; OWLDataPropertyAssertionAxiom tempDataPropertyAssertionAxiom; tempDataProperty = OWLFactory.getOWLDataProperty(":hasLiteral", topIxPrefixManager); tempDataPropertyAssertionAxiom = OWLFactory.getOWLDataPropertyAssertionAxiom( tempDataProperty, tempSolvedHouseIndividual, tempSolvedHouse.getSolvedHouseLiteral()); manager.addAxiom(topIxOnt, tempDataPropertyAssertionAxiom); tempDataProperty = OWLFactory.getOWLDataProperty(":hasL", topIxPrefixManager); tempDataPropertyAssertionAxiom = OWLFactory.getOWLDataPropertyAssertionAxiom( tempDataProperty, tempSolvedHouseIndividual, tempSolvedHouse.getSolvedHouseLength()); manager.addAxiom(topIxOnt, tempDataPropertyAssertionAxiom); tempDataProperty = OWLFactory.getOWLDataProperty(":hasW", topIxPrefixManager); tempDataPropertyAssertionAxiom = OWLFactory.getOWLDataPropertyAssertionAxiom( tempDataProperty, tempSolvedHouseIndividual, tempSolvedHouse.getSolvedHouseWidth()); manager.addAxiom(topIxOnt, tempDataPropertyAssertionAxiom); tempDataProperty = OWLFactory.getOWLDataProperty(":hasX", topIxPrefixManager); tempDataPropertyAssertionAxiom = OWLFactory.getOWLDataPropertyAssertionAxiom( tempDataProperty, tempSolvedHouseIndividual, tempSolvedHouse.getSolvedHouseX()); manager.addAxiom(topIxOnt, tempDataPropertyAssertionAxiom); tempDataProperty = OWLFactory.getOWLDataProperty(":hasY", topIxPrefixManager); tempDataPropertyAssertionAxiom = OWLFactory.getOWLDataPropertyAssertionAxiom( tempDataProperty, tempSolvedHouseIndividual, tempSolvedHouse.getSolvedHouseY()); manager.addAxiom(topIxOnt, tempDataPropertyAssertionAxiom); // logger.info("asserts the house"); // logger.info(tempSolvedHouse.getSolvedHouseLiteral()); } // assert SolvedRoom individuals and assert Solution->hasSolvedRoom objProperty. also assert // the DATA PROPERTIES for each solvedRoom indvidual for (OwlSolvedRoom tempSolvedRoom : tempSolution.getSolvedRooms()) { OWLClassExpression solvedRoomClassExpression = OWLFactory.getOWLClass(":SolvedRoom", topIxPrefixManager); OWLIndividual tempSolvedRoomIndividual = OWLFactory.getOWLNamedIndividual( ":" + tempSolutionID + "_SR_" + tempSolvedRoom.getSolvedRoomHash(), topIxPrefixManager); OWLClassAssertionAxiom tempClassAssAx = OWLFactory.getOWLClassAssertionAxiom( solvedRoomClassExpression, tempSolvedRoomIndividual); manager.addAxiom(topIxOnt, tempClassAssAx); OWLObjectProperty tempSolvedRoomObjectProperty = OWLFactory.getOWLObjectProperty(":hasSolvedRoom", topIxPrefixManager); OWLObjectPropertyAssertionAxiom tempRoomObjPropAssAx = OWLFactory.getOWLObjectPropertyAssertionAxiom( tempSolvedRoomObjectProperty, tempSolutionIndividual, tempSolvedRoomIndividual); manager.addAxiom(topIxOnt, tempRoomObjPropAssAx); OWLDataProperty tempDataProperty; OWLDataPropertyAssertionAxiom tempDataPropertyAssertionAxiom; tempDataProperty = OWLFactory.getOWLDataProperty(":hasLiteral", topIxPrefixManager); tempDataPropertyAssertionAxiom = OWLFactory.getOWLDataPropertyAssertionAxiom( tempDataProperty, tempSolvedRoomIndividual, tempSolvedRoom.getSolvedRoomLiteral()); manager.addAxiom(topIxOnt, tempDataPropertyAssertionAxiom); tempDataProperty = OWLFactory.getOWLDataProperty(":hasL", topIxPrefixManager); tempDataPropertyAssertionAxiom = OWLFactory.getOWLDataPropertyAssertionAxiom( tempDataProperty, tempSolvedRoomIndividual, tempSolvedRoom.getSolvedRoomLength()); manager.addAxiom(topIxOnt, tempDataPropertyAssertionAxiom); tempDataProperty = OWLFactory.getOWLDataProperty(":hasW", topIxPrefixManager); tempDataPropertyAssertionAxiom = OWLFactory.getOWLDataPropertyAssertionAxiom( tempDataProperty, tempSolvedRoomIndividual, tempSolvedRoom.getSolvedRoomWidth()); manager.addAxiom(topIxOnt, tempDataPropertyAssertionAxiom); tempDataProperty = OWLFactory.getOWLDataProperty(":hasH", topIxPrefixManager); tempDataPropertyAssertionAxiom = OWLFactory.getOWLDataPropertyAssertionAxiom( tempDataProperty, tempSolvedRoomIndividual, tempSolvedRoom.getSolvedRoomHeight()); manager.addAxiom(topIxOnt, tempDataPropertyAssertionAxiom); tempDataProperty = OWLFactory.getOWLDataProperty(":hasX", topIxPrefixManager); tempDataPropertyAssertionAxiom = OWLFactory.getOWLDataPropertyAssertionAxiom( tempDataProperty, tempSolvedRoomIndividual, tempSolvedRoom.getSolvedRoomX()); manager.addAxiom(topIxOnt, tempDataPropertyAssertionAxiom); tempDataProperty = OWLFactory.getOWLDataProperty(":hasY", topIxPrefixManager); tempDataPropertyAssertionAxiom = OWLFactory.getOWLDataPropertyAssertionAxiom( tempDataProperty, tempSolvedRoomIndividual, tempSolvedRoom.getSolvedRoomY()); manager.addAxiom(topIxOnt, tempDataPropertyAssertionAxiom); tempDataProperty = OWLFactory.getOWLDataProperty(":hasZ", topIxPrefixManager); tempDataPropertyAssertionAxiom = OWLFactory.getOWLDataPropertyAssertionAxiom( tempDataProperty, tempSolvedRoomIndividual, tempSolvedRoom.getSolvedRoomZ()); manager.addAxiom(topIxOnt, tempDataPropertyAssertionAxiom); } } return true; }