List of usage examples for org.jdom2 Element getText
public String getText()
From source file:eu.himeros.hocr.NgtMaker.java
License:Open Source License
private void parseOcrWord(Element ocrWord) { String word = trans.parse(ocrWord.getText()).replaceAll("[^-]*", "").trim(); if (word.length() == 0) return;/*from w w w. j a v a 2 s. co m*/ ocrAl.add(word); }
From source file:eus.ixa.ixa.pipe.convert.DSRCCorpus.java
License:Apache License
private static void DSRCToNAFNER(KAFDocument kaf, String wordsDoc, String markablesDoc) throws JDOMException, IOException { // reading the words xml file SAXBuilder sax = new SAXBuilder(); XPathFactory xFactory = XPathFactory.instance(); Document docWords = sax.build(wordsDoc); XPathExpression<Element> expr = xFactory.compile("//word", Filters.element()); List<Element> words = expr.evaluate(docWords); List<WF> sentWFs = new ArrayList<>(); List<Term> sentTerms = new ArrayList<>(); // building the NAF containing the WFs and Terms // naf sentence counter int sentCounter = 1; for (Element word : words) { // sentence id and original text String token = word.getText(); // the list contains just one list of tokens WF wf = kaf.newWF(0, token, sentCounter); final List<WF> wfTarget = new ArrayList<WF>(); wfTarget.add(wf);// ww w. j a v a 2 s . c o m sentWFs.add(wf); Term term = kaf.newTerm(KAFDocument.newWFSpan(wfTarget)); term.setPos("O"); term.setLemma(token); sentTerms.add(term); Matcher endMatcher = endOfSentence.matcher(token); if (endMatcher.matches()) { sentCounter++; } } // end of processing words String[] tokenIds = new String[sentWFs.size()]; for (int i = 0; i < sentWFs.size(); i++) { tokenIds[i] = sentWFs.get(i).getId(); } // processing markables document in mmax opinion expression files Document markDoc = sax.build(markablesDoc); XPathFactory markFactory = XPathFactory.instance(); XPathExpression<Element> markExpr = markFactory.compile("//ns:markable", Filters.element(), null, Namespace.getNamespace("ns", "www.eml.org/NameSpaces/OpinionExpression")); List<Element> markables = markExpr.evaluate(markDoc); for (Element markable : markables) { if (markable.getAttributeValue("annotation_type").equalsIgnoreCase("target")) { String markSpan = markable.getAttributeValue("span"); System.err.println("--> span: " + markSpan); String removeCommaSpan = markSpan.replaceAll(",word_.*", ""); System.err.println("--> newSpan: " + removeCommaSpan); String[] spanWords = removeCommaSpan.split("\\.\\."); int startIndex = Integer.parseInt(spanWords[0].replace("word_", "")); int endIndex = Integer.parseInt(spanWords[spanWords.length - 1].replace("word_", "")) + 1; List<String> wfIds = Arrays.asList(Arrays.copyOfRange(tokenIds, startIndex - 1, endIndex - 1)); List<String> wfTermIds = getWFIdsFromTerms(sentTerms); if (checkTermsRefsIntegrity(wfIds, wfTermIds)) { List<Term> nameTerms = kaf.getTermsFromWFs(wfIds); ixa.kaflib.Span<Term> neSpan = KAFDocument.newTermSpan(nameTerms); List<ixa.kaflib.Span<Term>> references = new ArrayList<ixa.kaflib.Span<Term>>(); references.add(neSpan); Entity neEntity = kaf.newEntity(references); neEntity.setType("TARGET"); System.err.println("--> target: " + neEntity.getStr()); } } // end of create entity } }
From source file:firstPackage.WorkWithFile.java
public void readInfromationFromFile() { try {//from w ww . j ava 2 s . co m wwhm.mapOfAppointments.clear(); doc = saxBuilder.build(new File(file)); Element root = doc.getRootElement(); List<Element> listOfAppointments = root.getChildren(); Appointment app; for (int i = 0; i < listOfAppointments.size(); i++) { Element appointment_data = listOfAppointments.get(i); Element name = appointment_data.getChild("Name"); Element description = appointment_data.getChild("Description"); Element dateOfEditing = appointment_data.getChild("Date of editing"); Element typeOfAppointment = appointment_data.getChild("Type of appointment"); TypeOfAppointments typeOfAppointmentEnum = null; if (typeOfAppointment.getText().equals(TypeOfAppointments.meeting.toString())) typeOfAppointmentEnum = TypeOfAppointments.meeting; else if (typeOfAppointment.getText().equals(Appointment.TypeOfAppointments.task.toString())) typeOfAppointmentEnum = TypeOfAppointments.task; app = new Appointment(name.getText(), description.getText(), dateOfEditing.getText(), typeOfAppointmentEnum); wwhm.mapOfAppointments.put(name.getText(), app); } } catch (JDOMException ex) { Logger.getLogger(WorkWithFile.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(WorkWithFile.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:fr.amap.amapvox.io.tls.rsp.Rsp.java
License:Open Source License
public void read(final File rspFile) throws JDOMException, IOException { sxb = new SAXBuilder(); rxpList = new ArrayList<>(); //avoid loading of dtd file sxb.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); try {/*w w w . j a va2s . c om*/ document = sxb.build(new FileInputStream(rspFile)); root = document.getRootElement(); projectName = root.getAttributeValue("name"); Element scanPositions = root.getChild("scanpositions"); String folderScanPositions = scanPositions.getAttributeValue("fold"); List<Element> childrens = scanPositions.getChildren("scanposition"); popMatrix = extractMat4D(root.getChild("pop").getChildText("matrix")); //scan id int scanCount = 0; for (Element child : childrens) { Scans rxp = new Scans(); rxp.setName(child.getAttributeValue("name")); rxp.setFold(child.getAttributeValue("fold")); Element registeredElement = child.getChild("registered"); if (registeredElement != null) { if (Integer.valueOf(registeredElement.getText()) == 1) { Element singlescans = child.getChild("singlescans"); String singlescansFold = singlescans.getAttributeValue("fold"); Map<Integer, RxpScan> scanList = new HashMap<>(); List<Element> scans = singlescans.getChildren("scan"); Element sop = child.getChild("sop"); Matrix4d sopMatrix = extractMat4D(sop.getChildText("matrix")); rxp.setSopMatrix(sopMatrix); int compteur = 0; for (Element sc : scans) { RxpScan scan = new RxpScan(); scan.setName(sc.getAttributeValue("name")); scan.setFileName(sc.getChildText("file")); String rspFilePathOnly = rspFile.getAbsolutePath().substring(0, rspFile.getAbsolutePath().lastIndexOf(File.separator)); scan.setAbsolutePath(rspFilePathOnly + File.separator + folderScanPositions + File.separator + rxp.getFold() + File.separator + singlescansFold + File.separator + scan.getFileName()); scanList.put(scanCount, scan); if (scan.getName().contains(".mon")) { rxp.setRxpLiteFile(new File(scan.getAbsolutePath())); rxp.setScanLite(scan); } else { rxp.setScanFull(scan); } scan.setFile(new File(scan.getAbsolutePath())); scan.setSopMatrix(sopMatrix); compteur++; scanCount++; } rxp.setScanList(scanList); rxpList.add(rxp); } else { //logger.info("Scan "+ rxp.getName() +" skipped cause unregistered"); } } } } catch (JDOMException ex) { throw new JDOMException("error parsing or reading rsp: " + rspFile.getAbsolutePath(), ex); } catch (IOException ex) { throw new IOException("error parsing or reading rsp: " + rspFile.getAbsolutePath(), ex); } }
From source file:fr.crnan.videso3d.databases.aip.AIP.java
License:Open Source License
private void getFrequences() { try {//from w ww .ja v a 2 s . c om Element racineFrequenceS = getDocumentRoot().getChild("FrequenceS"); List<Element> frequences = racineFrequenceS.getChildren(); for (Element freq : frequences) { Element secteur = freq.getChild("SecteurSituation"); if (secteur != null) { String frequence = freq.getChildText("Frequence"); if (frequence.startsWith("1")) insertFrequence(secteur.getText(), frequence); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:fr.crnan.videso3d.databases.aip.AIP.java
License:Open Source License
/** * Mme chose que org.jdom.Element.getChildText mais renvoie null si l'enfant n'existe pas au lieu de lever une exception. * @param e/* w w w .java2s.c om*/ * @param childName * @return */ public String getChildText(Element e, String childName) { Element child = e.getChild(childName); return child != null ? child.getText() : null; }
From source file:ilarkesto.integration.jdom.JDom.java
License:Open Source License
public static String getChildText(Element parent, String name) { Element child = getChild(parent, name); return child == null ? null : child.getText(); }
From source file:ilarkesto.tools.TatbestandskatalogParser.java
License:Open Source License
private List<Tatbestand> processPage(Element ePage) { String pageNumber = ePage.getAttributeValue("number"); if (pageNumber.equals("443")) return Collections.emptyList(); System.out.println("page " + pageNumber); List<Element> eTexts = new ArrayList<Element>(JDom.getChildren(ePage, "text")); Collections.sort(eTexts, new TopComparator()); List<Tatbestand> ret = new ArrayList<Tatbestandskatalog.Tatbestand>(); TatbestandBuilder tb = null;/*from w w w.ja v a 2 s. c o m*/ for (Element eText : eTexts) { int top = Integer.parseInt(eText.getAttributeValue("top")); int left = Integer.parseInt(eText.getAttributeValue("left")); int width = Integer.parseInt(eText.getAttributeValue("width")); int height = Integer.parseInt(eText.getAttributeValue("height")); int font = Integer.parseInt(eText.getAttributeValue("font")); String text = eText.getText(); if (top < 163) continue; // header if (top >= 992) continue; // footer if ("TBNR".equals(eText.getChildText("b"))) { if (tb != null) { ret.add(tb.createTatbestand()); tb = null; } // System.out.println("---> footer"); return ret; // footer } if ((left >= 627 && left <= 638) && height == 11 && font == 1) { // fap pkt // System.out.println(" fap pkt: " + text); tb.appendFapPkt(text.trim()); continue; } if ((left >= 701 && left <= 744) && height == 11 && font == 1) { // eur // System.out.println(" eur: " + text); int euro = Integer.parseInt(text.trim().replace(",", "")); tb.setEuro(euro); continue; } if (left == 765 && height == 11 && font == 1) { // fv // System.out.println(" fv: " + text); int fv = Integer.parseInt(text.substring(0, text.indexOf(' '))); tb.setFv(fv); continue; } if (isTatbestandBeginner(text)) { if (tb != null) { ret.add(tb.createTatbestand()); tb = null; } text = text.trim(); int tbnr = Integer.parseInt(text.substring(0, 6)); text = text.substring(8); tb = new TatbestandBuilder(tbnr); tb.appendText(text.trim()); // System.out.println(" @@@ new " + tbnr); continue; } if (text.trim().isEmpty()) continue; tb.appendText(text.trim()); // throw new RuntimeException("Unprocessed text element -> left=" + left + " text=" + text); } if (tb != null) { ret.add(tb.createTatbestand()); tb = null; } return ret; }
From source file:instanceXMLParser.Instance.java
public void buildINstanceJDom(String path) { //creating JDOM SAX parser SAXBuilder builder = new SAXBuilder(); //reading XML document Document xml = null;// w ww .java2 s. c om try { xml = builder.build(new File(path)); } catch (JDOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } //getting root element from XML document Element root = xml.getRootElement(); List<Element> list = root.getChildren(); for (Element element : list) { List<Element> list1; if (element.getName().equals("board")) { list1 = element.getChildren(); for (Element element2 : list1) { if (element2.getName().equals("size_n")) {//size of the space size_n = Integer.parseInt(element2.getText()); } else if (element2.getName().equals("size_m")) {//size of the space size_m = Integer.parseInt(element2.getText()); //inizializzo matrice solo dop aver letto le due dimensioni //NOTA CHE SIZE_M E SIZE_N devono essere i primi elementi e in quell ordine! boardState = new CellLogicalState[size_n][size_m]; for (int j = 0; j < size_n; j++) { for (int k = 0; k < size_m; k++) { boardState[j][k] = new CellLogicalState(); } } } else if (element2.getName().equals("tile_state")) {//tile states int x, y, value; CellLogicalState state = new CellLogicalState(); String stateString; x = Integer.parseInt(element2.getAttribute("x").getValue()); y = Integer.parseInt(element2.getAttribute("y").getValue()); stateString = element2.getText(); if (stateString.equals("obstacle")) { state.setLocState(LocationState.Obstacle); } else if (stateString.equals("dirty")) { state.setLocState(LocationState.Dirty); value = 1; if (element2.getAttribute("value").getValue() != null) { value = Integer.parseInt(element2.getAttribute("value").getValue()); } state.setDirtyAmount(value); } boardState[x][y] = state; } } } else if (element.getName().equals("agent")) {//agent List<Element> list3 = element.getChildren(); for (Element element3 : list3) { if (element3.getName().equals("x")) { agentPos.setX(Integer.parseInt(element3.getValue())); } else if (element3.getName().equals("y")) { agentPos.setY(Integer.parseInt(element3.getValue())); } else if (element3.getName().equals("energy")) { energy = Double.parseDouble(element3.getValue()); } } } else if (element.getName().equals("base")) {//agent List<Element> list3 = element.getChildren(); for (Element element3 : list3) { if (element3.getName().equals("x")) { basePos.setX(Integer.parseInt(element3.getValue())); } else if (element3.getName().equals("y")) { basePos.setY(Integer.parseInt(element3.getValue())); } } } else if (element.getName().equals("action_costs")) {//agent List<Element> list3 = element.getChildren(); for (Element element3 : list3) { if (element3.getName().equals("up") || element3.getName().equals("left") || element3.getName().equals("down") || element3.getName().equals("right") || element3.getName().equals("suck")) { actionCosts.put(element3.getName(), Double.parseDouble(element3.getValue())); } } } } }
From source file:io.smartspaces.master.server.services.internal.support.JdomMasterDomainModelImporter.java
License:Apache License
/** * Get a space controller configuration. * * @param rootElement// www . ja v a 2 s. c o m * the XML element that might contain an space controller * configuration * @param spaceControllerRepository * repository for space controller entities * * @return a space controller configuration, if there was one, or {@code null} */ private SpaceControllerConfiguration getSpaceControllerConfiguration(Element rootElement, SpaceControllerRepository spaceControllerRepository) { Element configurationElement = rootElement.getChild(ELEMENT_NAME_SPACE_CONTROLLER_CONFIGURATION); if (configurationElement != null) { SpaceControllerConfiguration configuration = spaceControllerRepository .newSpaceControllerConfiguration(); Element parametersElement = configurationElement .getChild(ELEMENT_NAME_SPACE_CONTROLLER_CONFIGURATION_ROOT_PARAMETERS); if (parametersElement != null) { List<Element> parameterElements = parametersElement .getChildren(ELEMENT_NAME_SPACE_CONTROLLER_CONFIGURATION_INDIVIDUAL_PARAMETER); for (Element parameterElement : parameterElements) { ConfigurationParameter parameter = spaceControllerRepository .newSpaceControllerConfigurationParameter(); String name = parameterElement .getAttributeValue(ATTRIBUTE_NAME_SPACE_CONTROLLER_CONFIGURATION_PARAMETER_NAME); String value = parameterElement.getText(); parameter.setName(name); parameter.setValue(value); configuration.addParameter(parameter); } } return configuration; } return null; }