All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.isi.nlp.parsing.CompositeHeadRule Maven / Gradle / Ivy

There is a newer version: 8.3.0
Show newest version
package edu.isi.nlp.parsing;

import com.google.common.annotations.Beta;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import edu.isi.nlp.ConstituentNode;

@Beta
final class CompositeHeadRule> implements HeadRule {

  private final ImmutableList> rulesInOrder;

  private CompositeHeadRule(final Iterable> rulesInOrder) {
    this.rulesInOrder = ImmutableList.copyOf(rulesInOrder);
  }

  public static > CompositeHeadRule create(
      final Iterable> rulesInOrder) {
    return new CompositeHeadRule(rulesInOrder);
  }

  @SafeVarargs
  public static > CompositeHeadRule create(
      final HeadRule... rulesInOrder) {
    return new CompositeHeadRule(ImmutableList.copyOf(rulesInOrder));
  }

  @Override
  public Optional matchForChildren(final Iterable children) {
    for (final HeadRule r : rulesInOrder) {
      final Optional ret = r.matchForChildren(children);
      if (ret.isPresent()) {
        return ret;
      }
    }
    return Optional.absent();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy