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

// -*-Mode: Java-*- 
// $Id: SpringReleaseUtteranceRule.java,v 1.5 2005/02/17 21:40:57 moltmans Exp $
// SpringReleaseUtteranceRule.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Tue May 16 01:17:08 2000> 
// Time-stamp: <2005-02-16 14:04:48 moltmans> 
package rec.annotate.rules;

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

public class SpringReleaseUtteranceRule extends AnnotateRule 
{
  /**
   * Match: "the spring releases"
   **/
  public LinkedList getTriggers() 
  {
    LinkedList triggers = new LinkedList();
    triggers.add( Type.SENTENCE );
    triggers.add( Type.SPRING );
    triggers.add( Type.BODY );
    return triggers;
  }

  public boolean match( LinkedList params ) 
  {
    Sentence sent = (Sentence)params.get(0);
    if( !sent.isReleasesStatement() )
      return false;
    if( params.size() < 3 )
      return true;
    
    Spring spring = (Spring)params.get(1);
    Body body = (Body)params.get(2);
    // if it is anchored on one end the other end must move
    return ( spring.isAnchored() &&
	     spring.isAttachedTo( body ) &&
	     !body.isAnchored() );
  }

  public void run( Surface s, Notebook book, LinkedList params )
  {
    Sentence sent = (Sentence)params.get(0);
    Spring spring = (Spring)params.get(1);
    Body body = (Body)params.get(2);

    MotionEvent motion = new MotionEvent( s, body, sent );
    book.myassert( motion, "Spring Release Rule", params );
  }
}

