blob: 8f6ee103b898ed1d0b46087b9cd640d9095b1851 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.fsa.topicpredictor;
/**
* Class encapsulation of a predicted topic. A topic has a weight and
* a term vector string of topicSegments.
*
* @author gjoranv
**/
public class PredictedTopic {
private String topic = "";
private double weight = 0.0;
private String vector = "";
public PredictedTopic(String topic, double weight, String vector){
this.topic = topic;
this.weight = weight;
this.vector = vector;
}
public PredictedTopic(String topic, double weight){
this(topic, weight, "");
}
/** Returns the topic */
public String getTopic() { return topic; }
/** Returns the weight */
public double getWeight() { return weight; }
/** Returns the vector*/
public String getVector() { return vector; }
/** Sets the weight */
public void setWeight(double weight) {
this.weight = weight;
}
/** Adds to the weight */
public void addWeight(double weight) {
this.weight += weight;
}
/** Sets the vector*/
public void setVector(String vector) {
this.vector = vector;
}
/** Compares this topic to another topic, according to weight descending */
public int compareDescendWeight(Object o) {
PredictedTopic pt = (PredictedTopic)o;
double wgt1 = getWeight();
double wgt2 = pt.getWeight();
if (wgt1 < wgt2) { return 1; }
if (wgt1 > wgt2) { return -1;}
return 0;
}
}
|