public class CSVDefaultCognitiveModelLiteHandler
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
FORMAT_NAME
The name of the format that the file parses.
|
static double |
FORMAT_VERSION
The current version that is parsed.
|
Modifier | Constructor and Description |
---|---|
protected |
CSVDefaultCognitiveModelLiteHandler()
Creates a new instance of CommaSeparatedValueHandler.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addLink(java.lang.String fromName,
java.lang.String toName,
double weight)
Called when the "link" directive is seen.
|
protected void |
addNode(java.lang.String name)
Called when the "node" directive is seen.
|
protected DefaultSemanticLabel |
getLabel(java.lang.String name)
Takes a name and returns its DefaultSemanticLabel or null if there is
none.
|
protected CognitiveModuleFactory |
getMutableModuleFactory()
Gets the sharable module factory that has been read in.
|
protected DefaultSemanticNetwork |
getNetwork()
Gets the underlying network.
|
protected CognitiveModuleFactory |
getSharedModuleFactory()
Gets the sharable module factory that has been read in.
|
protected boolean |
parse(java.io.BufferedReader br)
The main parsing function.
|
static CognitiveModelLiteFactory |
parseCSVToModelFactory(java.io.BufferedReader br,
boolean mutable)
Reads a default CognitiveModuleFactory from the given buffered reader and
puts it in a default CognitiveModelFactory.
|
static CognitiveModelLiteFactory |
parseCSVToModelFactory(java.lang.String fileName,
boolean mutable)
Reads a default CognitiveModuleFactory from the given file and puts it in
a default CognitiveModelFactory.
|
static CognitiveModuleFactory |
parseCSVToModuleFactory(java.io.BufferedReader br,
boolean mutable)
Reads a default CognitiveModuleFactory from the given buffered reader and
then returns it.
|
static CognitiveModuleFactory |
parseCSVToModuleFactory(java.lang.String fileName,
boolean mutable)
Reads a default CognitiveModuleFactory from the given CSV file and
returns it.
|
protected double |
parseHeader(java.io.BufferedReader br)
Parses the header and returns the version number.
|
protected void |
setLabels(java.util.HashMap<java.lang.String,DefaultSemanticLabel> labels)
Sets the label mapping.
|
protected void |
setNetwork(DefaultSemanticNetwork network)
Set the network being parsed.
|
static void |
write(java.io.File file,
SemanticNetwork network)
Writes a SemanticNetwork to the given file using the CSV format.
|
static void |
write(java.io.PrintWriter pw,
SemanticNetwork network)
Writes a SemanticNetwork to the given stream using the CSV format.
|
static void |
write(java.lang.String fileName,
SemanticNetwork network)
Writes a SemanticNetwork to the given file using the CSV format.
|
public static final java.lang.String FORMAT_NAME
public static final double FORMAT_VERSION
protected CSVDefaultCognitiveModelLiteHandler()
protected boolean parse(java.io.BufferedReader br) throws CSVParseException, java.io.IOException
br
- The reader to read the CSV values from.CSVParseException
- If there is an error in the CSV formatting.java.io.IOException
- If there is an IO error.protected double parseHeader(java.io.BufferedReader br) throws CSVParseException, java.io.IOException
br
- The reader to read the CSV values from.CSVParseException
- If there is an error in the CSV formatting.java.io.IOException
- If there is an IO error.protected void addNode(java.lang.String name) throws CSVParseException
name
- The name of the node to add.CSVParseException
- If there is an error in adding the node, such as it already
existing.protected void addLink(java.lang.String fromName, java.lang.String toName, double weight) throws CSVParseException
fromName
- The node the link is from.toName
- The node the link is to.weight
- The weight for the link.CSVParseException
- If there is an error in adding the link, such as one of the
nodes not existing.protected CognitiveModuleFactory getSharedModuleFactory()
protected CognitiveModuleFactory getMutableModuleFactory()
protected DefaultSemanticLabel getLabel(java.lang.String name)
name
- The name of the label to get.protected DefaultSemanticNetwork getNetwork()
protected void setNetwork(DefaultSemanticNetwork network)
network
- The new network being parsed.protected void setLabels(java.util.HashMap<java.lang.String,DefaultSemanticLabel> labels)
labels
- The new label mapping.public static CognitiveModuleFactory parseCSVToModuleFactory(java.lang.String fileName, boolean mutable) throws CSVParseException, java.io.IOException
fileName
- The file to read from.mutable
- True to create a mutable module.CSVParseException
- If the CSV file is not properly formatted.java.io.IOException
- If there is an IO error, such as the file not existing.public static CognitiveModuleFactory parseCSVToModuleFactory(java.io.BufferedReader br, boolean mutable) throws CSVParseException, java.io.IOException
br
- The reader to read from.mutable
- True to create a mutable module.CSVParseException
- If the CSV file is not properly formatted.java.io.IOException
- If there is an IO error, such as the file not existing.public static CognitiveModelLiteFactory parseCSVToModelFactory(java.lang.String fileName, boolean mutable) throws CSVParseException, java.io.IOException
fileName
- The file to read from.mutable
- True to create a mutable module.CSVParseException
- If the CSV file is not properly formatted.java.io.IOException
- If there is an IO error, such as the file not existing.public static CognitiveModelLiteFactory parseCSVToModelFactory(java.io.BufferedReader br, boolean mutable) throws CSVParseException, java.io.IOException
br
- The reader to read from.mutable
- True to create a mutable model factory.CSVParseException
- If the CSV file is not properly formatted.java.io.IOException
- If there is an IO error, such as the file not existing.public static void write(java.lang.String fileName, SemanticNetwork network) throws java.io.FileNotFoundException
fileName
- The name of the file to write the network.network
- The network to write.java.io.FileNotFoundException
- If the file cannot be written to.public static void write(java.io.File file, SemanticNetwork network) throws java.io.FileNotFoundException
file
- The file to write the network.network
- The network to write.java.io.FileNotFoundException
- If the file cannot be written to.public static void write(java.io.PrintWriter pw, SemanticNetwork network)
pw
- The place to write the network.network
- The network to write.