pitt.search.semanticvectors.CloseableVectorStore Java Examples

The following examples show how to use pitt.search.semanticvectors.CloseableVectorStore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SemVectorsPeer.java    From seldon-server with Apache License 2.0 5 votes vote down vote up
/**
 * Will search for a file "recreated_<key>" if this exists will try to reload the semantic vector stores
 * @param folder
 * @param changedTermFilename
 * @param changedDocFilename
 */
public void reloadVectorStoresIfPossibleFile(String folder,String changedTermFilename,String changedDocFilename)
{
	lock.writeLock().lock();
	try
	{
		String recreatedFilename = folder + "/recreated_"+key;
		File recreated = new File(recreatedFilename);
		if (recreated.exists())
		{
			logger.info("Reloading vec stores at " + folder+" with key "+key);
			if (!useRamStores)
			{
				((CloseableVectorStore)termVecReader).close();
				((CloseableVectorStore)docVecReader).close();
			}
			File changedTermFile = new File(folder+"/"+changedTermFilename);
			File changedDocFile = new File(folder+"/"+changedDocFilename);
			File liveTermFile = new File(termFilename);
			File liveDocFile = new File(docFilename);
			changedTermFile.renameTo(liveTermFile);
			changedDocFile.renameTo(liveDocFile);
			openVectorStores(termFilename,docFilename);
			recreated.delete();
		}
		else
			logger.info("No file "+recreatedFilename+" so no reload done");
	}
	finally
	{
		lock.writeLock().unlock();
	}
}
 
Example #2
Source File: BeagleTest.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void testQuery(FlagConfig flagConfig, String searchfile, String indexfile, String query )
{
	VectorSearcher vs;
	LuceneUtils lUtils = null;
	CloseableVectorStore queryVecReader, searchVecReader;
	LinkedList<SearchResult> results;
	int numResults = 20;

	BeagleUtils utils = BeagleUtils.getInstance();
	utils.setFFTCacheSize(100);

	try
	{
		queryVecReader = VectorStoreReader.openVectorStore(indexfile, flagConfig);
		searchVecReader = VectorStoreReader.openVectorStore(searchfile, flagConfig);

		//BeagleCompoundVecBuilder bcb = new BeagleCompoundVecBuilder ();

		String[] queryTerms = query.split(" ");

		// Create VectorSearcher and search for nearest neighbors.
		vs = new BeagleVectorSearcher( queryVecReader, searchVecReader, lUtils, flagConfig, queryTerms);
		System.err.print("Searching term vectors, searchtype BEAGLE ... ");
		queryVecReader.close();
		searchVecReader.close();

		results = vs.getNearestNeighbors(numResults);

	}
	catch (Exception e)
	{
		System.err.println(e.getMessage());
		results = new LinkedList<SearchResult>();
	}

	// Print out results.
	if (results.size() > 0) {
		System.err.println("Search output follows ...\n");
		for (SearchResult result: results) {
			System.out.println(result.getScore() + ":" +
                                                  ((ObjectVector)result.getObjectVector()).getObject().toString());
		}
	} else {
		System.err.println("No search output.");
	}
}