Skip to content

Commit

Permalink
Forcing GenericMain to check the validity of the output sspace format…
Browse files Browse the repository at this point in the history
… before any text processing
  • Loading branch information
fozziethebeat committed Jul 26, 2012
1 parent 6129c28 commit bcd5b9f
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/main/java/edu/ucla/sspace/mains/GenericMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,12 @@ public void run(String[] args) throws Exception {
props.setProperty(IteratorFactory.TOKEN_COUNT_LIMIT_PROPERTY,
argOptions.getStringOption("wordLimit"));

// Get the format to be used when writing the semantic space.
SSpaceFormat format = (argOptions.hasOption("outputFormat"))
? SSpaceFormat.valueOf(
argOptions.getStringOption("outputFormat").toUpperCase())
: getSpaceFormat();

IteratorFactory.setProperties(props);

// use the System properties in case the user specified them as
Expand Down Expand Up @@ -477,7 +483,7 @@ public void run(String[] args) throws Exception {
System.out.println("output File: " + outputFile);

long startTime = System.currentTimeMillis();
saveSSpace(space, outputFile);
saveSSpace(space, outputFile, format);
long endTime = System.currentTimeMillis();
verbose("printed space in %.3f seconds",
((endTime - startTime) / 1000d));
Expand All @@ -486,17 +492,12 @@ public void run(String[] args) throws Exception {
}

/**
* Serializes the {@link SemanticSpace} object to {@code outputFile}.
* This uses {@code outputFormat} if set by the commandline. If not, this
* uses the {@link SSpaceFormat} returned by {@link #getSpaceFormat}.
* Serializes the {@link SemanticSpace} object to {@code outputFile} using a
* given {@link SSpaceFormat}.
*/
protected void saveSSpace(SemanticSpace sspace, File outputFile)
throws IOException{
SSpaceFormat format = (argOptions.hasOption("outputFormat"))
? SSpaceFormat.valueOf(
argOptions.getStringOption("outputFormat").toUpperCase())
: getSpaceFormat();

protected void saveSSpace(SemanticSpace sspace,
File outputFile,
SSpaceFormat format) throws IOException {
SemanticSpaceIO.save(sspace, outputFile, format);
}

Expand Down

0 comments on commit bcd5b9f

Please sign in to comment.