// (c) MIT 2003.  All rights reserved.

// -*-Mode: Java-*- 
// $Id: MotionUtteranceRule.java,v 1.2 2003/03/06 00:40:43 moltmans Exp $
// MotionUtteranceRule.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Tue May 09 16:55:23 2000> 
// Time-stamp: <2000-05-12 12:04:40 moltmans> 
package rec.annotate.rules;

import java.util.*;
import rec.util.*;
import rec.tms.*;
import rec.sys.*;

/**
 * Recognize "moves" statements and assert motion events for them.
 **/
public class MotionUtteranceRule extends AnnotateRule
{

  public LinkedList getTriggers() 
  {
    LinkedList triggers = new LinkedList();
    triggers.add( Type.SENTENCE );
    triggers.add( Type.BODY );
    return triggers;
  }

  /**
   * The rule matches when it describes a motion event
   **/
  public boolean match( LinkedList params ) 
  {
    Sentence sent = (Sentence)params.get(0);
    DebugWindow.addLine( "JTRE", "MotionUtteranceRule: " + params );

    DebugWindow.addLine( "JTRE",
			 "***is moves: " + sent.isMovesStatement() );
    if( !sent.isMovesStatement() ) {
      return false;
    }
    if( params.size() < 2 ) {
      return true;
    }

    Body body = (Body)params.get(1);
    DebugWindow.addLine( "JTRE", "***bodyname = " + body.getName() );
    DebugWindow.addLine( "JTRE", "***sentname = " +
			 sent.getSubject() );
    return sent.getSubject().equals( body.getName() );
  }

  public void run( Surface s, Notebook book, LinkedList params )
  {
    Sentence sent = (Sentence)params.get(0);
    Body body = (Body)params.get(1);
    MotionEvent event = new MotionEvent( s, body, sent );
    book.assert( event, "motion utterance", params );
  }
}

