-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSentenceGenerator.java
More file actions
executable file
·94 lines (80 loc) · 2.39 KB
/
SentenceGenerator.java
File metadata and controls
executable file
·94 lines (80 loc) · 2.39 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
89
90
91
92
93
94
package sentenceGenerator;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.swing.JFileChooser;
/**
* This is my version of a CIT594 assignment to read in a BNF grammar
* and produce sentences from that grammar.
*/
public class SentenceGenerator {
private Grammar grammar;
private Random random = new Random();
/**
* Prompts the user for a file containing a BNF grammar, then
* generates several sentences from that grammar.
*
* @param args Unused.
*/
public static void main(String[] args) {
try {
new SentenceGenerator().run();
}
catch (IOException e) {
e.printStackTrace();
}
}
/**
* Does the work of this class.
*
* @throws IOException If an input exception occurs.
*/
private void run() throws IOException {
// TODO: Your code goes here
}
/**
* Expands the given term into a list of terminals. If the given
* term is already a terminal, a list containing this single term
* is returned.
*
* @param term A terminal or nonterminal to expand into a list.
* @return A list of terminals.
*/
List<String> generate(String term) {
List<String> result = new ArrayList<String>();
// TODO: Your code goes here
return result;
}
/**
* Randomly choose and return one element from a list.
*
* @param list The list from which the selection is to be made.
* @return The randomly selected element.
*/
private Object chooseRandomElement(List list) {
return (list.get(random.nextInt(list.size())));
}
/**
* Prints the given list of words as a sentence. The first word is
* capitalized, and a period is printed at the end.
*
* @param list The words to be printed.
*/
void printAsSentence(List<String> list) {
// TODO: Your code goes here
}
/**
* Prompts the user to choose a file, which should contain a BNF grammar.
*
* @return The chosen file, or <code>null</code> if none is chosen.
*/
private BufferedReader getFileReader() {
BufferedReader reader = null;
// TODO: Your code goes here
return reader;
}
}