當前位置: 首頁>>代碼示例>>Java>>正文


Java VectorStoreWriter類代碼示例

本文整理匯總了Java中pitt.search.semanticvectors.VectorStoreWriter的典型用法代碼示例。如果您正苦於以下問題:Java VectorStoreWriter類的具體用法?Java VectorStoreWriter怎麽用?Java VectorStoreWriter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


VectorStoreWriter類屬於pitt.search.semanticvectors包,在下文中一共展示了VectorStoreWriter類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import pitt.search.semanticvectors.VectorStoreWriter; //導入依賴的package包/類
public static void main(String[] args) throws IOException {
  FlagConfig flagConfig = null;
  try {
    flagConfig = FlagConfig.getFlagConfig(args);
    args = flagConfig.remainingArgs;
  } catch (IllegalArgumentException e) {
    System.err.println(usageMessage);
    throw e;
  }

  if (flagConfig.remainingArgs.length != 1) {
    throw new IllegalArgumentException("Wrong number of arguments after parsing command line flags.\n" + usageMessage);
  }

  VerbatimLogger.info("Building vector index of table in file: " + args[0] + "\n");
  BufferedReader fileReader = new BufferedReader(new FileReader(args[0]));
  String[] columnHeaders = fileReader.readLine().split(",");
  ArrayList<String[]> dataRows = new ArrayList<>();
  String dataLine;
  while((dataLine = fileReader.readLine()) != null) {
    String[] dataEntries = dataLine.split(",");
    if (dataEntries.length != columnHeaders.length) {
      throw new IllegalArgumentException(String.format(
          "Column headers have length %d and this row has length %d. This indicates a data error or a csv parsing error."
          + "\nColumn headers:%s\nData row: %s\n",
          columnHeaders.length, dataEntries.length,
          StringUtils.join(columnHeaders), StringUtils.join(dataEntries)));
    }
    dataRows.add(dataEntries);
  }
  fileReader.close();
  
  Table table = new Table(flagConfig, columnHeaders, dataRows);
  VectorStoreWriter.writeVectors(flagConfig.termvectorsfile(), flagConfig, table.getRowVectorStore());

  queryForSpecialValues(table);
  //queryForName(table, "J. Adams");
 // queryForName(table, "T. Roosevelt");
  
}
 
開發者ID:semanticvectors,項目名稱:semanticvectors,代碼行數:41,代碼來源:TableIndexer.java

示例2: createNGrams

