public class CooccWriter
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private java.lang.StringBuilder |
buffer |
static java.lang.String |
BUFFER_SIZE_PROPERTY
A system property to configure the buffer size of the CooccWriter.
|
private boolean |
buffered |
private int |
bufferSize |
static java.lang.String |
DEFAULT_BUFFER_SIZE |
private static java.lang.String |
DELEM |
private static byte[] |
DELEM_B |
private static java.lang.String |
LINE_END |
private static byte[] |
LINE_END_B |
private int |
maxVectorSize |
private java.io.OutputStream |
out |
| Constructor and Description |
|---|
CooccWriter(java.io.OutputStream out)
Directly use an OutputStream (preferably a BufferedOutputStream)
|
CooccWriter(java.io.OutputStream out,
boolean buffered)
Directly use an OutputStream (preferably a BufferedOutputStream)
|
CooccWriter(java.lang.String filename,
boolean buffered)
Creates a new CooccWriter and opens the file determined by the filename
attribute for writing.
|
CooccWriter(java.lang.String filename,
boolean append,
boolean buffered)
Creates a new CooccWriter and opens the file determined by the filename
attribute for writing.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
checkBuffer(boolean forceWrite)
Writes the buffer out if it's full.
|
void |
close()
Closes the file and write the buffer to disk, if the CooccWriter is used
in buffered mode.
|
private static int |
getBufferSize()
Reads the system property.
|
int |
getMaxVectorSize()
The maximum size of the written vectors (may be used for padding)
|
static void |
main(java.lang.String[] argv) |
static void |
paddVectors(java.lang.String filename,
java.lang.String pad,
int maxVectorSize)
Pads a coocc file with a pattern, so that all vectors have equal size.
|
void |
writeVector(int[] vec,
int length)
Appends an integer vector to the current file.
|
void |
writeVector(java.lang.Integer[] vec)
Appends an integer vector to the current file.
|
void |
writeVector(java.lang.String[] vec)
Appends a vector to the current file.
|
public static final java.lang.String BUFFER_SIZE_PROPERTY
public static final java.lang.String DEFAULT_BUFFER_SIZE
private static final java.lang.String DELEM
private static final byte[] DELEM_B
private static final java.lang.String LINE_END
private static final byte[] LINE_END_B
private java.io.OutputStream out
private boolean buffered
private java.lang.StringBuilder buffer
private int bufferSize
private int maxVectorSize
public CooccWriter(java.lang.String filename,
boolean append,
boolean buffered)
throws java.io.FileNotFoundException
filename - The name of the output fileappend - if true, then bytes will be written to the end of the file
rather than the beginningbuffered - if true an internal buffer is used. You must properly use the
close method to be sure that the buffer is written to disk.java.io.FileNotFoundExceptionpublic CooccWriter(java.lang.String filename,
boolean buffered)
throws java.io.FileNotFoundException
filename - The name of the file to write to.buffered - if true an internal buffer is used. You must properly use the
close method to be sure that the buffer is written to disk.java.io.FileNotFoundExceptionpublic CooccWriter(java.io.OutputStream out)
out - The Stream to write to.public CooccWriter(java.io.OutputStream out,
boolean buffered)
out - out The Stream to write to.buffered - buffered or not(true or false)public void writeVector(java.lang.String[] vec)
throws java.io.IOException
vec - java.io.IOExceptionpublic void writeVector(java.lang.Integer[] vec)
throws java.io.IOException
vec - java.io.IOExceptionpublic void writeVector(int[] vec,
int length)
throws java.io.IOException
vec - java.io.IOExceptionprivate void checkBuffer(boolean forceWrite)
throws java.io.IOException
forceWrite - java.io.IOExceptionpublic void close()
throws java.io.IOException
java.io.IOExceptionprivate static int getBufferSize()
BUFFER_SIZE_PROPERTY,
DEFAULT_BUFFER_SIZEpublic int getMaxVectorSize()
public static void paddVectors(java.lang.String filename,
java.lang.String pad,
int maxVectorSize)
throws java.io.IOException,
java.io.FileNotFoundException
filename - The filename of the file to pad.pad - The String to pad with ("0" or "-1" for example)maxVectorSize - The max vector size.java.io.IOExceptionjava.io.FileNotFoundExceptionpublic static void main(java.lang.String[] argv)
throws java.lang.Exception
java.lang.Exception2005-2013 Marco Büchler, Natural Language Processing Group, University of Leipzig, Germany. 2013-2016 Marco Büchler, Georg August University Göttingen, Göttingen, Germany