-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtensionFunctions.cs
74 lines (63 loc) · 2.91 KB
/
ExtensionFunctions.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace SaiPrototype
{
static class ExtensionFunctions
{
/// <summary>
/// <para>Takes strings and turns them into a similar format so comparisons are easier.</para>
/// <para>Works by assuming certain things are universally considered the same.</para>
/// <para>For example, we can assume that in any case someone says "where can I find bla bla bla...",
/// they could have said "where is bla bla bla...", so we replace "can I find" with "is".</para>
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string Standardize(this string str)
{
str = str.TrimAndReduce();
str = str.ToLower();
// Standard replacements
str = Regex.Replace(str, @"can i find", "is");
str = Regex.Replace(str, @"how do i get to", "where is");
str = Regex.Replace(str, @"can you tell me ", "");
str = Regex.Replace(str, @"i want to know ", "");
str = Regex.Replace(str, @"tell me ", "");
// contractions
str = Regex.Replace(str, @"where's|wheres", "where is");
str = Regex.Replace(str, @"who's|whos", "who is");
str = Regex.Replace(str, @"what's|whats", "what is");
str = Regex.Replace(str, @"when's|whens", "when is");
str = Regex.Replace(str, @"why's|whys", "why is");
str = Regex.Replace(str, @"how's|hows", "how is");
str = Regex.Replace(str, @"where're|wherere", "where are");
str = Regex.Replace(str, @"who're", "who are");
str = Regex.Replace(str, @"what're|whatre", "what are");
str = Regex.Replace(str, @"when're|whenre", "when are");
str = Regex.Replace(str, @"why're|whyre", "why are");
str = Regex.Replace(str, @"how're|howre", "how are");
str = Regex.Replace(str, @"i'm|im", "i am");
str = Regex.Replace(str, @"you're|youre", "you are");
str = Regex.Replace(str, @"he's|hes", "he is");
str = Regex.Replace(str, @"she's|shes", "she is");
str = Regex.Replace(str, @"it's", "it is");
str = Regex.Replace(str, @"we're", "we are");
str = Regex.Replace(str, @"they're|theyre", "they are");
// remove punctuation
str = Regex.Replace(str, @"\?", "");
str = Regex.Replace(str, @"\.", "");
str = Regex.Replace(str, @"!", "");
str = Regex.Replace(str, @";", "");
str = Regex.Replace(str, @",", "");
return str;
}
public static string TrimAndReduce(this string str)
{
str = Regex.Replace(str, @"[ ]{2}", " ");
return str;
}
}
}