corpus-services  1.0
ExbNormalize.java
Go to the documentation of this file.
1 /*
2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6 package de.uni_hamburg.corpora.validation;
7 
14 import java.io.IOException;
15 import java.net.URISyntaxException;
16 import java.util.Collection;
17 import javax.xml.parsers.ParserConfigurationException;
18 import javax.xml.transform.TransformerException;
19 import javax.xml.xpath.XPathExpressionException;
20 import org.jdom.Document;
21 import org.jdom.JDOMException;
22 import org.exmaralda.partitureditor.jexmaralda.BasicTranscription;
23 import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException;
24 import org.xml.sax.SAXException;
25 
34 public class ExbNormalize extends Checker implements CorpusFunction {
35 
36  Document doc = null;
37  BasicTranscriptionData btd = null;
38  Boolean fixWhiteSpaces = false;
39 
40  public ExbNormalize() {
41  super(true);
42  }
43 
44  @Override
45  public Report function(CorpusData cd, Boolean fix) throws TransformerException, ParserConfigurationException, SAXException, IOException, XPathExpressionException, JDOMException {
46  if (fix) {
47  btd = (BasicTranscriptionData) cd;
48  BasicTranscription bt = btd.getEXMARaLDAbt();
49  bt.normalize();
50  if (fixWhiteSpaces) {
51  bt.normalizeWhiteSpace();
52  }
53  btd.setReadbtasjdom(bt.toJDOMDocument());
54  btd.setOriginalString(bt.toXML());
55  //btd.updateReadbtasjdom();
56  cd = (CorpusData) btd;
57  CorpusIO cio = new CorpusIO();
58  cio.write(cd, cd.getURL());
59  if (cd != null) {
60  report.addFix(function, cd, "normalized the file");
61  } else {
62  report.addCritical(function, cd, "normalizing was not possible");
63  }
64  } else {
65  report.addCritical(function, cd, "Checking option is not available");
66  }
67  return report;
68  }
69 
70  @Override
71  public Collection<Class<? extends CorpusData>> getIsUsableFor() {
72  try {
73  Class cl = Class.forName("de.uni_hamburg.corpora.BasicTranscriptionData");
74  IsUsableFor.add(cl);
75 
76  } catch (ClassNotFoundException ex) {
77  report.addException(ex, "unknown class not found error");
78  }
79  return IsUsableFor;
80  }
81 
82  public void setfixWhiteSpaces(String s) {
83  fixWhiteSpaces = false;
84  if (s.equals("true") || s.equals("wahr") || s.equals("ja") || s.equals("yes")) {
85  fixWhiteSpaces = true;
86  }
87  }
88 
93  @Override
94  public String getDescription() {
95  String description = "This class normalises the basic transcription data using "
96  + "the EXMARaLDA function and fixes white spaces if set by a parameter. ";
97  return description;
98  }
99 
100  @Override
101  public Report function(Corpus c, Boolean fix) throws SAXException, IOException, ParserConfigurationException, URISyntaxException, JDOMException, TransformerException, XPathExpressionException {
102  Report stats = new Report();
103  for (CorpusData cdata : c.getBasicTranscriptionData()) {
104  stats.merge(function(cdata, fix));
105  }
106  return stats;
107  }
108 
109 }
Collection< Class<?extends CorpusData > > getIsUsableFor()
void merge(Report sr)
Definition: Report.java:73
void addCritical(String description)
Definition: Report.java:104
void addException(Throwable e, String description)
Definition: Report.java:287
void write(CorpusData cd, URL url)
Definition: CorpusIO.java:66
void addFix(String statId, CorpusData cd, String description)
Definition: Report.java:155