edu.ucla.sspace.svs.SelectionalPreference Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sspace-wordsi Show documentation
Show all versions of sspace-wordsi Show documentation
The S-Space Package is a collection of algorithms for building
Semantic Spaces as well as a highly-scalable library for designing new
distributional semantics algorithms. Distributional algorithms process text
corpora and represent the semantic for words as high dimensional feature
vectors. This package also includes matrices, vectors, and numerous
clustering algorithms. These approaches are known by many names, such as
word spaces, semantic spaces, or distributed semantics and rest upon the
Distributional Hypothesis: words that appear in similar contexts have
similar meanings.
The newest version!
package edu.ucla.sspace.svs;
import edu.ucla.sspace.vector.CompactSparseVector;
import edu.ucla.sspace.vector.ScaledSparseDoubleVector;
import edu.ucla.sspace.vector.SparseDoubleVector;
import edu.ucla.sspace.vector.Vectors;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* @author Keith Stevens
*/
public class SelectionalPreference implements Serializable {
private static final long serialVersionUID = 1L;
public SparseDoubleVector lemmaVector;
public Map selPreferences;
public Map inverseSelPreferences;
private final VectorCombinor combinor;
public SelectionalPreference(VectorCombinor combinor) {
this.combinor = combinor;
lemmaVector = new CompactSparseVector();
selPreferences = new HashMap();
inverseSelPreferences = new HashMap();
}
public void addPreference(String relation,
SparseDoubleVector vector,
double frequency) {
add(relation, new ScaledSparseDoubleVector(vector, frequency),
selPreferences);
}
public void addInversePreference(String relation,
SparseDoubleVector vector,
double frequency) {
add(relation, new ScaledSparseDoubleVector(vector, frequency),
inverseSelPreferences);
}
private void add(String relation,
SparseDoubleVector vector,
Map map) {
SparseDoubleVector preference = map.get(relation);
if (preference == null) {
map.put(relation,
(SparseDoubleVector) Vectors.copyOf(vector));
return;
}
map.put(relation, combinor.combine(preference, vector));
}
public SparseDoubleVector preference(String relation) {
return selPreferences.get(relation);
}
public SparseDoubleVector inversePreference(String relation) {
return inverseSelPreferences.get(relation);
}
}