import pitt.search.semanticvectors.VectorStoreWriter; //導入依賴的package包/類
public void createNGrams(String fileOut, FlagConfig flagConfig, int numGrams )
{
	BeagleNGramVectors bngv;
	BeagleUtils utils = BeagleUtils.getInstance();

	long time;

	try
	{
		time = System.currentTimeMillis();

		bngv = new BeagleNGramVectors(
		    flagConfig, "index", 5, 2, new String[] {"contents"}, numGrams, "stoplist.txt");

		time = System.currentTimeMillis() - time;

		System.out.println("\nTime to process: " + time/1000 + " secs.");
		System.out.println("\nNumber of convolutions: " + utils.getNumConvolutions());

		VectorStoreWriter.writeVectors(
		    fileOut + "_" + flagConfig.dimension() + "_" + numGrams + ".bin", flagConfig, bngv);

		VectorStore indexVectors = bngv.getIndexVectors();
		VectorStoreWriter.writeVectors(
		    fileOut + "_" + flagConfig.dimension() + "_" + numGrams + "_index.bin", flagConfig, indexVectors);

		bngv = null;
		System.gc();
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
}
 
開發者ID:semanticvectors,項目名稱:semanticvectors,代碼行數:35,代碼來源:BeagleTest.java

示例3: main

import pitt.search.semanticvectors.VectorStoreWriter; //導入依賴的package包/類
public static void main(String[] args) throws IOException {
  FlagConfig flagConfig = null;
  try {
    flagConfig = FlagConfig.getFlagConfig(args);
    args = flagConfig.remainingArgs;
  } catch (IllegalArgumentException e) {
    System.err.println(usageMessage);
    throw e;
  }
  
  VerbatimLogger.info("Building vector index of table in file: " + args[0] + "\n");
  BufferedReader fileReader = new BufferedReader(new FileReader(args[0]));
  String[] columnHeaders = fileReader.readLine().split(",");
  ArrayList<String[]> dataRows = new ArrayList<>();
  String dataLine;
  while((dataLine = fileReader.readLine()) != null) {
    String[] dataEntries = dataLine.split(",");
    if (dataEntries.length != columnHeaders.length) {
      throw new IllegalArgumentException(String.format(
          "Column headers have length %d and this row has length %d. This indicates a data error or a csv parsing error."
          + "\nColumn headers:%s\nData row: %s\n",
          columnHeaders.length, dataEntries.length,
          StringUtils.join(columnHeaders), StringUtils.join(dataEntries)));
    }
    dataRows.add(dataEntries);
  }
  fileReader.close();
  
  Table table = new Table(flagConfig, columnHeaders, dataRows);
  VectorStoreWriter.writeVectors(flagConfig.termvectorsfile(), flagConfig, table.getRowVectorStore());
  queryForSpecialValues(table);
}
 
開發者ID:tuxdna,項目名稱:semanticvectors-googlecode,代碼行數:33,代碼來源:TableIndexer.java

示例4: main

import pitt.search.semanticvectors.VectorStoreWriter; //導入依賴的package包/類
/**
 * Main class of a utility method that takes as input:
 * (1) -queryvectorfile: the original vector store OR
 * (1.1) -elementalvectofile, -semanticvectorfile, -predicatevectorfile (for PSI queries)
 * (2) -startlistfile: the list of queries (e.g. terms), one per line, from which to construct a new vector store 
 * @param args
 * @throws IOException 
 */


public static void main(String[] args) throws IOException {
	
	FlagConfig flagConfig = FlagConfig.getFlagConfig(args);
	boolean PSIquery = true;
	
	VectorStoreRAM queryVectors = new VectorStoreRAM(flagConfig);
	VectorStoreRAM elementalVectors = new VectorStoreRAM(flagConfig);
	VectorStoreRAM predicateVectors = new VectorStoreRAM(flagConfig);
	VectorStoreRAM semanticVectors = new VectorStoreRAM(flagConfig);

	
	//if all PSI/ESP query files are at the default value, assume this is not a PSI/ESP query
	if (flagConfig.elementalvectorfile().equals("elementalvectors")
			&& flagConfig.semanticvectorfile().equals("semanticvectors")
			  && flagConfig.elementalpredicatevectorfile().equals("predicatevectors")
			) 
		{
			PSIquery = false;
			queryVectors.initFromFile(flagConfig.queryvectorfile());
		}
	else
	{
		elementalVectors.initFromFile(flagConfig.elementalvectorfile());
		semanticVectors.initFromFile(flagConfig.semanticvectorfile());
		predicateVectors.initFromFile(flagConfig.elementalpredicatevectorfile());
	}
	
	VectorStoreRAM outGoingVectors = new VectorStoreRAM(flagConfig);
	
	
	BufferedReader theReader = new BufferedReader(new FileReader(new File(flagConfig.startlistfile())));
	
	String inputString = theReader.readLine();
	while (inputString != null)
	{
		Vector vectorToAdd = null;
		
		if (!PSIquery) vectorToAdd = CompoundVectorBuilder.getQueryVectorFromString(queryVectors, null, flagConfig, inputString);
		else 		   vectorToAdd = CompoundVectorBuilder.getBoundProductQueryVectorFromString(flagConfig, elementalVectors, semanticVectors, predicateVectors, null, inputString);
		
		if (vectorToAdd == null || 
				vectorToAdd.isZeroVector() || 
					(flagConfig.vectortype().equals(VectorType.REAL) && (Float.isNaN(  ((RealVector) vectorToAdd).getCoordinates()[0]))) ||
					(flagConfig.vectortype().equals(VectorType.COMPLEX) && (Float.isNaN(  ((ComplexVector) vectorToAdd).getCoordinates()[0])))
						
				)
		{	VerbatimLogger.info("Could not represent "+inputString);}
		else
		{
			VerbatimLogger.info("Adding "+inputString.replaceAll(" ", "_"));
			outGoingVectors.putVector(inputString.replaceAll(" ", "_"),vectorToAdd);
		}  
		
		inputString = theReader.readLine();
	}
	
	theReader.close();
	
	VerbatimLogger.info("\nFinished adding vectors, proceeding to write out\n");
	
	VectorStoreWriter.writeVectorsInLuceneFormat(flagConfig.startlistfile().replaceAll("\\..*", "_subset.bin"), flagConfig, outGoingVectors);
	

}
 
開發者ID:semanticvectors,項目名稱:semanticvectors,代碼行數:75,代碼來源:VectorStoreSubset.java

示例5: main

import pitt.search.semanticvectors.VectorStoreWriter; //導入依賴的package包/類
/**
 * @param args
 */
public static void main(String[] args) {
	// TODO Auto-generated method stub

	try {
	FlagConfig flagConfig 			= FlagConfig.getFlagConfig(args);
	VectorStoreRAM objectVectors 	= new VectorStoreRAM(flagConfig);
	String[] argsRemaining			= flagConfig.remainingArgs;
	String incomingVecs				= argsRemaining[0];
	int newDimension				= Integer.parseInt(argsRemaining[1]);
	objectVectors.initFromFile(incomingVecs);
	
	if (newDimension > flagConfig.dimension())
		{
		
				System.out.println("Incoming file has dimensionality of " +flagConfig.dimension());
				System.out.println("New dimensionality must be less than incoming vector length, quitting");
				System.exit(0);	
		}
	
		String vectorFileName = incomingVecs.replaceAll("\\.bin", "")+"_"+newDimension+".bin";
	  	File vectorFile = new File(vectorFileName);
	    String parentPath = vectorFile.getParent();
	    if (parentPath == null) parentPath = "";
	    FSDirectory fsDirectory = FSDirectory.open(FileSystems.getDefault().getPath(parentPath));
	    IndexOutput outputStream = fsDirectory.createOutput(vectorFile.getName(), IOContext.DEFAULT);
	 	flagConfig.setDimension(newDimension);
		outputStream.writeString(VectorStoreWriter.generateHeaderString(flagConfig));
	    Enumeration<ObjectVector> vecEnum = objectVectors.getAllVectors();

	    // Write each vector.
	    while (vecEnum.hasMoreElements()) {
	      ObjectVector objectVector = vecEnum.nextElement();
	      outputStream.writeString(objectVector.getObject().toString());
	      objectVector.getVector().writeToLuceneStream(outputStream,flagConfig.dimension());
	    }
	    
	    
	    outputStream.close();
	    fsDirectory.close();
		
	    VerbatimLogger.info("wrote "+objectVectors.getNumVectors()+" vectors to file "+ vectorFileName);
	    VerbatimLogger.info("finished writing vectors.\n");
	 		
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		System.out.println("Usage: VectorStoreTruncater incomingFile.bin newDimensinoality");
	}
	
	
	
}
 
開發者ID:semanticvectors,項目名稱:semanticvectors,代碼行數:56,代碼來源:VectorStoreTruncater.java


注:本文中的pitt.search.semanticvectors.VectorStoreWriter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。