inpro.nlu
Class AVM

java.lang.Object
  extended by inpro.nlu.AVM

public class AVM
extends java.lang.Object

Class representing an AVM with methods for equality, unification and setting attributes.

Author:
okko

Field Summary
private  java.util.HashMap<java.lang.String,java.lang.Object> attributes
           
private  boolean monotonic
           
private  java.lang.String type
           
 
Constructor Summary
protected AVM(AVM avm)
          Copy constructor.
  AVM(java.lang.String type, boolean monotonic, java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,java.lang.String>> avmStructures)
          String type, boolean monotonic, HashMap avmStructures constructor.
  AVM(java.lang.String type, java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,java.lang.String>> avmStructures)
          String type, HashMap avmStructures constructor.
 
Method Summary
 void clearValues()
          Clears values of all AVPairs in this AVM.
 boolean equals(java.lang.Object o)
          Convenience method checking equality of two AVMs.
 java.util.HashMap<java.lang.String,java.lang.Object> getAttributes()
          Returns the attributes of this AVM.
 java.util.ArrayList<AVPair> getAVPairs()
          Gets an ArrayList of all AVPairs attributed to this AVM, including null ones.
 java.util.ArrayList<AVPair> getDeepAVPairs()
          Gets an ArrayList of all AVPairs attributed to this AVM, including null ones.
 AVPair getSalientAVPair()
          Returns a salient AVPair for this AVM.
 java.lang.String getType()
          Returns the type of this AVM.
 int hashCode()
          hashCode method for use by Collections.
 boolean isEmpty()
          Returns the type of this AVM.
 boolean setAttribute(AVPair avp)
          Attempts setting an attribute to this AVM.
 java.lang.String toLongString()
          Builds a complete string representation of the AVM with nested brackets.
 java.lang.String toPrettyString()
          Builds a pretty string representation of the AVM containing only its type and non-empty AVPairs.
 java.lang.String toShortString()
          Builds a short string representation of the AVM containing only its type.
 java.lang.String toString()
          Builds a string representation of the AVM with nested brackets.
 boolean unifies(AVM avm)
          Checks if unification is possible for two AVMs.
 AVM unify(AVM avm)
          Attempts unifying AVM with the input to this method.
private  java.util.HashMap<java.lang.String,java.lang.Object> unpackStructures(java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,java.lang.String>> avmStructures, java.lang.String type)
          Builds attribute map from flat string map (read from file by AVMStructureUtil).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

type

private final java.lang.String type

attributes

private java.util.HashMap<java.lang.String,java.lang.Object> attributes

monotonic

private boolean monotonic
Constructor Detail

AVM

public AVM(java.lang.String type,
           java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,java.lang.String>> avmStructures)
String type, HashMap avmStructures constructor.


AVM

public AVM(java.lang.String type,
           boolean monotonic,
           java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,java.lang.String>> avmStructures)
String type, boolean monotonic, HashMap avmStructures constructor.


AVM

protected AVM(AVM avm)
Copy constructor.

Parameters:
avm - - the AVM to copy.
Method Detail

unpackStructures

private java.util.HashMap<java.lang.String,java.lang.Object> unpackStructures(java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,java.lang.String>> avmStructures,
                                                                              java.lang.String type)
Builds attribute map from flat string map (read from file by AVMStructureUtil).

Parameters:
avmStructures - HashMap
type - of the AVM

equals

public boolean equals(java.lang.Object o)
Convenience method checking equality of two AVMs.

Overrides:
equals in class java.lang.Object
Parameters:
avm - - an AVM to compare this AVM with.
Returns:
true if they are the same.

hashCode

public int hashCode()
hashCode method for use by Collections.

Overrides:
hashCode in class java.lang.Object

unify

public AVM unify(AVM avm)
Attempts unifying AVM with the input to this method.

Parameters:
avm - - the AVM to unify with this AVM.
Returns:
the resulting unified AVM if unification was successful, null otherwise.

unifies

public boolean unifies(AVM avm)
Checks if unification is possible for two AVMs.

Parameters:
avm - - an AVM to check against whether unification would be successful.
Returns:
true if so, false otherwise

setAttribute

public boolean setAttribute(AVPair avp)
Attempts setting an attribute to this AVM. Recurses through local complex attributes (ie. AVMs or lists thereof) to attempt setting the attribute to child AVMs.

Parameters:
avp - - an AVPair to attempt setting against this AVM or its children.
Returns:
true if setting was successful, false otherwise.

clearValues

public void clearValues()
Clears values of all AVPairs in this AVM.


getAVPairs

public java.util.ArrayList<AVPair> getAVPairs()
Gets an ArrayList of all AVPairs attributed to this AVM, including null ones.

Returns:
avps - an ArrayList<AVPair>.

getDeepAVPairs

public java.util.ArrayList<AVPair> getDeepAVPairs()
Gets an ArrayList of all AVPairs attributed to this AVM, including null ones. If the attribute's value is another (list of) AVM(s), it returns those as pairs.

Returns:
avps - an ArrayList<AVPair>.

getType

public java.lang.String getType()
Returns the type of this AVM.

Returns:
this.type

getAttributes

public java.util.HashMap<java.lang.String,java.lang.Object> getAttributes()
Returns the attributes of this AVM. Values can be String or ArrayList. Classes using this should verify this using instanceof.

Returns:
a HashMap<String, Object>.

getSalientAVPair

public AVPair getSalientAVPair()
Returns a salient AVPair for this AVM. Currently the first one from the definition.

Returns:
the first AVPair in this AVM's definition

isEmpty

public boolean isEmpty()
Returns the type of this AVM.

Returns:
this.type

toString

public java.lang.String toString()
Builds a string representation of the AVM with nested brackets. Empty AVMs are not represented. Use AVM.toLongString() to do this instead.

Overrides:
toString in class java.lang.Object
Returns:
String representation of the AVM

toShortString

public java.lang.String toShortString()
Builds a short string representation of the AVM containing only its type.

Returns:
Short string representation of the AVM

toLongString

public java.lang.String toLongString()
Builds a complete string representation of the AVM with nested brackets. Use AVM.toString() for something more readible.

Returns:
Long string representation of the AVM

toPrettyString

public java.lang.String toPrettyString()
Builds a pretty string representation of the AVM containing only its type and non-empty AVPairs.

Returns:
pretty string representation of the AVM