ch.uzh.ifi.attempto.chartparser
Class Category

java.lang.Object
  extended by ch.uzh.ifi.attempto.chartparser.Category
Direct Known Subclasses:
Nonterminal, Preterminal, Terminal

public abstract class Category
extends java.lang.Object

This class represents a grammatical category.

Author:
Tobias Kuhn

Field Summary
protected  FeatureMap featureMap
          The feature map of the category.
protected  java.lang.String name
          The name of the category.
static java.lang.String[] specialCategories
          This static array contains all category names that denote special categories.
 
Constructor Summary
Category()
           
 
Method Summary
 void addNegFeatureMap(FeatureMap fm)
          Adds a negative feature map in the case of backward references, or does nothing for all other categories.
 void addPosFeatureMap(FeatureMap fm)
          Adds a positive feature map in the case of backward references, or does nothing for all other categories.
 boolean canUnify(Category category)
          This method detects whether this category can unify with the given category.
 Category deepCopy()
          Creates a deep copy of this category.
 boolean equals(java.lang.Object obj)
           
 StringRef getFeature(java.lang.String featureName)
          Returns a feature value.
 FeatureMap getFeatureMap()
          Returns the map of features of this category.
 java.util.Set<java.lang.String> getFeatureNames()
          Returns the used feature names within the feature map.
 java.util.Collection<StringRef> getFeatureValues()
          Returns the used feature values within the feature map.
 java.lang.String getName()
          Returns the name of the category.
 java.util.List<FeatureMap> getNegFeatureMaps()
          This method returns the list of negative feature maps for backward references, or null for all other categories.
 java.util.List<FeatureMap> getPosFeatureMaps()
          This method returns the list of positive feature maps for backward references, or null for all other categories.
protected abstract  java.lang.String getType()
          This method returns the type of the category.
 boolean isSimilar(Category c)
          This methods checks whether two categories are similar.
 boolean isSpecialCategory()
          Returns true if this category is a special category.
 void setFeature(java.lang.String featureName, java.lang.String featureValue)
          Sets a feature.
 void setFeature(java.lang.String featureName, StringRef featureValue)
          Sets a feature.
 void skolemize()
          Skolemizes the feature values of this category.
 boolean subsumes(Category c)
          This method returns true if this category subsumes (in other words "is more general than") the given category, or false otherwise.
abstract  java.lang.String toString()
           
 void tryToUnify(Category c)
          Tries to unify this category with another category.
 void unify(Category c)
          Unifies this category with another category.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

specialCategories

public static final java.lang.String[] specialCategories
This static array contains all category names that denote special categories. These special category names are ">" and ">>" for forward references, "<" and "/<" for backward references, "//" for scope openers, and "#" for position operators.


name

protected java.lang.String name
The name of the category.


featureMap

protected FeatureMap featureMap
The feature map of the category. Backward references do not use this field, since they can have multiple feature maps.

Constructor Detail

Category

public Category()
Method Detail

getType

protected abstract java.lang.String getType()
This method returns the type of the category. For example, "term" is returned for terminal categories and "nonterm" for non-terminal ones.

Returns:
The type of the category.

getName

public java.lang.String getName()
Returns the name of the category.

Returns:
The name of the category.

isSpecialCategory

public boolean isSpecialCategory()
Returns true if this category is a special category. Special categories are references, scope openers, and position operators.

Returns:
true if this category is a special category.

getFeatureMap

public FeatureMap getFeatureMap()
Returns the map of features of this category. It returns null in the case of backward references, where the methods for positive and negative feature maps have to be used.

Returns:
The feature map.

getPosFeatureMaps

public java.util.List<FeatureMap> getPosFeatureMaps()
This method returns the list of positive feature maps for backward references, or null for all other categories.

Returns:
The list of positive feature maps in the case of backward references.

getNegFeatureMaps

public java.util.List<FeatureMap> getNegFeatureMaps()
This method returns the list of negative feature maps for backward references, or null for all other categories.

Returns:
The list of negative feature maps in the case of backward references.

addPosFeatureMap

public void addPosFeatureMap(FeatureMap fm)
Adds a positive feature map in the case of backward references, or does nothing for all other categories.

Parameters:
fm - The positive feature map to be added.

addNegFeatureMap

public void addNegFeatureMap(FeatureMap fm)
Adds a negative feature map in the case of backward references, or does nothing for all other categories.

Parameters:
fm - The negative feature map to be added.

setFeature

public void setFeature(java.lang.String featureName,
                       StringRef featureValue)
Sets a feature. This method cannot be used for backward references, which can have more than one feature map.

Parameters:
featureName - The feature name
featureValue - The string reference that points to the value of the feature.

setFeature

public void setFeature(java.lang.String featureName,
                       java.lang.String featureValue)
Sets a feature. This method cannot be used for backward references, which can have more than one feature map.

Parameters:
featureName - The feature name
featureValue - The value of the feature.

getFeature

public StringRef getFeature(java.lang.String featureName)
Returns a feature value. This method cannot be used for backward references, which can have more than one feature map.

Parameters:
featureName - The name of the feature.
Returns:
The value of the feature.

unify

public void unify(Category c)
           throws UnificationFailedException
Unifies this category with another category. Two categories can unify if and only if they have the same names and the same types and they have no features with conflicting values. If the unification fails, a UnificationFailedException is thrown. In this case, the two categories remain partly unified, i.e. no backtracking is done. Thus, this operation should be perfomed only if it is certain that the unification succeeds, or if the operation is performed on copies of objects that are not used anymore afterwards.

Parameters:
c - The category to be unified with this category.
Throws:
UnificationFailedException - If unification fails.

tryToUnify

public void tryToUnify(Category c)
                throws UnificationFailedException
Tries to unify this category with another category. If unification is not possible, an exception is thrown. In the case unification would be possible, the unification is not performed completely. In any case the two categories remain in an unconsistent state afterwards. Thus, this operation should be performed only on copies of objects that are not used anymore afterwards.

Parameters:
c - The category to be unified with this category.
Throws:
UnificationFailedException - If unification fails.

canUnify

public boolean canUnify(Category category)
This method detects whether this category can unify with the given category. Neither of the two categories are changed.

Parameters:
category - The category for the unification check.
Returns:
true if the two categories can unify.

isSimilar

public boolean isSimilar(Category c)
This methods checks whether two categories are similar. Two categories are similar if and only if the categories have the same name and the same type and no feature with the same name is present in both categories with values that do not unify locally. Two categories that are unifiable are always similar, but not necessarily vice versa. This check for similarity is computationally less expensive than the check for unification.

Parameters:
c - The category for which similarity with this category should be checked.
Returns:
true if the two categories are similar.

subsumes

public boolean subsumes(Category c)
This method returns true if this category subsumes (in other words "is more general than") the given category, or false otherwise.

Parameters:
c - The category for which it is checked whether this category subsumes it.
Returns:
true if this category subsumes the given category.

skolemize

public void skolemize()
Skolemizes the feature values of this category.


getFeatureNames

public java.util.Set<java.lang.String> getFeatureNames()
Returns the used feature names within the feature map.

Returns:
The used feature names.

getFeatureValues

public java.util.Collection<StringRef> getFeatureValues()
Returns the used feature values within the feature map.

Returns:
The used feature values.

deepCopy

public Category deepCopy()
Creates a deep copy of this category.

Returns:
A deep copy.

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

toString

public abstract java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright 2008-2012, AceWiki developers