wasBayesSharp – Diff between revs 1 and 3
?pathlinks?
Rev 1 | Rev 3 | |||
---|---|---|---|---|
Line 139... | Line 139... | |||
139 | /// Import Bayes Text Classifier from a json string |
139 | /// Import Bayes Text Classifier from a json string |
|
140 | /// </summary> |
140 | /// </summary> |
|
141 | /// <param name="json">The json content to be loaded</param> |
141 | /// <param name="json">The json content to be loaded</param> |
|
142 | public void ImportJsonData(string json) |
142 | public void ImportJsonData(string json) |
|
143 | { |
143 | { |
|
144 | _tags = JsonConvert.DeserializeObject<TagDictionary<TTokenType, TTagType>>(json); |
144 | var result = JsonConvert.DeserializeObject<TagDictionary<TTokenType, TTagType>>(json); |
|
- | 145 | switch (result != null) |
||
- | 146 | { |
||
- | 147 | case true: |
||
- | 148 | _tags = result; |
||
145 | _mustRecache = true; |
149 | _mustRecache = true; |
|
- | 150 | break; |
||
- | 151 | |
||
- | 152 | default: |
||
- | 153 | _tags = new TagDictionary<TTokenType, TTagType>(); |
||
- | 154 | break; |
||
- | 155 | } |
||
146 | } |
156 | } |
|
Line 147... | Line 157... | |||
147 | |
157 | |
|
148 | /// <summary> |
158 | /// <summary> |
|
149 | /// Export Bayes Text Classifier to a json string |
159 | /// Export Bayes Text Classifier to a json string |
|
150 | /// </summary> |
160 | /// </summary> |
|
151 | public string ExportJsonData() |
161 | public string ExportJsonData() |
|
- | 162 | { |
||
- | 163 | return _tags?.Items != null && |
||
152 | { |
164 | _tags.Items.Any() ? |
|
- | 165 | JsonConvert.SerializeObject(_tags) : |
||
153 | return JsonConvert.SerializeObject(_tags); |
166 | string.Empty; |
|
Line 154... | Line 167... | |||
154 | } |
167 | } |
|
155 | |
168 | |
|
156 | /// <summary> |
169 | /// <summary> |
|
Line 315... | Line 328... | |||
315 | { |
328 | { |
|
316 | var probs = tokens.Where(tag.Items.ContainsKey).Select(t => tag.Items[t]); |
329 | var probs = tokens.Where(tag.Items.ContainsKey).Select(t => tag.Items[t]); |
|
317 | return probs.OrderByDescending(p => p).Take(2048); |
330 | return probs.OrderByDescending(p => p).Take(2048); |
|
318 | } |
331 | } |
|
Line 319... | Line 332... | |||
319 | |
332 | |
|
320 | #endregion |
- | ||
321 | |
333 | #endregion Private Methods |
|
322 | } |
- | ||
323 | } |
334 | } |
|
- | 335 | } |