List of usage examples for org.dom4j Node valueOf
String valueOf(String xpathExpression);
valueOf
evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.
From source file:neat.NEAT.java
License:Open Source License
@Override public NEAT loadFromXML(Node nd) { // Add properties loadProperties();//w ww. j a v a 2 s . c o m // set generator generator = new NESRandom(FrevoMain.getSeed()); this.input_number = Integer.parseInt(nd.valueOf("./@input_nodes")); this.output_number = Integer.parseInt(nd.valueOf("./@output_nodes")); this.recurrent = Boolean.parseBoolean(nd.valueOf("./@recurrent")); String fitnessString = nd.valueOf("./@fitness"); if (!fitnessString.isEmpty()) { this.setFitness(Double.parseDouble(fitnessString)); } // load genes ArrayList<NEATGene> genes = new ArrayList<NEATGene>(); Node dgenes = nd.selectSingleNode("./genes"); @SuppressWarnings("unchecked") List<? extends Node> gs = dgenes.selectNodes("./*"); Iterator<? extends Node> it = gs.iterator(); while (it.hasNext()) { Node n = it.next(); String name = n.getName(); if (name.equals("NEATlinkGene")) genes.add(new NEATLinkGene(n)); else if (name.equals("NEATNodeGene")) genes.add(new NEATNodeGene(n)); else genes.add(new NEATFeatureGene(n)); } this.chromosome = new NEATChromosome(genes); updateNetStructure(); return this; }
From source file:net.asteasolutions.cinusuidi.sluncho.utils.XmlParse.java
private void setRelCommentProperties(Node originalQuestion, Map<String, Object> relQuestionMap) { Node thread = originalQuestion.selectSingleNode("Thread"); List<Node> relComments = thread.selectNodes("RelComment"); for (Node comment : relComments) { String commentId = comment.valueOf("@RELC_ID"); if (relQuestionMap.isEmpty() || !relQuestionMap.containsKey(commentId)) { Map<String, Object> relCommentInfo = new LinkedHashMap<>(); relCommentInfo.put("RelCBody", comment.selectSingleNode("RelCClean").getText()); relCommentInfo.put("IsRelevantToOrgQ", comment.valueOf("@RELC_RELEVANCE2ORGQ")); relCommentInfo.put("IsRelevantToRelQ", comment.valueOf("@RELC_RELEVANCE2RELQ")); relQuestionMap.put(commentId, relCommentInfo); }/*from www . j a v a2 s. co m*/ } }
From source file:net.asteasolutions.cinusuidi.sluncho.utils.XmlParse.java
private Map<String, Object> setRelQProperties(Node originalQuestion, Map<String, Object> relQuestionMap) { Node thread = originalQuestion.selectSingleNode("Thread"); Node relQuestion = thread.selectSingleNode("RelQuestion"); String relQId = relQuestion.valueOf("@RELQ_ID"); Map<String, Object> relQuestionInfo = new LinkedHashMap<>(); if (relQuestionMap.isEmpty() || !relQuestionMap.containsKey(relQId)) { relQuestionInfo.put("IsRelevant", relQuestion.valueOf("@RELQ_RELEVANCE2ORGQ")); relQuestionInfo.put("RelQBody", relQuestion.valueOf("RelQClean")); relQuestionInfo.put("RelComment", new LinkedHashMap<String, Object>()); relQuestionMap.put(relQId, relQuestionInfo); }//from ww w .j a v a 2s . co m return relQuestionInfo; }
From source file:net.asteasolutions.cinusuidi.sluncho.utils.XmlParse.java
public Map<String, Object> parseFile() { Map<String, Object> documentMap = new LinkedHashMap<>(); try {/* w w w. java 2 s.c om*/ Document document = ParseXml(); List<Node> orgQuestions = document.selectNodes("/xml/OrgQuestion"); for (Node question : orgQuestions) { String originalQuestionId = question.valueOf("@ORGQ_ID"); if (documentMap.isEmpty() || !documentMap.containsKey(originalQuestionId)) { Map<String, Object> orgQ = setOriginalQProperties(question); Map<String, Object> relQuestion = (Map<String, Object>) orgQ.get("RelQuestion"); relQuestion = setRelQProperties(question, relQuestion); Map<String, Object> relComment = (Map<String, Object>) relQuestion.get("RelComment"); setRelCommentProperties(question, relComment); documentMap.put(originalQuestionId, orgQ); } else if (documentMap.containsKey(originalQuestionId)) { Map<String, Object> orgQ = (Map<String, Object>) documentMap.get(originalQuestionId); Map<String, Object> relQuestion = (Map<String, Object>) orgQ.get("RelQuestion"); relQuestion = setRelQProperties(question, relQuestion); Map<String, Object> relComment = (Map<String, Object>) relQuestion.get("RelComment"); setRelCommentProperties(question, relComment); } } } catch (DocumentException ex) { Logger.getLogger(XmlParse.class.getName()).log(Level.SEVERE, null, ex); } return documentMap; }
From source file:net.bpfurtado.ljcolligo.GetComments.java
License:Open Source License
private Comment from(Node node) { Comment c = new Comment(); c.setId(node.valueOf("@id")); c.setEventId(Integer.parseInt(node.valueOf("@jitemid"))); c.setDate(dateFrom(node, "date")); c.setBody(textFrom(node, "body")); c.setSubject(textFrom(node, "subject")); // TODO URGENT add rest of fields return c;/*from w ww . java2 s. c o m*/ }
From source file:net.bpfurtado.tas.model.persistence.XMLAdventureReader.java
License:Open Source License
@SuppressWarnings("unchecked") private void readScenes() { Node startNode = xmlDocument.selectSingleNode("//scene[@id='0']"); Scene start = adventure.getStart();/*from www . ja v a2 s .c o m*/ loadSceneAttributes(startNode, start.getId()); Collection<Scene> allScenes = new LinkedList<Scene>(); List<Node> scenesNodes = new LinkedList(xmlDocument.selectNodes("//scene")); for (Node node : scenesNodes) { allScenes.add(loadSceneAttributes(node, Integer.parseInt(node.valueOf("@id")))); } findAllTos(start, allScenes); // For the ones not visited, because can't be reached from the start scene. for (Scene s : allScenes) { findAllTos(s, null); } }
From source file:net.bpfurtado.tas.model.persistence.XMLAdventureReader.java
License:Open Source License
private Scene loadSceneAttributes(Node n, int id) { Scene s = null;/*ww w .ja v a 2 s. co m*/ if (id == 0) { s = adventure.getStart(); } else { s = adventure.createScene(id, Boolean.valueOf(n.valueOf("@isEnd"))); } s.setImageId(n.valueOf("@imageId")); if (s.getImageId() != null && s.getImageId().trim().length() == 0) { s.setImageId(null); } s.setName(n.valueOf("@name")); s.setTags(n.valueOf("@tags")); s.setText(n.selectSingleNode("./text").getText()); try { s.setCode(n.selectSingleNode("./code").getText()); if (s.getCode() == null) { s.setCode(""); } } catch (NullPointerException npe) { logger.warn("No code node"); } loadCombat(n, s); loadSkillTest(n, s); return s; }
From source file:net.bpfurtado.tas.model.persistence.XMLAdventureReader.java
License:Open Source License
private void loadSkillTest(Node n, Scene s) { Node cn = n.selectSingleNode("skill-test"); if (cn == null) { return;//w w w. j a v a 2 s. c o m } String name = cn.valueOf("@name"); s.setType(SceneType.skillTest); s.setSkillToTest(new Skill(name)); }
From source file:net.bpfurtado.tas.model.persistence.XMLAdventureReader.java
License:Open Source License
private void loadCombat(Node n, Scene s) { Node cn = n.selectSingleNode("combat"); if (cn == null) { return;//from w ww . j a va 2 s . co m } Combat c = new Combat(); String type = cn.valueOf("@type"); c.setType(CombatType.fromPersistentRepr(type)); List<Node> enemyNodes = cn.selectNodes("./enemy"); for (Node en : enemyNodes) { Fighter fighter = new Fighter(en.valueOf("@name"), Integer.valueOf(en.valueOf("@skill")), Integer.valueOf(en.valueOf("@stamina"))); fighter.setDamage(Integer.valueOf(en.valueOf("@damage"))); c.add(fighter); } s.setType(SceneType.combat); s.setCombat(c); }
From source file:net.bpfurtado.tas.model.persistence.XMLAdventureReader.java
License:Open Source License
/** * @param scene/* ww w . ja v a 2 s . c o m*/ * @param scenesNotScannedYet * Just to keep the scenes not yet visited. */ @SuppressWarnings("unchecked") private void findAllTos(Scene scene, Collection<Scene> scenesNotScannedYet) { if (scenesNotScannedYet != null) { scenesNotScannedYet.remove(scene); } Node sceneNode = xmlDocument.selectSingleNode("//scene[@id='" + scene.getId() + "']"); List<Node> pathNodes = sceneNode.selectNodes("./path"); int i = 0; logger.debug("Scene=" + scene + ", pathNodes.sz=" + pathNodes.size()); for (Node pathNode : pathNodes) { logger.debug(i); IPath p = scene.createPath(pathNode.getText()); String orderStr = pathNode.valueOf("@order"); if (orderStr == null || orderStr.length() == 0) { p.setOrder(i++); } String idToStr = pathNode.valueOf("@toScene"); if (!GenericValidator.isBlankOrNull(idToStr)) { Scene to = adventure.getScene(Integer.parseInt(idToStr)); boolean hadScenesFrom = !to.getScenesFrom().isEmpty(); p.setTo(to); logger.debug(p); if (!hadScenesFrom) { logger.debug("BEFORE RECURSION: to=" + to); logger.debug("BEFORE RECURSION: all=" + scenesNotScannedYet); if (scenesNotScannedYet.contains(to)) { findAllTos(to, scenesNotScannedYet); } } } else { logger.debug(p); } } }