-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTagDegree.java
More file actions
76 lines (67 loc) · 1.74 KB
/
TagDegree.java
File metadata and controls
76 lines (67 loc) · 1.74 KB
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
66
67
68
69
70
71
72
73
package com.briup.knn;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableComparable;
/**
* 对于相似度排序时进行使用的
* tag degree group三个属性
* 前两个用来存放数据,group属性控制分组
* 故group属性值,给出相同的值即可
* */
public class TagDegree
implements WritableComparable<TagDegree>{
//标签值,前缀名
private Text tag = new Text();
//待识别图片与该标签的相似度
private DoubleWritable degree = new DoubleWritable();
//该属性不参与计算,仅用于分组
private Text group = new Text("1");
public TagDegree() {
}
public TagDegree(String tag,double degree) {
this.tag = new Text(tag);
this.degree = new DoubleWritable(degree);
}
@Override
public void readFields(DataInput in) throws IOException {
tag.readFields(in);
degree.readFields(in);
group.readFields(in);
}
@Override
public void write(DataOutput out) throws IOException {
tag.write(out);
degree.write(out);
group.write(out);
}
@Override
public int compareTo(TagDegree o) {
return o.degree.compareTo(this.degree);
}
public Text getTag() {
return tag;
}
public void setTag(Text tag) {
this.tag = new Text(tag.toString());
}
public DoubleWritable getDegree() {
return degree;
}
public void setDegree(DoubleWritable degree) {
this.degree =new DoubleWritable(degree.get());
}
public Text getGroup() {
return group;
}
public void setGroup(Text group) {
this.group =new Text(group.toString());
}
@Override
public String toString() {
// TODO Auto-generated method stub
return this.tag.toString()+"\t"+this.degree.get();
}
}