/*
 * $Id: ClassifyResultEntry.java,v 1.8 2006/07/17 13:04:02 lawern Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: ClassifyResultEntry.java,v $
 * Revision 1.8  2006/07/17 13:04:02  lawern
 * Neuer typografiegewichteter Index und k-NN-Klassifikation aus meiner Diss.
 *
 * Revision 1.7  2005/06/28 00:02:08  marbobo
 * + Darstellungsprobleme mit Nahost-Schriftarten korrigiert
 *
 * Revision 1.6  2004/03/12 15:44:17  bigmac
 * Methoden für (lokale) zusätzliche Attribute aus VKCDynAttributeSerializer
 * nach VKCAddAttributeSerializer verschoben
 *
 * Unbenutze private Methoden projektweit entsorgt
 *
 * Revision 1.5  2004/02/24 08:49:51  bigmac
 * Formatierung der Prozentwerte ergänzt
 *
 * Revision 1.4  2003/08/05 20:24:24  bigmac
 * *** empty log message ***
 *
 * Revision 1.3  2003/06/04 12:42:06  koppy
 * + categoryAbsPath und score Formatierung
 *
 * Revision 1.2  2003/04/15 15:33:05  koppy
 * get/set-Methoden zugefügt
 *
 * Revision 1.1  2003/04/09 14:15:27  lawern
 * initiale Version
 *
 * Revision 1.1  2003/04/03 13:15:54  lawern
 * initiale Version
 *
 */
package vkc.search;

import vkc.db.serializer.VKCCategorySerializer;

import vkc.exception.DBException;

import vkc.util.VKCCategoryAbsPath;
import vkc.util.VKCStringUtils;

import java.text.DecimalFormat;


/**
 * Diese Klasse dient zur Auflistung der Suchergebnisse.
 *
 * @author lawern
 */
public class ClassifyResultEntry implements Comparable {
    public String categoryId;
    public String name;
    public String keywords;
    public String description;
    private float score;
    private VKCCategoryAbsPath categoryAbsPath = null;
    private DecimalFormat formatter = new DecimalFormat("##.##");
    private int scores = 1;

    /**
     * Konstruktor
     */
    public ClassifyResultEntry(String categoryId, String name, String keywords,
        String description, float score) {
        this.categoryId = categoryId;
        this.name = name;
        this.keywords = keywords;
        this.description = description;
        this.score = score;

        formatter.setMultiplier(100);
        formatter.setMaximumFractionDigits(2);
        formatter.setMinimumFractionDigits(2);
    }

    /**
     * @return
     */
    public String getCategoryId() {
        return categoryId;
    }

    /**
     * @return
     */
    public String getDescription() {
        return description;
    }

    /**
     * @return
     */
    public String getKeywords() {
        return keywords;
    }

    /**
     * @return
     */
    public String getName() {
        return name;
    }

    /**
     * Returns the absolute path of the cotaining category
     * @return
     * @throws DBException
     */
    public VKCCategoryAbsPath getCategoryAbsPath() throws DBException {
        if (categoryAbsPath == null) {
            categoryAbsPath = VKCCategorySerializer.getCategoryAbsPath(new Integer(
                        categoryId));
        }

        return categoryAbsPath;
    }

	public String getNl2BrDescription(){
	    return VKCStringUtils.filterUnicodeChars( getDescription() );
	}

    public float getScore() {
        return score;///((float)scores);
    }

    public String getScorePercent() {
        return formatter.format(this.score);
    }

    /**
     * @param string
     */
    public void setCategoryId(String string) {
        categoryId = string;
    }

    /**
     * @param string
     */
    public void setDescription(String string) {
        description = string;
    }

    /**
     * @param string
     */
    public void setKeywords(String string) {
        keywords = string;
    }

    /**
     * @param string
     */
    public void setName(String string) {
        name = string;
    }

    /**
     * @param f
     */
    public void setScore(float f) {
        score = f;
    }

    /* (non-Javadoc)
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    public int compareTo(Object arg0) {
        return Float.compare(getScore(), ((ClassifyResultEntry) arg0).getScore());
    }

	/**
	 * Dient zur Mittelwertbildung im NNClassifier.
	 */
	public void incScore(float score) {
		this.score += score;
		scores++;
	}
}
