pars = (filter == null)
+ ? new ElementList(doc.getElementsByTagName("par"))
+ : filter.selectElements(doc);
+
+ for (int npar = 0; npar < pars.size(); ++npar) {
+ Element par = pars.get(npar);
+ readFR10Par(par);
+ }
+ }
+
+ /**
+ * Reads textual content from HOCR HTML file
+ *
+ * @param file
+ * the input HTML file
+ */
+ private void readHOCRFile(File file) throws WarningException {
+ try {
+ org.jsoup.nodes.Document doc = org.jsoup.Jsoup.parse(file, null);
+ Charset htmlEncoding = doc.outputSettings().charset();
+
+ if (htmlEncoding == null) {
+ encoding = Encoding.detect(file);
+ Messages.warning("No charset declaration in "
+ + file + ". Using " + encoding);
+ } else {
+ encoding = htmlEncoding;
+ Messages.info("HTML file " + file
+ + " encoding is " + encoding);
+ }
+
+ for (org.jsoup.nodes.Element e : doc.body().select(
+ "*[class=ocr_line")) {
+ String text = e.text();
+ add(text);
+
+ }
+ } catch (IOException ex) {
+ Messages.info(Text.class.getName() + ": " + ex);
+ }
+ }
+
+ /**
+ * Reads textual content in ALTO XML element of type TextLine
+ *
+ * @param file
+ * the input ALTO file
+ */
+ private void readALTOTextLine(Element line) throws WarningException {
+ NodeList strings = line.getElementsByTagName("String");
+
+ for (int nstring = 0; nstring < strings.getLength(); ++nstring) {
+ Element string = (Element) strings.item(nstring);
+ String text = string.getAttribute("CONTENT");
+ add(text);
+ }
+
+ }
+
+ /**
+ * Reads textual content from ALTO XML file
+ *
+ * @param file
+ * the input ALTO file
+ */
+ private void readALTOFile(File file) throws WarningException {
+ Document doc = loadXMLFile(file);
+ NodeList lines = doc.getElementsByTagName("TextLine");
+
+ for (int nline = 0; nline < lines.getLength(); ++nline) {
+ Element line = (Element) lines.item(nline);
+ readALTOTextLine(line);
+ }
+ }
+
+ /**
+ * Extract text content (under the filtered elements)
+ *
+ * @throws java.io.IOException
+ */
+ public static void main(String[] args) throws IOException,
+ WarningException, XPathExpressionException, SchemaLocationException {
+ if (args.length < 1 | args[0].equals("-h")) {
+ System.err.println("usage: Text xmlfile [xpathfile] [xpathfile]");
+ } else {
+ File xmlfile = new File(args[0]);
+ File inclusions = args.length > 1 ? new File(args[1]) : null;
+ File exclusions = args.length > 2 ? new File(args[2]) : null;
+ XPathFilter filter = (inclusions == null)
+ ? null
+ : new XPathFilter(inclusions, exclusions);
+
+ Text text = new Text(xmlfile, null, filter);
+ System.out.println(text);
+ }
+ }
+}
diff --git a/ocrevalUAtion/src/main/java/eu/digitisation/text/UnicodeReader.java b/ocrevalUAtion/src/main/java/eu/digitisation/text/UnicodeReader.java
new file mode 100644
index 00000000..1ce17c81
--- /dev/null
+++ b/ocrevalUAtion/src/main/java/eu/digitisation/text/UnicodeReader.java
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2013 Universidad de Alicante
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+package eu.digitisation.text;
+
+import eu.digitisation.log.Messages;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+
+/**
+ * Transformations between Unicode strings and codepoints
+ *
+ * @version 2012.06.20
+ */
+public class UnicodeReader {
+
+ /**
+ * Transform a sequence of Unicode values (blocks of four hexadecimal
+ * digits) into the string they represent. For example, "00410042" (or "0041
+ * 0042") represents "AB"
+ *
+ * @param codes the sequence of one or more Unicode hex values
+ * @return the string represented by these codes
+ * @throws java.io.IOException
+ */
+ protected static String codepointsToString(String codes) throws IOException {
+ StringBuilder builder = new StringBuilder();
+ String[] tokens = codes.trim().split("\\p{Space}+");
+
+ for (String token : tokens) {
+ if (token.length() % 4 != 0) {
+ throw new IOException(token
+ + " is not a valid Unicode hex sequence");
+ }
+ for (int pos = 0; pos + 3 < token.length(); pos += 4) {
+ String sub = token.substring(pos, pos + 4);
+ int val = Integer.parseInt(sub, 16);
+ builder.append((char) val);
+ }
+ }
+ return builder.toString();
+ }
+
+ /**
+ * Build a string from the codepoints (Unicode values) defining its content
+ *
+ * @param codes
+ * @return the string represented by those codepoints
+ */
+ public static String codepointsToString(int[] codes) {
+ StringBuilder buff = new StringBuilder();
+ for (int code : codes) {
+ buff.append((char) code);
+ }
+ return buff.toString();
+ }
+
+ /**
+ * Convert a string into a sequence of Unicode values
+ *
+ * @param s a Java String
+ * @return The array of Unicode values of the characters in s
+ */
+ public static int[] toCodepoints(String s) {
+ int[] codes = new int[s.length()];
+ for (int n = 0; n < s.length(); ++n) {
+ codes[n] = (int) s.charAt(n);
+ }
+ return codes;
+ }
+
+ /**
+ * Transform an array of integers into their hexadecimal representation
+ *
+ * @param values an integer array
+ * @return the hexadecimal strings representing their value.
+ */
+ private static String[] toHexString(int[] values) {
+ String[] hex = new String[values.length];
+ for (int n = 0; n < values.length; ++n) {
+ hex[n] = Integer.toHexString(values[n]);
+ }
+ return hex;
+ }
+
+ /**
+ * Convert a string into a sequence of Unicode hexadecimal values
+ *
+ * @param s a Java String
+ * @return The array of Unicode values (hexadecimal representation) of the
+ * characters in s
+ */
+ public static String[] toHexCodepoints(String s) {
+ return toHexString(toCodepoints(s));
+ }
+
+ /**
+ * Read a text file and print the content as codepoints (Unicode values) in
+ * it
+ *
+ * @param file the input file
+ * @throws Exception
+ */
+ public static void printHexCodepoints(File file)
+ throws Exception {
+ BufferedReader reader = new BufferedReader(new FileReader(file));
+ while (reader.ready()) {
+ String line = reader.readLine();
+ String[] hexcodes = toHexCodepoints(line);
+ System.out.println(java.util.Arrays.toString(hexcodes));
+ }
+ reader.close();
+ }
+
+ /**
+ * Search for a Unicode sequence and highlight them in browser
+ *
+ * @param files files where the sequence is searched
+ * @param outFile the output file
+ * @param codepoints the Unicode sequence
+ */
+ public static void find(File[] files, String codepoints, File outFile) {
+ try {
+ String pattern = codepointsToString(codepoints);
+ for (File file : files) {
+ BufferedReader reader = new BufferedReader(new FileReader(file));
+ PrintWriter writer = new PrintWriter(outFile);
+ writer.print(""
+ + file + "
");
+ while (reader.ready()) {
+ String line = reader.readLine();
+ if (line.contains(pattern)) {
+ writer.print(""
+ + StringNormalizer.encode(line) + "
");
+ } else {
+ writer.print("" + StringNormalizer.encode(line) + "
");
+ }
+ }
+ reader.close();
+ writer.close();
+ }
+ } catch (IOException ex) {
+ Messages.info(CharFilter.class.getName() + ": " + ex);
+ }
+ }
+}
diff --git a/ocrevalUAtion/src/main/java/eu/digitisation/text/WordScanner.java b/ocrevalUAtion/src/main/java/eu/digitisation/text/WordScanner.java
new file mode 100644
index 00000000..67773865
--- /dev/null
+++ b/ocrevalUAtion/src/main/java/eu/digitisation/text/WordScanner.java
@@ -0,0 +1,209 @@
+/*
+ * Copyright (C) 2013 Universidad de Alicante
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+package eu.digitisation.text;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A simple and fast text scanner which reads words from a file and performs the
+ * tokenization oriented by information-retrieval requirements.
+ *
+ * @version 2012.06.20
+ */
+public class WordScanner {
+
+ static Pattern pattern;
+ Matcher matcher;
+ BufferedReader reader;
+
+ static {
+ StringBuilder builder = new StringBuilder();
+ builder.append("(");
+ builder.append("(\\p{L}+([-\\x26'+/@·.]\\p{L}+)*)");
+ builder.append("|");
+ builder.append("([\\p{Nd}\\p{Nl}\\p{No}]+([-',./][\\p{Nd}\\p{Nl}\\p{No}]+)*[%‰]?)");
+ builder.append(")");
+ pattern = Pattern.compile(builder.toString());
+ }
+
+ /**
+ * Open an InputStream for scanning
+ *
+ * @param is the InputStream
+ * @param encoding the character encoding (e.g., UTF-8).
+ * @param regex the regular expression for words
+ * @throws IOException
+ */
+ public WordScanner(InputStream is, Charset encoding, String regex)
+ throws IOException {
+ InputStreamReader isr = new InputStreamReader(is, encoding);
+
+ if (regex != null) {
+ pattern = Pattern.compile(regex);
+ }
+
+ reader = new BufferedReader(isr);
+ if (reader.ready()) {
+ matcher = pattern.matcher(reader.readLine());
+ } else {
+ matcher = pattern.matcher("");
+ }
+ }
+
+ /**
+ * Open an InputStream for scanning
+ *
+ * @param is the InputStream
+ * @param encoding the character encoding (e.g., UTF-8).
+ * @throws IOException
+ */
+ public WordScanner(InputStream is, Charset encoding)
+ throws IOException {
+ this(is, encoding, null);
+ }
+
+ /**
+ * Open file with specific encoding for scanning.
+ *
+ * @param file the input file.
+ * @param encoding the encoding (e.g., UTF-8).
+ * @param regex the regular expression for words
+ * @throws java.io.IOException
+ */
+ public WordScanner(File file, Charset encoding, String regex)
+ throws IOException {
+ this(new FileInputStream(file), encoding, regex);
+ }
+
+ /**
+ * Open file with specific encoding for scanning.
+ *
+ * @param file the input file.
+ * @param encoding the encoding (e.g., UTF-8).
+ * @throws java.io.IOException
+ */
+ public WordScanner(File file, Charset encoding)
+ throws IOException {
+ this(new FileInputStream(file), encoding);
+ }
+
+ /**
+ * Open a file for scanning.
+ *
+ * @param file the input file.
+ * @throws java.io.IOException
+ */
+ public WordScanner(File file, String regex)
+ throws IOException {
+ this(file, Encoding.detect(file), regex);
+ }
+
+ /**
+ * Open a string for scanning
+ *
+ * @param s the input string to be tokenized
+ * @param regex the regular expression for words
+ * @throws IOException
+ */
+ public WordScanner(String s, String regex) throws IOException {
+ this(new ByteArrayInputStream(s.getBytes("UTF-8")),
+ Charset.forName("UTF-8"), regex);
+ }
+
+ /**
+ * Open a string for scanning
+ *
+ * @param s the input string to be tokenized
+ * @throws IOException
+ */
+ public WordScanner(String s) throws IOException {
+ this(new ByteArrayInputStream(s.getBytes("UTF-8")),
+ Charset.forName("UTF-8"));
+ }
+
+ /**
+ *
+ * @param file the input file to be processed
+ * @param regex the regular expression for words
+ * @return a StringBuilder with the file content
+ * @throws java.io.IOException
+ */
+ public static StringBuilder scanToStringBuilder(File file, String regex)
+ throws IOException {
+ StringBuilder builder = new StringBuilder();
+ WordScanner scanner = new WordScanner(file, regex);
+ String word;
+
+ while ((word = scanner.nextWord()) != null) {
+ builder.append(' ').append(word);
+ }
+ return builder;
+ }
+
+ /**
+ * Returns the next word in file.
+ *
+ * @return the next word in the scanned file
+ * @throws java.io.IOException
+ */
+ public String nextWord()
+ throws IOException {
+ String res = null;
+ while (res == null) {
+ if (matcher.find()) {
+ res = matcher.group(0);
+ } else if (reader.ready()) {
+ matcher = pattern.matcher(reader.readLine());
+ } else {
+ break;
+ }
+ }
+ return res;
+ }
+
+ /**
+ * Sample main.
+ *
+ * @param args
+ */
+ public static void main(String[] args) {
+ WordScanner scanner;
+
+ for (String arg : args) {
+ try {
+ String word;
+ File file = new File(arg);
+ scanner = new WordScanner(file, "[^\\p{Space}]+");
+ while ((word = scanner.nextWord()) != null) {
+ System.out.println(word);
+ }
+ } catch (IOException ex) {
+ System.err.println(ex);
+ }
+ }
+ }
+}
diff --git a/ocrevalUAtion/src/main/java/eu/digitisation/text/WordSet.java b/ocrevalUAtion/src/main/java/eu/digitisation/text/WordSet.java
new file mode 100644
index 00000000..bf29fa29
--- /dev/null
+++ b/ocrevalUAtion/src/main/java/eu/digitisation/text/WordSet.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2014 Universidad de Alicante
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+package eu.digitisation.text;
+
+import eu.digitisation.input.WarningException;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.HashSet;
+
+/**
+ *
+ * @author R.C.C.
+ */
+public class WordSet extends HashSet {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Default constructor
+ *
+ * @param file the file containing the list of stop-words (separated by
+ * blanks or newlines)
+ * @throws IOException
+ */
+ public WordSet(File file) throws WarningException {
+ try {
+ BufferedReader reader = new BufferedReader(new FileReader(file));
+ while (reader.ready()) {
+ String line = reader.readLine().trim();
+ for (String word : line.split("\\p{Space}+")) {
+ if (word.length() > 0) {
+ add(word);
+ }
+ }
+ }
+ } catch (IOException ex) {
+ throw new WarningException("File " + file
+ + " is not a valid stop word file");
+ }
+ }
+}
diff --git a/ocrevalUAtion/src/main/java/eu/digitisation/xml/DocumentBuilder.java b/ocrevalUAtion/src/main/java/eu/digitisation/xml/DocumentBuilder.java
new file mode 100644
index 00000000..d63a4909
--- /dev/null
+++ b/ocrevalUAtion/src/main/java/eu/digitisation/xml/DocumentBuilder.java
@@ -0,0 +1,203 @@
+/*
+ * Copyright (C) 2013 Universidad de Alicante
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+package eu.digitisation.xml;
+
+import eu.digitisation.log.Messages;
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.parsers.ParserConfigurationException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Adds some useful auxiliary functions to handle XML documents
+ *
+ * @author R.C.C
+ */
+public class DocumentBuilder {
+
+ Document doc;
+
+ /**
+ * Create an empty document
+ *
+ * @param doctype the document type
+ */
+ public DocumentBuilder(String doctype) {
+ try {
+ doc = javax.xml.parsers.DocumentBuilderFactory
+ .newInstance().newDocumentBuilder()
+ .newDocument();
+ Element root = doc.createElement(doctype);
+ doc.appendChild(root);
+ } catch (ParserConfigurationException ex) {
+ Messages.info(DocumentBuilder.class.getName() + ": " + ex);
+ }
+ }
+
+ /**
+ * Create a copy of another document
+ *
+ * @param other
+ */
+ public DocumentBuilder(Document other) {
+ doc = clone(other);
+ }
+
+ /**
+ * Create a copy of another document
+ *
+ * @param source a source document
+ * @return a deep copy of the document
+ */
+ public static Document clone(Document source) {
+ try {
+ Document target = javax.xml.parsers.DocumentBuilderFactory
+ .newInstance().newDocumentBuilder()
+ .newDocument();
+ Node node = target.importNode(source.getDocumentElement(), true);
+ target.appendChild(node);
+ return target;
+ } catch (ParserConfigurationException ex) {
+ Messages.info(DocumentBuilder.class.getName() + ": " + ex);
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @return the org.w3c.dom.Document
+ */
+ public Document document() {
+ return doc;
+ }
+
+ /**
+ *
+ * @return the root element in this document
+ */
+ public Element root() {
+ return doc.getDocumentElement();
+ }
+
+ /**
+ *
+ * @param e The parent element
+ * @param name The child element name
+ * @return list of children of e with the given tag
+ */
+ public static List getChildElementsByTagName(Element e, String name) {
+ ArrayList list = new ArrayList();
+ NodeList children = e.getChildNodes();
+
+ for (int n = 0; n < children.getLength(); ++n) {
+ Node node = children.item(n);
+ if (node instanceof Element && node.getNodeName().equals(name)) {
+ list.add((Element) node);
+ }
+ }
+ return list;
+ }
+
+ /**
+ * Create a new element under the designated element in the document.
+ *
+ * @param parent the parent element
+ * @param tag The tag of the new child element
+ * @return the added element
+ */
+ public Element addElement(Element parent, String tag) {
+ Element element = doc.createElement(tag);
+ parent.appendChild(element);
+ return element;
+ }
+
+ /**
+ * Create a new element directly under the root element.
+ *
+ * @param tag The tag of the new child element
+ * @return the added element
+ */
+ public Element addElement(String tag) {
+ return addElement(root(), tag);
+ }
+
+ /**
+ * Insert an element as a child of another element
+ *
+ * @param parent the parent element
+ * @param child the child element (even external one)
+ * @return the parent element
+ */
+ public Element addElement(Element parent, Element child) {
+ if (parent.getOwnerDocument() == child.getOwnerDocument()) {
+ parent.appendChild(child);
+ } else {
+ parent.appendChild(doc.importNode(child, true));
+ }
+ return parent;
+ }
+
+ /**
+ * Add text content under the given element
+ *
+ * @param parent the container element
+ * @param content the textual content
+ */
+ public void addText(Element parent, String content) {
+ parent.appendChild(doc.createTextNode(content));
+ }
+
+ /**
+ * Add a text element with the specified textual content under the
+ * designated element in the document.
+ *
+ * @param parent the parent element
+ * @param tag the new child element tag
+ * @param content the textual content
+ * @return the added element
+ */
+ public Element addTextElement(Element parent, String tag, String content) {
+ Element element = doc.createElement(tag);
+ element.appendChild(doc.createTextNode(content));
+ parent.appendChild(element);
+ return element;
+ }
+
+ /**
+ * Dump content to string
+ *
+ * @return the content as a string
+ */
+ @Override
+ public String toString() {
+ return new DocumentWriter(doc).toString();
+ }
+
+ /**
+ * Dump content to file
+ *
+ * @param file the output file
+ */
+ public void write(java.io.File file) {
+ new DocumentWriter(doc).write(file);
+ }
+
+}
diff --git a/ocrevalUAtion/src/main/java/eu/digitisation/xml/DocumentParser.java b/ocrevalUAtion/src/main/java/eu/digitisation/xml/DocumentParser.java
new file mode 100644
index 00000000..73f9dc3d
--- /dev/null
+++ b/ocrevalUAtion/src/main/java/eu/digitisation/xml/DocumentParser.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2013 Universidad de Alicante
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+package eu.digitisation.xml;
+
+import eu.digitisation.log.Messages;
+import java.io.IOException;
+import javax.xml.parsers.ParserConfigurationException;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+/**
+ * A builder and parser for XML documents
+ *
+ * @author R.C.C.
+ * @version 2011.03.10
+ */
+public class DocumentParser {
+
+ static javax.xml.parsers.DocumentBuilder docBuilder;
+
+ static {
+ try {
+ docBuilder = javax.xml.parsers.DocumentBuilderFactory
+ .newInstance().newDocumentBuilder();
+ } catch (ParserConfigurationException ex) {
+ Messages.info(DocumentParser.class.getName() + ": " + ex);
+ }
+ }
+
+ /**
+ * Create XML document from file content
+ *
+ * @param file the input file
+ * @return an XML document
+ */
+ public static Document parse(java.io.File file) {
+ try {
+ return docBuilder.parse(file);
+ } catch (SAXException ex) {
+ Messages.info(DocumentParser.class.getName() + ": " + ex);
+ } catch (IOException ex) {
+ Messages.info(DocumentParser.class.getName() + ": " + ex);
+ }
+ return null;
+ }
+
+ /**
+ * Create XML document from InputStream content
+ *
+ * @param is the InputStream with XML content
+ * @return an XML document
+ */
+ public static Document parse(java.io.InputStream is) {
+ try {
+ return docBuilder.parse(is);
+ } catch (SAXException ex) {
+ Messages.info(DocumentParser.class.getName() + ": " + ex);
+ } catch (IOException ex) {
+ Messages.info(DocumentParser.class.getName() + ": " + ex);
+ }
+
+ return null;
+ }
+}
diff --git a/ocrevalUAtion/src/main/java/eu/digitisation/xml/DocumentWriter.java b/ocrevalUAtion/src/main/java/eu/digitisation/xml/DocumentWriter.java
new file mode 100644
index 00000000..08faf9b8
--- /dev/null
+++ b/ocrevalUAtion/src/main/java/eu/digitisation/xml/DocumentWriter.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2013 Universidad de Alicante
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+package eu.digitisation.xml;
+
+import eu.digitisation.log.Messages;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import org.w3c.dom.Document;
+
+/**
+ * Writes XML document to String or File
+ *
+ * @author R.C.C.
+ */
+public class DocumentWriter {
+
+ static javax.xml.transform.Transformer transformer;
+
+ javax.xml.transform.dom.DOMSource source;
+ javax.xml.transform.stream.StreamResult result;
+
+ static {
+ try {
+ transformer = javax.xml.transform.TransformerFactory
+ .newInstance().newTransformer();
+ } catch (TransformerConfigurationException ex) {
+ Messages.info(DocumentWriter.class.getName() + ": " + ex);
+ }
+ }
+
+ /**
+ * Create a DocumentWriter for a given document
+ *
+ * @param document the XML document
+ */
+ public DocumentWriter(Document document) {
+ source = new javax.xml.transform.dom.DOMSource(document);
+ }
+
+ /**
+ * Write XML to string
+ *
+ * @return string representation
+ */
+ @Override
+ public String toString() {
+ result = new javax.xml.transform.stream.StreamResult(new java.io.StringWriter());
+ try {
+ transformer.transform(source, result);
+ } catch (TransformerException ex) {
+ Messages.info(DocumentParser.class.getName() + ": " + ex);
+ }
+ return result.getWriter().toString();
+ }
+
+ /**
+ * Dump content to file
+ *
+ * @param file the output file
+ */
+ public void write(java.io.File file) {
+ result = new javax.xml.transform.stream.StreamResult(file);
+ try {
+ transformer.transform(source, result);
+ } catch (TransformerException ex) {
+ Messages.info(DocumentParser.class.getName() + ": " + ex);
+ }
+
+ }
+}
diff --git a/ocrevalUAtion/src/main/java/eu/digitisation/xml/ElementList.java b/ocrevalUAtion/src/main/java/eu/digitisation/xml/ElementList.java
new file mode 100644
index 00000000..20c4bf89
--- /dev/null
+++ b/ocrevalUAtion/src/main/java/eu/digitisation/xml/ElementList.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2014 Universidad de Alicante
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+package eu.digitisation.xml;
+
+import java.util.ArrayList;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * A class transforming a org.w3c.dom.NodeList into a list of elements
+ *
+ * @author R.C.C
+ */
+public class ElementList extends ArrayList