edu.ucla.sspace.tools.PsudoWordSelector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sspace Show documentation
Show all versions of sspace Show documentation
The S-Space Package is a Natural Language Processing library for
distributional semantics representations. Distributional semantics
representations model the meaning of words, phrases, and sentences as high
dimensional vectors or probability distributions. The library includes common
algorithms such as Latent Semantic Analysis, Random Indexing, and Latent
Dirichlet Allocation. The S-Space package also includes software libraries
for matrices, vectors, graphs, and numerous clustering
algorithms.
The newest version!
/*
* Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
* the Lawrence Livermore National Laboratory. Written by Keith Stevens,
* [email protected] OCEC-10-073 All rights reserved.
*
* This file is part of the C-Cat 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 .
*/
package edu.ucla.sspace.tools;
import edu.ucla.sspace.common.ArgOptions;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
/**
* A utility for selecting a set of pseudo words. It takes in a list of words
* and their scores, and optionally a list of words that should serve as the
* basis for any psuedoword. The output will be a list of mappings from the
* original term to it's pseudo word. This also supports separation by parts of
* speech. When using parts of speech, confounders will always have the same
* part of speech.
*
* @author Keith Stevens
*/
public class PsudoWordSelector {
private static boolean usePos;
public static void usage(ArgOptions options) {
System.out.println(
"Usage: PseudoWordselector [options] \n" +
options.prettyPrint());
System.exit(1);
}
public static void main(String[] args) throws Exception {
ArgOptions options = new ArgOptions();
options.addOption('w', "wordList",
"Specifies the wods that should be used in a " +
"pseudo word list",
true, "FILE", "Required (One of)");
options.addOption('n', "numberOfPseudoWords",
"Specifies the desired number of pseudo words " +
"to create. If usePartsOfSpeech is set, this " +
"number of words per part of speech will be selected",
true, "INT", "Requred (One of)");
options.addOption('P', "usePartsOfSpeech",
"If set, all terms are expected to have their part " +
"of speech as a suffix. Terms should have the " +
"form lemma-POS",
false, null, "Optional");
options.addOption('t', "typeOfPseudoWord",
"Specifies the specificity of the selected pseudo " +
"word confounders. high will pick the word with " +
"the closest score. med will select a score " +
"randomly from the 100 closest scoring words and " +
"low will select any confounder at random",
true, "high|med|low", "Required");
options.parseOptions(args);
if ((!options.hasOption('n') && !options.hasOption('w')) ||
!options.hasOption('t') ||
options.numPositionalArgs() != 2)
usage(options);
usePos = options.hasOption('P');
List