1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
| /*
* Copyright 2009 David Jurgens
*
* This file is part of the S-Space package and is covered under the terms and
* conditions therein.
*
* The S-Space package is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation and distributed hereunder to you.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND NO REPRESENTATIONS OR WARRANTIES,
* EXPRESS OR IMPLIED ARE MADE. BY WAY OF EXAMPLE, BUT NOT LIMITATION, WE MAKE
* NO REPRESENTATIONS OR WARRANTIES OF MERCHANT- ABILITY OR FITNESS FOR ANY
* PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE OR DOCUMENTATION
* WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER
* RIGHTS.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package edu.ucla.sspace.mains;
import edu.ucla.sspace.common.ArgOptions;
import edu.ucla.sspace.common.SemanticSpace;
import edu.ucla.sspace.hal.HyperspaceAnalogueToLanguage;
import java.io.IOError;
import java.io.IOException;
import java.util.Properties;
/**
* An executable class for running {@link HyperspaceAnalogueToLanguage} (HAL)
* from the command line. This class takes in several command line arguments.
*
* <ul>
*
* <li><u>Required (at least one of)</u>:
* <ul>
*
* <li> {@code -d}, {@code --docFile=FILE[,FILE...]} a file where each line is
* a document. This is the preferred input format for large corpora
*
* <li> {@code -f}, {@code --fileList=FILE[,FILE...]} a list of document files
* where each file is specified on its own line.
*
* </ul>
*
* <li><u>Algorithm Options</u>:
* <ul>
*
* <li> {@code -s}, {@code --windowSize=INT} how many words to consider in each
* direction
*
* <li> {@code -r}, {@code --retain=INT} how many column dimensions to retain
* in the final word co-occurrence matrix. The retained columns will be
* those that provide the most information for distinguishing the
* semantics of the words. Unlike the {@code --threshold} option, this
* specifies a hard limit for how many to retain. This option may not
* speciefied at the same time as {@code --threshold}
*
* <li> {@code -h}, {@code --threshold=DOUBLE} the minimum information
* theoretic entropy a word must have to be retained in the final word
* co-occurrence matrix. This option may not be used at the same time as
* {@code --retain}.
*
* <li> {@code -W}, {@code --weighting=CLASS} the fully qualified name of a
* {@link edu.ucla.sspace.hal.WeightingFunction} class to be used for
* weighting co-occurrences. HAL traditionally uses a linear weighting
* where the closest neighboring words receive the highest weight.
*
* <li> {@code -F}, {@code --tokenFilter=FILE[include|exclude][,FILE...]}
* specifies a list of one or more files to use for {@link
* edu.ucla.sspace.text.TokenFilter filtering} the documents. An option
* flag may be added to each file to specify how the words in the filter
* filter should be used: {@code include} if only the words in the filter
* file should be retained in the document; {@code exclude} if only the
* words <i>not</i> in the filter file should be retained in the
* document.
*
* </ul>
*
* <li><u>Program Options</u>:
* <ul>
*
* <li> {@code -o}, {@code --outputFormat=}<tt>text|binary}</tt> Specifies the
* output formatting to use when generating the semantic space ({@code
* .sspace}) file. See {@link edu.ucla.sspace.common.SemanticSpaceUtils
* SemanticSpaceUtils} for format details.
*
* <li> {@code -t}, {@code --threads=INT} how many threads to use when processing the
* documents. The default is one per core.
*
* <li> {@code -w}, {@code --overwrite=BOOL} specifies whether to overwrite
* the existing output files. The default is {@code true}. If set to
* {@code false}, a unique integer is inserted into the file name.
*
* <li> {@code -v}, {@code --verbose} specifies whether to print runtime
* information to standard out
*
* </ul>
*
* </ul>
*
* <p>
*
* An invocation will produce one file as output {@code
* hal-semantic-space.sspace}. If {@code overwrite} was set to {@code true},
* this file will be replaced for each new semantic space. Otherwise, a new
* output file of the format {@code hal-semantic-space<number>.sspace} will be
* created, where {@code <number>} is a unique identifier for that program's
* invocation. The output file will be placed in the directory specified on the
* command line.
*
* <p>
*
* This class is desgined to run multi-threaded and performs well with one
* thread per core, which is the default setting.
*
* @see HyperspaceAnalogueToLanguage
*
* @author David Jurgens
*/
public class HALMain extends GenericMain {
private HALMain() { }
/**
* Adds all of the options to the {@link ArgOptions}.
*/
protected void addExtraOptions(ArgOptions options) {
options.addOption('F', "tokenFilter", "filters to apply to the input " +
"token stream", true, "FILTER_SPEC",
"Algorithm Options");
options.addOption('h', "threshold", "minimum entropy for semantic " +
"dimensions (default: disabled)", true,
"DOUBLE", "Algorithm Options");
options.addOption('r', "retain", "maximum number of dimensions " +
"(default: disabled)", true,
"INT", "Algorithm Options");
options.addOption('s', "windowSize", "how many words to consider " +
"in each direction (default: 5)", true,
"INT", "Algorithm Options");
options.addOption('W', "weighting", "WeightingFunction class name"
+ "(default: LinearWeighting)", true,
"CLASSNAME", "Algorithm Options");
}
public static void main(String[] args) {
HALMain hal = new HALMain();
try {
hal.run(args);
}
catch (Throwable t) {
t.printStackTrace();
}
}
protected SemanticSpace getSpace() {
return new HyperspaceAnalogueToLanguage();
}
protected Properties setupProperties() {
// use the System properties in case the user specified them as
// -Dprop=<val> to the JVM directly.
Properties props = System.getProperties();
if (argOptions.hasOption("windowSize")) {
props.setProperty(HyperspaceAnalogueToLanguage.WINDOW_SIZE_PROPERTY,
argOptions.getStringOption("windowSize"));
}
if (argOptions.hasOption("threshold")) {
props.setProperty(HyperspaceAnalogueToLanguage.ENTROPY_THRESHOLD_PROPERTY,
argOptions.getStringOption("threshold"));
}
if (argOptions.hasOption("retain")) {
props.setProperty(HyperspaceAnalogueToLanguage.RETAIN_PROPERTY,
argOptions.getStringOption("retain"));
}
if (argOptions.hasOption("weighting")) {
props.setProperty(HyperspaceAnalogueToLanguage.WINDOW_SIZE_PROPERTY,
argOptions.getStringOption("weighting"));
}
if (argOptions.hasOption("tokenFilter")) {
props.setProperty(HyperspaceAnalogueToLanguage.TOKEN_FILTER_PROPERTY,
argOptions.getStringOption("tokenFilter"));
}
return props;
}
/**
* Prints the instructions on how to execute this program to standard out.
*/
public void usage() {
System.out.println(
"usage: java HALMain [options] <output-dir>\n" +
argOptions.prettyPrint() + "\n" +
"Note that the --retain and --threshold properties are mutually " +
"exclusive;\nusing both will cause an exception\n\n" +
"Token filter configurations are specified as a comman-separated " +
"list of file\nnames, where each file name has an optional string" +
" with values:inclusive or\nexclusive, which species whether the" +
" token are to be used for an exclusive\nfilter. The default " +
"value is include. An example configuration might look like:\n" +
" --tokenFilter=english-dictionary.txt=include," +
"stop-list.txt=exclude");
}
} |
Partager