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


Java FSDirectory.close方法代碼示例

本文整理匯總了Java中org.apache.lucene.store.FSDirectory.close方法的典型用法代碼示例。如果您正苦於以下問題:Java FSDirectory.close方法的具體用法?Java FSDirectory.close怎麽用?Java FSDirectory.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.lucene.store.FSDirectory的用法示例。


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

示例1: copyFiles

import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
public void copyFiles(Directory sourceDir, Collection<String> files,
    File destDir) throws IOException {
  // does destinations directory exist ?
  if (destDir != null && !destDir.exists()) {
    destDir.mkdirs();
  }
  
  FSDirectory dir = FSDirectory.open(destDir);
  try {
    for (String indexFile : files) {
      copyFile(sourceDir, indexFile, new File(destDir, indexFile), dir);
    }
  } finally {
    dir.close();
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:17,代碼來源:SnapShooter.java

示例2: writeVectorsInLuceneFormat

import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
/**
 * Outputs a vector store in Lucene binary format.
 * 
 * @param vectorFileName The name of the file to write to
 * @param objectVectors The vector store to be written to disk
 */
public static void writeVectorsInLuceneFormat(String vectorFileName, FlagConfig flagConfig, VectorStore objectVectors)
    throws IOException {
  VerbatimLogger.info("About to write " + objectVectors.getNumVectors() + " vectors of dimension "
      + flagConfig.dimension() + " to Lucene format file: " + vectorFileName + " ... ");
  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);
  writeToIndexOutput(objectVectors, flagConfig, outputStream);
  outputStream.close();
  fsDirectory.close();
}
 
開發者ID:semanticvectors,項目名稱:semanticvectors,代碼行數:20,代碼來源:VectorStoreWriter.java

示例3: main

import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
  if (args.length < 4 || args.length > 5) {
    System.err.println("Usage: QueryDriver <topicsFile> <qrelsFile> <submissionFile> <indexDir> [querySpec]");
    System.err.println("topicsFile: input file containing queries");
    System.err.println("qrelsFile: input file containing relevance judgements");
    System.err.println("submissionFile: output submission file for trec_eval");
    System.err.println("indexDir: index directory");
    System.err.println("querySpec: string composed of fields to use in query consisting of T=title,D=description,N=narrative:");
    System.err.println("\texample: TD (query on Title + Description). The default is T (title only)");
    System.exit(1);
  }
  
  File topicsFile = new File(args[0]);
  File qrelsFile = new File(args[1]);
  SubmissionReport submitLog = new SubmissionReport(new PrintWriter(args[2], IOUtils.UTF_8 /* huh, no nio.Charset ctor? */), "lucene");
  FSDirectory dir = FSDirectory.open(new File(args[3]));
  String fieldSpec = args.length == 5 ? args[4] : "T"; // default to Title-only if not specified.
  IndexReader reader = DirectoryReader.open(dir);
  IndexSearcher searcher = new IndexSearcher(reader);

  int maxResults = 1000;
  String docNameField = "docname";

  PrintWriter logger = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()), true);

  // use trec utilities to read trec topics into quality queries
  TrecTopicsReader qReader = new TrecTopicsReader();
  QualityQuery qqs[] = qReader.readQueries(new BufferedReader(IOUtils.getDecodingReader(topicsFile, StandardCharsets.UTF_8)));

  // prepare judge, with trec utilities that read from a QRels file
  Judge judge = new TrecJudge(new BufferedReader(IOUtils.getDecodingReader(qrelsFile, StandardCharsets.UTF_8)));

  // validate topics & judgments match each other
  judge.validateData(qqs, logger);

  Set<String> fieldSet = new HashSet<>();
  if (fieldSpec.indexOf('T') >= 0) fieldSet.add("title");
  if (fieldSpec.indexOf('D') >= 0) fieldSet.add("description");
  if (fieldSpec.indexOf('N') >= 0) fieldSet.add("narrative");
  
  // set the parsing of quality queries into Lucene queries.
  QualityQueryParser qqParser = new SimpleQQParser(fieldSet.toArray(new String[0]), "body");

  // run the benchmark
  QualityBenchmark qrun = new QualityBenchmark(qqs, qqParser, searcher, docNameField);
  qrun.setMaxResults(maxResults);
  QualityStats stats[] = qrun.execute(judge, submitLog, logger);

  // print an avarage sum of the results
  QualityStats avg = QualityStats.average(stats);
  avg.log("SUMMARY", 2, logger, "  ");
  reader.close();
  dir.close();
}
 
開發者ID:europeana,項目名稱:search,代碼行數:55,代碼來源:QueryDriver.java

示例4: main

import org.apache.lucene.store.FSDirectory; //導入方法依賴的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


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