001    package org.maltparser.core.syntaxgraph.headrules;
002    
003    import org.maltparser.core.exception.MaltChainedException;
004    import org.maltparser.core.io.dataformat.ColumnDescription;
005    import org.maltparser.core.symbol.SymbolTable;
006    /**
007    *
008    *
009    * @author Johan Hall
010    */
011    public class PrioSetMember {
012            protected enum RelationToPrevMember {
013                    START, DISJUNCTION, CONJUNCTION
014            };
015            protected PrioSet prioSet;
016            protected SymbolTable table;
017            protected ColumnDescription column;
018            protected int symbolCode;
019            protected RelationToPrevMember relationToPrevMember;
020        
021            public PrioSetMember(PrioSet prioSet, SymbolTable table, ColumnDescription column, int symbolCode, RelationToPrevMember relationToPrevMember) {
022                    setPrioSet(prioSet);
023                    setTable(table);
024                    setColumn(column);
025                    setSymbolCode(symbolCode);
026                    setRelationToPrevMember(relationToPrevMember);
027            }
028    
029            public PrioSetMember(PrioSet prioSet, SymbolTable table, ColumnDescription column, String symbolString, RelationToPrevMember relationToPrevMember) throws MaltChainedException {
030                    setPrioSet(prioSet);
031                    setTable(table);
032                    setColumn(column);
033                    if (table != null) {
034                            setSymbolCode(table.getSymbolStringToCode(symbolString));
035                    } else {
036                            setSymbolCode(-1);
037                    }
038                    setRelationToPrevMember(relationToPrevMember);
039            }
040            
041            public PrioSet getPrioSet() {
042                    return prioSet;
043            }
044    
045            public void setPrioSet(PrioSet prioSet) {
046                    this.prioSet = prioSet;
047            }
048    
049            
050            public ColumnDescription getColumn() {
051                    return column;
052            }
053    
054            public void setColumn(ColumnDescription column) {
055                    this.column = column;
056            }
057    
058            public SymbolTable getTable() {
059                    return table;
060            }
061    
062            public void setTable(SymbolTable table) {
063                    this.table = table;
064            }
065    
066            public int getSymbolCode() {
067                    return symbolCode;
068            }
069    
070            public String getSymbolString() throws MaltChainedException {
071                    if (table != null && symbolCode >= 0) {
072                            return table.getSymbolCodeToString(symbolCode);
073                    } else {
074                            return null;
075                    }
076            }
077            
078            public void setSymbolCode(int symbolCode) {
079                    this.symbolCode = symbolCode;
080            }
081            
082            public RelationToPrevMember getRelationToPrevMember() {
083                    return relationToPrevMember;
084            }
085    
086            public void setRelationToPrevMember(RelationToPrevMember relationToPrevMember) {
087                    this.relationToPrevMember = relationToPrevMember;
088            }
089            
090            public int hashCode() {
091                    final int prime = 31;
092                    int result = 1;
093                    result = prime * result + symbolCode;
094                    result = prime
095                                    * result
096                                    + ((relationToPrevMember == null) ? 0 : relationToPrevMember
097                                                    .hashCode());
098                    return result;
099            }
100    
101    
102            public boolean equals(Object obj) {
103                    if (this == obj)
104                            return true;
105                    if (obj == null)
106                            return false;
107                    if (getClass() != obj.getClass())
108                            return false;
109                    PrioSetMember other = (PrioSetMember) obj;
110                    if (symbolCode != other.symbolCode)
111                            return false;
112                    if (relationToPrevMember == null) {
113                            if (other.relationToPrevMember != null)
114                                    return false;
115                    } else if (!relationToPrevMember.equals(other.relationToPrevMember))
116                            return false;
117    
118                    return true;
119            }
120    
121            public String toString() {
122                    final StringBuilder sb = new StringBuilder();
123                    sb.append(table.getName());
124                    sb.append(':');
125                    try {
126                            sb.append(getSymbolString());
127                    } catch (MaltChainedException e) {
128                            if (prioSet.getLogger().isDebugEnabled()) {
129                                    prioSet.getLogger().debug("",e);
130                            } else {
131                                    prioSet.getLogger().error(e.getMessageChain());
132                            }
133                    }
134                    return sb.toString();
135            }
136    }