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