-
Notifications
You must be signed in to change notification settings - Fork 1
/
InferenceResourceItem.cs
119 lines (97 loc) · 3.45 KB
/
InferenceResourceItem.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Grammophone.LanguageModel.Provision;
using Grammophone.LanguageModel.TrainingSources;
using Grammophone.EnnounInference.Configuration;
namespace Grammophone.EnnounInference
{
/// <summary>
/// An item associated with an <see cref="InferenceResource"/>.
/// </summary>
[Serializable]
public abstract class InferenceResourceItem
{
#region Private fields
///// <summary>
///// This should be manually set after serialization through the internal setter of
///// <see cref="InferenceResourceItem.InferenceResource"/> property.
///// </summary>
//[NonSerialized]
[System.Runtime.Serialization.OptionalField]
private InferenceResource inferenceResource;
#endregion
#region Construction
/// <summary>
/// Create.
/// </summary>
/// <param name="inferenceResource">The inference resource associated with this item.</param>
public InferenceResourceItem(InferenceResource inferenceResource)
{
if (inferenceResource == null) throw new ArgumentNullException("inferenceResource");
this.InferenceResource = inferenceResource;
}
#endregion
#region Public properties
/// <summary>
/// The inference resource associated with this item.
/// </summary>
public InferenceResource InferenceResource
{
get
{
return inferenceResource;
}
internal set
{
inferenceResource = value;
}
}
#endregion
#region Protected methods
/// <summary>
/// Get the training set that corresponds to the <see cref="LanguageProvider"/>
/// of the <see cref="InferenceResourceItem.InferenceResource"/>.
/// </summary>
/// <returns>
/// Returns the corresponding <see cref="TrainingSet"/>, if it exists,
/// else throws a <see cref="SetupException"/>.
/// </returns>
/// <exception cref="SetupException">
/// When no <see cref="TrainingSet"/> exists in <see cref="Setup"/> corresponding to
/// the <see cref="LanguageProvider"/> of the <see cref="InferenceResourceItem.InferenceResource"/>.
/// </exception>
protected TrainingSet GetTrainingSet()
{
var trainingSets = InferenceEnvironment.Setup.TrainingSets;
var languageProvider = this.InferenceResource.LanguageProvider;
if (!trainingSets.ContainsKey(languageProvider))
throw new SetupException("No training set is defined for the specified language provider.");
var trainingSet = trainingSets[languageProvider];
return trainingSet;
}
/// <summary>
/// Get the validation set that corresponds to the <see cref="LanguageProvider"/>
/// of the <see cref="InferenceResourceItem.InferenceResource"/>.
/// </summary>
/// <returns>
/// Returns the corresponding <see cref="ValidationSet"/>, if it exists,
/// else throws a <see cref="SetupException"/>.
/// </returns>
/// <exception cref="SetupException">
/// When no <see cref="ValidationSet"/> exists in <see cref="Setup"/> corresponding to
/// the <see cref="LanguageProvider"/> of the <see cref="InferenceResourceItem.InferenceResource"/>.
/// </exception>
protected ValidationSet GetValidationSet()
{
var validationSets = InferenceEnvironment.Setup.ValidationSets;
var languageProvider = this.InferenceResource.LanguageProvider;
if (!validationSets.ContainsKey(languageProvider))
throw new SetupException("No validation set is defined for the specified language provider.");
var validationSet = validationSets[languageProvider];
return validationSet;
}
#endregion
}
}