From bcd5b9f8f8a9c23c8d8ac6c165ff0f1994807aea Mon Sep 17 00:00:00 2001 From: fozziethebeat Date: Thu, 26 Jul 2012 01:58:19 -0700 Subject: [PATCH] Forcing GenericMain to check the validity of the output sspace format before any text processing --- .../edu/ucla/sspace/mains/GenericMain.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/edu/ucla/sspace/mains/GenericMain.java b/src/main/java/edu/ucla/sspace/mains/GenericMain.java index aa233eb0..46cb8226 100644 --- a/src/main/java/edu/ucla/sspace/mains/GenericMain.java +++ b/src/main/java/edu/ucla/sspace/mains/GenericMain.java @@ -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 @@ -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)); @@ -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); }