File size: 2,711 Bytes
6f3ebfa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | package org.maltparser.parser.transition;
/**
* Transition contains one individual transition. For example, Nivre arc-eager algorithms have the unlabeled
* transition <code>SH</code>, <code>RE</code> and the labeled transition<code>RA</code>, <code>LA</code>. These
* transition will be four individual transition.
*
* @author Joakim Nivre
* @author Johan Hall
*/
public class Transition implements Comparable<Transition> {
/**
* Transition code
*/
private final int code;
/**
* Transition symbol
*/
private final String symbol;
/**
* <code>true</code> if the transition is labeled, otherwise <code>false</code>
*/
private final boolean labeled;
private final int cachedHash;
/**
* Creates a transition
*
* @param code Transition code
* @param symbol Transition name
* @param labeled <code>true</code> if the transition is labeled, otherwise <code>false</code>
*/
public Transition(int code, String symbol, boolean labeled) {
this.code = code;
this.symbol = symbol;
this.labeled = labeled;
final int prime = 31;
int result = prime + code;
result = prime * result + (labeled ? 1231 : 1237);
this.cachedHash = prime * result + ((symbol == null) ? 0 : symbol.hashCode());
}
/**
* Returns the transition code
*
* @return the transition code
*/
public int getCode() {
return code;
}
/**
* Returns the transition symbol
*
* @return the transition symbol
*/
public String getSymbol() {
return symbol;
}
/**
* Returns true if the transition is labeled, otherwise false
*
* @return <code>true</code> if the transition is labeled, otherwise <code>false</code>
*/
public boolean isLabeled() {
return labeled;
}
public int compareTo(Transition that) {
final int BEFORE = -1;
final int EQUAL = 0;
final int AFTER = 1;
if (this.code < that.code) return BEFORE;
if (this.code > that.code) return AFTER;
return EQUAL;
}
@Override
public int hashCode() {
return cachedHash;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Transition other = (Transition) obj;
if (code != other.code)
return false;
if (labeled != other.labeled)
return false;
if (symbol == null) {
if (other.symbol != null)
return false;
} else if (!symbol.equals(other.symbol))
return false;
return true;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
return symbol + " [" + code +"] " + labeled;
}
}
|