-
Notifications
You must be signed in to change notification settings - Fork 0
/
Table.java
36 lines (29 loc) · 942 Bytes
/
Table.java
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
import java.util.*;
/**
* A Table that contains words that are mapped with a list of their following words.
*/
class Table {
Map<String, Pattern> occurrences;
public Table() {
occurrences = new HashMap<>();
}
/**
* This method updates the Table.
* @param current the key that we want to update
* @param follow the following word that we want to update
*/
public void updateTable(String current, String follow) {
if (!occurrences.containsKey(current)) {
occurrences.put(current, new Pattern());
}
occurrences.get(current).updatePattern(follow);
}
/**
* This method gets the most likely word to follow a given word.
* @param current the word that we want to find another word to follow
* @return String the most likely string to follow the given word
*/
public String getNext(String current) {
return occurrences.get(current).getNextWord();
}
}