当前位置: 首页>>代码示例>>Java>>正文


Java SemanticSpace类代码示例

本文整理汇总了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;
}
 
开发者ID:lkrcmar,项目名称:MWEs,代码行数:25,代码来源:CompoNeigboursDataProvider.java

示例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;
}
 
开发者ID:lkrcmar,项目名称:MWEs,代码行数:26,代码来源:AlternativesProvider.java

示例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;
}
 
开发者ID:lkrcmar,项目名称:MWEs,代码行数:25,代码来源:AltsAndCountsDataProvider.java

示例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;
}
 
开发者ID:lkrcmar,项目名称:MWEs,代码行数:25,代码来源:CompositionalityDataProvider.java

示例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);
    }
}
 
开发者ID:germanattanasio,项目名称:traceability-assistant,代码行数:19,代码来源:LSA.java

示例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;
    }
 
开发者ID:gizemsogancioglu,项目名称:biosses,代码行数:40,代码来源:LsaDocumentSimilarity.java

示例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);
}
 
开发者ID:lkrcmar,项目名称:MWEs,代码行数:11,代码来源:AlternativesProvider.java

示例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;
}
 
开发者ID:lkrcmar,项目名称:MWEs,代码行数:29,代码来源:EndocentricityDataProvider.java

示例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;
    }
}
 
开发者ID:lkrcmar,项目名称:MWEs,代码行数:12,代码来源:NeigborsGenerator.java

示例10: getEndocentricityDataForCompounds

import edu.ucla.sspace.common.SemanticSpace; //导入依赖的package包/类
public void getEndocentricityDataForCompounds(SemanticSpace sspace, WordComparatorChanged wordCom) {
    for (CompoundSS compound: compounds) {
        //compound.fillWithEndocentricityData(sspace, wordCom);
    }
}
 
开发者ID:lkrcmar,项目名称:MWEs,代码行数:6,代码来源:CompoundSet.java

示例11: getSSpace

import edu.ucla.sspace.common.SemanticSpace; //导入依赖的package包/类
public SemanticSpace getSSpace(String semanticSpaceName) {
    if (this.semanticSpaceName != semanticSpaceName) {
        loadSemanticSpace(semanticSpaceName);
    }
    return space;
}
 
开发者ID:lkrcmar,项目名称:MWEs,代码行数:7,代码来源:SSpaceProvider.java

示例12: ignoreTags

import edu.ucla.sspace.common.SemanticSpace; //导入依赖的package包/类
public static boolean ignoreTags(SemanticSpace space) {
    return space.getSpaceName().endsWith(Constants.SSNOTAGSFN_EXTENSION);
}
 
开发者ID:lkrcmar,项目名称:MWEs,代码行数:4,代码来源:Common.java

示例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);
    }
 
开发者ID:lkrcmar,项目名称:MWEs,代码行数:57,代码来源:EndocentricityDataProvider.java


注:本文中的edu.ucla.sspace.common.SemanticSpace类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。