Class HeadRules

java.lang.Object
opennlp.tools.parser.lang.en.HeadRules
All Implemented Interfaces:
GapLabeler, HeadRules, SerializableArtifact

public class HeadRules extends Object implements HeadRules, GapLabeler, SerializableArtifact
Class for storing the English HeadRules associated with parsing.
  • Constructor Details

    • HeadRules

      @Deprecated public HeadRules(String ruleFile) throws IOException
      Deprecated.
      Use HeadRules(Reader) instead.
      Creates a new set of head rules based on the specified ruleFile.
      Parameters:
      ruleFile - A string representation for a head rules file.
      Throws:
      IOException - Thrown if the head rules file can not be read.
    • HeadRules

      public HeadRules(Reader rulesReader) throws IOException
      Creates a new set of head rules based on the specified reader.
      Parameters:
      rulesReader - A Reader for a head rules file.
      Throws:
      IOException - Thrown f the head rules reader can not be read.
  • Method Details

    • getPunctuationTags

      public Set<String> getPunctuationTags()
      Specified by:
      getPunctuationTags in interface HeadRules
      Returns:
      Retrieves the set of punctuation tags. Attachment decisions for these tags will not be modeled.
    • getHead

      public Parse getHead(Parse[] constituents, String type)
      Description copied from interface: HeadRules
      Retrieves the head constituent for the specified constituents of given type.
      Specified by:
      getHead in interface HeadRules
      Parameters:
      constituents - The constituents which make up a constituent of the specified type.
      type - The type of a constituent which is made up of the constituents.
      Returns:
      The constituent which represents the head.
    • labelGaps

      public void labelGaps(Stack<Constituent> stack)
      Description copied from interface: GapLabeler
      Labels constituents found in the stack with gap labels if appropriate.
      Specified by:
      labelGaps in interface GapLabeler
      Parameters:
      stack - The Stack of un-completed constituents.
    • serialize

      public void serialize(Writer writer) throws IOException
      Serializes the head rules via a Writer in a format suitable for loading the head rules again. The encoding must be taken into account while working with the writer and reader.

      Once the entries have been written, the writer is flushed.

      Note: The writer remains open after this method returns.

      Parameters:
      writer - The Writer to write the head rules to.
      Throws:
      IOException - Thrown if IO errors occurred during write operation.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getArtifactSerializerClass

      public Class<?> getArtifactSerializerClass()
      Description copied from interface: SerializableArtifact
      Retrieves the class which can serialize and recreate this artifact.

      Note: The serializer class must have a public zero argument constructor or an exception is thrown during model serialization/loading.

      Specified by:
      getArtifactSerializerClass in interface SerializableArtifact
      Returns:
      The corresponding ArtifactSerializer class.