本文整理汇总了Java中edu.ucla.sspace.common.SemanticSpace类的典型用法代码示例。如果您正苦于以下问题:Java SemanticSpace类的具体用法?Java SemanticSpace怎么用?Java SemanticSpace使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SemanticSpace类属于edu.ucla.sspace.common包,在下文中一共展示了SemanticSpace类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCompoNeigbors
import edu.ucla.sspace.common.SemanticSpace; //导入依赖的package包/类
public Map<CompoundSS, OneCompoundWithCompoNeighborsData> getCompoNeigbors(
CompoundSet compoundSet,
String semanticSpaceName, ECompoundsOrdering compoundsOrdering) {
String dataName = "COMPONEIGHBORS-" + compoundSet.getName() + "-" + semanticSpaceName + "-" + compoundsOrdering.toString();
CompoundsWithCompoNeigborsData oneCompoNeigborsData = cashedData.get(dataName);
if (oneCompoNeigborsData == null) {
oneCompoNeigborsData = (CompoundsWithCompoNeigborsData)DataSerializer.deserialiazeData(dataName);
cashedData.put(dataName, oneCompoNeigborsData);
}
if (oneCompoNeigborsData == null) {
SemanticSpace space = SSpaceProvider.getInstance().getSSpace(semanticSpaceName);
oneCompoNeigborsData = getCompoNeighborsData(compoundSet, space, compoundsOrdering);
oneCompoNeigborsData.storeToFile(Config.ACL2011_RESULTS_DIR + dataName);
DataSerializer.serializeData(oneCompoNeigborsData, dataName);
cashedData.put(dataName, oneCompoNeigborsData);
}
return oneCompoNeigborsData.compoundsXcompoNeigborsData;
}
示例2: findAlternatives
import edu.ucla.sspace.common.SemanticSpace; //导入依赖的package包/类
private ArrayList<SSWord> findAlternatives(SSWord word, String demandedType, SemanticSpace sspace, int neigboursCount) {
ArrayList<SSWord> neighbors = new ArrayList<SSWord>();
// Using the provided or default arguments find the closest
// neighbors to the target word in the current semantic space
boolean ignoreTags = Common.ignoreTags(sspace);
if (ignoreTags) demandedType = Constants.NOTAG;
SortedMultiMap<Double,String> mostSimilar =
wordComparatorChanged.getMostSimilar(word.getSSpaceRep(ignoreTags), demandedType, sspace, neigboursCount);
if (mostSimilar == null) {
System.out.println(word.getSSpaceRep(ignoreTags) + " is not in the current semantic space");
}
else {
// reverse returned order to be A-Z
synchronized(mostSimilar) {
for (Map.Entry<Double,String> e : mostSimilar.entrySet()) {
neighbors.add(0, new SSWord(e.getValue()));
}
}
}
return neighbors;
}
示例3: getAltsAndCounts
import edu.ucla.sspace.common.SemanticSpace; //导入依赖的package包/类
public Map<CompoundSS, OneCompoundWithAltsAndCountsData> getAltsAndCounts(
CompoundSet compoundSet,
String semanticSpaceName, ECompoundsOrdering compoundsOrdering) {
String dataName = "NEIGHBORS-" + compoundSet.getName() + "-" + semanticSpaceName + "-" + compoundsOrdering.toString();
CompoundsWithAltsAndCountsData oneAltsAndCountsData = cashedData.get(dataName);
if (oneAltsAndCountsData == null) {
oneAltsAndCountsData = (CompoundsWithAltsAndCountsData)DataSerializer.deserialiazeData(dataName);
cashedData.put(dataName, oneAltsAndCountsData);
}
if (oneAltsAndCountsData == null) {
SemanticSpace space = SSpaceProvider.getInstance().getSSpace(semanticSpaceName);
oneAltsAndCountsData = getAltsAndCounts(compoundSet, space, compoundsOrdering);
oneAltsAndCountsData.storeToFile(Config.ACL2011_RESULTS_DIR + dataName);
DataSerializer.serializeData(oneAltsAndCountsData, dataName);
cashedData.put(dataName, oneAltsAndCountsData);
}
return oneAltsAndCountsData.compoundsXaltsAndCount;
}
示例4: getCompositionality
import edu.ucla.sspace.common.SemanticSpace; //导入依赖的package包/类
public Map<CompoundSS, OneCompoundWithCompositionalityData> getCompositionality (
CompoundSet compoundSet,
String semanticSpaceName) {
String dataName = "COMPOSITIONALITY-" + compoundSet.getName() + "-" + semanticSpaceName;
CompoundsWithCompositionalityData oneCompositionalityData = cashedData.get(dataName);
if (oneCompositionalityData == null) {
oneCompositionalityData = (CompoundsWithCompositionalityData)DataSerializer.deserialiazeData(dataName);
cashedData.put(dataName, oneCompositionalityData);
}
if (oneCompositionalityData == null) {
SemanticSpace space = SSpaceProvider.getInstance().getSSpace(semanticSpaceName);
oneCompositionalityData = getCompositionalityData(compoundSet, space);
// oneCompositionalityData.storeToFile(Config.ACL2011_RESULTS_DIR + dataName);
DataSerializer.serializeData(oneCompositionalityData, dataName);
cashedData.put(dataName, oneCompositionalityData);
}
return oneCompositionalityData.compoundsXcompositionality;
}
示例5: getSpace
import edu.ucla.sspace.common.SemanticSpace; //导入依赖的package包/类
protected SemanticSpace getSpace() {
try {
int dimensions = argOptions.getIntOption("dimensions", 300);
Transform transform = new LogEntropyTransform();
if (argOptions.hasOption("preprocess"))
transform = ReflectionUtil.getObjectInstance(
argOptions.getStringOption("preprocess"));
String algName = argOptions.getStringOption("svdAlgorithm", "ANY");
MatrixFactorization factorization = SVD.getFactorization(
Algorithm.valueOf(algName.toUpperCase()));
basis = new StringBasisMapping();
return new LatentSemanticAnalysis(
false, dimensions, transform, factorization, false, basis);
} catch (IOException ioe) {
throw new IOError(ioe);
}
}
示例6: documentVectorSimilarity
import edu.ucla.sspace.common.SemanticSpace; //导入依赖的package包/类
public static double documentVectorSimilarity(String[] args) throws IOException {
SemanticSpace sspace = SemanticSpaceIO.load(Resources.getResource(args[0]).getFile());
// See how many dimensions are present in the SemanticSpace so that
// we can initialize the document vectors correctly.
int numDims = sspace.getVectorLength();
// Create the DocumentVectorBuilder which will use the
// term-to-vector mapping in the SemanticSpace to construct
// document-level representations
DocumentVectorBuilder builder = new DocumentVectorBuilder(sspace);
// Create the first document's vector. We create this manually (as
// the caller) because we should have some sense of how big the
// document is and whether it makes sense to have the document be
// represented as a sparse or full vector.
DoubleVector documentVector = new DenseVector(numDims);
// Read in the first document and create a representation of it by
// summing the vectors for all of its tokens
BufferedReader br = new BufferedReader(new FileReader(args[1]));
builder.buildVector(br, documentVector);
br.close();
// Read in a second document and create a representation of it by
// summing the vectors for all of its tokens
br = new BufferedReader(new FileReader(args[2]));
DoubleVector documentVector2 = new DenseVector(numDims);
builder.buildVector(br, documentVector2);
br.close();
double similarity =
Similarity.cosineSimilarity(documentVector, documentVector2);
System.out.printf("The similarity of %s and %s is %f%n",
args[1], args[2], similarity);
return similarity;
}
示例7: getAlternatives
import edu.ucla.sspace.common.SemanticSpace; //导入依赖的package包/类
public ArrayList<SSWord> getAlternatives(SSWord word, String demandedType, SemanticSpace sspace, int neigboursCount,
Similarity.SimType similarity) {
if (wordComparatorChanged == null) {
wordComparatorChanged = new WordComparatorChanged(similarity, true, Constants.TAG_LENGTH);
}
else {
wordComparatorChanged.setSimType(similarity);
}
return findAlternatives(word, demandedType, sspace, neigboursCount);
}
示例8: getEndocentricity
import edu.ucla.sspace.common.SemanticSpace; //导入依赖的package包/类
/** Provides given set of compounds with endocentricity data */
public Map<CompoundSS, OneCompoundWithEndocentricityData> getEndocentricity (
CompoundSet compoundSet,
String semanticSpaceName,
ECompoundsOrdering compoundsOrdering) {
String dataName = "ENDOCENTRICITY-" + compoundSet.getName() + "-" + semanticSpaceName.toString() + "-" + compoundsOrdering.toString();
CompoundsWithEndocentricityData oneEndocentricityData = cashedData.get(dataName);
if (oneEndocentricityData == null) { // data are not in cash
oneEndocentricityData = (CompoundsWithEndocentricityData)DataSerializer.deserialiazeData(dataName);
cashedData.put(dataName, oneEndocentricityData);
}
if (oneEndocentricityData == null) { // data are not in cash nor serialized
SemanticSpace space = SSpaceProvider.getInstance().getSSpace(semanticSpaceName);
//System.out.println("+"+space.getSpaceName());
oneEndocentricityData = getEndocentricityData(compoundSet, space, compoundsOrdering);
oneEndocentricityData.storeToFile(Config.ACL2011_RESULTS_DIR + dataName);
DataSerializer.serializeData(oneEndocentricityData, dataName);
cashedData.put(dataName, oneEndocentricityData); // cash data
}
return oneEndocentricityData.compoundsXendocentricity;
}
示例9: getNeigbors
import edu.ucla.sspace.common.SemanticSpace; //导入依赖的package包/类
private static List<String> getNeigbors(String word, SemanticSpace space) {
try {
SSWord wordSS = new SSWord(word + "_XX");
List<SSWord> wordNeigbors = AlternativesProvider.getInstance().getAlternatives(wordSS, "ANY", space, 100, ECompoundsOrdering.COSSIM);
return getRidOfSSpostfix(wordNeigbors);
}
catch (IllegalArgumentException e) {
System.out.println("catched word not found in space");
return null;
}
}
示例10: getEndocentricityDataForCompounds
import edu.ucla.sspace.common.SemanticSpace; //导入依赖的package包/类
public void getEndocentricityDataForCompounds(SemanticSpace sspace, WordComparatorChanged wordCom) {
for (CompoundSS compound: compounds) {
//compound.fillWithEndocentricityData(sspace, wordCom);
}
}
示例11: getSSpace
import edu.ucla.sspace.common.SemanticSpace; //导入依赖的package包/类
public SemanticSpace getSSpace(String semanticSpaceName) {
if (this.semanticSpaceName != semanticSpaceName) {
loadSemanticSpace(semanticSpaceName);
}
return space;
}
示例12: ignoreTags
import edu.ucla.sspace.common.SemanticSpace; //导入依赖的package包/类
public static boolean ignoreTags(SemanticSpace space) {
return space.getSpaceName().endsWith(Constants.SSNOTAGSFN_EXTENSION);
}
示例13: getEndocentricityData
import edu.ucla.sspace.common.SemanticSpace; //导入依赖的package包/类
/**
* loads endocentricity data from given semantic space
*/
private CompoundsWithEndocentricityData getEndocentricityData(CompoundSet compoundSet, SemanticSpace space,
ECompoundsOrdering compoundsOrdering) {
Map<CompoundSS, OneCompoundWithEndocentricityData> compoundsXendocentricity = new LinkedHashMap<CompoundSS, OneCompoundWithEndocentricityData>();
boolean ignoreTags = Common.ignoreTags(space);
for (CompoundSS oneCompound : compoundSet.getCompounds()) {
SSWord leftWordSS = oneCompound.getWordLeftSS();
SSWord rightWordSS = oneCompound.getWordRightSS();
SSWord compoundAsWord = new SSWord(oneCompound.getSSpaceRep(ignoreTags));
//ACLCompoundTag compoundTag = oneCompound.getTag();
//System.out.println(oneCompound.getSSpaceRep(ignoreTags));
double simLeft;
double simRight;
int distanceLeft = Constants.MAX_DISTANCE;
int distanceRight = Constants.MAX_DISTANCE;
simLeft = Similarity.getSimilarity(AlternativesProvider.getInstance().castFrom(compoundsOrdering),
space.getVector(compoundAsWord.getSSpaceRep(ignoreTags)),
space.getVector(leftWordSS.getSSpaceRep(ignoreTags)));
simRight = Similarity.getSimilarity(AlternativesProvider.getInstance().castFrom(compoundsOrdering),
space.getVector(compoundAsWord.getSSpaceRep(ignoreTags)),
space.getVector(rightWordSS.getSSpaceRep(ignoreTags)));
// using distance is problematic in hybrid semantic spaces since their getWords returns
// only main words and not the other words (lower freq e.g.)
// therefore distances would be Constants.MAX_DISTANCE in most cases probably
// solution: create alternative of hybrid semantic space with getWords method providing other words also..
//
// ArrayList<SSWord> altsCompoundWordLeft = AlternativesProvider.getInstance().
// getAlternatives(compoundAsWord, firstWord.getTag().toString(), space, neigboursCount, compoundsOrdering);
// int distance = 1;
// for (SSWord oneSSWord : altsCompoundWordLeft) {
// if (oneSSWord.getSSpaceRep().equals(firstWord.getSSpaceRep(ignoreTags))) {
// distanceLeft = distance;
// }
// distance++;
// }
// ArrayList<SSWord> altsCompoundWordRight = AlternativesProvider.getInstance().
// getAlternatives(compoundAsWord, secondWord.getTag().toString(), space, neigboursCount, compoundsOrdering);
// distance = 1;
// for (SSWord oneSSWord : altsCompoundWordRight) {
// if (oneSSWord.getSSpaceRep().equals(secondWord.getSSpaceRep(ignoreTags))) {
// distanceRight = distance;
// }
// distance++;
// }
compoundsXendocentricity.put(oneCompound, new OneCompoundWithEndocentricityData(
simLeft, simRight, distanceLeft, distanceRight));
}
return new CompoundsWithEndocentricityData(compoundsXendocentricity, ignoreTags);
}