public class PtIndexer
extends java.lang.Object
This class has a method append(String, String)
takes a
key and value and splits the value into alpha-numeric words that
are then saved in a data structure for later searching. Common
words are filtered out.
The write(String)
method saves the data structure to
disk via serialization.
The read(String)
method reads the data structure.
The search(String)
returns a list of values that match a key
Modifier and Type | Field and Description |
---|---|
(package private) static java.util.Set<java.lang.String> |
_common
The set of common words that are not indexed.
|
Constructor and Description |
---|
PtIndexer() |
Modifier and Type | Method and Description |
---|---|
void |
append(java.lang.String location,
java.lang.String words)
Append all the words to the dictionary.
|
static void |
main(java.lang.String[] args)
A test driver for the indexer.
|
void |
read(java.lang.String fileName)
Read the dictionary to a file or URL.
|
java.util.Collection<java.lang.String> |
search(java.lang.String target)
Search the dictionary for matches.
|
java.lang.String |
statistics()
Return statistics about the dictionary.
|
void |
write(java.lang.String fileName)
Write the dictionary to a file or URL.
|
static java.util.Set<java.lang.String> _common
public void append(java.lang.String location, java.lang.String words) throws java.io.IOException
The value of the words parameter is split into words and a map entry is created where the word is the key and the location is an element in a List.
location
- The dot separated classname where the
value of the words parameter is found.words
- The words found in the location.java.io.IOException
- If thrown by the tokenizer.public static void main(java.lang.String[] args) throws java.io.IOException, java.lang.ClassNotFoundException
Usage:
java -classpath $PTII doc.doclets.PtIndexer [-c] [target]
If called with no arguments, create the dictionary PtIndexer.ser The standard input is read and assumed to be file names. Each file is read and the dictionary is updated with words and locations. The location is determined by substituting "." for "/" in the file name.
Typically, the PtDoclet creates the dictionary, but this driver can be used for testing. To create the .xml file to be read:
cd $PTII/doc; make docs
To run the tool on the .xml files and create the dictionary again:
cd codeDoc find . -name "*.xml" | java -classpath $PTII doc.doclets.PtIndexer
If called with -c
then use compression.
If called with one argument that is not -c
,
then the argument is assumed to be a target and the collection
of places where target is found is returned.
args
- The arguments, if anyjava.io.IOException
- If thrown while reading the input files or dictionary.java.lang.ClassNotFoundException
- If the file does not contain the
dictionary class.public void read(java.lang.String fileName) throws java.io.IOException, java.lang.ClassNotFoundException
fileName
- the file or URL of the dictionaryjava.io.IOException
- If the dictionary cannot be written.java.lang.ClassNotFoundException
- If the file does not contain the
dictionary class.public java.util.Collection<java.lang.String> search(java.lang.String target)
The target is converted to lower case and then the dictionary is searched.
target
- The string to match.public java.lang.String statistics()
public void write(java.lang.String fileName) throws java.io.IOException
fileName
- the file or URL of the dictionaryjava.io.IOException
- If the dictionary cannot be written.