Giter Site home page Giter Site logo

jtgt's Introduction

CI License: LGPL v3

JTGT

JTGT is a Java library for loading, manipulating, and writing Praat TextGrid files, and similar annotation files, such as XWaves lab. It's inspired by the TextGridTools module for Python.

Dependency Information

Snapshot builds are OSSRH. Release versions are hosted on OSSRH and indexed in Maven Central.

Examples

Loading a TextGrid file

String tgStr = new File("path/to/my.TextGrid").getText();
TextGrid tg = new TextGridSerializer().fromString(tgStr);

Iterating over intervals

for (Annotation annot : tg.getTiers().get(0).getAnnotations()) {
    System.out.println(annot.getText());
}

jtgt's People

Contributors

psibre avatar seblemaguer avatar

Stargazers

 avatar

Watchers

 avatar

jtgt's Issues

Saving big TextGrids is extremely slow

Expected behavior

Big TextGrids should be saved quickly.

Actual behavior (with the stacktrace!)

Saving a big TextGrid can take up to several minutes!

Steps to reproduce the behavior

Create a big TextGrid, try saving it.
Implemented a test to expose this issue.

Additional information

The root of the problem is that even though TextGridSerializer#save uses a BufferedWriter, it still attempts to create a single String containing the entire TextGrid before writing it. And within TextGridSerializer#toString, there is excessive String concatenation instead of using an efficient class such as a StringBuilder.

Middle field -1 in lab files created by XWaveLabelSerializer

this issue is a follow up to this issue

Behavior

described in detail here

separator ;
nfields 1
#
     0.38 -1 _
     0.47 -1 n
     0.57 -1 A
...

TL;DR
The middle field -1 (added in XWaveLabelSerializer.java, ln. 135) affects other programs when working with these lab files.

The standard for Praat is a 26 there. Is there a specific reason for having a -1 instead of 26 which would imitate the Praat-approach?
This is the first time I've seen that the middle field of the lab file affects the behavior of another program but this might not be a singular problem.

Add support for chronological TextGrid format

Expected behavior

Loading a TextGrid file in chronological format should work just like the default format.

Actual behavior (with the stacktrace!)

Fails with an error:

Caused by: org.m2ci.msp.jtgt.io.TextGridIOException: Header is not correctly formatted ("Praat chronological TextGrid text file")
        at org.m2ci.msp.jtgt.io.TextGridSerializer.fromString(TextGridSerializer.java:74)
        at org.m2ci.msp.jtgt.io.TextGridSerializer$fromString.call(Unknown Source)

Steps to reproduce the behavior

Load a chronological TextGrid file.

Additional information

Format looks like this:

"Praat chronological TextGrid text file"
0 5.14   ! Time domain.
1   ! Number of tiers.
"IntervalTier" "phones" 0 5.14

! phones:
1 0 1.09
"sil"

! phones:
1 1.09 1.25
"O"

! phones:
1 1.25 1.35
"T"

! phones:
1 1.35 1.46
"r="

! phones:
1 1.46 1.53
"V"

! phones:
1 1.53 1.59
"v"

! phones:
1 1.59 1.64
"D"

! phones:
1 1.64 1.68
"@"

! phones:
1 1.68 1.78
"d"

! phones:
1 1.78 1.89
"EI"

! phones:
1 1.89 1.94
"n"

! phones:
1 1.94 2.02
"dZ"

! phones:
1 2.02 2.12
"r="

! phones:
1 2.12 2.24
"t"

! phones:
1 2.24 2.3
"r"

! phones:
1 2.3 2.38
"EI"

! phones:
1 2.38 2.58
"l"

! phones:
1 2.58 2.61
"sil"

! phones:
1 2.61 2.74
"f"

! phones:
1 2.74 2.78
"I"

! phones:
1 2.78 2.86
"l"

! phones:
1 2.86 2.92
"@"

! phones:
1 2.92 2.98
"p"

! phones:
1 2.98 3.05
"s"

! phones:
1 3.05 3.1
"t"

! phones:
1 3.1 3.18
"i"

! phones:
1 3.18 3.3
"l"

