1 package de.uni_hamburg.corpora.validation;
10 import java.io.IOException;
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.List;
15 import java.util.regex.Pattern;
16 import javax.xml.parsers.ParserConfigurationException;
17 import javax.xml.transform.TransformerException;
18 import javax.xml.xpath.XPathExpressionException;
19 import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException;
20 import org.xml.sax.SAXException;
21 import org.jdom.Document;
22 import org.jdom.Element;
23 import org.jdom.JDOMException;
24 import org.jdom.xpath.XPath;
32 static String filename;
34 String path2ExternalFSM =
"";
46 report.
addCritical(
function, cd,
"Checking option is not available");
59 List<Element> toRemove =
new ArrayList<Element>();
63 context = XPath.newInstance(
"//Transcription[Description/Key[@Name='segmented']/text()='true']");
65 List allContextInstances = context.selectNodes(comaDoc);
66 if (!allContextInstances.isEmpty()) {
67 for (
int i = 0; i < allContextInstances.size(); i++) {
68 Object o = allContextInstances.get(i);
69 if (o instanceof Element) {
70 Element e = (Element) o;
71 List<Element> descKeys;
73 descKeys = e.getChild(
"Description")
75 for (Element ke : (List<Element>) descKeys) {
76 if (Pattern.matches(
"#(..).*", ke.getAttributeValue(
"Name"))) {
80 for (Element re : toRemove) {
84 String s = e.getChildText(
"NSLink");
88 List segmentCounts = exs.getSegmentCounts();
89 for (Object segmentCount : segmentCounts) {
90 if (segmentCount instanceof Element) {
91 Element segmentCountEl = (Element) segmentCount;
93 Object key = segmentCountEl.getAttributeValue(
"attribute-name");
94 Object value = segmentCountEl.getValue();
96 Element newKey =
new Element(
"Key");
97 newKey.setAttribute(
"Name", (String) key);
98 newKey.setText(value.toString());
99 e.getChild(
"Description").addContent(
101 report.
addFix(
function, cd,
"Updated segment count " + key.toString() +
":" + value.toString() +
"for transcription " + e.getAttributeValue(
"Name"));
108 if (comaDoc != null) {
111 report.
addCorrect(
function, cd,
"Updated the segment counts!");
113 report.
addCritical(
function, cd,
"Updating the segment counts was not possible!");
115 }
catch (IOException ex) {
116 report.
addException(ex,
function, cd,
"unknown IO exception");
117 }
catch (TransformerException ex) {
118 report.
addException(ex,
function, cd,
"unknown xml exception");
119 }
catch (ParserConfigurationException ex) {
120 report.
addException(ex,
function, cd,
"unknown xml exception");
121 }
catch (SAXException ex) {
122 report.
addException(ex,
function, cd,
"unknown xml exception");
123 }
catch (XPathExpressionException ex) {
124 report.
addException(ex,
function, cd,
"unknown xml exception");
125 }
catch (JDOMException ex) {
126 report.
addException(ex,
function, cd,
"unknown xml exception");
127 }
catch (ClassNotFoundException ex) {
128 report.
addException(ex,
function, cd,
"class not found exception");
141 Class cl = Class.forName(
"de.uni_hamburg.corpora.ComaData");
143 }
catch (ClassNotFoundException ex) {
155 String description =
"This class takes a coma file, updates the info using" 156 +
" the linked exbs and saves the coma file afterwards without changing" 163 throw new UnsupportedOperationException(
"Not supported yet.");
167 public Report function(
CorpusData cd, Boolean
fix)
throws SAXException, IOException, ParserConfigurationException, JexmaraldaException, TransformerException, XPathExpressionException {
168 throw new UnsupportedOperationException(
"Not supported yet.");
Collection< Class<?extends CorpusData > > getIsUsableFor()
ComaUpdateSegmentCounts()
String toSaveableString()
CorpusData readFileURL(URL url, Collection< Class<?extends CorpusData >> clcds)
Report check(CorpusData cd)
void addCritical(String description)
void addCorrect(String statId, String description)
static org.jdom.Document String2JdomDocument(String stringRespresentingDocument)
static String JdomDocument2String(org.jdom.Document jdomDocument)
void addException(Throwable e, String description)
void updateUnformattedString(String newUnformattedString)
void write(CorpusData cd, URL url)
void addFix(String statId, CorpusData cd, String description)
Report fix(CorpusData cd)