List of usage examples for org.jdom2 Document getRootElement
public Element getRootElement()
Element
for this Document
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 ww.jav a 2s. co m*/ } ps.close(); } } }
From source file:count_dep.Miscellaneous.java
private void MergeACE() throws FileNotFoundException, JDOMException, IOException { String[] corpusfolders = {//from ww w.j av a 2 s. c o m "D:\\LDC2006D06\\LDC2006D06\\Data\\LDC2006T06_Original\\data\\English\\bn\\fp1\\", "D:\\LDC2006D06\\LDC2006D06\\Data\\LDC2006T06_Original\\data\\English\\nw\\fp1\\", "D:\\LDC2006D06\\LDC2006D06\\Data\\LDC2006T06_Original\\data\\English\\wl\\fp1\\" }; PrintStream ps = new PrintStream(new FileOutputStream("D:\\wordvec\\ACE.txt")); for (int i = 0; i < corpusfolders.length; i++) { File folder = new File(corpusfolders[i]); File[] listFiles = folder.listFiles(); for (File f : listFiles) { if (f.getName().contains(".sgm")) { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(f); Element foo = doc.getRootElement(); String text = foo.getChild("BODY").getChild("TEXT").getText(); // int titleend = text.indexOf("\n\n"); // text = text.substring(titleend + 1); ps.println(text); } } } ps.close(); }
From source file:cz.cesnet.shongo.connector.device.AdobeConnectConnector.java
@Override public void importRoomSettings(String roomId, String settings) throws CommandException { SAXBuilder saxBuilder = new SAXBuilder(); Document document; try {/*from w w w . j a v a 2 s . c om*/ document = saxBuilder.build(new StringReader(settings)); } catch (Exception exception) { throw new CommandException(exception.getMessage(), exception); } XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); String xmlString = outputter.outputString(document); RequestAttributeList attributes = new RequestAttributeList(); attributes.add("sco-id", roomId); // attributes.add("date-begin", document.getRootElement().getChild("sco").getChild("date-begin").getText()); // attributes.add("date-end", document.getRootElement().getChild("sco").getChild("date-end").getText()); if (document.getRootElement().getChild("sco").getChild("description") != null) { attributes.add("description", document.getRootElement().getChild("sco").getChild("description").getText()); } attributes.add("url-path", document.getRootElement().getChild("sco").getChild("url-path").getText()); attributes.add("name", document.getRootElement().getChild("sco").getChild("name").getText()); execApi("sco-update", attributes); }
From source file:cz.cesnet.shongo.connector.device.AdobeConnectConnector.java
/** * Execute command on Adobe Connect server and returns XML response. Throws CommandException when some error on Adobe Connect server occured or some parser error occured. * * @param action name of Adobe Connect action * @param attributes attributes of action * @return XML action response// w w w . j a v a 2 s. c o m * @throws CommandException */ protected Element execApi(String action, RequestAttributeList attributes) throws CommandException { try { if (this.connectionSession == null) { if (action.equals("logout")) { return null; } else { login(); } } String actionUrl = getActionUrl(action, attributes); logger.debug(String.format("Calling action %s on %s", actionUrl, deviceAddress)); int retryCount = 5; while (retryCount > 0) { // Read result from url Document result; try { // Read result InputStream resultStream = execApi(actionUrl, requestTimeout); result = new SAXBuilder().build(resultStream); } catch (IOException exception) { if (isRequestApiRetryPossible(exception)) { retryCount--; logger.warn("{}: Trying again...", exception.getMessage()); continue; } else { throw exception; } } // Check for error and reconnect if login is needed if (isError(result)) { if (isLoginNeeded(result)) { retryCount--; logger.debug(String.format("Reconnecting to server %s", deviceAddress)); this.connectionState = ConnectionState.RECONNECTING; connectionSession = null; login(); continue; } throw new RequestFailedCommandException(actionUrl, result); } else { logger.debug(String.format("Command %s succeeded on %s", action, deviceAddress)); return result.getRootElement(); } } throw new CommandException(String.format("Command %s failed.", action)); } catch (IOException e) { throw new RuntimeException("Command issuing error", e); } catch (JDOMParseException e) { throw new RuntimeException("Command result parsing error", e); } catch (JDOMException e) { throw new RuntimeException("Error initializing parser", e); } catch (RequestFailedCommandException exception) { logger.warn(String.format("Command %s has failed on %s: %s", action, deviceAddress, exception)); throw exception; } }
From source file:cz.cesnet.shongo.connector.device.AdobeConnectConnector.java
/** * @param result Document returned by AC API call * @return true if the given {@code result} represents and error, * false otherwise/*from w w w.j a va 2 s . c o m*/ */ private boolean isError(Document result) { return isError(result.getRootElement()); }
From source file:cz.cesnet.shongo.connector.device.AdobeConnectConnector.java
/** * @param result XML result to parse for error * @return true if the given {@code result} saying that login is needed, * false otherwise/*ww w.j a v a 2 s. c o m*/ */ private boolean isLoginNeeded(Document result) { Element status = result.getRootElement().getChild("status"); if (status != null) { String code = status.getAttributeValue("code"); if ("no-access".equals(code)) { String subCode = status.getAttributeValue("subcode"); if ("no-login".equals(subCode)) { return true; } } } return false; }
From source file:cz.lbenda.dbapp.rc.SessionConfiguration.java
License:Apache License
public static void loadFromDocument(final Document document) { configurations.clear();//from w ww . java 2s. c o m Element root = document.getRootElement(); Element sessions = root.getChild("sessions"); for (Element session : sessions.getChildren("session")) { LOG.trace("loadFromDocument - session"); SessionConfiguration sc = new SessionConfiguration(); configurations.add(sc); sc.fromElement(session); } }
From source file:cz.lbenda.dbapp.rc.SessionConfiguration.java
License:Apache License
private void loadExtendedConfigurationFromFile() { SAXBuilder builder = new SAXBuilder(); try {/*from w w w . jav a 2 s . co m*/ File file = new File(extendedConfigurationPath); Document document = builder.build(new FileReader(file)); Element root = document.getRootElement(); loadSchemas(root.getChild("schemas")); tableOfKeysSQLFromElement(root.getChild("tableOfKeySQLs")); tableDescriptionExtensionsFromElement(root.getChild("tableDescriptionExtensions")); } catch (JDOMException e) { LOG.error("The file isn't parsable: " + extendedConfigurationPath, e); throw new RuntimeException("The file isn't parsable: " + extendedConfigurationPath, e); } catch (IOException e) { LOG.error("The file can't be opend as StringReader: " + extendedConfigurationPath, e); throw new RuntimeException("The file cant be opend as StringReader: " + extendedConfigurationPath, e); } }
From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.FunctionNormalizer.java
License:Apache License
@Override public void execute(final Document doc) { if (doc == null) { throw new NullPointerException("doc"); }// www.j a v a 2 s . com normalizeFunctionApplication(doc.getRootElement(), getPropertySet(APPLY_FUNCTION_OPERATORS)); }
From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.MrowNormalizer.java
License:Apache License
@Override public void execute(final Document doc) { if (doc == null) { throw new NullPointerException("doc"); }/*from www . j a va2s . c om*/ traverseChildrenElements(doc.getRootElement()); }