FAQ
right, luke rocks. Such things are best placed in luke indeed...

Image gets just too big without intensity trick, for really large bit vectors, I had to use 32 bits per pixel.

how I can see these plugins, is it somewhere on http://www.getopt.org/luke/?

----- Original Message ----
From: mark harwood <markharw00d@yahoo.co.uk>
To: java-dev@lucene.apache.org; eks dev <eksdev@yahoo.co.uk>
Sent: Wednesday, 31 May, 2006 5:12:06 PM
Subject: Re: trivial util to Visualize BitSets (Query results actually)

I added something similar to Luke but without the
colour intensity - I may add your code in to do this.
Another Luke plugin I have visualizes "vocabulary
growth" for a field as a chart over time. This is
useful to see if a field is "matured" or is still
accumulating new terms.
A Zipf term distribution would be another good
visualization.

--- eks dev wrote:
Maybe there are some more people that like to see
bits. Feel free to do whatever you like with it.

Idea is simple, map 8 bits from HitCollector to one
pixel by changing gray levels. Implementation is
Quick 'n Dirty, but does the job.

/**
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0
(the "License");
* you may not use this file except in compliance
with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in
writing, software
* distributed under the License is distributed on
an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied.
* See the License for the specific language
governing permissions and
* limitations under the License.
*/

import javax.imageio.ImageIO;

import org.apache.lucene.analysis.Analyzer;
import
org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.HitCollector;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Searcher;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;

import java.awt.image.*;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.BitSet;

/*
* Generates .png image of the search result. Maps
bits from result
* sequentially from left to right untill specified
image lenth is achieved
* and then continues from the begining in the next
line.
*
* Mapps 8 bits to one pixel, by changing leves of
gray
* e.g
* WHITE PIXEL: 0 of eight bits set
* GRAY PIXEL: some bits set (more set => darker)
* BLACK PIXEL: all 8 bits set
*
* main has 3 params: index path, Query, and
optional imageWidth
*/
public class VisualizeBitVector {

// Invoke the init method in BufImagePanel to
build the image.
public static void main(String[] args) throws
IOException, ParseException {
Img fImg;
Directory dir;
IndexReader reader;

fImg = new Img();
if (args.length < 2) {
System.out.println("VisualizeBitVector
index_path query [imageWidth]");
System.exit(-1);
}

String path = args[0];
String query = args[1];

int imageWidth = 800;
if(args.length > 2){
imageWidth = Integer.parseInt(args[2]);
}

System.getProperties().setProperty(

"org.apache.lucene.FSDirectory.class",

"org.apache.lucene.store.MMapDirectory");
dir = FSDirectory.getDirectory(path, false);
reader = IndexReader.open(dir);

BufferedImage img;

img = fImg.makeImage(reader, query,
imageWidth);
File file = new File("queryBits.png");
ImageIO.write(img, "png", file);

}

}


class Img {
BitSet bs;

BufferedImage fBufferedImage = null;

int fWidth = 0, fHeight = 0;

byte[] fPixels = null;

/** Build a BufferedImage from a pixel array. *
* @throws ParseException */

public BufferedImage makeImage(IndexReader
reader, String query, int imageWidth)
throws IOException, ParseException {

int maxDocs = reader.maxDoc();

fWidth = imageWidth;
fHeight = (maxDocs / 8 / fWidth) + 1;
fPixels = new byte[fWidth * fHeight];

//reset
Arrays.fill(fPixels, (byte) (0 | 0xFF));

Searcher s = new IndexSearcher(reader);
bs = new BitSet(maxDocs);

HitCollector hc = new HitCollector() {
public void collect(int doc, float
score) {
bs.set(doc);
}
};

Analyzer analyzer = new StandardAnalyzer();
QueryParser parser = new QueryParser("",
analyzer);
Query q = parser.parse(query);

s.search(q, null, hc);

//This is the only interesting thing here
for (int i = bs.nextSetBit(0); i >= 0; i =
bs.nextSetBit(i + 1)) {
int pos = i >> 3;
fPixels[pos] = (byte) ((fPixels[pos] &
0xFF) >>> 1);
}


s.close();
reader.close();

// Create a BufferedIamge of the gray values
in bytes.
fBufferedImage = new BufferedImage(fWidth,
fHeight,
BufferedImage.TYPE_BYTE_GRAY);

// Get the writable raster so that data can
be changed.
WritableRaster wr =
fBufferedImage.getRaster();

// Now write the byte data to the raster
wr.setDataElements(0, 0, fWidth, fHeight,
fPixels);
return fBufferedImage;
}

}





---------------------------------------------------------------------
To unsubscribe, e-mail:
java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail:
java-dev-help@lucene.apache.org



___________________________________________________________
Next-generation email? Now you can have it with All New Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-dev @
categorieslucene
postedMay 31, '06 at 7:55p
activeMay 31, '06 at 7:55p
posts1
users1
websitelucene.apache.org

1 user in discussion

Eks dev: 1 post

People

Translate

site design / logo © 2022 Grokbase