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

// -*-Mode: Java-*- 
// $Id: WhenUtteranceRule.java,v 1.2 2003/03/06 00:40:43 moltmans Exp $
// WhenUtteranceRule.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Mon May 01 23:01:29 2000> 
// Time-stamp: <2000-05-12 18:08:36 moltmans> 
package rec.annotate.rules;

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

public class WhenUtteranceRule extends AnnotateRule 
{
  // "when <event1> then <event2>" and the 2 events
  public LinkedList getTriggers() 
  {
    LinkedList triggers = new LinkedList();
    triggers.add( Type.SENTENCE );
    triggers.add( Type.EVENT );
    triggers.add( Type.EVENT );
    return triggers;
  }

  public boolean match( LinkedList params ) 
  {
    DebugWindow.addLine( "JTRE", "WhenUtteranceRule: " + params );
    
    if( params.size() < 3 )
      return true;
    
    Sentence sent = (Sentence)params.get(0);
    Event e1 = (Event)params.get(1);
    Event e2 = (Event)params.get(2);

    DebugWindow.addLine( "JTRE", "***is when?: " +
			 sent.isWhenStatement() );
    DebugWindow.addLine( "JTRE", "***Clause 1: " +
			 sent.getClause1() );
    DebugWindow.addLine( "JTRE", "***Clause 2: " +
			 sent.getClause2() );
	
    return( sent.isWhenStatement() &&
	    e1.isBasedOn( sent.getClause1() ) &&
	    e2.isBasedOn( sent.getClause2() ) );
  }

  public void run( Surface s, Notebook book, LinkedList params )
  {
    DebugWindow.addLine( "JTRE",
			 "Running WhenUtteranceRule: " + params );
    Event cause = (Event)params.get(1);
    Event effect = (Event)params.get(2);

    LeadsTo link = new LeadsTo( cause, effect );
    book.assert( link, "when statement", new LinkedList( params ) );
  }
}

