-
Notifications
You must be signed in to change notification settings - Fork 0
/
WordDefinitionService.cs
executable file
·69 lines (57 loc) · 1.83 KB
/
WordDefinitionService.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Net;
using System.Xml.Linq;
using System.IO;
namespace Strider.Client.TextMiner.Client
{
public class WordDefinitionService : StriderService
{
private string endPoint;
public WordDefinitionService(string _endPoint)
{
this.endPoint = _endPoint;
}
public WordDefinitions GetWordDefinitions(string word)
{
string response = Get(this.endPoint + word);
WordDefinitions dto = new WordDefinitions();
List<string> defList = new List<string>();
var xml_res = XElement.Parse(response);
string requestedWord;
XElement xmlElement = xml_res.Element("word");
if (xmlElement != null)
{
requestedWord = xmlElement.Value;
}
else
{
dto.Word = word;
return dto;
}
var element = xml_res.Element("definitions");
var definitions = new string[] { };
if (element == null)
{
return null;
}
definitions = xml_res.Element("definitions").Elements("definition").Select(ox => ox.Value.Trim()).ToArray();
if (definitions.Count() == 0)
{
return null;
}
dto = new WordDefinitions();
defList = new List<string>();
dto.Word = requestedWord;
for (int i = 0; i < definitions.Length; i++)
{
defList.Add(definitions[i]);
}
dto.definitions = defList;
return dto;
}
}
}