public class SerializationHelper extends Object
TextAnnotation
objects to byte arrays.Constructor and Description |
---|
SerializationHelper() |
Modifier and Type | Method and Description |
---|---|
static TextAnnotation |
deserializeFromJson(String jsonString)
Read a text annotation from a json string.
|
static TextAnnotation |
deserializeFromProtobuf(String fileName)
Read a text annotation from a Protocol Buffer encoding of Text Annotation.
|
static TextAnnotation |
deserializeTextAnnotationFromBytes(byte[] obj)
Read a text annotation from a byte array.
|
static TextAnnotation |
deserializeTextAnnotationFromFile(String fileName)
Read serialized record from file and deserialize it.
|
static TextAnnotation |
deserializeTextAnnotationFromFile(String fileName,
boolean isJson)
Read serialized record from file and deserialize it.
|
static byte[] |
serializeTextAnnotationToBytes(TextAnnotation ta)
Serialize a text annotation into a byte array.
|
static void |
serializeTextAnnotationToFile(TextAnnotation ta,
String fileName,
boolean forceOverwrite)
Serialize a
TextAnnotation and then write to file. |
static void |
serializeTextAnnotationToFile(TextAnnotation ta,
String fileName,
boolean forceOverwrite,
boolean useJson)
Serialize a TextAnnotation and then write to file.
|
static void |
serializeTextAnnotationToProtobuf(TextAnnotation ta,
String fileName,
boolean forceOverwrite)
Serialize a text annotation into a protocol buffer encoded output file.
|
static String |
serializeToJson(TextAnnotation ta)
Serialize a text annotation into a json string.
|
static String |
serializeToJson(TextAnnotation ta,
boolean writeTokenCharacterOffsets)
Serialize a text annotation into a json string, with option for explicit offsets for tokens.
|
public static void serializeTextAnnotationToFile(TextAnnotation ta, String fileName, boolean forceOverwrite) throws IOException
TextAnnotation
and then write to file. If forceOverwrite_ is set to false and
file already exists, this method throws an exception. Uses binary serialization for TextAnnotation.ta
- The text annotation to be serializedfileName
- Name of file to write toforceOverwrite
- Whether or not to overwrite existing file.IOException
public static void serializeTextAnnotationToFile(TextAnnotation ta, String fileName, boolean forceOverwrite, boolean useJson) throws IOException
ta
- The text annotation to be serializedfileName
- Name of file to write toforceOverwrite
- Whether or not to overwrite existing file.IOException
public static byte[] serializeTextAnnotationToBytes(TextAnnotation ta) throws IOException
SerializationUtils
.ta
- The text annotation to be serializedIOException
public static TextAnnotation deserializeTextAnnotationFromFile(String fileName) throws Exception
fileName
- Name of file to read fromException
public static TextAnnotation deserializeTextAnnotationFromFile(String fileName, boolean isJson) throws Exception
fileName
- Name of file to read fromException
public static TextAnnotation deserializeTextAnnotationFromBytes(byte[] obj)
serializeTextAnnotationToBytes(TextAnnotation)
function. Uses Apache's
SerializationUtils
.obj
- The byte arraypublic static String serializeToJson(TextAnnotation ta, boolean writeTokenCharacterOffsets)
ta
- The text annotation to be serializedwriteTokenCharacterOffsets
- whether or not to write explicit token offsets.public static String serializeToJson(TextAnnotation ta)
ta
- The text annotation to be serializedpublic static TextAnnotation deserializeFromJson(String jsonString) throws Exception
serializeToJson(TextAnnotation)
functionjsonString
- The json string representation for the textException
public static void serializeTextAnnotationToProtobuf(TextAnnotation ta, String fileName, boolean forceOverwrite) throws Exception
ta
- Text Annotation to be serializedfileName
- Name of the file to write toforceOverwrite
- Boolean indicating if the output file should be overwritten if it already existsException
public static TextAnnotation deserializeFromProtobuf(String fileName) throws Exception
fileName
- Input file nameException
Copyright © 2017. All rights reserved.