/* * TextSearcher.java * * Created on January 13, 2003, 11:14 PM */ package project1; /* This starting code is supplied 1. To give more information about how the oracle operates. Please read every comment. 2. To give some information about the omen type for this oracle 3. To give possible code for a constructor, which reads the text file and places it in an array. The array can then be searched by other methods which may need to do so. The code is incomplete. It should not be expected to compile as given. You can modify this code in any way you wish, within the requirements of the project. */ /** The oracle works by consulting a sacred text (the Sonnets of William Shakespeare). * If the request is found in the text, as a string (case-insensitive), the oracle * returns an omen which tells the line number when the first match was found, * and also includes the full line in its descriptions. * The earlier in the the match is found, the more favorable it is considered. Ties are broken arbitrarily. * Line numbers start at 1. * Every element in the array of strings is considered a "line", regardless of * how long it is. * * Notes on the omen type for this class: The omen brief description should include the line number (at least). The omen detailed description should include the line number, the original request, and the text of the line where the request was located. */ public class TextSearcher implements IOracle { /** Holds the complete text to be searched, one line per array entry. * Some lines may be empty, but none will be null. * Line 1 of the text is in position 0 of the array. */ private String[] theText; /** Creates a new instance of TextSearcher */ /* This is a complete implementation of the constructor, and does not need to be modified. Of course, you are free to do so. */ public TextSearcher() { theText = TextSearcherUtils.readTextIntoArray(); } /** See if some data is suitable to be presented to the oracle. * See interface for the general requirements. * * For this particular oracle, any non-empty string is acceptable. */ public boolean checkRequestData(String requestData) { } /** Search the entrails and return the omen found. * For general requirements, see the interface definition. * * For this oracle, the text is searched line by line, case-insensitive. * Matches are looked for only within lines, not across lines. * For example, if two lines of the file are * cse * 143 * Then this matches, among other things, "cse", "CSE", "C", "1", "43", etc. * but does not match "cse143" or "se143", etc. */ public IOmen searchEntrailsForOmen(String requestData) { //end method } //end TextSearcher }