List of usage examples for org.jdom2 Element setAttribute
public Element setAttribute(final String name, final String value)
This sets an attribute value for this element.
From source file:delfos.group.io.xml.casestudy.GroupCaseStudyXML.java
License:Open Source License
private static void caseStudyToXMLFile_aggregateResults(GroupCaseStudy caseStudyGroup, File file) { if (!caseStudyGroup.isFinished()) { throw new UnsupportedOperationException("No se ha ejecutado el caso de uso todava"); }/* ww w . ja va2 s . c o m*/ Document doc = new Document(); Element casoDeUso = new Element(CASE_ROOT_ELEMENT_NAME); casoDeUso.setAttribute(SeedHolder.SEED.getName(), Long.toString(caseStudyGroup.getSeedValue())); casoDeUso.setAttribute(NUM_EXEC_ATTRIBUTE_NAME, Integer.toString(caseStudyGroup.getNumExecutions())); casoDeUso.setAttribute(ParameterOwner.ALIAS.getName(), caseStudyGroup.getAlias()); casoDeUso.setAttribute(HASH_ATTRIBUTE_NAME, Integer.toString(caseStudyGroup.hashCode())); casoDeUso.setAttribute(HASH_DATA_VALIDATION_ATTRIBUTE_NAME, Integer.toString(caseStudyGroup.hashDataValidation())); casoDeUso.setAttribute(HASH_TECHNIQUE_ATTRIBUTE_NAME, Integer.toString(caseStudyGroup.hashTechnique())); casoDeUso.addContent(GroupRecommenderSystemXML.getElement(caseStudyGroup.getGroupRecommenderSystem())); casoDeUso.addContent(DatasetLoaderXML.getElement(caseStudyGroup.getDatasetLoader())); casoDeUso.addContent(GroupFormationTechniqueXML.getElement(caseStudyGroup.getGroupFormationTechnique())); casoDeUso.addContent(ValidationTechniqueXML.getElement(caseStudyGroup.getValidationTechnique())); casoDeUso.addContent(GroupPredictionProtocolXML.getElement(caseStudyGroup.getGroupPredictionProtocol())); casoDeUso.addContent(RelevanceCriteriaXML.getElement(caseStudyGroup.getRelevanceCriteria())); casoDeUso.addContent(getAggregatedResultsElement(caseStudyGroup)); doc.addContent(casoDeUso); XMLOutputter outputter = new XMLOutputter(Constants.getXMLFormat()); FileUtilities.createDirectoriesForFile(file); try (FileWriter fileWriter = new FileWriter(file)) { outputter.output(doc, fileWriter); } catch (IOException ex) { ERROR_CODES.CANNOT_WRITE_RESULTS_FILE.exit(ex); } }
From source file:delfos.group.io.xml.evaluationmeasures.PRSpaceGroupsXML.java
License:Open Source License
public static Element getElement(ConfusionMatricesCurve curve) { Element measureElement = new Element(MEASURE_ELEMENT); measureElement.setAttribute(GroupEvaluationMeasure.VALUE, Double.toString(curve.getAreaPRSpace())); Element detailedResultElement = new Element(DETAILED_RESULT_ELEMENT); for (int i = 1; i < curve.size(); i++) { String precision = Double.toString(curve.getPrecisionAt(i)); String recall = Double.toString(curve.getRecallAt(i)); Element curvePointElement = new Element(CURVE_POINT_ELEMENT); curvePointElement.setAttribute(K_ATTRIBUTE, Integer.toString(i)); curvePointElement.setAttribute(PRECISION_ATTRIBUTE, precision); curvePointElement.setAttribute(RECALL_ATTRIBUTE, recall); detailedResultElement.addContent(curvePointElement); }//from w ww . ja v a 2 s . c om measureElement.addContent(detailedResultElement); Element confusionMatricesCurveElement = ConfusionMatricesCurveXML.getElement(curve); measureElement.addContent(confusionMatricesCurveElement); return measureElement; }
From source file:delfos.group.io.xml.grs.GroupRecommenderSystemXML.java
License:Open Source License
/** * Construye el objeto en memoria que representa al sistema de recomendacin * para grupos descrito en el elemento que se pasa por parmetro. * * @param grsElement Objeto XML que describe el sistema de recomendacin * para grupos// w ww . j av a 2 s .c o m * @return Sistema de recomendacin para grupos recuperado del elemento. */ public static GroupRecommenderSystem<Object, Object> getGroupRecommenderSystem(Element grsElement) { String name = grsElement.getAttributeValue(ParameterOwnerXML.PARAMETER_OWNER_ATTRIBUTE_NAME); String parameterOwnerType = grsElement.getAttributeValue(ParameterOwnerXML.PARAMETER_OWNER_ATTRIBUTE_TYPE); if (parameterOwnerType == null) { grsElement.setAttribute(ParameterOwnerXML.PARAMETER_OWNER_ATTRIBUTE_TYPE, ParameterOwnerType.RECOMMENDER_SYSTEM.name()); } ParameterOwner parameterOwner = ParameterOwnerXML.getParameterOwner(grsElement); if (parameterOwner instanceof GroupRecommenderSystem) { GroupRecommenderSystem groupRecommenderSystem = (GroupRecommenderSystem) parameterOwner; return groupRecommenderSystem; } else { IllegalStateException ex = new IllegalStateException( "The XML does not have the expected structure: The loaded parameter owner is not a group recommender system [" + parameterOwner + "]"); ERROR_CODES.CANNOT_LOAD_CONFIG_FILE.exit(ex); throw ex; } }
From source file:delfos.group.io.xml.prefiltersforgroup.PreFilteringTechniqueXML.java
License:Open Source License
/** * Devuelve el elemento que describe totalmente el filtro, almacenando * tambin los parmetros que posee y su valor. * * @param groupRatingsPreFilter Filtro de valoraciones a almacenar * @return Objeto XML que lo describe//from w w w . j a v a2 s .c o m */ public static Element getElement(GroupRatingsFilter groupRatingsPreFilter) { Element groupRatingsPreFilterElement = new Element(PRE_FILTERING_TECHNIQUE_ELEMENT); groupRatingsPreFilterElement.setAttribute("name", groupRatingsPreFilter.getName()); for (Parameter p : groupRatingsPreFilter.getParameters()) { Element parameter = ParameterXML.getElement(groupRatingsPreFilter, p); groupRatingsPreFilterElement.addContent(parameter); } return groupRatingsPreFilterElement; }
From source file:delfos.group.results.groupevaluationmeasures.diversity.ils.IntraListSimilarity.java
License:Open Source License
private static synchronized Element getXMLElement(IntraListSimilarity intraListSimilarity, IntraListSimilarityByRecommendationLenght intraListSimilarityByRecommendationLenght) { double measureValue; if (intraListSimilarityByRecommendationLenght.size() >= intraListSimilarity.listSizeOfMeasure) { measureValue = intraListSimilarityByRecommendationLenght.getILS(intraListSimilarity.listSizeOfMeasure); } else {//from w w w.j a v a 2 s . co m measureValue = intraListSimilarityByRecommendationLenght .getILS(intraListSimilarityByRecommendationLenght.size()); } Element ilsXMLElement = new Element(intraListSimilarity.getClass().getSimpleName()); ilsXMLElement.setAttribute(GroupEvaluationMeasure.VALUE, Double.toString(measureValue)); Element detailedElement = new Element("ILSdetailed"); for (int listSize = 1; listSize <= intraListSimilarityByRecommendationLenght.size(); listSize++) { double intraListSimilarityValue = intraListSimilarityByRecommendationLenght.getILS(listSize); Element thisListSizeElement = new Element("Size"); thisListSizeElement.setAttribute("k", Integer.toString(listSize)); thisListSizeElement.setAttribute("ils", Double.toString(intraListSimilarityValue)); detailedElement.addContent(thisListSizeElement); } ilsXMLElement.setContent(detailedElement); return ilsXMLElement; }
From source file:delfos.group.results.groupevaluationmeasures.GroupEvaluationMeasureResult.java
License:Open Source License
public Element getXMLElement() { Element measureElement = new Element(groupEvaluationMeasure.getAlias()); measureElement.setAttribute(EvaluationMeasure.VALUE_ATTRIBUTE_NAME, Double.toString(value)); return measureElement; }
From source file:delfos.group.results.groupevaluationmeasures.NormalizedIndividualSatisfaction.java
License:Open Source License
@Override public GroupEvaluationMeasureResult getMeasureResult(GroupRecommenderSystemResult groupRecommenderSystemResult, DatasetLoader<? extends Rating> originalDatasetLoader, RelevanceCriteria relevanceCriteria, DatasetLoader<? extends Rating> trainingDatasetLoader, DatasetLoader<? extends Rating> testDatasetLoader) { MeanIterative media = new MeanIterative(); Element measureElement = new Element(getName()); for (GroupOfUsers groupOfUsers : groupRecommenderSystemResult.getGroupsOfUsers()) { Collection<Recommendation> groupRecommendations = groupRecommenderSystemResult .getGroupOutput(groupOfUsers).getRecommendations().getRecommendations(); Element groupElement = new Element("Group"); Map<Integer, Number> predicciones = new TreeMap<>(); groupRecommendations.stream().forEach((r) -> { predicciones.put(r.getIdItem(), r.getPreference()); });//from ww w. ja v a 2s . co m MeanIterative groupNIS = new MeanIterative(); for (int idUser : groupOfUsers) { Element userElement = new Element("User"); userElement.setAttribute("idUser", Integer.toString(idUser)); try { Map<Integer, ? extends Rating> userRated = testDatasetLoader.getRatingsDataset() .getUserRatingsRated(idUser); double denominador = 0; double numerador = 0; List<Recommendation> recomendacionesAlGrupoParaUser = new ArrayList<>(predicciones.size()); List<Recommendation> recomendacionesOptimasAlUser = new ArrayList<>(userRated.size()); for (int idItem : userRated.keySet()) { recomendacionesOptimasAlUser .add(new Recommendation(idItem, userRated.get(idItem).getRatingValue())); } int minLength = Math.min(recomendacionesAlGrupoParaUser.size(), recomendacionesOptimasAlUser.size()); Collections.sort(recomendacionesOptimasAlUser); recomendacionesOptimasAlUser = recomendacionesOptimasAlUser.subList(0, minLength); Collections.sort(recomendacionesAlGrupoParaUser); recomendacionesAlGrupoParaUser = recomendacionesAlGrupoParaUser.subList(0, minLength); for (Recommendation r : recomendacionesAlGrupoParaUser) { numerador += r.getPreference().doubleValue(); } for (Recommendation r : recomendacionesOptimasAlUser) { //Suma del mximo posible para este usuario denominador += r.getPreference().doubleValue(); } if (denominador != 0) { groupNIS.addValue(numerador / denominador); } userElement.setAttribute("normalizedIndividualSatisfaction", Double.toString(numerador / denominador)); } catch (UserNotFound ex) { ERROR_CODES.USER_NOT_FOUND.exit(ex); } groupElement.addContent(userElement); } groupElement.setAttribute("value", Double.toString(groupNIS.getMean())); media.addValue(groupNIS.getMean()); measureElement.addContent(groupElement); } measureElement.setAttribute("value", Double.toString(media.getMean())); return new GroupEvaluationMeasureResult(this, media.getMean()); }
From source file:delfos.group.results.groupevaluationmeasures.precisionrecall.PRSpace_EachMember.java
License:Open Source License
@Override public GroupEvaluationMeasureResult getMeasureResult(GroupRecommenderSystemResult groupRecommenderSystemResult, DatasetLoader<? extends Rating> originalDatasetLoader, RelevanceCriteria relevanceCriteria, DatasetLoader<? extends Rating> trainingDatasetLoader, DatasetLoader<? extends Rating> testDatasetLoader) { Map<GroupOfUsers, ConfusionMatricesCurve> groupsCurves = new TreeMap<>(); Element measureElement = new Element(getName()); for (GroupOfUsers group : groupRecommenderSystemResult.getGroupsOfUsers()) { Collection<Recommendation> groupRecommendations = groupRecommenderSystemResult.getGroupOutput(group) .getRecommendations().getRecommendations(); Set<Integer> recommendedItems = new TreeSet<>(); for (Recommendation r : groupRecommendations) { recommendedItems.add(r.getIdItem()); }/* w ww. ja v a 2 s . c o m*/ Element groupElement = new Element(GROUP_OF_USERS_ELEMENT); groupElement.setAttribute(USERS_ATTRIBUTE, group.getIdMembers().toString()); List<ConfusionMatrix> matrices = new ArrayList<>(); /** * Estas variables se utilizan en la generacin de la curva para el grupo, pero se pueden inicializar en el * clculo de la curva de cada usuario */ int truePositive_group = 0; int falseNegative_group = 0; int falsePositive_group = 0; int trueNegative_group = 0; /** * Almacena una lista de conjuntos. Cada elemento de la lista representa cada un conjunto con un booleano si * al usuario est satisfecho con esa recomendacin. */ List<Set<Boolean>> relevanteParaUser = new ArrayList<>(group.size()); for (int i = 0; i < groupRecommendations.size(); i++) { relevanteParaUser.add(new TreeSet<>()); } Map<Integer, ConfusionMatricesCurve> matricesParaCadaMiembro = new TreeMap<>(); for (int idUser : group.getIdMembers()) { Element userElement = new Element("User"); userElement.setAttribute("idUser", Integer.toString(idUser)); int truePositive = 0; int falseNegative = 0; int falsePositive = 0; int trueNegative = 0; Map<Integer, ? extends Rating> userRatings = null; try { userRatings = testDatasetLoader.getRatingsDataset().getUserRatingsRated(idUser); } catch (UserNotFound ex) { ERROR_CODES.USER_NOT_FOUND.exit(ex); throw new IllegalArgumentException(ex); } for (int idItem : userRatings.keySet()) { if (recommendedItems.contains(idItem) && relevanceCriteria.isRelevant(userRatings.get(idItem).getRatingValue())) { falseNegative++; } else { trueNegative++; } } falseNegative_group += falseNegative; trueNegative_group += trueNegative; int i = 0; for (Recommendation r : groupRecommendations) { int idItem = r.getIdItem(); if (!userRatings.containsKey(idItem)) { continue; } if (relevanceCriteria.isRelevant(userRatings.get(idItem).getRatingValue())) { relevanteParaUser.get(i).add(true); truePositive++; falseNegative--; } else { relevanteParaUser.get(i).add(false); falsePositive++; trueNegative--; } matrices.add(new ConfusionMatrix(falsePositive, falseNegative, truePositive, trueNegative)); i++; } matricesParaCadaMiembro.put(idUser, new ConfusionMatricesCurve(matrices.toArray(new ConfusionMatrix[1]))); //Aado la curva del usuario a los resultados del grupo userElement.addContent(ConfusionMatricesCurveXML.getElement(matricesParaCadaMiembro.get(idUser))); groupElement.addContent(userElement); } List<ConfusionMatrix> groupMatrices = new ArrayList<>(); //Ahora se calcula la curva para el grupo for (int i = 0; i < relevanteParaUser.size(); i++) { Set<Boolean> set = relevanteParaUser.get(i); for (boolean b : set) { if (b) { relevanteParaUser.get(i).add(true); truePositive_group++; falseNegative_group--; } else { relevanteParaUser.get(i).add(false); falsePositive_group++; trueNegative_group--; } } double precision; double recall; if (((double) truePositive_group + (double) falsePositive_group) == 0) { precision = 0; } else { precision = (double) truePositive_group / ((double) truePositive_group + (double) falsePositive_group); } if (((double) truePositive_group + (double) falseNegative_group) == 0) { recall = 0; } else { recall = (double) truePositive_group / ((double) truePositive_group + (double) falseNegative_group); } groupMatrices.add(new ConfusionMatrix(falsePositive_group, falseNegative_group, truePositive_group, trueNegative_group)); } groupsCurves.put(group, new ConfusionMatricesCurve(groupMatrices.toArray(new ConfusionMatrix[1]))); groupElement.addContent(ConfusionMatricesCurveXML.getElement(groupsCurves.get(group))); measureElement.addContent(groupElement); } ConfusionMatricesCurve curvaTotal = ConfusionMatricesCurve.mergeCurves(groupsCurves.values()); measureElement.addContent(ConfusionMatricesCurveXML.getElement(curvaTotal)); return new GroupEvaluationMeasureResult(this, curvaTotal.getAreaUnderROC()); }
From source file:delfos.group.results.groupevaluationmeasures.printers.neighbor.RecommendationsWithNeighborToXML.java
License:Open Source License
public static Element getNeighborsElement(String targetId, List<Neighbor> neighbors) { Element element = new Element(NEIGHBORS_ELEMENT_NAME); element.setAttribute(ID_TARGET_ATTRIBUTE_NAME, targetId); ArrayList<Neighbor> neighborsSortedById = new ArrayList<>(neighbors); Collections.sort(neighborsSortedById, Neighbor.BY_ID); List<Neighbor> neighborsSortedBySimilarity = new ArrayList<>(neighbors); Collections.sort(neighborsSortedBySimilarity, Neighbor.BY_SIMILARITY_DESC); Map<Neighbor, Integer> neighborsRank = new TreeMap<>(); neighborsSortedBySimilarity.stream().forEachOrdered(neighbor -> { neighborsRank.put(neighbor, neighborsRank.size() + 1); });//w ww . j a va 2 s . com neighborsSortedById.stream().forEachOrdered((neighbor) -> { element.addContent(getNeighborElement(neighbor, neighborsRank.get(neighbor))); }); if (Constants.isRawResultDefined()) { Element rawDataElement = new Element(NEIGHBORS_ELEMENT_NAME + "_RAW"); rawDataElement.setAttribute(ID_TARGET_ATTRIBUTE_NAME, targetId); StringBuilder rawData = new StringBuilder(); neighborsSortedById.stream().forEachOrdered((neighbor) -> { rawData.append(neighbor.getIdNeighbor()).append("\t").append(neighbor.getSimilarity()).append("\t") .append(neighborsRank.get(neighbor)).append("\n"); }); rawDataElement.addContent(rawData.toString()); element.addContent(rawDataElement); } return element; }
From source file:delfos.group.results.groupevaluationmeasures.printers.neighbor.RecommendationsWithNeighborToXML.java
License:Open Source License
private static Element getNeighborElement(Neighbor neighbor, int rank) { Element neighborElement = new Element("neighbor"); neighborElement.setAttribute(ID_NEIGHBOR_TTRIBUTE_NAME, Integer.toString(neighbor.getIdNeighbor())); neighborElement.setAttribute(SIMILARITY_ATTRIBUTE_NAME, Double.toString(neighbor.getSimilarity())); neighborElement.setAttribute(RANK_ATTRIBUTE_NAME, Integer.toString(rank)); return neighborElement; }