120 |
120 |
super.processCharacters();
|
121 |
121 |
}
|
122 |
122 |
}
|
123 |
|
|
|
123 |
|
|
124 |
protected void writeWord(String word) {
|
|
125 |
writer.writeStartElement("w") // start the initial word
|
|
126 |
for (String attr : wInfos.keySet() ) {
|
|
127 |
writer.writeAttribute(attr, wInfos[attr])
|
|
128 |
}
|
|
129 |
writer.writeCharacters(word)
|
|
130 |
writer.writeEndElement() // w
|
|
131 |
}
|
|
132 |
|
|
133 |
def startOtherReg = /^(.*)\*([^ ]+.*)$/
|
|
134 |
def endOtherReg = /^(.*[^ ]+)\*(.*)$/
|
|
135 |
String previousOtherStarting = "<none>"
|
124 |
136 |
@Override
|
125 |
137 |
protected void processEndElement() throws XMLStreamException {
|
126 |
138 |
if (localname.equals("w")) {
|
127 |
139 |
|
128 |
140 |
inW = false
|
129 |
141 |
String word = wordBuffer.toString().trim()
|
130 |
|
if (word.startsWith("*")) {
|
|
142 |
def m1 = word =~ startOtherReg
|
|
143 |
|
|
144 |
if (m1.matches()) {
|
|
145 |
if (debug) println "OPEN OTHER at $word"
|
131 |
146 |
if (other) {
|
132 |
147 |
println "Warning: found a starting * when one 'other' is already started at "+getLocation()
|
|
148 |
println "Previous starting 'other' at "+previousOtherStarting
|
133 |
149 |
} else {
|
134 |
150 |
//close current Turn and start a 'other' Turn
|
|
151 |
previousOtherStarting = ["word="+word+ " location="+getLocation()]
|
|
152 |
String group1 = m1.group(1)
|
|
153 |
if (group1.length() > 0) {
|
|
154 |
writeWord(group1)
|
|
155 |
writer.writeCharacters("\n")
|
|
156 |
}
|
|
157 |
|
135 |
158 |
writer.writeEndElement() // current Turn
|
136 |
159 |
writer.writeCharacters("\n")
|
137 |
160 |
|
... | ... | |
149 |
172 |
for (String attr : tmpInfos.keySet()) {
|
150 |
173 |
writer.writeAttribute(attr, tmpInfos[attr])
|
151 |
174 |
}
|
|
175 |
writer.writeCharacters("\n")
|
152 |
176 |
|
153 |
177 |
other = true
|
154 |
|
word = word.substring(1)
|
|
178 |
word = m1.group(2)
|
155 |
179 |
}
|
156 |
180 |
}
|
157 |
181 |
|
158 |
182 |
boolean shouldCloseOtherTurn = false;
|
159 |
|
if (word.endsWith("*")) {
|
|
183 |
def m2 = word =~ endOtherReg
|
|
184 |
if (m2.matches()) {
|
|
185 |
if (debug) println "DETECT END OTHER at $word"
|
|
186 |
previousOtherStarting = ["word="+word+ " location="+getLocation()]
|
160 |
187 |
if (other) {
|
161 |
188 |
shouldCloseOtherTurn = true;
|
162 |
189 |
|
163 |
|
word = word.substring(0, word.length()-1)
|
|
190 |
word = m2.group(1)
|
164 |
191 |
other = false
|
165 |
192 |
} else {
|
166 |
193 |
println "Warning: found a ending * when one 'other' is not started at "+getLocation()
|
|
194 |
println "Previous closing 'other' Turn at "+previousOtherStarting
|
167 |
195 |
}
|
168 |
196 |
}
|
169 |
197 |
|
170 |
|
if ("XXX".equals(word)) { // <Event desc="XXX" type="unknown" extent="next"/>
|
171 |
|
writer.writeStartElement("event") // start the initial word
|
172 |
|
writer.writeAttribute("desc", "XXX from "+wInfos["start"] + " to "+wInfos["end"])
|
173 |
|
writer.writeAttribute("type", "unknown")
|
174 |
|
writer.writeAttribute("extent", "instantaneous")
|
175 |
|
writer.writeEndElement() // event
|
176 |
|
word = "" // don't write the word
|
177 |
|
}
|
|
198 |
// if ("XXX".equals(word)) { // <Event desc="XXX" type="unknown" extent="next"/>
|
|
199 |
// writer.writeStartElement("event") // start the initial word
|
|
200 |
// writer.writeAttribute("desc", "XXX from "+wInfos["start"] + " to "+wInfos["end"])
|
|
201 |
// writer.writeAttribute("type", "unknown")
|
|
202 |
// writer.writeAttribute("extent", "instantaneous")
|
|
203 |
// writer.writeEndElement() // event
|
|
204 |
// word = "" // don't write the word
|
|
205 |
// }
|
178 |
206 |
|
179 |
207 |
if (word.length() > 0) {
|
180 |
|
|
181 |
|
writer.writeStartElement("w") // start the initial word
|
182 |
|
for (String attr : wInfos.keySet() ) {
|
183 |
|
writer.writeAttribute(attr, wInfos[attr])
|
184 |
|
}
|
185 |
|
writer.writeCharacters(word)
|
186 |
|
writer.writeEndElement() // w
|
|
208 |
writeWord(word)
|
187 |
209 |
}
|
188 |
210 |
|
189 |
211 |
if (shouldCloseOtherTurn) {
|
|
212 |
if (debug) println "CLOSE OTHER at $word"
|
190 |
213 |
shouldCloseOtherTurn = false;
|
191 |
214 |
//close the current 'other' Turn and restart the actual Turn
|
|
215 |
writer.writeCharacters("\n")
|
192 |
216 |
writer.writeEndElement() // current 'other' Turn
|
|
217 |
writer.writeCharacters("\n")
|
193 |
218 |
|
194 |
219 |
writer.writeStartElement("Turn") // rebuild the orig Turn and fix its start-end infos
|
195 |
220 |
turnInfos["startTime"] = wInfos["end"] // fix the startTime using the current word end time
|
196 |
221 |
for (String attr : turnInfos.keySet()) {
|
197 |
222 |
writer.writeAttribute(attr, turnInfos[attr])
|
198 |
223 |
}
|
|
224 |
writer.writeCharacters("\n")
|
199 |
225 |
|
|
226 |
if (m2.group(2).length() > 0) {
|
|
227 |
writeWord(m2.group(2))
|
|
228 |
}
|
|
229 |
|
200 |
230 |
other = false
|
201 |
231 |
}
|
202 |
232 |
} else {
|