corpus-services  1.0
ExbMakeTimelineConsistent.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 
35 public class ExbMakeTimelineConsistent extends Checker implements CorpusFunction {
36 
37  Document doc = null;
38  BasicTranscriptionData btd = null;
39  Boolean interpolateTimeline = false;
40 
42  //fixing option available
43  super(true);
44  }
45 
46  @Override
47  public Report function(CorpusData cd, Boolean fix) throws JDOMException, IOException, TransformerException, ParserConfigurationException, SAXException, XPathExpressionException {
48  if (fix) {
49 
50  btd = (BasicTranscriptionData) cd;
51  BasicTranscription bt = btd.getEXMARaLDAbt();
52  bt.getBody().getCommonTimeline().makeConsistent();
53  if (interpolateTimeline) {
54  bt.getBody().getCommonTimeline().completeTimes();
55  }
56 
57  btd.setReadbtasjdom(bt.toJDOMDocument());
58  btd.setOriginalString(bt.toXML(bt.getTierFormatTable()));
59  //btd.updateReadbtasjdom();
60  cd = (CorpusData) btd;
61  CorpusIO cio = new CorpusIO();
62  cio.write(cd, cd.getURL());
63  if (cd != null) {
64  report.addFix(function, cd, "made timeline consistent");
65  } else {
66  report.addCritical(function, cd, "making timeline consistent not possible");
67  }
68 
69  } else {
70  report.addCritical(function, cd, "Checking option is not available");
71  }
72  return report;
73  }
74 
75  @Override
76  public Collection<Class<? extends CorpusData>> getIsUsableFor() {
77  try {
78  Class cl = Class.forName("de.uni_hamburg.corpora.BasicTranscriptionData");
79  IsUsableFor.add(cl);
80 
81  } catch (ClassNotFoundException ex) {
82  report.addException(ex, "unknown class not found error");
83  }
84  return IsUsableFor;
85  }
86 
87  public void setInterpolateTimeline(String s) {
88  interpolateTimeline = false;
89  if (s.equals("true") || s.equals("wahr") || s.equals("ja") || s.equals("yes")) {
90  interpolateTimeline = true;
91  }
92  }
93 
98  @Override
99  public String getDescription() {
100  String description = "This class makes the timeline of exbs consistent by removing "
101  + "incorrect timepoints and interpolates timeline items without time "
102  + "info if the parameter is set. ";
103  return description;
104  }
105 
106  @Override
107  public Report function(Corpus c, Boolean fix) throws SAXException, IOException, ParserConfigurationException, URISyntaxException, JDOMException, TransformerException, XPathExpressionException {
108  Report stats = new Report();
109  for (CorpusData cdata : c.getBasicTranscriptionData()) {
110  stats.merge(function(cdata, fix));
111  }
112  return stats;
113  }
114 }
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