List of usage examples for org.jdom2 Element getChild
public Element getChild(final String cname)
From source file:core.LectorXml.java
@Override public void readNodeFile() { try {//from w w w . j a v a2 s. c o m this.setDocument((Document) this.getBuilder().build(this.getFile())); this.setRootNode(this.getDocument().getRootElement()); List list = (List) this.getRootNode().getChildren(); for (Object object : list) { Element ob = (Element) object; System.out.println(ob.getName()); if (ob.getName().equalsIgnoreCase("autor")) { try { this.getXml().getAutor().setNombre(ob.getChild("nombre").getText()); } catch (NullPointerException r) { this.getXml().getAutor().setNombre(""); } try { this.getXml().getAutor().setDescripcion(ob.getChild("descripcion").getText()); } catch (NullPointerException r) { this.getXml().getAutor().setDescripcion(""); } try { this.getXml().getAutor().setVersion(ob.getChild("version").getText()); } catch (NullPointerException r) { this.getXml().getAutor().setVersion(""); } } else if (ob.getName().equalsIgnoreCase("cuerpo")) { try { Element tipo = ob.getChild("tipo"); this.getXml().getCuerpo() .setColumnas(Integer.parseInt(tipo.getAttribute("columnas").getValue())); this.getXml().getCuerpo() .setTipo_datos(tipo.getAttribute("tipodatocolumna").getValue().split(",")); } catch (NullPointerException r) { this.getXml().getCuerpo().setColumnas(0); this.getXml().getCuerpo().setTipo_datos(new String[] {}); } catch (NumberFormatException n) { this.getXml().getCuerpo().setColumnas(0); this.getXml().getCuerpo().setTipo_datos(new String[] {}); } try { Element tipo = ob.getChild("claseprincipal"); this.getXml().getCuerpo().setMain(ob.getChild("claseprincipal").getValue()); } catch (NullPointerException r) { this.getXml().getCuerpo().setMain(""); } ArrayList<String> parametros = new ArrayList<>(); try { System.out.println("*************** " + ob.getChild("parametro")); Element param = ob.getChild("parametro"); for (Element e : param.getChildren()) { System.out.println(e.getName()); try { System.out.println(e.getName()); parametros.add(e.getName()); } catch (NullPointerException r) { System.err.println("Se exploto"); } } } catch (NullPointerException r) { } finally { this.getXml().getCuerpo().setParametros(parametros); } } } } catch (JDOMException ex) { Logger.getLogger(LectorXml.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(LectorXml.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:core.ListComponenXml.java
@Override public void readNodeFile() { try {// w w w.j a va 2 s . c o m this.setDocument((Document) this.getBuilder().build(this.getFile())); this.setRootNode(this.getDocument().getRootElement()); List list = (List) this.getRootNode().getChildren(); for (Object object : list) { Element tem = (Element) object; this.setXml(new Xml()); for (Element ob : tem.getChildren()) { System.out.println(ob.getName()); if (ob.getName().equalsIgnoreCase("autor")) { try { this.getXml().getAutor().setNombre(ob.getChild("nombre").getText()); } catch (NullPointerException r) { this.getXml().getAutor().setNombre(""); } try { this.getXml().getAutor().setDescripcion(ob.getChild("descripcion").getText()); } catch (NullPointerException r) { this.getXml().getAutor().setDescripcion(""); } try { this.getXml().getAutor().setVersion(ob.getChild("version").getText()); } catch (NullPointerException r) { this.getXml().getAutor().setVersion(""); } } else if (ob.getName().equalsIgnoreCase("status")) { try { this.getXml().getStatus() .setActive(Boolean.valueOf(ob.getAttribute("active").getValue())); } catch (Exception e) { this.getXml().getStatus().setActive(true); } } else if (ob.getName().equalsIgnoreCase("cuerpo")) { try { Element tipo = ob.getChild("tipo"); this.getXml().getCuerpo() .setColumnas(Integer.parseInt(tipo.getAttribute("columnas").getValue())); this.getXml().getCuerpo() .setTipo_datos(tipo.getAttribute("tipodatocolumna").getValue().split(",")); } catch (NullPointerException r) { this.getXml().getCuerpo().setColumnas(0); this.getXml().getCuerpo().setTipo_datos(new String[] {}); } catch (NumberFormatException n) { this.getXml().getCuerpo().setColumnas(0); this.getXml().getCuerpo().setTipo_datos(new String[] {}); } try { Element tipo = ob.getChild("claseprincipal"); this.getXml().getCuerpo().setMain(ob.getChild("claseprincipal").getValue()); } catch (NullPointerException r) { this.getXml().getCuerpo().setMain(""); } ArrayList<String> parametros = new ArrayList<>(); try { System.out.println("*************** " + ob.getChild("parametro")); Element param = ob.getChild("parametro"); for (Element e : param.getChildren()) { System.out.println(e.getName()); try { System.out.println(e.getName()); parametros.add(e.getName()); } catch (NullPointerException r) { System.err.println("Se exploto"); } } } catch (NullPointerException r) { } finally { this.getXml().getCuerpo().setParametros(parametros); } } } this.getXmls().add(this.getXml()); } } catch (JDOMException ex) { Logger.getLogger(LectorXml.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(LectorXml.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:core.ListComponenXml.java
@Override public void readFile(Xml xml) { try {//from w ww.j ava2 s . c o m this.setDocument((Document) this.getBuilder().build(this.getFile())); this.setRootNode(this.getDocument().getRootElement()); List list = (List) this.getRootNode().getChildren(); for (Object object : list) { Element tem = (Element) object; this.setXml(new Xml()); for (Element ob : tem.getChildren()) { System.out.println(ob.getName()); if (ob.getName().equalsIgnoreCase("autor")) { try { this.getXml().getAutor().setNombre(ob.getChild("nombre").getText()); } catch (NullPointerException r) { this.getXml().getAutor().setNombre(""); } try { this.getXml().getAutor().setDescripcion(ob.getChild("descripcion").getText()); } catch (NullPointerException r) { this.getXml().getAutor().setDescripcion(""); } try { this.getXml().getAutor().setVersion(ob.getChild("version").getText()); } catch (NullPointerException r) { this.getXml().getAutor().setVersion(""); } } else if (ob.getName().equalsIgnoreCase("status")) { try { this.getXml().getStatus() .setActive(Boolean.valueOf(ob.getAttribute("active").getValue())); } catch (Exception e) { this.getXml().getStatus().setActive(true); } } else if (ob.getName().equalsIgnoreCase("cuerpo")) { try { Element tipo = ob.getChild("tipo"); this.getXml().getCuerpo() .setColumnas(Integer.parseInt(tipo.getAttribute("columnas").getValue())); this.getXml().getCuerpo() .setTipo_datos(tipo.getAttribute("tipodatocolumna").getValue().split(",")); } catch (NullPointerException r) { this.getXml().getCuerpo().setColumnas(0); this.getXml().getCuerpo().setTipo_datos(new String[] {}); } catch (NumberFormatException n) { this.getXml().getCuerpo().setColumnas(0); this.getXml().getCuerpo().setTipo_datos(new String[] {}); } try { Element tipo = ob.getChild("claseprincipal"); this.getXml().getCuerpo().setMain(ob.getChild("claseprincipal").getValue()); } catch (NullPointerException r) { this.getXml().getCuerpo().setMain(""); } ArrayList<String> parametros = new ArrayList<>(); try { System.out.println("*************** " + ob.getChild("parametro")); Element param = ob.getChild("parametro"); for (Element e : param.getChildren()) { System.out.println(e.getName()); try { System.out.println(e.getName()); parametros.add(e.getName()); } catch (NullPointerException r) { System.err.println("Se exploto"); } } } catch (NullPointerException r) { } finally { this.getXml().getCuerpo().setParametros(parametros); } } } this.xmls.add(this.getXml()); } } catch (JDOMException ex) { Logger.getLogger(LectorXml.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(LectorXml.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:core.ValidXml.java
@Override public boolean validEstructura(File xml_file) { try {//from w w w .ja va 2 s . c o m SAXBuilder builder = new SAXBuilder(); Document document = (Document) builder.build(xml_file); Element rootNode = document.getRootElement(); List list = (List) rootNode.getChildren(); Xml xml = new Xml(); for (Object object : list) { Element ob = (Element) object; System.out.println(ob.getName()); if (ob.getName().equalsIgnoreCase("autor")) { try { xml.getAutor().setNombre(ob.getChild("nombre").getText()); } catch (NullPointerException r) { xml.getAutor().setNombre(""); } try { xml.getAutor().setDescripcion(ob.getChild("descripcion").getText()); } catch (NullPointerException r) { xml.getAutor().setDescripcion(""); } try { xml.getAutor().setVersion(ob.getChild("version").getText()); } catch (NullPointerException r) { xml.getAutor().setVersion(""); } } else if (ob.getName().equalsIgnoreCase("cuerpo")) { try { Element tipo = ob.getChild("tipo"); xml.getCuerpo().setColumnas(Integer.parseInt(tipo.getAttribute("columnas").getValue())); xml.getCuerpo().setTipo_datos(tipo.getAttribute("tipodatocolumna").getValue().split(",")); } catch (NullPointerException r) { xml.getCuerpo().setColumnas(0); xml.getCuerpo().setTipo_datos(new String[] {}); } catch (NumberFormatException n) { xml.getCuerpo().setColumnas(0); xml.getCuerpo().setTipo_datos(new String[] {}); } try { Element tipo = ob.getChild("claseprincipal"); xml.getCuerpo().setMain(ob.getChild("claseprincipal").getValue()); } catch (NullPointerException r) { xml.getCuerpo().setMain(""); } ArrayList<String> parametros = new ArrayList<>(); try { System.out.println("*************** " + ob.getChild("parametro")); Element param = ob.getChild("parametro"); for (Element e : param.getChildren()) { System.out.println(e.getName()); try { System.out.println(e.getName()); parametros.add(e.getName()); } catch (NullPointerException r) { System.err.println("Se exploto"); } } } catch (NullPointerException r) { } finally { xml.getCuerpo().setParametros(parametros); } } } boolean respuesta = true; if (!xml.getAutor().getNombre().equals("")) { return false; } else if (xml.getCuerpo().getTipo_datos().length == 0) { return false; } else if (xml.getCuerpo().getParametros().size() == 0) { return false; } } catch (JDOMException ex) { Logger.getLogger(ValidXml.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ValidXml.class.getName()).log(Level.SEVERE, null, ex); } finally { } return true; }
From source file:count_dep.AlanRitter.java
public void ACE2Alan() throws JDOMException, IOException { Properties props = new Properties(); props.put("annotators", "tokenize, ssplit"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); File corpus = new File("D:\\LDC2006D06\\LDC2006D06\\Data\\LDC2006T06_Original\\data\\English\\nw\\fp1"); File[] listFiles = corpus.listFiles(); for (File f : listFiles) { if (f.getName().endsWith(".sgm")) { PrintStream ps = new PrintStream(new FileOutputStream("D:\\ACEAlan\\" + f.getName())); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(f); Element foo = doc.getRootElement(); String text = foo.getChild("BODY").getChild("TEXT").getText(); Annotation document = new Annotation(text); pipeline.annotate(document); List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class); for (CoreMap cm : sentences) { String str = cm.toString(); String str2 = str.replace('\n', ' '); ps.println(str2);/*w ww . j av a2 s .com*/ } ps.close(); } } }
From source file:count_dep.CountParagraph.java
public static LinkedList<String> GetSentences(File documentfile, StanfordCoreNLP pipeline) throws JDOMException, IOException { LinkedList<String> sentencelist = new LinkedList<>(); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(documentfile); Element foo = doc.getRootElement(); String text = foo.getChild("BODY").getChild("TEXT").getText(); int titleend = text.indexOf("\n\n"); text = text.substring(titleend + 1).replace("\n\n", ". "); Annotation document = new Annotation(text); // run all Annotators on this text pipeline.annotate(document);/* w w w. j a v a 2 s. c o m*/ // these are all the sentences in this document // a CoreMap is essentially a Map that uses class objects as keys and has values with custom types List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class); for (CoreMap cm : sentences) { sentencelist.add(cm.toString()); } return sentencelist; }
From source file:count_dep.CountParagraph.java
private LinkedList<String> GetParagraphs(File documentfile) throws JDOMException, IOException { LinkedList<String> paralist = new LinkedList<>(); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(documentfile); Element foo = doc.getRootElement(); String text = foo.getChild("BODY").getChild("TEXT").getText(); String[] split = text.split("\n\n"); for (int i = 0; i < split.length; i++) { paralist.add(split[i]);/* ww w.j a v a 2 s. co m*/ } return paralist; }
From source file:count_dep.Count_dep.java
public static LinkedList<Event> ReadEvents(File f) throws JDOMException, IOException { LinkedList<Event> res = new LinkedList<>(); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(f); Element foo = doc.getRootElement(); List<Element> one_document = foo.getChildren(); for (Element one_document1 : one_document) { List<Element> ERE = one_document1.getChildren(); for (Element e : ERE) { if ("event".equals(e.getName())) { List<Element> mentions = e.getChildren("event_mention"); for (Element m : mentions) { Event eve = new Event(); Element charseq; Element ldcscpope = m.getChild("ldc_scope"); charseq = ldcscpope.getChild("charseq"); eve.span = charseq.getText().replace("\n", " "); Element anchor = m.getChild("anchor"); charseq = anchor.getChild("charseq"); eve.trigger = charseq.getText(); if (eve.trigger.equalsIgnoreCase("saturday")) { int a = 0; a = a + 1;//w w w .j a v a 2 s.c om } eve.eventtype = e.getAttribute("SUBTYPE").getValue(); eve.eventlargetype = e.getAttribute("TYPE").getValue(); List<Element> arguments = m.getChildren("event_mention_argument"); for (Element argu : arguments) { String argumentstr = argu.getChild("extent").getChild("charseq").getText(); if ("U.S".equals(argumentstr) || "U.N".equals(argumentstr) || "Feb".equals(argumentstr)) { argumentstr += "."; } if (argumentstr.equalsIgnoreCase("Basra")) { int a = 0; a = a + 1; } eve.arguments.add(new EventArgument(argumentstr, argu.getAttributeValue("ROLE"))); } eve.filename = f.getName(); res.add(eve); } } } } return res; }
From source file:count_dep.Count_dep.java
public static LinkedList<Event> ReadGrishmanEvents(File f) throws JDOMException, IOException { LinkedList<Event> res = new LinkedList<>(); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(f); Element foo = doc.getRootElement(); List<Element> one_document = foo.getChildren(); for (Element one_document1 : one_document) { List<Element> ERE = one_document1.getChildren(); for (Element e : ERE) { if ("event".equals(e.getName())) { List<Element> mentions = e.getChildren("event_mention"); for (Element m : mentions) { Event eve = new Event(); eve.filename = f.getName(); Element charseq; Element anchor = m.getChild("anchor"); charseq = anchor.getChild("charseq"); eve.span = m.getChild("extent").getChild("charseq").getText(); eve.trigger = charseq.getText(); eve.eventtype = e.getAttribute("SUBTYPE").getValue(); List<Element> arguments = m.getChildren("event_mention_argument"); for (Element argu : arguments) { eve.arguments/*from w ww . j a v a 2s .c o m*/ .add(new EventArgument(argu.getChild("extent").getChild("charseq").getText(), argu.getAttributeValue("ROLE"))); } // eve.filename = f.getName(); res.add(eve); } } } } return res; }
From source file:count_dep.CRF.java
private void transfer_into_inputfiles() throws JDOMException, IOException { Properties props = new Properties(); props.put("annotators", "tokenize, ssplit, pos, lemma"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); File corpus = new File("D:\\LDC2006D06\\LDC2006D06\\Data\\LDC2006T06_Original\\data\\English\\nw\\fp1"); File[] listFiles = corpus.listFiles(); for (File f : listFiles) { if (f.getName().endsWith(".sgm")) { PrintStream ps = new PrintStream(new FileOutputStream("D:\\ACEAlan\\UIUCNERInput\\" + f.getName())); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(f); Element foo = doc.getRootElement(); String text = foo.getChild("BODY").getChild("TEXT").getText(); Annotation document = new Annotation(text); pipeline.annotate(document); List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class); for (CoreMap cm : sentences) { String str = cm.toString(); String str2 = str.replace('\n', ' '); ps.println(str2);//from w w w.j av a 2 s . co m } ps.close(); } } }