Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
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.
/*
* Copyright 2011 David Jurgens
*
* This file is part of the S-Space 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.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
/**
* A utility class that receives a collection of tasks to execute internally and
* then distributes the tasks among a thread pool. This class offers to methods
* of use. In the first, a user can pass in a collection of tasks to run and
* then wait until the tasks are finished.
*
*Collection tasks = new LinkedList();
*WorkQueue q = new WorkQueue();
*for (int i = 0; i < numTasks; ++i)
* tasks.add(new Runnable() { }); // job to do goes here
*q.run(tasks);
*
*
*
* Alternately, a use may register a task group identifier and then iteratively
* add new tasks associated with that identifier. At some point in the future,
* the user can then wait for all the tasks associated with that identifier to
* finish. This second method allows for the iterative construction of tasks,
* or for cases where not all of the data for the tasks is availabe at once
* (although the number of tasks is known).
*
*WorkQueue q = new WorkQueue();
*Object taskGroupId = Thread.currentThread(); // a unique id
*q.registerTaskGroup(taskGroupId, numTasks);
*for (int i = 0; i < numTasks; ++i)
* q.add(taskGroupId, new Runnable() { }); // job to do goes here
*q.await(taskGroupId);
*
*
* In the above example, the current thread is used as the group identifier,
* which ensures that any other thread executing the same code won't use the
* same identifier, which could result in either thread returning prematurely
* before its tasks have finished. However, a shared group identifier
* can allow multiple threads to add tasks for a common goal, with each being
* able await until all the tasks are finished.
*
* @author David Jurgens
*/
public class WorkQueue {
/**
* The list of all threads drawing work from the queue.
*/
private final List threads;
/**
* The queue from which worker threads draw jobs to execute
*/
private final BlockingQueue workQueue;
/**
* A mapping from a group identifier to the associated latch.
*/
private final ConcurrentMap