-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
TrainSet0002Dat.cs
78 lines (66 loc) · 2.13 KB
/
TrainSet0002Dat.cs
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
74
75
76
77
78
using System.Collections.Generic;
using System.Globalization;
using cs_unittest;
using VW.Labels;
using VW.Serializer.Attributes;
namespace TrainSet0002Dat
{
public class Data : BaseData
{
[Feature(FeatureGroup = 'T', Name = "")]
public string T { get; set; }
[Feature(FeatureGroup = 'f')]
public List<KeyValuePair<string, float>> F { get; set; }
public ILabel Label
{
get;
set;
}
}
public class DataListener : VowpalWabbitListenerToEvents<Data>
{
private Data example;
public override void EnterExample(VowpalWabbitParser.ExampleContext context)
{
this.example = new Data()
{
F = new List<KeyValuePair<string, float>>()
};
}
public override void ExitExample(VowpalWabbitParser.ExampleContext context)
{
this.example.Line = context.GetText();
this.Created(this.example.Line, this.example, this.example.Label);
}
public override void ExitLabel_simple(VowpalWabbitParser.Label_simpleContext context)
{
var simpleLabel = new SimpleLabel()
{
Label = context.value.value
};
if (context.weight != null)
simpleLabel.Weight = context.weight.value;
this.example.Label = simpleLabel;
}
public override void ExitNumber(VowpalWabbitParser.NumberContext context)
{
context.value = float.Parse(context.GetText(), CultureInfo.InvariantCulture);
}
public override void ExitFeatureSparse(VowpalWabbitParser.FeatureSparseContext context)
{
var index = context.index;
var weight_index = index.Text;
var x = context.x;
if (x == null)
{
// hashed feature
this.example.T = weight_index;
}
else
{
// sparse feature
this.example.F.Add(new KeyValuePair<string, float>(weight_index, context.x.value));
}
}
}
}