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

// -*-Mode: Java-*- 
// $Id: WhenParseRule.java,v 1.7 2005/02/17 21:40:57 moltmans Exp $
// WhenParseRule.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Mon May 01 23:19:27 2000> 
// Time-stamp: <2005-02-16 14:00:29 moltmans> 
package rec.annotate.rules;

import rec.annotate.facts.*;
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);
    return( sent.isWhenStatement() || sent.isWhenContinuation() );
  }

  /** It breaks the composite sentence into its two clauses. **/
  public void run( Surface s, Notebook book, LinkedList 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();

    if( cause != null )
      book.myassert( cause, "WhenParseRule", params );
    if( effect != null )
      book.myassert( effect, "WhenParseRule", params );
  }
}

