Examples of NearestNeighborFinder


Examples of edu.ucla.sspace.util.NearestNeighborFinder

            throws IOException {
       
        LOGGER.info("printing the most similar words for the semantic partition" +
                    " starting at: " + dateString);

        NearestNeighborFinder nnf =
            new SimpleNearestNeighborFinder(semanticPartition);

        // generate the similarity lists
        for (String toExamine : interestingWords) {
            SortedMultiMap<Double,String> mostSimilar =
                nnf.getMostSimilar(toExamine, interestingWordNeighbors);

            if (mostSimilar != null) {
                File neighborFile =
                    new File(outputDir, toExamine + "-" + dateString + ".txt");
                neighborFile.createNewFile(); // iff it doesn't already exist
View Full Code Here

Examples of edu.ucla.sspace.util.NearestNeighborFinder

        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 {
View Full Code Here

Examples of edu.ucla.sspace.util.NearestNeighborFinder

                                  outputDir);

        final PrintWriter outputWriter = new PrintWriter(output);
           
        final Set<String> words = sspace.getWords();
        NearestNeighborFinder nnf =
            new PartitioningNearestNeighborFinder(sspace);


        for (String word : words) {           
            // compute the k most-similar words to this word
            SortedMultiMap<Double,String> mostSimilar =
                nnf.getMostSimilar(word, numSimilar);
           
            // once processing has finished write the k most-similar words to
            // the output file.
            StringBuilder sb = new StringBuilder(256);
            sb.append(word).append("|");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.