List of usage examples for org.jdom2 Element getChildText
public String getChildText(final String cname)
From source file:eus.ixa.ixa.pipe.convert.TassFormat.java
License:Apache License
public static void generalToTabulated(String fileName) throws JDOMException, IOException { StringBuilder sb = new StringBuilder(); // reading the TASS General Corpus xml file SAXBuilder sax = new SAXBuilder(); XPathFactory xFactory = XPathFactory.instance(); Document doc = sax.build(fileName); XPathExpression<Element> expr = xFactory.compile("//tweet", Filters.element()); List<Element> tweets = expr.evaluate(doc); for (Element tweet : tweets) { String tokenizedTweetContent = null; String tweetPolarity = null; String tweetId = tweet.getChildText("tweetid"); String tweetContentString = tweet.getChildText("content"); // the list contains just one list of tokens List<List<Token>> segmentedSentences = StringUtils.tokenizeSentence(tweetContentString, LANGUAGE); for (List<Token> tokenizedSentence : segmentedSentences) { String[] tokenizedTweetArray = eus.ixa.ixa.pipe.ml.utils.StringUtils .convertListTokenToArrayStrings(tokenizedSentence); tokenizedTweetContent = StringUtils.getStringFromTokens(tokenizedTweetArray); }//from ww w . j a v a 2 s . c o m if (tweet.getChild("sentiments").getChild("polarity").getChildText("value") != null) { tweetPolarity = tweet.getChild("sentiments").getChild("polarity").getChildText("value"); } sb.append(tweetId).append("\t").append(tweetPolarity).append("\t").append(tokenizedTweetContent) .append("\n"); } System.out.println(sb.toString()); }
From source file:eus.ixa.ixa.pipe.convert.TassFormat.java
License:Apache License
public static void generalToWFs(String fileName) { SAXBuilder sax = new SAXBuilder(); XPathFactory xFactory = XPathFactory.instance(); try {//from www . j a va2 s .c om Document doc = sax.build(fileName); XPathExpression<Element> expr = xFactory.compile("//tweet", Filters.element()); List<Element> tweets = expr.evaluate(doc); for (Element tweet : tweets) { String tweetId = tweet.getChildText("tweetid"); KAFDocument kaf = new KAFDocument(LANGUAGE, "v1.naf"); kaf.createPublic().publicId = tweetId; String tweetContentString = tweet.getChildText("content"); List<List<Token>> segmentedSentences = StringUtils.tokenizeSentence(tweetContentString, LANGUAGE); for (List<Token> sentence : segmentedSentences) { for (Token token : sentence) { kaf.newWF(token.startOffset(), token.getTokenValue(), 1); } } Path outfile = Files.createFile(Paths.get(tweetId + ".naf")); Files.write(outfile, kaf.toString().getBytes(StandardCharsets.UTF_8)); System.err.println(">> Wrote naf document to " + outfile); } } catch (JDOMException | IOException e) { e.printStackTrace(); } }
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 {/*from w ww. j a v a 2 s. c o m*/ 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 {// w ww .j a v a2s .c o m 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
private void getAerodromes() throws SQLException { try {/* w w w.ja v a 2 s . c om*/ Element racineAds = getDocumentRoot().getChild("AdS"); List<Element> ads = racineAds.getChildren(); for (Element ad : ads) { if (!ad.getChildText("AdStatut").equals("OFF")) insertAerodrome(ad); } Element racineRwys = getDocumentRoot().getChild("RwyS"); List<Element> rwys = racineRwys.getChildren(); for (Element rwy : rwys) { insertRunway(rwy); } } catch (Exception e) { e.printStackTrace(); } }
From source file:fr.crnan.videso3d.databases.aip.AIP.java
License:Open Source License
private void insertAerodrome(Element ad) throws SQLException { int pk = Integer.parseInt(ad.getAttributeValue("pk")); String code = ad.getAttributeValue("lk").replaceAll("\\p{Punct}", "").toUpperCase(Locale.ENGLISH); String nom = ad.getChildText("AdNomComplet"); int type = code.matches("[A-Z]{4}") ? 0 : (code.matches("LF[0-9]{2}") ? 2 : 1); double latRef = Double.parseDouble(ad.getChildText("ArpLat")); double lonRef = Double.parseDouble(ad.getChildText("ArpLong")); PreparedStatement ps = this.conn.prepareStatement( "insert into aerodromes (pk, code, nom, type, latRef, lonRef) VALUES (?, ?, ?, ?, ?, ?)"); ps.setInt(1, pk);/*from ww w .j a va2s .c o m*/ ps.setString(2, code); ps.setString(3, nom); ps.setInt(4, type); ps.setDouble(5, latRef); ps.setDouble(6, lonRef); ps.executeUpdate(); }
From source file:fr.crnan.videso3d.databases.aip.AIP.java
License:Open Source License
private void insertRunway(Element rwy) throws SQLException { int pk = Integer.parseInt(rwy.getAttributeValue("pk")); int pkAerodrome = Integer.parseInt(rwy.getChild("Ad").getAttributeValue("pk")); String rwyName = rwy.getChildText("Rwy"); int orientation = getRunwayOrientation(rwyName); String largeurString = rwy.getChildText("Largeur"); double largeur = -1; if (largeurString != null) largeur = Double.parseDouble(largeurString); String longueurString = rwy.getChildText("Longueur"); double longueur = -1; if (longueurString != null) longueur = Double.parseDouble(longueurString); PreparedStatement ps = this.conn.prepareStatement( "insert into runways (pk, pk_ad, nom, orientation, longueur, largeur) VALUES (?, ?, ?, ?, ?, ?)"); ps.setInt(1, pk);//from ww w.j a va 2 s .c o m ps.setInt(2, pkAerodrome); ps.setString(3, rwyName); ps.setInt(4, orientation); ps.setDouble(5, longueur); ps.setDouble(6, largeur); ps.executeUpdate(); String latThr1 = rwy.getChildText("LatThr1"); String lonThr1 = rwy.getChildText("LongThr1"); String latThr2 = rwy.getChildText("LatThr2"); String lonThr2 = rwy.getChildText("LongThr2"); if (latThr1 != null && latThr2 != null) { PreparedStatement ps2 = this.conn .prepareStatement("update runways set lat1=?, lon1=?,lat2=?,lon2=? where pk=?"); ps2.setDouble(1, Double.parseDouble(latThr1)); ps2.setDouble(2, Double.parseDouble(lonThr1)); ps2.setDouble(3, Double.parseDouble(latThr2)); ps2.setDouble(4, Double.parseDouble(lonThr2)); ps2.setInt(5, pk); ps2.executeUpdate(); } }
From source file:fr.crnan.videso3d.databases.aip.AIP.java
License:Open Source License
private void insertNavFix(Element navFix) throws SQLException { String pk = navFix.getAttributeValue("pk"); String type = navFix.getChildText("NavType"); String name = navFix.getChildText("Ident"); String territoireID = navFix.getChild("Territoire").getAttributeValue("pk"); double latitude = Double.parseDouble(navFix.getChildText("Latitude")); double longitude = Double.parseDouble(navFix.getChildText("Longitude")); if (!territoireID.equals("100")) { name += " - " + getTerritoireName(territoireID); }/*w w w.j a v a2 s .c o m*/ double freq = 0; if (!type.equals("VFR") && !type.equals("WPT") && !type.equals("PNP")) { List<Element> elts = findElementsByChildId( document.getRootElement().getChild("Situation").getChild("RadioNavS"), "NavFix", pk); if (elts.size() > 0) { freq = Double.parseDouble(elts.get(0).getChildText("Frequence")); } } PreparedStatement ps = this.conn.prepareStatement( "insert into NavFix (pk, type, nom, lat, lon, frequence) VALUES (?, ?, ?, ?, ?, ?)"); ps.setInt(1, Integer.parseInt(pk)); ps.setString(2, type); ps.setString(3, name); ps.setDouble(4, latitude); ps.setDouble(5, longitude); ps.setDouble(6, freq); ps.executeUpdate(); }
From source file:fr.crnan.videso3d.databases.aip.AIP.java
License:Open Source License
private void insertRoute(Element route) throws SQLException { String pkRoute = route.getAttributeValue("pk"); int routeID = Integer.parseInt(pkRoute); String routeName = route.getChildText("Prefixe") + " " + route.getChildText("Numero"); String territoireID = route.getChild("Territoire").getAttributeValue("pk"); if (!territoireID.equals("100")) { routeName += " - " + getTerritoireName(territoireID); }//from ww w . j a va 2 s . co m PreparedStatement ps; int navFixExtremite = Integer.parseInt(route.getChild("Origine").getAttributeValue("pk")); ps = this.conn.prepareStatement("insert into routes (pk,type,nom, navFixExtremite) VALUES (?, ?, ?, ?)"); ps.setInt(1, routeID); ps.setString(2, route.getChildText("RouteType")); ps.setString(3, routeName); ps.setInt(4, navFixExtremite); ps.executeUpdate(); Element racineSegments = document.getRootElement().getChild("Situation").getChild("SegmentS"); List<Element> segments = findElementsByChildId(racineSegments, "Route", pkRoute); for (Element segment : segments) { int segmentID = Integer.parseInt(segment.getAttributeValue("pk")); int sequence = Integer.parseInt(segment.getChildText("Sequence")); navFixExtremite = Integer.parseInt(segment.getChild("NavFixExtremite").getAttributeValue("pk")); ps = this.conn.prepareStatement( "insert into segments (pk, pkRoute, sequence, navFixExtremite) VALUES (?, ?, ?, ?)"); ps.setInt(1, segmentID); ps.setInt(2, routeID); ps.setInt(3, sequence); ps.setInt(4, navFixExtremite); ps.executeUpdate(); //Insertion des centres traverss par la route : pour chaque segment, on ajoute le centre la liste des centres traverss String nomACC = segment.getChildText("Acc"); if (nomACC != null) { if (nomACC.contains(" ")) { String[] nomsACCs = nomACC.split(" "); insertACCs(nomsACCs, pkRoute); } else if (nomACC.contains("#")) { String[] nomsACCs = nomACC.split("#"); insertACCs(nomsACCs, pkRoute); } else { insertACC(nomACC, pkRoute); } } } }
From source file:fr.crnan.videso3d.databases.aip.AIP.java
License:Open Source License
/** * Insre dans la base de donnes la zone passe en paramtre * @param zone Le secteur (ou zone...) insrer dans la base. * @param displaySequence Boolen indiquant s'il faut afficher le numro de squence de la zone ou pas. * @param type//from w w w . j a v a 2 s . c o m * @throws SQLException */ private void insertZone(Element zone, String name, boolean displaySequence, String type) throws SQLException { int zoneID = Integer.parseInt(zone.getAttributeValue("pk")); //on teste s'il s'agit d'une zone Pje, Aer, Vol, Bal ou TrPla en regardant si le deuxime caractre est en minuscule : si c'est le cas, // on recherche le nom usuel. On cherche aussi le nom usuel pour les zones P et PRN. if (type.length() > 1) { if (Character.isLowerCase(type.charAt(1)) || type.equals("PRN")) { String usualName = getUsualName(zone); if (usualName != null) { name += " -- " + usualName; } } } else if (type.equals("P")) { String usualName = getUsualName(zone); if (usualName != null) { name += " -- " + usualName; } } if (displaySequence) { name += " " + zone.getChildText("Sequence"); } getZones(string2type(type)).add(new Couple<Integer, String>(zoneID, name)); PreparedStatement ps = this.conn.prepareStatement("insert into volumes (pk,type,nom) VALUES (?, ?, ?)"); ps.setInt(1, zoneID); ps.setString(2, type); ps.setString(3, removeType(name)); ps.executeUpdate(); }