10 package de.uni_hamburg.corpora.validation;
19 import java.io.IOException;
21 import java.io.UnsupportedEncodingException;
23 import java.util.Collection;
24 import java.util.List;
25 import java.util.ArrayList;
26 import java.util.logging.Level;
27 import java.util.logging.Logger;
28 import javax.xml.parsers.ParserConfigurationException;
29 import javax.xml.transform.TransformerException;
30 import javax.xml.xpath.XPathExpressionException;
32 import org.apache.commons.cli.Option;
33 import org.xml.sax.SAXException;
35 import org.exmaralda.partitureditor.jexmaralda.BasicTranscription;
36 import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException;
37 import org.exmaralda.partitureditor.jexmaralda.segment.AbstractSegmentation;
38 import org.exmaralda.partitureditor.fsm.FSMException;
39 import org.exmaralda.partitureditor.jexmaralda.SegmentedTranscription;
40 import org.jdom.Document;
41 import org.jdom.JDOMException;
48 static String filename;
49 static BasicTranscription bt;
52 AbstractSegmentation segmentation;
54 final String EXB_SEG =
"exb-segmentation-checker";
55 String segmentationName =
"GENERIC";
56 String path2ExternalFSM =
"";
62 }
catch (SAXException saxe) {
63 saxe.printStackTrace();
64 }
catch (JexmaraldaException je) {
72 filename = f.getAbsolutePath();
73 bt =
new BasicTranscription(filename);
85 public static void main(String[] args) {
87 "Checks Exmaralda .exb file for segmentation problems",
88 "If input is a directory, performs recursive check " 89 +
"from that directory, otherwise checks input file");
92 System.out.println(
"Checking EXB files for segmentation " 97 System.out.println(
" * " + f.getName());
118 }
catch (SAXException saxe) {
119 saxe.printStackTrace();
120 }
catch (JexmaraldaException je) {
121 je.printStackTrace();
122 }
catch (IOException ex) {
124 }
catch (ParserConfigurationException ex) {
135 throws SAXException, IOException, ParserConfigurationException, JexmaraldaException {
138 if (segmentationName.equals(
"HIAT")) {
139 segmentation =
new org.exmaralda.partitureditor.jexmaralda.segment.HIATSegmentation();
140 }
else if (segmentationName.equals(
"GAT")) {
141 segmentation =
new org.exmaralda.partitureditor.jexmaralda.segment.GATSegmentation();
142 }
else if (segmentationName.equals(
"cGAT_MINIMAL")) {
143 segmentation =
new org.exmaralda.partitureditor.jexmaralda.segment.cGATMinimalSegmentation();
144 }
else if (segmentationName.equals(
"CHAT")) {
145 segmentation =
new org.exmaralda.partitureditor.jexmaralda.segment.CHATSegmentation();
146 }
else if (segmentationName.equals(
"CHAT_MINIMAL")) {
147 segmentation =
new org.exmaralda.partitureditor.jexmaralda.segment.CHATMinimalSegmentation();
148 }
else if (segmentationName.equals(
"DIDA")) {
149 segmentation =
new org.exmaralda.partitureditor.jexmaralda.segment.DIDASegmentation();
150 }
else if (segmentationName.equals(
"IPA")) {
151 segmentation =
new org.exmaralda.partitureditor.jexmaralda.segment.IPASegmentation();
153 segmentation =
new org.exmaralda.partitureditor.jexmaralda.segment.GenericSegmentation();
155 if (!path2ExternalFSM.equals(
"")) {
156 segmentation.pathToExternalFSM = path2ExternalFSM;
158 List v = segmentation.getSegmentationErrors(btd.
getEXMARaLDAbt());
160 FSMException fsme = (FSMException) o;
161 String text = fsme.getMessage();
163 exmaError.addError(EXB_SEG, filename, fsme.getTierID(), fsme.getTLI(),
false, text);
176 }
catch (SAXException saxe) {
177 saxe.printStackTrace();
178 }
catch (JexmaraldaException je) {
179 je.printStackTrace();
180 }
catch (IOException ex) {
182 }
catch (JDOMException ex) {
184 }
catch (FSMException ex) {
186 }
catch (TransformerException ex) {
188 }
catch (ParserConfigurationException ex) {
190 }
catch (XPathExpressionException ex) {
197 public Report exceptionalFix(
CorpusData cd)
throws SAXException, JDOMException, IOException, JexmaraldaException, FSMException, TransformerException, ParserConfigurationException, UnsupportedEncodingException, XPathExpressionException {
200 if (segmentationName.equals(
"HIAT")) {
201 segmentation =
new org.exmaralda.partitureditor.jexmaralda.segment.HIATSegmentation();
202 }
else if (segmentationName.equals(
"GAT")) {
203 segmentation =
new org.exmaralda.partitureditor.jexmaralda.segment.GATSegmentation();
204 }
else if (segmentationName.equals(
"cGAT_MINIMAL")) {
205 segmentation =
new org.exmaralda.partitureditor.jexmaralda.segment.cGATMinimalSegmentation();
206 }
else if (segmentationName.equals(
"CHAT")) {
207 segmentation =
new org.exmaralda.partitureditor.jexmaralda.segment.CHATSegmentation();
208 }
else if (segmentationName.equals(
"CHAT_MINIMAL")) {
209 segmentation =
new org.exmaralda.partitureditor.jexmaralda.segment.CHATMinimalSegmentation();
210 }
else if (segmentationName.equals(
"DIDA")) {
211 segmentation =
new org.exmaralda.partitureditor.jexmaralda.segment.DIDASegmentation();
212 }
else if (segmentationName.equals(
"IPA")) {
213 segmentation =
new org.exmaralda.partitureditor.jexmaralda.segment.IPASegmentation();
215 segmentation =
new org.exmaralda.partitureditor.jexmaralda.segment.GenericSegmentation();
217 if (!path2ExternalFSM.equals(
"")) {
218 segmentation.pathToExternalFSM = path2ExternalFSM;
220 List v = segmentation.getSegmentationErrors(btd.
getEXMARaLDAbt());
222 SegmentedTranscription st = segmentation.BasicToSegmented(btd.
getEXMARaLDAbt());
227 stats.
addCorrect(EXB_SEG, cd,
"Exs successfully created at " + url);
230 FSMException fsme = (FSMException) o;
231 String text = fsme.getMessage();
233 exmaError.addError(EXB_SEG, filename, fsme.getTierID(), fsme.getTLI(),
false, text);
247 Class cl = Class.forName(
"de.uni_hamburg.corpora.BasicTranscriptionData");
249 }
catch (ClassNotFoundException ex) {
250 Logger.getLogger(
ExbSegmenter.class.getName()).log(Level.SEVERE, null, ex);
256 segmentationName = s;
260 path2ExternalFSM = s;
Collection< Class<?extends CorpusData > > getIsUsableFor()
CommandLine handleCommandLine(String[] args, List< Option > extraOptions)
String getFilenameWithoutFileEnding()
BasicTranscription getEXMARaLDAbt()
Collection< File > getInputFiles()
static Report exceptionalCheck(File f)
static ExmaErrorList exmaError
Report exceptionalFix(CorpusData cd)
static void main(String[] args)
static Report check(File f)
void addCritical(String description)
Report fix(CorpusData cd)
void addCorrect(String statId, String description)
static org.jdom.Document String2JdomDocument(String stringRespresentingDocument)
void setExternalFSM(String s)
void addException(Throwable e, String description)
Report check(CorpusData cd)
void setSegmentation(String s)