-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lexicon.cs
47 lines (39 loc) · 1.29 KB
/
Lexicon.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ArtificialTalk.net
{
public class Lexicon
{
private readonly Dictionary<string, SentenceWord> words;
public Lexicon()
{
words = new Dictionary<string, SentenceWord>();
}
public IEnumerable<SentenceWord> Words()
{
return words.Values;
}
public void ManageWord(SentenceWord sentenceWord)
{
var word = sentenceWord.Word;
if (words.ContainsKey(word))
{
var existingWord = words[word];
existingWord.CanStartSentence = existingWord.CanStartSentence ? existingWord.CanStartSentence : sentenceWord.CanStartSentence;
existingWord.CanEndSentence = existingWord.CanEndSentence ? existingWord.CanEndSentence : sentenceWord.CanEndSentence;
foreach (var followingWord in sentenceWord.GetPossibleFollowingWords())
{
existingWord.AddPossibleFollowingWord(followingWord);
}
words[word] = existingWord;
}
else
{
words.Add(word, sentenceWord);
}
}
}
}