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

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

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

/**
 * Need to break up: "When <clause> [then] <clause>" into multiple
 **/
public class WhenParseRule extends AnnotateRule 
{

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

  /**
   * The rule matches when it has a when sentence.
   **/
  public boolean match( LinkedList params ) 
  {
    Sentence sent = (Sentence)params.get(0);
    DebugWindow.addLine( "JTRE", "WhenParseRule: " + params );
    DebugWindow.addLine( "JTRE", "***" + sent.isWhenStatement() );
    
    return( sent.isWhenStatement() );
  }

  /** It breaks the composite sentence into its two clauses. **/
  public void run( Surface s, Notebook book, LinkedList params )
  {
    DebugWindow.addLine( "JTRE", "WhenParseRule fired: " + params );
    Sentence sent = (Sentence)params.get(0);

    // set up supports so that the full utterance leads to sub
    // utterances and then the sub utterances can be recognized as
    // events and recognized by the rule that builds causality
    Sentence cause = sent.getClause1();
    Sentence effect = sent.getClause2();

    book.assert( cause, "parse-when", new LinkedList( params ) );
    book.assert( effect, "parse-when", new LinkedList( params ) );
  }
}

