src.server
Class QueryRule

java.lang.Object
  extended bysrc.server.QueryRule
Direct Known Subclasses:
ModuleQueryRule, ServerQueryRule

public abstract class QueryRule
extends java.lang.Object

Describes a query rule, based on regexp. Queries can be checked against the query rule to see if they match. The rule also specifies what keys the result should have. An example: "What is todays lunch at Nymble?" could be turned into a map with keys "regexp" and "place" containing "lunch" and "Nymble" with a rule named "lunch"with the following pattern: "lunch( at| in)? ([^ ?]+)" and the following keys 0=>"place".

Version:
2005-apr-27

Constructor Summary
QueryRule(java.lang.String regexpPattern, java.lang.String[] keys)
          Constructor for QueryRule.
 
Method Summary
 java.util.HashMap getResult(java.lang.String query)
          Gets a query formatted according to the rule's settings.
 boolean matches(java.lang.String query)
          Checks if a query matches the rule's pattern.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QueryRule

public QueryRule(java.lang.String regexpPattern,
                 java.lang.String[] keys)
Constructor for QueryRule.

Parameters:
regexpPattern - The regexp pattern which descibes what queries that should match the rule.
keys - The keys that should be used in the resulting map.
Method Detail

matches

public boolean matches(java.lang.String query)
Checks if a query matches the rule's pattern.

Parameters:
query - The query to check.
Returns:
True if they match, false otherwise.

getResult

public java.util.HashMap getResult(java.lang.String query)
Gets a query formatted according to the rule's settings. The query should match (checked with matches()) before calling this method.

Parameters:
query - The query to format.
Returns:
A map containing the extracted groups as the keys specified at construction time. Returns an empty HashMap if not groups could be extracted.

toString

public java.lang.String toString()