Skip to content

Commit e7c287c

Browse files
committed
if rougnly one utterance in the file, use the filename instead of utterance for the text name
1 parent 65a81af commit e7c287c

File tree

6 files changed

+66
-2
lines changed

6 files changed

+66
-2
lines changed

Diff for: .travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: node_js
2+
node_js:
3+
- '0.10'
4+
before_script:

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Build Status](https://travis-ci.org/OpenSourceFieldlinguistics/PraatTextGridJS.png)](https://travis-ci.org/OpenSourceFieldlinguistics/PraatTextGridJS)
12
# textgrid
23

34
A small library which can parse TextGrid into json and json into TextGrid

Diff for: data/sampleEmpty.TextGrid

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
File type = "ooTextFile"
2+
Object class = "TextGrid"
3+
4+
xmin = 0
5+
xmax = 1.4729375
6+
tiers? <exists>
7+
size = 1
8+
item []:
9+
item [1]:
10+
class = "IntervalTier"
11+
name = "utterances"
12+
xmin = 0
13+
xmax = 1.4729375
14+
intervals: size = 1
15+
intervals [1]:
16+
xmin = 0
17+
xmax = 1.4729375
18+
text = "utterance"

Diff for: lib/textgrid.js

+18
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
currentItem = null,
4747
type,
4848
fileName = "Unknown",
49+
fileNames = [],
4950
key,
5051
value,
5152
text;
@@ -74,6 +75,7 @@
7475
if (key === "File_name") {
7576
fileName = value + "";
7677
console.log(" Found a file name " + fileName);
78+
fileNames.push(fileName);
7779
}
7880
}
7981
} else {
@@ -116,6 +118,7 @@
116118
currentItem.fileName = fileName;
117119
json.items.push(currentItem);
118120
}
121+
json.fileNames = fileNames;
119122
return json;
120123
};
121124

@@ -177,6 +180,16 @@
177180

178181
text = interval.text ? interval.text.trim().toLocaleLowerCase().replace(maximizeFindingTextInAudio, "") : "";
179182
if (text) {
183+
// if its the only interval, and it says utterance, put the file name there instead under the assumption that the filename is probably meaningful
184+
if (text === "utterance" && json.items[itemIndex].intervals.length < 3) {
185+
text = interval.fileName;
186+
if (text.indexOf(".") > -1) {
187+
text = text.substring(0, interval.fileName.lastIndexOf("."));
188+
}
189+
text = text.trim().replace(/_/g, " ");
190+
// console.log("text replaced with filename. " + text);
191+
interval.text = text;
192+
}
180193
json.intervalsByText[text] = json.intervalsByText[text] || [];
181194
length = json.intervalsByText[text].length;
182195
json.intervalsByText[text][length] = interval;
@@ -226,6 +239,11 @@
226239
}
227240
// console.log(histogram[bin]);
228241
}
242+
243+
// If there are more than 4 files, they are probably not IGT across files.
244+
if (json.fileNames && json.fileNames.length > 4) {
245+
probablyAligned = false;
246+
}
229247
// console.log(histogram);
230248
// console.log("probably aligned " + probablyAligned);
231249

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "textgrid",
33
"description": "A small library which can parse TextGrid into json and json into TextGrid",
4-
"version": "0.1.0",
4+
"version": "2.2.0",
55
"homepage": "https://github.com/OpenSourceFieldlinguistics/PraatTextGridJS",
66
"author": {
77
"name": "OpenSourceFieldLinguistics Contribs",

Diff for: test/textgrid-spec.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,30 @@ describe("lib/textgrid", function() {
140140
expect(json.items[0].fileName).toEqual("sampleMultipleSpeakers");
141141
expect(json.items[2].fileName).toEqual("Unknown");
142142
// console.log(JSON.stringify(json.items[json.items.length-1].fileName, null, 2));
143-
expect(json.items[json.items.length-1].fileName).toEqual("sampleNested");
143+
expect(json.items[json.items.length - 1].fileName).toEqual("sampleNested");
144+
expect(json.fileNames).toEqual([ 'sampleMultipleSpeakers', 'sampleNested' ]);
144145
});
145146

147+
it("should put the filename as the text of an interval if there is only 1 or two intervals and the interval text is utterance", function() {
148+
var sampleEmptyTextGrid = "\n\nFile name = sampleEmpty\n" + fs.readFileSync(__dirname + "/../data/sampleEmpty.TextGrid", {
149+
encoding: "UTF-8"
150+
});
151+
var json = textgrid.textgridToIGT(sampleEmptyTextGrid);
152+
// console.log(JSON.stringify(json, null, 2));
153+
expect(typeof json).toBe("object");
154+
// console.log(json.items.length);
155+
expect(json.items.length).toEqual(1);
156+
expect(json.items[0].intervals[0].text).toEqual("sampleEmpty");
157+
});
158+
159+
xit("should create one interval if there were no intervals in the TextGrid", function() {
160+
var sampleEmptyTextGrid = fs.readFileSync(__dirname + "/../data/sampleEmpty.TextGrid", {
161+
encoding: "UTF-8"
162+
});
163+
var json = textgrid.textgridToIGT(sampleEmptyTextGrid);
164+
// console.log(JSON.stringify(json, null, 2));
165+
expect(typeof json).toBe("object");
166+
console.log(json.items.length);
167+
expect(json.items.length).toEqual(1);
168+
});
146169
});

0 commit comments

Comments
 (0)