-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWordNetData.cs
More file actions
88 lines (75 loc) · 4.58 KB
/
Copy pathWordNetData.cs
File metadata and controls
88 lines (75 loc) · 4.58 KB
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
using System.Collections.Generic;
using System.Data.SqlClient;
namespace WordNet.Linq
{
public static class WordNetData
{
private static string ConnectionString
{
get
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder
{
DataSource = $"{Properties.Settings.Default.WordNet_ServerHost},{Properties.Settings.Default.WordNet_ServerPort}",
InitialCatalog = "WordNet",
PersistSecurityInfo = true,
UserID = "WordNetEditor",
Password = "Yxc5R0&cwbNnqfi^R4HjRfJy"
};
return builder.ToString();
}
}
/// <summary>The WordNetDataContext singleton used for all Linq-to-SQL operations on the WordNet database.</summary>
public static WordNetDataContext Context { get; } = new WordNetDataContext(ConnectionString);
/// <summary>The parts of speech recognized by WordNet.</summary>
public enum PartOfSpeech
{
Unspecified,
Noun,
Verb,
Adjective,
AdjectiveHead,
AdjectiveSatellite,
Adverb
}
/// <summary>Maps WordNet part-of-speech codes to values of the <see cref="PartOfSpeech"/> enum</summary>
private static readonly Dictionary<char, PartOfSpeech> PartOfSpeechMappings = new Dictionary<char, PartOfSpeech>
{
{ 'n', PartOfSpeech.Noun },
{ 'v', PartOfSpeech.Verb },
{ 'a', PartOfSpeech.AdjectiveHead },
{ 's', PartOfSpeech.AdjectiveSatellite },
{ 'r', PartOfSpeech.Adverb },
};
/// <summary>Return the <see cref="PartOfSpeech"/> value corresponding to <paramref name="wordNetPartOfSpeechCode"/>.</summary>
private static PartOfSpeech PartOfSpeechCorrespondingTo(char wordNetPartOfSpeechCode)
{
PartOfSpeech result;
if (!PartOfSpeechMappings.TryGetValue(wordNetPartOfSpeechCode, out result)) result = PartOfSpeech.Unspecified;
return result;
}
/// <summary>Return true if <paramref name="wordNetPartOfSpeechCode"/> represents PartOfSpeech.Noun</summary>
internal static bool IsNoun(char wordNetPartOfSpeechCode) => PartOfSpeechCorrespondingTo(wordNetPartOfSpeechCode).Equals(PartOfSpeech.Noun);
/// <summary>Return true if <paramref name="wordNetPartOfSpeechCode"/> represents PartOfSpeech.Verb</summary>
internal static bool IsVerb(char wordNetPartOfSpeechCode) => PartOfSpeechCorrespondingTo(wordNetPartOfSpeechCode).Equals(PartOfSpeech.Verb);
/// <summary>Return true if <paramref name="wordNetPartOfSpeechCode"/> represents PartOfSpeech.Adjective</summary>
internal static bool IsAdjective(char wordNetPartOfSpeechCode) => IsAdjectiveHead(wordNetPartOfSpeechCode) || IsAdjectiveSatellite(wordNetPartOfSpeechCode);
/// <summary>Return true if <paramref name="wordNetPartOfSpeechCode"/> represents PartOfSpeech.Adjective</summary>
internal static bool IsAdjectiveHead(char wordNetPartOfSpeechCode) => PartOfSpeechCorrespondingTo(wordNetPartOfSpeechCode).Equals(PartOfSpeech.AdjectiveHead);
/// <summary>Return true if <paramref name="wordNetPartOfSpeechCode"/> represents PartOfSpeech.Adjective</summary>
internal static bool IsAdjectiveSatellite(char wordNetPartOfSpeechCode) => PartOfSpeechCorrespondingTo(wordNetPartOfSpeechCode).Equals(PartOfSpeech.AdjectiveSatellite);
/// <summary>Return true if <paramref name="wordNetPartOfSpeechCode"/> represents PartOfSpeech.Adverb</summary>
internal static bool IsAdverb(char wordNetPartOfSpeechCode) => PartOfSpeechCorrespondingTo(wordNetPartOfSpeechCode).Equals(PartOfSpeech.Adverb);
/// <summary>Return a string that describes the part of speech represented by <paramref name="wordNetPartOfSpeechCode"/> in a well-known form, like you might see in a dictionary.</summary>
internal static string UserFriendlyPartOfSpeechFrom(char wordNetPartOfSpeechCode) => PartOfSpeechCorrespondingTo(wordNetPartOfSpeechCode) switch
{
PartOfSpeech.Noun => "n",
PartOfSpeech.Verb => "v",
PartOfSpeech.AdjectiveHead => "adj-h",
PartOfSpeech.AdjectiveSatellite => "adj-s",
PartOfSpeech.Adverb => "adv",
_ => "Unspecified",
};
internal static bool PartsOfSpeechMatch(PartOfSpeech partOfSpeech, char wordNetPartOfSpeechCode) => partOfSpeech.Equals(PartOfSpeechCorrespondingTo(wordNetPartOfSpeechCode));
}
}