private float execute(OntClass c1, OntClass c2) { int max = 0, min = 0; Collection<OntProperty> listaProps2 = OntologyCache.getOrAddListProperties(c2); for (Iterator i = OntologyCache.getOrAddListProperties(c1).iterator(); i.hasNext(); ) { OntProperty p1 = (OntProperty) i.next(); if (p1.isDatatypeProperty()) { max += 1; for (OntProperty p2 : listaProps2) { if (p2.isDatatypeProperty()) { SimilarityVO similarityVO = new SimilarityVO(); similarityVO.setElementA(p1); similarityVO.setElementB(p2); similarityVO.setSimilarity( strategyEditDistance.compute(p1.getLocalName(), p2.getLocalName())); similaridade.add(similarityVO); } } } } // Loop para pegar o numero de datatypeproperty de c2 for (OntProperty p2 : listaProps2) if (p2.isDatatypeProperty()) min += 1; similaridade = strategyCalculation.explore(similaridade); return averageWithPenalty(sumSimilarities(), max, min); }
@Override public UpdateContainer doIt(VWorkspace vWorkspace) throws CommandException { OntologyManager ontMgr = vWorkspace.getWorkspace().getOntologyManager(); JSONArray classesList = new JSONArray(); JSONArray classesMap = new JSONArray(); JSONArray propertiesList = new JSONArray(); JSONArray propertiesMap = new JSONArray(); Map<String, String> prefixMap = vWorkspace.getWorkspace().getOntologyManager().getPrefixMap(); ExtendedIterator<OntClass> iter = ontMgr.getOntModel().listNamedClasses(); // ExtendedIterator<DatatypeProperty> propsIter = ontMgr.getOntModel() // .listDatatypeProperties(); ExtendedIterator<OntProperty> propsIter = ontMgr.getOntModel().listAllOntProperties(); final JSONObject outputObj = new JSONObject(); try { while (iter.hasNext()) { OntClass cls = iter.next(); String pr = prefixMap.get(cls.getNameSpace()); String classLabel = cls.getLocalName(); // if (cls.getLabel(null) != null && !cls.getLabel(null).equals("")) // classLabel = cls.getLabel(null); String clsStr = (pr != null && !pr.equals("")) ? pr + ":" + classLabel : classLabel; classesList.put(clsStr); JSONObject classKey = new JSONObject(); classKey.put(clsStr, cls.getURI()); classesMap.put(classKey); } while (propsIter.hasNext()) { // DatatypeProperty prop = propsIter.next(); OntProperty prop = propsIter.next(); if (prop.isObjectProperty() && !prop.isDatatypeProperty()) continue; String pr = prefixMap.get(prop.getNameSpace()); String propLabel = prop.getLocalName(); // if (prop.getLabel(null) != null && !prop.getLabel(null).equals("")) // propLabel = prop.getLabel(null); String propStr = (pr != null && !pr.equals("")) ? pr + ":" + propLabel : propLabel; propertiesList.put(propStr); JSONObject propKey = new JSONObject(); propKey.put(propStr, prop.getURI()); propertiesMap.put(propKey); } // Populate the JSON object that will hold everything in output outputObj.put(JsonKeys.classList.name(), classesList); outputObj.put(JsonKeys.classMap.name(), classesMap); outputObj.put(JsonKeys.propertyList.name(), propertiesList); outputObj.put(JsonKeys.propertyMap.name(), propertiesMap); } catch (JSONException e) { logger.error("Error populating JSON!"); } UpdateContainer upd = new UpdateContainer( new AbstractUpdate() { @Override public void generateJson(String prefix, PrintWriter pw, VWorkspace vWorkspace) { pw.print(outputObj.toString()); } }); return upd; }