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 o) { 051 if (this == o) return true; 052 if (!(o instanceof ScoredCandidate)) { 053 return false; 054 } 055 ScoredCandidate item = (ScoredCandidate)o; 056 return (score == item.score && actionCode == item.actionCode); 057 } 058 059 public int hashCode() { 060 return (31 * 7 + actionCode) * 31 + Float.floatToIntBits(score); 061 } 062 063 /* (non-Javadoc) 064 * @see java.lang.Object#toString() 065 */ 066 public String toString() { 067 StringBuilder sb = new StringBuilder(); 068 sb.append(super.toString()); 069 sb.append('\t'); 070 sb.append(score); 071 return sb.toString(); 072 } 073 }