Package org.sf.mustru.docs

Source Code of org.sf.mustru.docs.MediaDoc

package org.sf.mustru.docs;

import java.io.IOException;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.sf.mustru.crawl.ClassifyDoc;

//import com.aliasi.tokenizer.NGramTokenizerFactory;
import com.sleepycat.bind.tuple.TupleBinding;
import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;

/**
* Media class for image, audio, animation, and video objects
*
*/
public class MediaDoc extends IndexableDoc
{
String textType = "";
/**
  * A generic media document class
  * String File name containing the image
  */
public MediaDoc ()
{ super(); setBdbBinding( new MediaDocDb() )}

public MediaDoc (String ifile)
{ super(ifile); setBdbBinding( new MediaDocDb() )}

public void loadSpecific(ClassifyDoc cdoc)
{
  setTextType(cdoc.classifyTextContents(this));
  //*-- file type is set in CrawlThread
}

//*-- create the Lucene Index
public void loadIndex(IndexWriter ramIW, boolean storeTermVector) throws IOException
{
  Document doc = new Document();
  doc.add( new Field("key", getFileName(), Field.Store.YES, Field.Index.NO) );
  doc.add(new Field("contents", getContents().toString(), Field.Store.NO, Field.Index.TOKENIZED) );
  doc.add( new Field("type", getFileType(), Field.Store.YES, Field.Index.NO) );
  ramIW.addDocument(doc);
}

public TupleBinding getBdbBinding()
{ return bdbBinding; }

public void setBdbBinding(TupleBinding bdbBinding)
{ this.bdbBinding = bdbBinding; }

public String  toString()
{
  StringBuffer sb = new StringBuffer();
  sb.append(super.toString());

  //*-- add media specific data

  return sb.toString();
}

public String getTextType()
{ return textType; }

public void setTextType(String textType)
{ this.textType = textType; }

}

final class MediaDocDb extends TupleBinding
{
static IndexableDocBinding idb = new IndexableDocBinding();
IndexableDoc idoc;

public Object entryToObject(TupleInput ti)
{
  idoc = (IndexableDoc) idb.entryToObject(ti);
  MediaDoc o = new MediaDoc();
  o.loadGeneric(idoc); idoc = null;
  //*-- write any media specific information to o

  return o;
}

public void objectToEntry(Object o, TupleOutput to)
{
  idb.objectToEntry(o, to);
  //MediaDoc id = (MediaDoc) o;

  //*-- write any media specific information to tuple output

}
}
TOP

Related Classes of org.sf.mustru.docs.MediaDoc

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.