-
Notifications
You must be signed in to change notification settings - Fork 0
/
SynonymService.cs
executable file
·69 lines (57 loc) · 1.76 KB
/
SynonymService.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 SynonymService : StriderService
{
private string endPoint;
public SynonymService(string _endPoint)
{
this.endPoint = _endPoint;
}
public Synonyms GetSynonyms(string word)
{
string response = Get(this.endPoint + word);
Synonyms dto = new Synonyms();
List<string> synList = 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("synonyms");
var synonyms = new string[] { };
if (element == null)
{
return null;
}
synonyms = xml_res.Element("synonyms").Elements("syn").Select(ox => ox.Value.Trim()).ToArray();
if (synonyms.Count() == 0)
{
return null;
}
dto = new Synonyms();
synList = new List<string>();
dto.Word = requestedWord;
for (int i = 0; i < synonyms.Length; i++)
{
synList.Add(synonyms[i]);
}
dto.synonyms = synList;
return dto;
}
}
}