List of usage examples for org.jdom2 Element getAttributeValue
public String getAttributeValue(final String attname)
This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.
From source file:delfos.group.io.xml.casestudy.GroupCaseStudyXML.java
License:Open Source License
/** * Carga la descripcin de un caso de estudio para sistemas de recomendacin * para grupos./* ww w . ja v a 2s . c o m*/ * * @param file Archivo donde se encuentra almacenado el caso de estudio. * @return Caso de estudio recuperado del archivo. * @throws org.jdom2.JDOMException Cuando se intenta cargar un xml que no * tiene la estructura esperada. Chequear si esta desfasada la versin. * @throws IOException Cuando no se puede leer el archivo indicado o existe * algun fallo de conversin de datos al leer el contenido del mismo. */ public static GroupCaseStudyConfiguration loadGroupCaseDescription(File file) throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(file); Element caseStudy = doc.getRootElement(); if (!caseStudy.getName().equals(CASE_ROOT_ELEMENT_NAME)) { throw new IllegalArgumentException("The XML does not contains a Case Study."); } GroupRecommenderSystem<Object, Object> groupRecommenderSystem = GroupRecommenderSystemXML .getGroupRecommenderSystem(caseStudy.getChild(GroupRecommenderSystemXML.ELEMENT_NAME)); GroupFormationTechnique groupFormationTechnique = GroupFormationTechniqueXML .getGroupFormationTechnique(caseStudy.getChild(GroupFormationTechniqueXML.ELEMENT_NAME)); ValidationTechnique validationTechnique = ValidationTechniqueXML .getValidationTechnique(caseStudy.getChild(ValidationTechniqueXML.ELEMENT_NAME)); GroupPredictionProtocol groupPredictionProtocol = GroupPredictionProtocolXML .getGroupPredictionProtocol(caseStudy.getChild(GroupPredictionProtocolXML.ELEMENT_NAME)); RelevanceCriteria relevanceCriteria = RelevanceCriteriaXML .getRelevanceCriteria(caseStudy.getChild(RelevanceCriteriaXML.ELEMENT_NAME)); DatasetLoader<? extends Rating> datasetLoader = DatasetLoaderXML .getDatasetLoader(caseStudy.getChild(DatasetLoaderXML.ELEMENT_NAME)); long seed = Long.parseLong(caseStudy.getAttributeValue(SeedHolder.SEED.getName())); int numExecutions = Integer.parseInt(caseStudy.getAttributeValue(NUM_EXEC_ATTRIBUTE_NAME)); String caseStudyAlias = caseStudy.getAttributeValue(ParameterOwner.ALIAS.getName()); return new GroupCaseStudyConfiguration(groupRecommenderSystem, datasetLoader, groupFormationTechnique, validationTechnique, groupPredictionProtocol, relevanceCriteria, caseStudyAlias, numExecutions, seed, null); }
From source file:delfos.group.io.xml.casestudy.GroupCaseStudyXML.java
License:Open Source License
/** * Carga la descripcin de un caso de estudio para sistemas de recomendacin * para grupos.// w w w . j av a 2 s. c o m * * @param file Archivo donde se encuentra almacenado el caso de estudio. * @return Caso de estudio recuperado del archivo. * @throws org.jdom2.JDOMException Cuando se intenta cargar un xml que no * tiene la estructura esperada. Chequear si esta desfasada la versin. * @throws IOException Cuando no se puede leer el archivo indicado o existe * algun fallo de conversin de datos al leer el contenido del mismo. */ public static GroupCaseStudyConfiguration loadGroupCaseWithResults(File file) throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(file); Element caseStudy = doc.getRootElement(); if (!caseStudy.getName().equals(CASE_ROOT_ELEMENT_NAME)) { throw new IllegalArgumentException("The XML does not contains a Case Study."); } GroupRecommenderSystem<Object, Object> groupRecommenderSystem = GroupRecommenderSystemXML .getGroupRecommenderSystem(caseStudy.getChild(GroupRecommenderSystemXML.ELEMENT_NAME)); GroupFormationTechnique groupFormationTechnique = GroupFormationTechniqueXML .getGroupFormationTechnique(caseStudy.getChild(GroupFormationTechniqueXML.ELEMENT_NAME)); ValidationTechnique validationTechnique = ValidationTechniqueXML .getValidationTechnique(caseStudy.getChild(ValidationTechniqueXML.ELEMENT_NAME)); GroupPredictionProtocol groupPredictionProtocol = GroupPredictionProtocolXML .getGroupPredictionProtocol(caseStudy.getChild(GroupPredictionProtocolXML.ELEMENT_NAME)); RelevanceCriteria relevanceCriteria = RelevanceCriteriaXML .getRelevanceCriteria(caseStudy.getChild(RelevanceCriteriaXML.ELEMENT_NAME)); DatasetLoader<? extends Rating> datasetLoader = DatasetLoaderXML .getDatasetLoader(caseStudy.getChild(DatasetLoaderXML.ELEMENT_NAME)); Map<GroupEvaluationMeasure, GroupEvaluationMeasureResult> groupEvaluationMeasuresResults = getEvaluationMeasures( caseStudy); long seed = Long.parseLong(caseStudy.getAttributeValue(SeedHolder.SEED.getName())); int numExecutions = Integer.parseInt(caseStudy.getAttributeValue(NUM_EXEC_ATTRIBUTE_NAME)); String caseStudyAlias = caseStudy.getAttributeValue(ParameterOwner.ALIAS.getName()); return new GroupCaseStudyConfiguration(groupRecommenderSystem, datasetLoader, groupFormationTechnique, validationTechnique, groupPredictionProtocol, relevanceCriteria, caseStudyAlias, numExecutions, seed, groupEvaluationMeasuresResults); }
From source file:delfos.group.io.xml.casestudy.GroupCaseStudyXML.java
License:Open Source License
public static int extractResultNumExec(File groupCaseStudyXML) throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(groupCaseStudyXML); Element caseStudy = doc.getRootElement(); if (!caseStudy.getName().equals(CASE_ROOT_ELEMENT_NAME)) { throw new IllegalArgumentException("The XML does not contains a Case Study."); }/* www . j av a 2 s.com*/ Integer numExec = new Integer(caseStudy.getAttributeValue(NUM_EXEC_ATTRIBUTE_NAME)); return numExec; }
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/*ww w. j av a 2 s . c om*/ * @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
/** * Construye el objeto en memoria que representa a la tcnica de filtrado de * ratings para grupos descrita en el elemento que se pasa por parmetro. * * @param groupRatingsPreFilterElement Objeto XML que describe el filtro. * @return Tcnica de filtrado de ratings para grupo generada a partir de la * descripcin indicada en el parmetro./*from w w w . j av a 2s . c om*/ */ public static GroupRatingsFilter getGroupRatingsFilter(Element groupRatingsPreFilterElement) { String filterName = groupRatingsPreFilterElement.getAttributeValue("name"); GroupRatingsFilter filter = GroupRatingsFilterFactory.getInstance().getClassByName(filterName); for (Object o : groupRatingsPreFilterElement.getChildren(ParameterXML.PARAMETER_ELEMENT_NAME)) { Element parameterElement = (Element) o; ParameterXML.getParameterValue(filter, parameterElement); } return filter; }
From source file:delfos.group.results.groupevaluationmeasures.GroupEvaluationMeasure.java
License:Open Source License
public GroupEvaluationMeasureResult getGroupEvaluationMeasureResultFromXML( Element groupEvaluationMeasureResultElement) { String attributeValue = groupEvaluationMeasureResultElement.getAttributeValue(VALUE); double measureValue = Double.parseDouble(attributeValue); return new GroupEvaluationMeasureResult(this, measureValue); }
From source file:delfos.io.xml.casestudy.CaseStudyXML.java
License:Open Source License
static EvaluationMeasuresResults getAggregateEvaluationMeasures(Element element) { if (!element.getName().equals("Aggregate_values")) { throw new IllegalArgumentException("The XML element is not an aggregate values element."); }/*from w w w . ja v a 2 s. c o m*/ Map<EvaluationMeasure, Double> ret = new TreeMap<>(); long buildTime = -1; long recommendationTime = -1; for (Element child : element.getChildren()) { String evaluationMeasureName = child.getName(); EvaluationMeasure evaluationMeasure = EvaluationMeasuresFactory.getInstance() .getClassByName(evaluationMeasureName); String valueString = child.getAttributeValue("value"); if (valueString == null) { continue; } double measureValue = new Double(valueString); if (evaluationMeasure == null) { throw new IllegalStateException("Evaluation measure cannot be null."); } ret.put(evaluationMeasure, measureValue); } return new EvaluationMeasuresResults(ret, buildTime, recommendationTime); }
From source file:delfos.io.xml.dataset.DatasetLoaderXML.java
License:Open Source License
public static DatasetLoader<? extends Rating> getDatasetLoader(Element datasetLoaderElement) { if (!datasetLoaderElement.getName().equals(ELEMENT_NAME)) { throw new IllegalArgumentException("The element does not contains a dataset loader. [Element name '" + datasetLoaderElement.getName() + "']"); }/*from w w w . j ava 2 s . c o m*/ String name = datasetLoaderElement.getAttributeValue(ParameterOwnerXML.PARAMETER_OWNER_ATTRIBUTE_NAME); String parameterOwnerType = datasetLoaderElement .getAttributeValue(ParameterOwnerXML.PARAMETER_OWNER_ATTRIBUTE_TYPE); if (parameterOwnerType == null) { datasetLoaderElement.setAttribute(ParameterOwnerXML.PARAMETER_OWNER_ATTRIBUTE_TYPE, ParameterOwnerType.DATASET_LOADER.name()); } if (datasetLoaderElement.getAttribute(CONFIGURED_DATASET_ATTRIBUTE) != null && "true".equals(datasetLoaderElement.getAttributeValue(CONFIGURED_DATASET_ATTRIBUTE))) { //Es un dataset configurado, hay que recuperarlo de la factora de dataset configurados. DatasetLoader<? extends Rating> datasetLoader = ConfiguredDatasetsFactory.getInstance() .getDatasetLoader(name); return datasetLoader; } else { //Un dataset de toda la vida. ParameterOwner parameterOwner = ParameterOwnerXML.getParameterOwner(datasetLoaderElement); if (parameterOwner instanceof DatasetLoader) { DatasetLoader<? extends Rating> datasetLoader = (DatasetLoader) parameterOwner; return datasetLoader; } else { IllegalStateException ex = new IllegalStateException( "The XML does not have the expected structure: The loaded parameter owner is not a dataset loader [" + parameterOwner + "]"); ERROR_CODES.CANNOT_LOAD_CONFIG_FILE.exit(ex); throw ex; } } }
From source file:delfos.io.xml.dataset.DatasetLoaderXML.java
License:Open Source License
public static Object getDatasetLoader(ParameterOwner parameterOwner, Element element) { String datasetLoaderName = element.getAttributeValue("name"); DatasetLoader<? extends Rating> datasetLoader = DatasetLoadersFactory.getInstance() .getClassByName(datasetLoaderName); for (Object o : element.getChildren()) { Element parameterElement = (Element) o; ParameterXML.getParameterValue(datasetLoader, parameterElement); }/* ww w . ja v a 2 s. c o m*/ return datasetLoader; }
From source file:delfos.io.xml.evaluationmeasures.confusionmatricescurve.ConfusionMatricesCurveXML.java
License:Open Source License
/** * Convierte un {@link Element} que contenga la informacin de un * ConfusionMatricesCurve en un objeto {@link ConfusionMatricesCurve}. * * * @param element Objeto {@link Element} que contiene la informacin * necesaria para construir el objeto {@link ConfusionMatricesCurve} * * @return {@link ConfusionMatricesCurve} con la informacin que el * parmetro element contiene// ww w . ja v a 2 s .com * * @throws UnrecognizedElementException cuando el {@link Element} que se * desea convertir no tiene la informacin que se necesita para construir un * {@link ConfusionMatricesCurve} o no est estructurada como se esperaba. */ public static ConfusionMatricesCurve getConfusionMatricesCurve(Element element) throws UnrecognizedElementException { List<ConfusionMatrix> matrices = new ArrayList<ConfusionMatrix>(); /* * Recorro todos los elementos que representan un punto dentro de esta * curva */ List<Element> pares = element.getChildren(MATRIX); if (pares.isEmpty()) { if ((element.getChild(CURVE_ELEMENT) != null && !element.getChild(CURVE_ELEMENT).getChildren(MATRIX).isEmpty()) || !element.getChildren().isEmpty()) { // (Si el elemento tiene como hijo una curva y este tiene varias matrices ) o el elemento tiene algn hijo. //Global.showWarning("BAD USAGE, the curve belongs to a group of users. Perform 'element.getChild(CURVE_ELEMENT)' to call this method"); pares = element.getChild(CURVE_ELEMENT).getChildren(MATRIX); } } for (Object par : pares) { Element parElement = (Element) par; int k = Integer.parseInt(parElement.getAttributeValue(K)); int falsePositive = Integer.parseInt(parElement.getAttributeValue(FALSE_POSITIVE)); int falseNegative = Integer.parseInt(parElement.getAttributeValue(FALSE_NEGATIVE)); int truePositive = Integer.parseInt(parElement.getAttributeValue(TRUE_POSITIVE)); int trueNegative = Integer.parseInt(parElement.getAttributeValue(TRUE_NEGATIVE)); matrices.add(new ConfusionMatrix(falsePositive, falseNegative, truePositive, trueNegative)); } if (matrices.isEmpty()) { return ConfusionMatricesCurve.emptyCurve(); } else { return new ConfusionMatricesCurve(matrices.toArray(new ConfusionMatrix[0])); } }