001 package org.maltparser.parser.history.kbest; 002 003 /** 004 * 005 * @author Johan Hall 006 * @since 1.1 007 **/ 008 public class ScoredCandidate extends Candidate { 009 /** 010 * The candidate score 011 */ 012 protected float score; 013 014 /** 015 * Constructs a candidate object 016 */ 017 public ScoredCandidate() { 018 super(); 019 } 020 021 /** 022 * Returns the score for this candidate if it is available, otherwise Double.NaN 023 * 024 * @return the score for this candidate if it is available, otherwise Double.NaN 025 */ 026 public float getScore() { 027 return score; 028 } 029 030 /** 031 * Sets the score for this candidate. 032 * 033 * @param score a score 034 */ 035 public void setScore(Float score) { 036 this.score = score; 037 } 038 039 /** 040 * Resets the candidate object 041 */ 042 public void reset() { 043 super.reset(); 044 this.score = Float.NaN; 045 } 046 047 /* (non-Javadoc) 048 * @see java.lang.Object#equals(java.lang.Object) 049 */ 050 public boolean equals(Object obj) { 051 if (this == obj) 052 return true; 053 if (obj == null) 054 return false; 055 if (getClass() != obj.getClass()) 056 return false; 057 ScoredCandidate item = (ScoredCandidate)obj; 058 return actionCode == item.actionCode && score == item.score; 059 } 060 061 public int hashCode() { 062 return (31 * 7 + actionCode) * 31 + Float.floatToIntBits(score); 063 } 064 065 /* (non-Javadoc) 066 * @see java.lang.Object#toString() 067 */ 068 public String toString() { 069 StringBuilder sb = new StringBuilder(); 070 sb.append(super.toString()); 071 sb.append('\t'); 072 sb.append(score); 073 return sb.toString(); 074 } 075 }