Package grammar.model.verbs

Source Code of grammar.model.verbs.AuxiliaryVerb

package grammar.model.verbs;

import grammar.model.Language;
import grammar.model.MatchType;
import grammar.model.WordMatcher;
import grammar.model.Form.FormCategory;
//import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* <p>A secondary verb, used for conjugating some tenses. In many languages,
* the inflection of verbs in some tenses requires the use of
* an <i>auxiliary verb</i> form. For instance, in English, to indicate that
* an action occured in the past, you can say "I <i>have</i> eaten", "we <i>had</i>
* seen", or "you <i>were</i> dreaming". In the first two examples, a form of the
* auxiliary <i>to have</i> is used to denote past tense forms; in the third example,
* the auxiliary used is <i>to be</i>.</p>
*
* <p>Auxiliary verbs function as model verbs, and thus sit within the same
* inheritance hierarchy of conjugation rules. However, they have two additional
* features:</p>
*
* <ol>
*   <li>They are 'singletons' in that they match exactly one verb infinitive
* (there is thus one ConjugatedVerb per AuxiliaryVerb).</li>
*   <li>They define a list of auxiliary match criteria; the lists against each
* model verb are used when conjugating a verb to determine which auxiliary is
* the best match.</li>
* </ol>
*
* <p>As with ModelVerb instances, each AuxiliaryVerb instance is defined by an XML
* file in <code>{language}/model-verbs</code>.
*
* @author Duncan Roberts
*/
public class AuxiliaryVerb extends ModelVerb {
  private final boolean pronounAgreement;
  private final boolean reflexiveAuxiliary;
  private final List<WordMatcher> auxiliaryOf;

  public AuxiliaryVerb(Language language, String infinitive,
      List<ModelVerb> parents, List<WordMatcher> infinitiveMatchers,
      Map<Tense, Map<FormCategory, Map<Segment, String>>> tenseMap,
      Map<Tense, Map<FormCategory, Map<Segment, Tense>>> refTenseMap,
      Map<Tense, Map<FormCategory, Map<Segment, FormCategory>>> refPronounMap,
      Map<Tense, Map<FormCategory, Map<Segment, Tense>>> auxiliaryRefTenseMap,
      Map<Tense, Map<FormCategory, Map<Segment, FormCategory>>> auxiliaryRefPronounMap,
      List<WordMatcher> auxiliaryOf, String summary, boolean pronounAgreement,
      boolean reflexiveAuxiliary) {
    super(language, infinitive, parents, infinitiveMatchers, tenseMap, refTenseMap, refPronounMap,
        auxiliaryRefTenseMap, auxiliaryRefPronounMap, summary);
    this.auxiliaryOf = auxiliaryOf;
    this.pronounAgreement = pronounAgreement;
    this.reflexiveAuxiliary = reflexiveAuxiliary;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = super.hashCode();
    result = prime * result
        + ((auxiliaryOf == null) ? 0 : auxiliaryOf.hashCode());
    result = prime * result + (pronounAgreement ? 1231 : 1237);
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (!super.equals(obj))
      return false;
    if (!(obj instanceof AuxiliaryVerb))
      return false;
    final AuxiliaryVerb other = (AuxiliaryVerb) obj;
    if (auxiliaryOf == null) {
      if (other.auxiliaryOf != null)
        return false;
    } else if (!auxiliaryOf.equals(other.auxiliaryOf))
      return false;
    if (pronounAgreement != other.pronounAgreement)
      return false;
    return true;
  }

  public ConjugatedVerb getConjugatedVerb() {
    return getConjugatedVerb(getName().toLowerCase());
  }

  public boolean isAuxiliaryOf(String infinitive, boolean reflexive) {
    return isAuxiliaryOfInternal(infinitive, reflexive) != MatchType.NONE;
  }

  private MatchType isAuxiliaryOfInternal(String infinitive, boolean reflexive) {
    //System.err.println("AuxiliaryVerb.isAuxiliaryOfInternal():"+new Date());

    if (reflexive && isReflexiveAuxiliary())
      return MatchType.REFLEXIVE;

    for (WordMatcher inf : auxiliaryOf) {
      MatchType matchType = inf.getMatchType();
      MatchType match = null;
      switch (matchType) {
      case ALL:
        match = MatchType.ALL;
        break;
      case NONE:
        break;
      case FULL_NAME:
        if (infinitive.equals(inf.getMatchString()))
          match = MatchType.FULL_NAME;
        break;
      case PATTERN:
        if (infinitive.matches(inf.getMatchString()))
          match = MatchType.PATTERN;
        break;
      case SUFFIX:
        if (infinitive.endsWith(inf.getMatchString()))
          match = MatchType.SUFFIX;
        break;
      }
      if (match != null)
        return match;
    }
    return MatchType.NONE;
  }

  private String getAuxiliaryMatchString(String infinitive) {
    //System.err.println("AuxiliaryVerb.getAuxiliaryMatchString():"+new Date());

    for (WordMatcher inf : auxiliaryOf) {
      MatchType matchType = inf.getMatchType();
      boolean match = false;
      switch (matchType) {
      case FULL_NAME:
        if (infinitive.equals(inf.getMatchString()))
          match = true;
        break;
      case PATTERN:
        if (infinitive.matches(inf.getMatchString()))
          match = true;
        break;
      case SUFFIX:
        if (infinitive.endsWith(inf.getMatchString()))
          match = true;
        break;
      }
      if (match)
        return inf.getMatchString();
    }
    return "";
  }

  public boolean isCloserMatch(String infinitive, boolean reflexive, AuxiliaryVerb other) {
    //System.err.println("AuxiliaryVerb.isCloserMatch():"+new Date());

    MatchType thisMt = isAuxiliaryOfInternal(infinitive, reflexive);
    MatchType otherMt = other.isAuxiliaryOfInternal(infinitive, reflexive);

    /*if (isReflexiveAuxiliary()) {
      System.out.println("SQUoooo");
      if (reflexive) {
        System.out.println("squOo2");
        return true;
      }
    }*/

    if (thisMt == MatchType.SUFFIX && otherMt == MatchType.SUFFIX) {
      return getAuxiliaryMatchString(infinitive).length() >
        other.getAuxiliaryMatchString(infinitive).length();
    }
    if (thisMt.ordinal() > otherMt.ordinal())
      return true;
    return false;
  }

  public boolean pronounAgreement() {
    return pronounAgreement;
  }

  public boolean isReflexiveAuxiliary() {
    return reflexiveAuxiliary;
  }

  public WordMatcher getInfinitiveMatcher(String infinitive, boolean reflexive) {
//    if (reflexive && isReflexiveAuxiliary())
//      return new WordMatcher(MatchType.REFLEXIVE, infinitive);
    return super.getInfinitiveMatcher(infinitive, reflexive);
  }
}
TOP

Related Classes of grammar.model.verbs.AuxiliaryVerb

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.