wyvern.kernel.commands
Class PrepositionParser

java.lang.Object
  extended bywyvern.kernel.commands.PrepositionParser

public class PrepositionParser
extends java.lang.Object

This class splits a string into a direct object and an indirect object, splitting it on a passed preposition token. For example, if the string is "all from corpse", and your preposition is "from", it'll extract the "all" and "corpse" parts, which can be obtained by calling getDirectObject() and getIndirectObject().

Because many commands that use this class also need to check for quantity, the parser sets a flag if it finds a quantity specified for the direct object. If so, it saves the quantity and direct object separately. E.g. "get 20 coins from bag" will set the quantity to 20 and the direct object to "coins".

Version:
1.0, Sep 02, 1997
Author:
Steve Yegge

Constructor Summary
PrepositionParser()
           
 
Method Summary
 boolean foundQuantity()
          Returns true if there was a quantity specified.
 java.lang.String getDirectObject()
          Returns the direct object from our sentence-parsing.
 java.lang.String getIndirectObject()
          Returns the indirect object from our sentence-parsing.
 int getQuantity()
          Returns the quantity specified.
 boolean parse(java.lang.String sentence, java.lang.String preposition)
          Split the passed string into direct & indirect objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrepositionParser

public PrepositionParser()
Method Detail

parse

public boolean parse(java.lang.String sentence,
                     java.lang.String preposition)
Split the passed string into direct & indirect objects.

Parameters:
sentence - the String to parse
preposition - the token to split the sentence on
Returns:
true if it found non-null (i.e. non-whitespace) strings for both the direct and indirect objects. false otherwise.

getDirectObject

public java.lang.String getDirectObject()
Returns the direct object from our sentence-parsing. parse() must have previously returned true() in order for this to be successful.

Returns:
the direct object string ( null if we didn't find one )

getIndirectObject

public java.lang.String getIndirectObject()
Returns the indirect object from our sentence-parsing. parse() must have previously returned true() in order for this to be successful.

Returns:
the indirect object string ( null if we didn't find one )

foundQuantity

public boolean foundQuantity()
Returns true if there was a quantity specified.


getQuantity

public int getQuantity()
Returns the quantity specified. Can be a negative or zero.