! phones:
1 3.3 3.43
"z"

! phones:
1 3.43 3.51
"E"

! phones:
1 3.51 3.59
"t"

! phones:
1 3.59 3.67
"s"

! phones:
1 3.67 3.73
"E"

! phones:
1 3.73 3.77
"t"

! phones:
1 3.77 3.91
"r="

! phones:
1 3.91 4.02
"@"

! phones:
1 4.02 5.12
"sil"

! phones:
1 5.12 5.14
"_"

Implement TextGrid#toString for easier debugging, etc.

Expected behavior

TextGrid#toString should be implemented for human inspection.

Actual behavior (with the stacktrace!)

This is not really helpful:

Gradle suite > Gradle test > org.m2ci.msp.jtgt.io.TextGridSerializerTest.testEquals FAILED
    java.lang.AssertionError: expected [org.m2ci.msp.jtgt.TextGrid@3538da99] but found [org.m2ci.msp.jtgt.TextGrid@41086e4c]
        at org.testng.Assert.fail(Assert.java:94)
        at org.testng.Assert.failNotEquals(Assert.java:494)
        at org.testng.Assert.assertEquals(Assert.java:123)
        at org.testng.Assert.assertEquals(Assert.java:165)
        at org.m2ci.msp.jtgt.io.TextGridSerializerTest.testEquals(TextGridSerializerTest.java:69)

Steps to reproduce the behavior

Checkout 122a8e4 and run ./gradlew check.

Additional information

Indicate any necessary additional information

cannot load windows formatted TextGrid (org.m2ci.msp.jtgt.io.TextGridIOException)

Expected behavior

opening TextGrid with TGSer

Actual behavior (with the stacktrace !)

org.m2ci.msp.jtgt.io.TextGridIOException: Header is not correctly formatted (File type = "ooTextFile"
)
	at org.m2ci.msp.jtgt.io.TextGridSerializer.fromString(TextGridSerializer.java:71)
	at org.m2ci.msp.jtgt.io.TextGridSerializerTest.testEquals(TextGridSerializerTest.java:62)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
	at org.testng.TestRunner.privateRun(TestRunner.java:767)
	at org.testng.TestRunner.run(TestRunner.java:617)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:348)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)
	at org.testng.SuiteRunner.run(SuiteRunner.java:254)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
	at org.testng.TestNG.run(TestNG.java:1057)
	at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.runTests(TestNGTestClassProcessor.java:129)
	at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.stop(TestNGTestClassProcessor.java:88)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
	at com.sun.proxy.$Proxy1.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:120)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:146)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:128)
	at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
	at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
	at java.lang.Thread.run(Thread.java:745)

Steps to reproduce the behavior

  • change TextGrid to windows EOL encoding

Cannot parse TextGrid written by Praat

Expected behavior

TextGrid written by Praat should be loaded without issues -- in fact, it should be the reference!

Actual behavior (with the stacktrace!)

java.lang.NumberFormatException: For input string: "3 "
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:580)
	at java.lang.Integer.parseInt(Integer.java:615)
	at org.m2ci.msp.jtgt.io.TextGridSerializer.fromString(TextGridSerializer.java:109)
	at org.m2ci.msp.jtgt.io.TextGridSerializerTest.testEquals(TextGridSerializerTest.java:66)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
	at org.testng.TestRunner.privateRun(TestRunner.java:767)
	at org.testng.TestRunner.run(TestRunner.java:617)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:348)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)
	at org.testng.SuiteRunner.run(SuiteRunner.java:254)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
	at org.testng.TestNG.run(TestNG.java:1057)
	at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.runTests(TestNGTestClassProcessor.java:129)
	at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.stop(TestNGTestClassProcessor.java:88)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
	at com.sun.proxy.$Proxy1.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:120)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:146)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:128)
	at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
	at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
	at java.lang.Thread.run(Thread.java:748)

Steps to reproduce the behavior

Write a TextGrid from Praat (reproduced with v6.0.40), try loading it.
Stacktrace is from testing at 97f5c55

Additional information

The problem is that Praat appends whitespace after numbers and labels, causing an error when parsing an integer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.