-
Notifications
You must be signed in to change notification settings - Fork 0
/
WordChecker.cs
116 lines (112 loc) · 3.6 KB
/
WordChecker.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Question_Getter_Front_End
{
class WordChecker
{
public WordChecker()
{
}
public string classifyWords(string text)
{
int x = 0;
int output;
string strtest;
string[] seperate;
Word wrd;
text = text.Trim();
while(true)
{
if (x >= text.Length)
return text;
if (x != 0)
{
strtest = text.Substring(x, 1);
while (!strtest.Equals(" "))
{
x++;
if (x == text.Length)
break;
strtest = text.Substring(x, 1);
}
if (x == text.Length)
return text;
}
seperate = seperateNextWord(x, text);
if (seperate == null)
{
x++;
continue;
}
else if (seperate[1].Contains("href"))
{
x++;
continue;
}
else if (seperate[1].Equals(""))
{
x++;
continue;
}
else if (int.TryParse(seperate[1],out output))
{
x += seperate.Length;
continue;
}
wrd = new Word(seperate[1]);
DictionaryInterface.findType(wrd);
if (wrd.type.Equals("unknown"))
{
text = seperate[0] +" "+ wrd.word +"() "+ seperate[2];
x += wrd.word.Length;
}
else
{
text = seperate[0] +" "+ wrd.word + "(" + wrd.type + ") " + seperate[2];
x += wrd.word.Length + wrd.type.Length + 2;
}
}
}
private string[] seperateNextWord(int start,string text)
{
string[] ret = new string[3];
string wrd;
text.Trim();
if (start == 0)
{
ret[1] = text.Substring(0, (text.IndexOf(" ")));
ret[0] = "";
ret[2] = text.Substring(ret[1].Length);
return ret;
}
int end = text.IndexOf(" ", start+1);
if (end == -1)
end = text.Length;
ret[0] = text.Substring(0, start).Trim();
wrd = text.Substring(start + 1, (end - start)-1);
if (hasPunc(wrd))
{
ret[2] = (wrd.Substring(wrd.Length - 1, 1) + ret[2]).Trim();
ret[1] = wrd.Substring(0, wrd.Length - 1).Trim();
}
else
ret[1] = text.Substring(start+1, (end - start)-1).Trim().Trim();
ret[2] = text.Substring(end).Trim();
return ret;
}
private bool hasPunc(string wrd)
{
string[] punctuation = { "!", ",", "?", ".", "(", ")", "\\", "/", ":", ";"};
bool ispunc = false;
foreach (string s in punctuation)
{
if (wrd.Contains(s))
ispunc = true;
}
return ispunc;
}
}
}