if (options.hasOption('C') && options.hasOption('L')) {
System.out.println("Cannot load and create a finder concurrently");
System.exit(1);
}
NearestNeighborFinder nnf = null;
if (options.hasOption('C')) {
try {
SemanticSpace sspace =
SemanticSpaceIO.load(options.getStringOption('C'));
int numWords = sspace.getWords().size();
// See how many principle vectors to create
int numPrincipleVectors = -1;
if (options.hasOption('p')) {
numPrincipleVectors = options.getIntOption('p');
if (numPrincipleVectors > numWords) {
throw new IllegalArgumentException(
"Cannot have more principle vectors than " +
"word vectors: " + numPrincipleVectors);
}
else if (numPrincipleVectors < 1) {
throw new IllegalArgumentException(
"Must have at least one principle vector");
}
}
else {
numPrincipleVectors =
Math.min((int)(Math.ceil(Math.log(numWords))), 1000);
System.err.printf("Choosing a heuristically selected %d " +
"principle vectors%n",
numPrincipleVectors);
}
nnf = new PartitioningNearestNeighborFinder(
sspace, numPrincipleVectors);
} catch (IOException ioe) {
throw new IOError(ioe);
}
}
else if (options.hasOption('L')) {
nnf = SerializableUtil.<NearestNeighborFinder>load(
new File(options.getStringOption('L')));
}
else {
throw new IllegalArgumentException(
"Must either create or load a NearestNeighborFinder");
}
if (options.hasOption('S')) {
SerializableUtil.save(nnf, new File(options.getStringOption('S')));
}
int numWords = options.numPositionalArgs();
for (int i = 0; i < numWords; ++i) {
String term = options.getPositionalArg(i);
long start = System.currentTimeMillis();
MultiMap<Double,String> m = nnf.getMostSimilar(term, 10);
if (m == null) {
System.out.println(term + " is not in the semantic " +
"space; no neighbors found.");
}
else {