Example: initial abstractions of KEngine
/**
@overview
Represents keyword search engines. An engine holds a mutable
collection of documents, which are obtained from some given URLs.
The engine is able to pocess a keyword query to search for
documents that contain the keywords.
The matching documents are ranked based on the frequencies of the
keywords found in them.
The engine has a private file that contains the list of
uninteresting words.
*/
class Engine {
Starts the engine running with NonKeyword
containing the words in the private file.
All other sets are empty.
}
addDocuments
/**
@checks u does not name a site in URL and
u names a site that provides documents
@effects
(1) System connects to web site at u,
(2) download all the documents contained therein,
(3) store the documents
(4) If a query is being asked then
(5) add any matching documents to matches of t
* @note
* - need an abstraction to represent Document
* -> creates abstraction Doc
* - also need for Match (later)
*/
addDocuments(String u)
query
addDocuments(String u)
/**
@checks: w is not in NonKeyword
@effects
Sets Keyword = {w} and
makes Match contain the documents that match w,
ordered as required. (using Match.sumFreq)
i.e
for all q: Query, m: Match, d: Document {
hasMatch(q, m) /\\ refers.to(m, d) =>
m.sumFreq =
sum(appears-in(w,d):frequency),
for all w in q
}
@note
(1) needs an abstraction to hold keyword and store matches
-> create an abstraction Query
(2) may use String for both Keyword and NonKeywords
*/
query(String w)
/**
@checks Key != {} and w not in NonKeyword and w not in Keyword
@effects
Adds w to Keyword and
makes Match be the documents already
in Match that additionally match w.
Orders Match properly (see #query(String))
@note
(1) needs an abstraction to hold keyword and store matches
-> create an abstraction Query
(2) may use String for both Keyword and NonKeywords
*/
queryMore
queryMore(String w)
/**
* @checks t is in titles
*
* @effects
* return d in document s.t. d's title = t
* @note
* (1) needs an abstraction to represent Document
* -> use Doc
* (2) Doc has attribute title
* -> create attribute Doc.title
*/
findDoc
queryMore(String w)
/**
* @checks t is in titles
*
* @effects
* return d in document s.t. d's title = t
* @note
* (1) needs an abstraction to represent Document
* -> use Doc
* (2) Doc has attribute title
* -> create attribute Doc.title
*/
findDoc(String t)
// end Engine
Inital design spec
/**
* @overview ...(omitted)...
*/
class Engine {
/**
* @effects
* If uninteresting words not retrievable
* throws NotPossibleException
* else
* creates NonKeyword and initialises app. state
* appropriately
*/
Engine() throws NotPossibleException
/**
* @effects
* If t not in Title throws NotPossibleException
* else returns the document with title t
*/
Doc findDoc (String t) throws NotPossibleException
/**
* @effects
* If u is not a URL for a site containing documents or u in URL
* throws NotPossibleException
* else adds the new documents to Doc.
* If no query was in progress
* returns the empty query result
* else
* returns query result that includes any new matching documents
*/
Query addDocs(String u) throws NotPossibleException
} // end Engine
D by A (1)
- Check that the input string w is a word
- Check that w is an interesting word
- Start a new query with w as the keyword
- For each document, determine if it is a match
- For each document, determine the freq of w
- Sort the matches by freq of w