public class InvertedIndex
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
java.io.File |
dirFile
The directory from which the indexed documents come.
|
java.util.List<DocumentReference> |
docRefs
A list of all indexed documents.
|
short |
docType
The type of Documents (text, HTML).
|
boolean |
feedback
Whether relevance feedback using the Ide_regular algorithm is used
|
static int |
MAX_RETRIEVALS
The maximum number of retrieved documents for a query to present to the user
at a time
|
boolean |
stem
Whether tokens should be stemmed with Porter stemmer
|
java.util.Map<java.lang.String,TokenInfo> |
tokenHash
A HashMap where tokens are indexed.
|
Constructor and Description |
---|
InvertedIndex(java.io.File dirFile,
short docType,
boolean stem,
boolean feedback)
Create an inverted index of the documents in a directory.
|
InvertedIndex(java.util.List<Example> examples)
Create an inverted index of the documents in a List of Example objects of documents
for text categorization.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear all documents from the inverted index
|
protected void |
computeIDFandDocumentLengths()
Compute the IDF factor for every token in the index and the length
of the document vector for every document referenced in the index.
|
protected Retrieval |
getRetrieval(double queryLength,
DocumentReference docRef,
double score)
Calculate the final score for a retrieval and return a Retrieval object representing
the retrieval with its final score.
|
double |
incorporateToken(java.lang.String token,
double count,
java.util.Map<DocumentReference,DoubleValue> retrievalHash)
Retrieve the documents indexed by this token in the inverted index,
add it to the retrievalHash if needed, and update its running total score.
|
protected void |
indexDocument(FileDocument doc,
HashMapVector vector)
Index the given document using its corresponding vector
|
protected void |
indexDocuments()
Index the documents in dirFile.
|
void |
indexDocuments(java.util.List<Example> examples)
Index the documents in the List of Examples for text categorization.
|
protected void |
indexToken(java.lang.String token,
int count,
DocumentReference docRef)
Add a token occurrence to the index.
|
static void |
main(java.lang.String[] args)
Index a directory of files and then interactively accept retrieval queries.
|
void |
presentRetrievals(HashMapVector queryVector,
Retrieval[] retrievals)
Print out a ranked set of retrievals.
|
void |
print()
Print out an inverted index by listing each token and the documents it occurs in.
|
void |
printRetrievals(Retrieval[] retrievals,
int start)
Print out at most MAX_RETRIEVALS ranked retrievals starting at given starting rank number.
|
void |
processQueries()
Enter an interactive user-query loop, accepting queries and showing the retrieved
documents in ranked order.
|
Retrieval[] |
retrieve(Document doc)
Perform ranked retrieval on this input query Document.
|
Retrieval[] |
retrieve(HashMapVector vector)
Perform ranked retrieval on this input query Document vector.
|
Retrieval[] |
retrieve(java.lang.String input)
Perform ranked retrieval on this input query.
|
boolean |
showRetrievals(Retrieval[] retrievals)
Show the top retrievals to the user if there are any.
|
int |
size()
Return the number of tokens indexed.
|
public static final int MAX_RETRIEVALS
public java.util.Map<java.lang.String,TokenInfo> tokenHash
public java.util.List<DocumentReference> docRefs
public java.io.File dirFile
public short docType
public boolean stem
public boolean feedback
public InvertedIndex(java.io.File dirFile, short docType, boolean stem, boolean feedback)
dirFile
- The directory of files to index.docType
- The type of documents to index (See docType in DocumentIterator)stem
- Whether tokens should be stemmed with Porter stemmer.feedback
- Whether relevance feedback should be used.public InvertedIndex(java.util.List<Example> examples)
examples
- A List containing the Example objects for text categorization to indexprotected void indexDocuments()
public void indexDocuments(java.util.List<Example> examples)
protected void indexDocument(FileDocument doc, HashMapVector vector)
protected void indexToken(java.lang.String token, int count, DocumentReference docRef)
token
- The token to index.count
- The number of times it occurs in the document.docRef
- A reference to the Document it occurs in.protected void computeIDFandDocumentLengths()
public void print()
public int size()
public void clear()
public Retrieval[] retrieve(java.lang.String input)
public Retrieval[] retrieve(Document doc)
public Retrieval[] retrieve(HashMapVector vector)
protected Retrieval getRetrieval(double queryLength, DocumentReference docRef, double score)
queryLength
- The length of the query vector, incorporated into the final scoredocRef
- The document reference for the document concernedscore
- The partially computed scorepublic double incorporateToken(java.lang.String token, double count, java.util.Map<DocumentReference,DoubleValue> retrievalHash)
token
- The token in the query to incorporate.count
- The count of this token in the query.retrievalHash
- The hash table of retrieved DocumentReferences and current
scores.public void processQueries()
public void presentRetrievals(HashMapVector queryVector, Retrieval[] retrievals)
public boolean showRetrievals(Retrieval[] retrievals)
public void printRetrievals(Retrieval[] retrievals, int start)
public static void main(java.lang.String[] args)