-
Notifications
You must be signed in to change notification settings - Fork 0
/
KernelDataTypes.cs
95 lines (87 loc) · 2.69 KB
/
KernelDataTypes.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Grammophone.Indexing
{
/// <summary>
/// Contracts and data types used in KernelSuffixTree classes.
/// </summary>
public static class KernelDataTypes
{
/// <summary>
/// The node data of the KernelSuffixTree, which is type parameter N, must at least implement
/// this interface.
/// </summary>
public interface INodeData
{
/// <summary>
/// The weighted sum of the leaves item values that are descendants of the node.
/// </summary>
double DescendantLeavesSum { get; set; }
/// <summary>
/// The accumulated weight of all the substrings starting from length zero up to
/// the end of the branch.
/// </summary>
double Weight { get; set; }
}
/// <summary>
/// An implementation of the <see cref="INodeData"/> interface in the form of a struct
/// to conserve heap and space overhead.
/// </summary>
[Serializable]
public struct NodeData : INodeData
{
/// <summary>
/// The weighted sum of the leaves values that are descendants of the node.
/// </summary>
public double DescendantLeavesSum { get; set; }
/// <summary>
/// The accumulated weight of all the substrings starting from length zero up to
/// the end of the branch.
/// </summary>
public double Weight { get; set; }
}
/// <summary>
/// The items that tag the words of a KernelSuffixTree, which are of type parameter D,
/// must at least implement this interface in order to provide a word weight.
/// </summary>
public interface IWordItem
{
/// <summary>
/// The weight associated with a word.
/// </summary>
double Weight { get; set; }
}
/// <summary>
/// An implementation of the <see cref="IWordItem"/> interface in the form of a struct
/// to conserve heap and space overhead. This is implicitly convertible
/// from and to double since the only property is <see cref="WordItem.Weight"/>
/// of type double.
/// </summary>
[Serializable]
public struct WordItem : IWordItem
{
/// <summary>
/// The weight associated with a word.
/// </summary>
public double Weight { get; set; }
/// <summary>
/// Implicit conversion from double into a <see cref="WordItem"/>
/// having property <see cref="Weight"/> equal to the supplied value.
/// </summary>
public static implicit operator WordItem(double weight)
{
return new WordItem() { Weight = weight };
}
/// <summary>
/// Implicit conversion from <see cref="WordItem"/> to double
/// of value equal to the <see cref="Weight"/> property.
/// </summary>
public static implicit operator double(WordItem wordItem)
{
return wordItem.Weight;
}
}
}
}