Skip to content

annotationpro/annotationpro-format-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

annotationpro-format-java

Java library to save annotation in Annotation Pro format.

Import using Maven

<dependencies>
    <dependency>
        <groupId>org.annotationpro</groupId>
        <artifactId>annotationpro-format</artifactId>
        <version>1.2</version>
    </dependency>
</dependencies>

Write annotation example

        // annotation model
        Annotation annotation = new Annotation(44100);

        // new layer
        Layer layer = new Layer("Example layer");
        layer.setFontSize(12);
        annotation.getLayers().add(layer);

        // new segments
        Segment segment = new Segment("word", 100, 44100);
        layer.getSegments().add(segment);

        Segment segment2 = new Segment("phrase", 52000, 44100);
        layer.getSegments().add(segment2);

        // serialization
        AnnotationSerializer annotationSerializer = new AnnotationSerializer();
        String antxContent = annotationSerializer.serializeAnnotation(annotation);

        // save to file
        try {
            Path file = Paths.get("c:\\annotation new.antx");
            Files.write(file, antxContent.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }

Read annotation example

try {
    // read from file
    Path file = Paths.get("c:\\annotation new.antx");
    String xmlContent = new String(Files.readAllBytes(file));

    // deserialize annotation
    AnnotationDeserializer annotationDeserializer = new AnnotationDeserializer();
    Annotation annotation = annotationDeserializer.deserializeAnnotation(xmlContent);

    // get first layer and first segment on this layer
    Layer layer = annotation.getLayers().get(0);
    Segment segment = layer.getSegments().get(0);

} catch (Exception e) {
    e.printStackTrace();
}

About

Java library to save annotation in Annotation Pro format.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages