corpus-services  1.0
EXB2EAF.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 
7 package de.uni_hamburg.corpora.conversion;
8 
11 import java.util.logging.Level;
12 import java.util.logging.Logger;
13 import javax.xml.transform.TransformerConfigurationException;
14 import javax.xml.transform.TransformerException;
15 import org.exmaralda.partitureditor.jexmaralda.BasicTranscription;
16 
24 public class EXB2EAF {
25 
28  static final String EX2ELAN_STYLESHEET = "/org/exmaralda/partitureditor/jexmaralda/xsl/BasicTranscription2EAF.xsl";
29 
30 
32  public EXB2EAF() {
33 
34  }
35 
36 
40  public String EXB2EAF(String basicTranscription){
41  return convert(basicTranscription);
42  }
43 
44 
48  public String convert(String basicTranscription){
49 
50  String result = null;
51 
52  try{
53  /* ELANConverter in EXMARaLDA works with BasicTranscription object */
54  BasicTranscription bt = TypeConverter.String2BasicTranscription(basicTranscription);
55 
56  /* NOTE: conversion method from ELANConverter in EXMARaLDA cannot be used directly (private),
57  so that directives from private method BasicTranscriptionToELAN method from ELANConverter
58  have to replicated here */
59 
60 
61  // interpolate the timeline, i.e. calculate absoulute time values for timeline items
62  // that don't have an absolute time value assigned
63  // (is this necessary or can ELAN also handle time slots without absolute time values?)
64  bt.getBody().getCommonTimeline().completeTimes();
65 
66  // read BasicTranscription into a String
67  String exb = bt.toXML();
68 
69  // read the XSL stylesheet into a String
70  String xsl = TypeConverter.InputStream2String(org.exmaralda.partitureditor.jexmaralda.convert.ELANConverter.class.getResourceAsStream(EX2ELAN_STYLESHEET));
71 
72  // create a class for performing a stylesheet transformation
73  XSLTransformer xt = new XSLTransformer();
74  result = xt.transform(exb, xsl);
75 
76  } catch (TransformerConfigurationException ex) {
77  Logger.getLogger(EXB2EAF.class.getName()).log(Level.SEVERE, null, ex);
78  } catch (TransformerException ex) {
79  Logger.getLogger(EXB2EAF.class.getName()).log(Level.SEVERE, null, ex);
80  }
81 
82  return result;
83  }
84 
85 }
String EXB2EAF(String basicTranscription)
Definition: EXB2EAF.java:40
static BasicTranscription String2BasicTranscription(String btAsString)
static String InputStream2String(InputStream is)
String convert(String basicTranscription)
Definition: EXB2EAF.java:48