Skip to content

Commit d44b187

Browse files
committed
updating the docs
1 parent 8158a5d commit d44b187

File tree

5 files changed

+79
-18
lines changed

5 files changed

+79
-18
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ coverage
1818

1919
# Compiled binary addons (http://nodejs.org/api/addons.html)
2020
build
21-
dist
2221

2322
# Dependency directory
2423
# Deployed apps should consider commenting this line out:

README.md

+71-10
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,28 @@ A small library which can parse TextGrid into json and json into TextGrid
55

66
## Getting Started
77
### On the server
8-
Install the module with: `npm install textgrid`
8+
Install the module with: `npm install textgrid --save`
99

1010
```javascript
1111
var textgrid = require('textgrid');
1212
textgrid.init(); // "init"
1313
```
1414

1515
### In the browser
16+
17+
Install the module with: `bower install textgrid --save` or,
18+
1619
Download the [production version][min] or the [development version][max].
1720

1821
[min]: https://raw.github.com/OpenSourceFieldlinguistics/PraatTextGridJS/master/dist/textgrid.min.js
1922
[max]: https://raw.github.com/OpenSourceFieldlinguistics/PraatTextGridJS/master/dist/textgrid.js
2023

21-
In your web page:
24+
In your web app:
2225

2326
```html
24-
<script src="dist/textgrid.min.js"></script>
27+
<script src="bower_components/textgrid/dist/textgrid.min.js"></script>
2528
<script>
26-
init(); // "init"
29+
var textgridAsJson = TextGrid.textgridToIGT(originalTextGridAsText);
2730
</script>
2831
```
2932

@@ -33,25 +36,83 @@ In your code, you can attach textgrid's methods to any object.
3336
<script>
3437
var exports = Bocoup.utils;
3538
</script>
36-
<script src="dist/textgrid.min.js"></script>
39+
<script src="bower_components/textgrid/dist/textgrid.min.js"></script>
3740
<script>
38-
Bocoup.utils.init(); // "init"
41+
var textgridAsJson = Bocoup.utils.textgridToIGT(originalTextGridAsText); // "init"
3942
</script>
4043
```
4144

45+
An example of what you can do with the result.
46+
47+
```js
48+
var textgrid = TextGrid.textgridToIGT(text);
49+
if (textgrid.isIGTNestedOrAlignedOrBySpeaker.probablyAligned) {
50+
for (itemIndex in textgrid.intervalsByXmin) {
51+
if (!textgrid.intervalsByXmin.hasOwnProperty(itemIndex)) {
52+
continue;
53+
}
54+
if (textgrid.intervalsByXmin[itemIndex]) {
55+
row = {};
56+
for (intervalIndex = 0; intervalIndex < textgrid.intervalsByXmin[itemIndex].length; intervalIndex++) {
57+
interval = textgrid.intervalsByXmin[itemIndex][intervalIndex];
58+
row.startTime = row.startTime ? row.startTime : interval.xmin;
59+
row.endTime = row.endTime ? row.endTime : interval.xmax;
60+
row.utterance = row.utterance ? row.utterance : interval.text.trim();
61+
row.modality = "spoken";
62+
row.tier = interval.tierName;
63+
row.speakers = interval.speaker;
64+
row.audioFileName = interval.fileName || audioFileName;
65+
row.CheckedWithConsultant = interval.speaker;
66+
consultants.push(row.speakers);
67+
row[interval.tierName] = interval.text;
68+
header.push(interval.tierName);
69+
}
70+
matrix.push(row);
71+
}
72+
}
73+
} else {
74+
for (itemIndex in textgrid.intervalsByXmin) {
75+
if (!textgrid.intervalsByXmin.hasOwnProperty(itemIndex)) {
76+
continue;
77+
}
78+
if (textgrid.intervalsByXmin[itemIndex]) {
79+
for (intervalIndex = 0; intervalIndex < textgrid.intervalsByXmin[itemIndex].length; intervalIndex++) {
80+
row = {};
81+
interval = textgrid.intervalsByXmin[itemIndex][intervalIndex];
82+
row.startTime = row.startTime ? row.startTime : interval.xmin;
83+
row.endTime = row.endTime ? row.endTime : interval.xmax;
84+
row.utterance = row.utterance ? row.utterance : interval.text.trim();
85+
row.modality = "spoken";
86+
row.tier = interval.tierName;
87+
row.speakers = interval.speaker;
88+
row.audioFileName = interval.fileName || audioFileName;
89+
row.CheckedWithConsultant = interval.speaker;
90+
consultants.push(row.speakers);
91+
row[interval.tierName] = interval.text;
92+
header.push(interval.tierName);
93+
matrix.push(row);
94+
}
95+
}
96+
}
97+
}
98+
99+
```
100+
42101
## Documentation
43-
_(Coming soon)_
102+
http://opensourcefieldlinguistics.github.io/FieldDB/
44103

45104
## Examples
46-
_(Coming soon)_
105+
See tests directory for more ways to use the library
47106

48107
## Contributing
49108
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
50109

51-
_Also, please don't edit files in the "dist" subdirectory as they are generated via Grunt. You'll find source code in the "lib" subdirectory!_
110+
_The "dist" subdirectory files are generated via Grunt. You'll find source code in the "lib" subdirectory!_
52111

53112
## Release History
54-
_(Nothing yet)_
113+
* v1.102.3 April 22 2014 Long audio import support
114+
* v2.2.0 April 22 2014 Support for multiple small files each corresponding to an utterance
115+
55116

56117
## License
57118
Copyright (c) 2014 OpenSourceFieldLinguistics Contribs

bower.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"OpenSourceFieldLinguistics Contribs"
77
],
88
"description": "A small library which can parse TextGrid into json and json into TextGrid",
9-
"main": "lib/textgrid.js",
9+
"main": "dist/textgrid.js",
1010
"moduleType": [
1111
"amd",
1212
"node"
@@ -22,7 +22,7 @@
2222
"bower_components",
2323
"test",
2424
"tests",
25-
"dist",
25+
"lib",
2626
"Gruntfile.js",
2727
"data",
2828
"package.json"

lib/.jshintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"undef": true,
1010
"boss": true,
1111
"eqnull": true,
12-
"predef": ["exports"]
12+
"predef": ["exports", "console"]
1313
}

lib/textgrid.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
return tier.name;
159159
});
160160
// console.log(tierNames);
161-
if (tierNames.length - probablyFromElanWithSpeakerEncodedInTierNameCount == 0) {
161+
if (tierNames.length - probablyFromElanWithSpeakerEncodedInTierNameCount === 0) {
162162
probablyFromElanWithSpeakerEncodedInTierName = true;
163163
}
164164
if (!json || !json.items) {
@@ -264,12 +264,13 @@
264264
};
265265

266266
TextGrid.printIGT = function(igtIntervalsJSON) {
267+
var mapper = function(interval) {
268+
return interval.xmin + "," + interval.xmax + "," + interval.text;
269+
};
267270
for (var interval in igtIntervalsJSON) {
268271
console.log(interval);
269272
if (igtIntervalsJSON.hasOwnProperty(interval)) {
270-
console.log(igtIntervalsJSON[interval].map(function(interval) {
271-
return interval.xmin + "," + interval.xmax + "," + interval.text;
272-
}));
273+
console.log(igtIntervalsJSON[interval].map(mapper));
273274
}
274275
}
275276
};

0 commit comments

Comments
 (0)