本文整理汇总了Java中net.semanticmetadata.lire.DocumentBuilder.createDocument方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentBuilder.createDocument方法的具体用法?Java DocumentBuilder.createDocument怎么用?Java DocumentBuilder.createDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.semanticmetadata.lire.DocumentBuilder
的用法示例。
在下文中一共展示了DocumentBuilder.createDocument方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: luceneIndexer
import net.semanticmetadata.lire.DocumentBuilder; //导入方法依赖的package包/类
/**
* Index for each builder type
* @param image
* @param picture_id
* @param prefix
* @param builder
* @param conf
* @throws IOException
*/
private static void luceneIndexer(BufferedImage image, UUID picture_id, String prefix, DocumentBuilder builder, IndexWriterConfig conf)
throws IOException
{
File path = getPath(prefix);
log.debug("creating indexed path " + path.getAbsolutePath());
IndexWriter iw = new IndexWriter(FSDirectory.open(path), conf);
try {
Document document = builder.createDocument(image, picture_id.toString());
iw.addDocument(document);
} catch (Exception e) {
System.err.println("Error reading image or indexing it.");
e.printStackTrace();
}
// closing the IndexWriter
iw.close();
}
示例2: indexFiles
import net.semanticmetadata.lire.DocumentBuilder; //导入方法依赖的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();
}
示例3: processImage
import net.semanticmetadata.lire.DocumentBuilder; //导入方法依赖的package包/类
public static double[] processImage(BufferedImage img, String imgName, int imageGrid, DocumentBuilder builder,
String featureName, double[] featureOutput, Map<String, LireFeature> lireFeatures, int featureUsed) throws IOException, DecoderException {
for (int i = 0; i < imageGrid; i++) {
for (int j = 0; j < imageGrid; j++) {
String subImgName = imgName + i + "," + j;
Document document = builder.createDocument(getSubImageByRowAndColumn(img, i, j, imageGrid), subImgName);
featureOutput[i * imageGrid + j] = getFeatures(document, featureName, lireFeatures)[featureUsed];
// if (i == 0 && j == 0) {
// System.out.println(featureName + " : " + getFeatures(document, featureName, lireFeatures).length);
// }
}
}
// normalize
featureOutput = HistUtil.normalizeArray(featureOutput);
return featureOutput;
}
示例4: testIndexing
import net.semanticmetadata.lire.DocumentBuilder; //导入方法依赖的package包/类
public void testIndexing() throws IOException, ParserConfigurationException, SAXException {
IndexWriterConfig iwConf = new IndexWriterConfig(Version.LUCENE_42, new SimpleAnalyzer(Version.LUCENE_42));
IndexWriter iw = new IndexWriter(FSDirectory.open(testIndex), iwConf);
// if you want to append the index to a pre-existing one use the next line.
// iwConf.setOpenMode(IndexWriterConfig.OpenMode.APPEND);
// create a LIRE DocumentBuilder for extracting FCTH (just an example, every other feature will do).
DocumentBuilder builder = DocumentBuilderFactory.getFCTHDocumentBuilder();
ArrayList<File> files = FileUtils.getAllImageFiles(new File("testdata/ferrari"), true);
// for handling the XML of the test data set
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
SAXParser saxParser = spf.newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
for (Iterator<File> iterator = files.iterator(); iterator.hasNext(); ) {
File img = iterator.next();
String path = img.getCanonicalPath();
// create the document with the LIRE DocumentBuilder, this adds the image features to the document.
Document d = builder.createDocument(new FileInputStream(img), path);
// handling the XML of the test data set
path = path.substring(0,path.lastIndexOf('.')) + ".xml";
TagHandler handler = new TagHandler();
xmlReader.setContentHandler(handler);
xmlReader.parse(new InputSource(new File(path).toURI().toString()));
// add the text to the document ...
d.add(new TextField("tags", handler.getTags(), Field.Store.YES));
// don't forget to add the document to the index.
iw.addDocument(d);
}
iw.close();
}
示例5: main
import net.semanticmetadata.lire.DocumentBuilder; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
// Checking if arg[0] is there and if it is a directory.
boolean passed = false;
if (args.length > 0) {
File f = new File(args[0]);
System.out.println("Indexing images in " + args[0]);
if (f.exists() && f.isDirectory()) passed = true;
}
if (!passed) {
System.out.println("No directory given as first argument.");
System.out.println("Run \"Indexer <directory>\" to index files of a directory.");
System.exit(1);
}
// Getting all images from a directory and its sub directories.
ArrayList<String> images = FileUtils.getAllImages(new File(args[0]), true);
// Creating a CEDD document builder and indexing all files.
DocumentBuilder builder = DocumentBuilderFactory.getCEDDDocumentBuilder();
// Creating an Lucene IndexWriter
IndexWriterConfig conf = new IndexWriterConfig(LuceneUtils.LUCENE_VERSION,
new WhitespaceAnalyzer(LuceneUtils.LUCENE_VERSION));
IndexWriter iw = new IndexWriter(FSDirectory.open(new File("index")), conf);
// Iterating through images building the low level features
for (Iterator<String> it = images.iterator(); it.hasNext(); ) {
String imageFilePath = it.next();
System.out.println("Indexing " + imageFilePath);
try {
BufferedImage img = ImageIO.read(new FileInputStream(imageFilePath));
Document document = builder.createDocument(img, imageFilePath);
iw.addDocument(document);
} catch (Exception e) {
System.err.println("Error reading image or indexing it.");
e.printStackTrace();
}
}
// closing the IndexWriter
iw.close();
System.out.println("Finished indexing.");
}