Java Reference
In-Depth Information
}
}
To demonstrate the actual lookup process, we use the get method to return an instance of
the Word object for the word "reef". The list of the positions is returned with the
getPositions method and then each position is displayed, as shown here:
Word word = wordMap.get("reef");
ArrayList<Positions> positions = word.getPositions();
for (Positions position : positions) {
System.out.println(word.getWord() + " is found at line
"
+ position.sentence + ", word " +
position.position);
}
The output is as follows:
reef is found at line 0, word 10
reef is found at line 29, word 6
reef is found at line 1885, word 8
reef is found at line 2062, word 12
This implementation is relatively simple but does demonstrate how to combine various
NLP techniques to create and use an index data structure that can be saved as an index
file. Other enhancements are possible including:
• Other filter operations
• Store document information in the Positions class
• Store chapter information in the Positions class
• Provide search options such as:
◦ Case-sensitive searches
◦ Exact text searches
• Better exception handling
These are left as exercises for the reader.
Search WWH ::




Custom Search