本文整理汇总了Java中net.semanticmetadata.lire.utils.LuceneUtils类的典型用法代码示例。如果您正苦于以下问题:Java LuceneUtils类的具体用法?Java LuceneUtils怎么用?Java LuceneUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LuceneUtils类属于net.semanticmetadata.lire.utils包,在下文中一共展示了LuceneUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: index
import net.semanticmetadata.lire.utils.LuceneUtils; //导入依赖的package包/类
/**
* Index a picture
* @param source
* @param picture_id
* @param conf
* @throws IOException
*/
public static void index(byte[] source, UUID picture_id, IndexWriterConfig conf) throws IOException
{
ByteArrayInputStream in = new ByteArrayInputStream(source);
BufferedImage image = ImageIO.read(in);
// Creating an Lucene IndexWriter
log.debug("Is Lucene configured? " + (conf == null));
if(conf == null) {
conf = new IndexWriterConfig(LuceneUtils.LUCENE_VERSION, new WhitespaceAnalyzer(LuceneUtils.LUCENE_VERSION));
conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
}
luceneIndexer(image, picture_id, FeatureEnumerate.AutoColorCorrelogram.getText(), DocumentBuilderFactory.getAutoColorCorrelogramDocumentBuilder(), conf);
luceneIndexer(image, picture_id, FeatureEnumerate.CEDD.getText(), DocumentBuilderFactory.getCEDDDocumentBuilder(), conf);
luceneIndexer(image, picture_id, FeatureEnumerate.ColorLayout.getText(), DocumentBuilderFactory.getColorLayoutBuilder(), conf);
luceneIndexer(image, picture_id, FeatureEnumerate.EdgeHistogram.getText(), DocumentBuilderFactory.getEdgeHistogramBuilder(), conf);
luceneIndexer(image, picture_id, FeatureEnumerate.ColorHistogram.getText(), DocumentBuilderFactory.getColorHistogramDocumentBuilder(), conf);
luceneIndexer(image, picture_id, FeatureEnumerate.PHOG.getText(), DocumentBuilderFactory.getPHOGDocumentBuilder(), conf);
}
示例2: deleteFromFeature
import net.semanticmetadata.lire.utils.LuceneUtils; //导入依赖的package包/类
private static void deleteFromFeature(UUID pictureId, Term term, String prefix, IndexWriterConfig conf) throws IOException {
File file = getPath(prefix);
// Creating an Lucene IndexWriter
log.debug("Is Lucene configured: " + (conf == null));
if(conf == null) {
conf = new IndexWriterConfig(LuceneUtils.LUCENE_VERSION, new WhitespaceAnalyzer(LuceneUtils.LUCENE_VERSION));
conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
}
IndexWriter iw = new IndexWriter(FSDirectory.open(file), conf);
iw.deleteDocuments(term);
iw.close();
}
示例3: run
import net.semanticmetadata.lire.utils.LuceneUtils; //导入依赖的package包/类
public void run() {
// do it ...
try {
// IndexWriter indexWriter = LuceneUtils.createIndexWriter(indexPath, overwriteIndex, LuceneUtils.AnalyzerType.WhitespaceAnalyzer);
IndexWriterConfig config = new IndexWriterConfig(LuceneUtils.LUCENE_VERSION, new WhitespaceAnalyzer(LuceneUtils.LUCENE_VERSION));
config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
config.setCodec(new LireCustomCodec());
IndexWriter indexWriter = new IndexWriter(FSDirectory.open(new File(indexPath)), config);
for (Iterator<File> iterator = inputFiles.iterator(); iterator.hasNext(); ) {
File inputFile = iterator.next();
if (verbose) System.out.println("Processing " + inputFile.getPath() + ".");
readFile(indexWriter, inputFile);
if (verbose) System.out.println("Indexing finished.");
}
indexWriter.commit();
indexWriter.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: indexFiles
import net.semanticmetadata.lire.utils.LuceneUtils; //导入依赖的package包/类
private void indexFiles(ArrayList<String> images, DocumentBuilder builder, String indexPath) throws IOException {
// System.out.println(">> Indexing " + images.size() + " files.");
// DocumentBuilder builder = DocumentBuilderFactory.getExtensiveDocumentBuilder();
// DocumentBuilder builder = DocumentBuilderFactory.getFastDocumentBuilder();
IndexWriter iw = LuceneUtils.createIndexWriter(indexPath, true);
int count = 0;
long time = System.currentTimeMillis();
for (String identifier : images) {
Document doc = builder.createDocument(new FileInputStream(identifier), identifier);
iw.addDocument(doc);
count++;
if (count % 100 == 0) System.out.println(count + " files indexed.");
// if (count == 200) break;
}
long timeTaken = (System.currentTimeMillis() - time);
float sec = ((float) timeTaken) / 1000f;
System.out.println(sec + " seconds taken, " + (timeTaken / count) + " ms per image.");
iw.commit();
iw.close();
}
示例5: indexFiles
import net.semanticmetadata.lire.utils.LuceneUtils; //导入依赖的package包/类
private void indexFiles(ArrayList<String> images, DocumentBuilder builder, String indexPath) throws IOException {
System.out.println(">> Indexing " + images.size() + " files.");
IndexWriter iw = LuceneUtils.createIndexWriter(indexPath, true);
int count = 0;
long time = System.currentTimeMillis();
for (String identifier : images) {
Document doc = builder.createDocument(new FileInputStream(identifier), identifier);
iw.addDocument(doc);
count++;
if (count % 100 == 0) System.out.println(count + " files indexed.");
// if (count == 200) break;
}
long timeTaken = (System.currentTimeMillis() - time);
float sec = ((float) timeTaken) / 1000f;
System.out.println(sec + " seconds taken, " + (timeTaken / count) + " ms per image.");
iw.close();
}
示例6: testIndexing
import net.semanticmetadata.lire.utils.LuceneUtils; //导入依赖的package包/类
public void testIndexing() throws IOException {
ChainedDocumentBuilder b = new ChainedDocumentBuilder();
b.addBuilder(new SiftDocumentBuilder());
// b.addBuilder(DocumentBuilderFactory.getCEDDDocumentBuilder());
ArrayList<String> files = net.semanticmetadata.lire.utils.FileUtils.getAllImages(new File("W:\\MultimediaShare\\image_datasets\\ukbench-nister\\full"), true);
System.out.println("files.size() = " + files.size());
IndexWriter writer = LuceneUtils.createIndexWriter("nisterindex_sift", true);
int count = 0;
long ms = System.currentTimeMillis();
for (Iterator<String> iterator = files.iterator(); iterator.hasNext(); ) {
String next = iterator.next();
Document d = b.createDocument(ImageIO.read(new File(next)), next);
writer.addDocument(d);
count++;
if (count % 100 == 0) {
float time = (float) (System.currentTimeMillis() - ms);
System.out.println("Finished " + count + " images, " + (((float) count) / 10200f) * 100 + "%. " + (time / (float) count) + " ms per image.");
}
}
writer.close();
}
示例7: indexFiles
import net.semanticmetadata.lire.utils.LuceneUtils; //导入依赖的package包/类
private void indexFiles(String dir, String index, int featureIndex, boolean createNewIndex) throws IOException {
ArrayList<String> images = FileUtils.getAllImages(new File(dir), true);
IndexWriter iw = LuceneUtils.createIndexWriter(index, createNewIndex, LuceneUtils.AnalyzerType.WhitespaceAnalyzer);
// select one feature for the large index:
int count = 0;
long ms = System.currentTimeMillis();
DocumentBuilder builder = new ChainedDocumentBuilder();
((ChainedDocumentBuilder) builder).addBuilder(builders[featureIndex]);
// ((ChainedDocumentBuilder) builder).addBuilder(builders[0]);
for (Iterator<String> iterator = images.iterator(); iterator.hasNext(); ) {
count++;
if (count > 100 && count % 5000 == 0) {
System.out.println(count + " files indexed. " + (System.currentTimeMillis() - ms) / (count) + " ms per file");
}
String file = iterator.next();
try {
iw.addDocument(builder.createDocument(new FileInputStream(file), file));
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
iw.close();
}
示例8: testIndexMissingFiles
import net.semanticmetadata.lire.utils.LuceneUtils; //导入依赖的package包/类
public void testIndexMissingFiles() throws IOException {
// first delete some of the existing ones ...
System.out.println("Deleting visual words from docs ...");
IndexReader ir = DirectoryReader.open(FSDirectory.open(new File(index)));
IndexWriter iw = LuceneUtils.createIndexWriter(index, false);
int maxDocs = ir.maxDoc();
for (int i = 0; i < maxDocs / 10; i++) {
Document d = ir.document(i);
d.removeFields(DocumentBuilder.FIELD_NAME_SURF_VISUAL_WORDS);
d.removeFields(DocumentBuilder.FIELD_NAME_SURF_LOCAL_FEATURE_HISTOGRAM);
// d.removeFields(DocumentBuilder.FIELD_NAME_SURF);
iw.updateDocument(new Term(DocumentBuilder.FIELD_NAME_IDENTIFIER, d.getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]), d);
}
System.out.println("# of deleted docs: " + maxDocs / 10);
System.out.println("Optimizing and closing ...");
iw.close();
ir.close();
System.out.println("Creating new visual words ...");
SurfFeatureHistogramBuilder surfFeatureHistogramBuilder = new SurfFeatureHistogramBuilder(DirectoryReader.open(FSDirectory.open(new File(index))), numSamples, clusters);
surfFeatureHistogramBuilder.indexMissing();
System.out.println("Finished.");
}
示例9: testCreateCEDDIndex
import net.semanticmetadata.lire.utils.LuceneUtils; //导入依赖的package包/类
public void testCreateCEDDIndex() throws IOException {
ArrayList<String> images = FileUtils.getAllImages(new File("E:/temp/flickrphotos/flickrphotos"), true);
ChainedDocumentBuilder builder = new ChainedDocumentBuilder();
builder.addBuilder(DocumentBuilderFactory.getCEDDDocumentBuilder());
IndexWriter iw = LuceneUtils.createIndexWriter(indexPath + "-cedd", true);
int count = 0;
long ms = System.currentTimeMillis();
for (String identifier : images) {
try {
Document doc = builder.createDocument(new FileInputStream(identifier), identifier);
iw.addDocument(doc);
} catch (Exception e) {
System.err.print("\n ;-( ");//e.printStackTrace();
}
count++;
if (count % 1000 == 0) System.out.println((100 * count) / images.size() + "% ");
}
System.out.println("Time taken: " + ((System.currentTimeMillis() - ms) / testFiles.length) + " ms");
iw.commit();
iw.close();
}
示例10: indexFiles
import net.semanticmetadata.lire.utils.LuceneUtils; //导入依赖的package包/类
private void indexFiles(String prefix, ArrayList<String> images, DocumentBuilder builder, String indexPath) throws IOException {
System.out.println(">> Indexing " + images.size() + " files.");
IndexWriter iw = LuceneUtils.createIndexWriter(indexPath, true);
int count = 0;
long time = System.currentTimeMillis();
for (String identifier : images) {
Document doc = builder.createDocument(new FileInputStream(identifier), identifier);
iw.addDocument(doc);
count++;
if (count % 100 == 0) System.out.print((100 * count) / images.size() + "% ");
}
long timeTaken = (System.currentTimeMillis() - time);
float sec = ((float) timeTaken) / 1000f;
System.out.println("");
System.out.println(prefix + sec + " seconds taken, " + (timeTaken / count) + " ms per image.");
// iw.optimize();
iw.close();
}
示例11: testExtendedIndexMSER
import net.semanticmetadata.lire.utils.LuceneUtils; //导入依赖的package包/类
public void testExtendedIndexMSER() throws IOException {
MSERDocumentBuilder builder = new MSERDocumentBuilder();
IndexWriterConfig conf = new IndexWriterConfig(LuceneUtils.LUCENE_VERSION,
new WhitespaceAnalyzer(LuceneUtils.LUCENE_VERSION));
IndexWriter iw = new IndexWriter(FSDirectory.open(indexPath), conf);
long ms = System.currentTimeMillis();
int count = 0;
ArrayList<File> files = FileUtils.getAllImageFiles(new File("D:\\DataSets\\WIPO\\CA\\sample"), true);
for (Iterator<File> i = files.iterator(); i.hasNext(); ) {
File imgFile = i.next();
BufferedImage img = ImageIO.read(imgFile);
if (Math.max(img.getWidth(), img.getHeight()) < 800) {
// scale image ...
img = ImageUtils.scaleImage(img, 800);
}
iw.addDocument(builder.createDocument(img, imgFile.getPath()));
count++;
if (count > 2 && count % 25 == 0) {
System.out.println(count + " files indexed. " + (System.currentTimeMillis() - ms) / (count) + " ms per file");
}
}
iw.close();
}
示例12: testSiftIndexing
import net.semanticmetadata.lire.utils.LuceneUtils; //导入依赖的package包/类
public void testSiftIndexing() throws IOException {
ArrayList<String> images = FileUtils.getAllImages(new File(testExtensive), true);
ChainedDocumentBuilder db = new ChainedDocumentBuilder();
db.addBuilder(new SiftDocumentBuilder());
db.addBuilder(DocumentBuilderFactory.getCEDDDocumentBuilder());
IndexWriter iw = LuceneUtils.createIndexWriter("sift-idx", true);
for (int i = 0; i < images.size(); i++) {
// int sampleQuery = sampleQueries[i];
// String s = testExtensive + "/" + sampleQuery + ".jpg";
iw.addDocument(db.createDocument(new FileInputStream(images.get(i)), images.get(i)));
if (i % 100 == 99) System.out.print(".");
if (i % 1000 == 999) System.out.print(" ~ " + i + " files indexed\n");
if (i > 1000) break;
}
System.out.println("");
iw.close();
}
示例13: testSurfIndexing
import net.semanticmetadata.lire.utils.LuceneUtils; //导入依赖的package包/类
public void testSurfIndexing() throws IOException {
ArrayList<String> images = FileUtils.getAllImages(new File(testExtensive), true);
ChainedDocumentBuilder db = new ChainedDocumentBuilder();
db.addBuilder(new SurfDocumentBuilder());
IndexWriter iw = LuceneUtils.createIndexWriter("sift-idx", true);
for (int i = 0; i < images.size(); i++) {
// int sampleQuery = sampleQueries[i];
// String s = testExtensive + "/" + sampleQuery + ".jpg";
iw.addDocument(db.createDocument(new FileInputStream(images.get(i)), images.get(i)));
if (i % 100 == 99) System.out.print(".");
if (i % 1000 == 999) System.out.print(" ~ " + i + " files indexed\n");
if (i > 1000) break;
}
System.out.println("");
iw.close();
}
示例14: indexFiles
import net.semanticmetadata.lire.utils.LuceneUtils; //导入依赖的package包/类
@SuppressWarnings("unused")
private Document indexFiles() throws IOException {
System.out.println("---< indexing >-------------------------");
int count = 0;
DocumentBuilder builder = getDocumentBuilder();
ArrayList<String> allImages = FileUtils.getAllImages(new File("wang-1000"), true);
IndexWriter iw = LuceneUtils.createIndexWriter(indexPath, true);
Document document = null;
for (Iterator<String> iterator = allImages.iterator(); iterator.hasNext(); ) {
String filename = iterator.next();
BufferedImage image = ImageIO.read(new FileInputStream(filename));
document = builder.createDocument(image, filename);
iw.addDocument(document);
count++;
if (count % 50 == 0)
System.out.println("finished " + (count * 100) / allImages.size() + "% of the images.");
}
iw.close();
return document;
}
示例15: testIndexing
import net.semanticmetadata.lire.utils.LuceneUtils; //导入依赖的package包/类
public void testIndexing() throws IOException {
List<String> allImages = FileUtils.getAllImages(new File(filePath), true);
System.out.println("Found " + allImages.size() + " files.");
IndexWriter iw = LuceneUtils.createIndexWriter(indexPath, true);
// ParallelIndexer pix = new ParallelIndexer(allImages, new MirFlickrDocumentBuilder());
ParallelIndexer pix = new ParallelIndexer(allImages, new MetadataBuilder());
new Thread(pix).start();
Document doc;
javax.swing.ProgressMonitor pm = new javax.swing.ProgressMonitor(null, "Indexing ...", "", 0, allImages.size());
int count = 0;
while ((doc = pix.getNext()) != null) {
iw.addDocument(doc);
pm.setProgress(++count);
pm.setNote(count + " documents finished");
}
iw.close();
}