In this assignment, you are going to write a Java program to build the DFA and
perform substring matching using the method discussed in class. In this assignment,
you need to read the data from file where the first line is the text and the second line
is the search pattern.
A skeleton program is provided. You do not need to modify the main(). All you need
is to provide two functions, ReadData(filename) and BuildDFA(pattern). The rest is
the same as the Assignment 1A. In your BuildDFA function, you should make use of
the function, FindSubstringMatch that you have written in Assignment 1A.
public class SubstringMatching {
static String uniqueChars = "";
public static void main(String[] args) {
ReadData data = new ReadData(args[0]);
String text = data.text;
String pattern = data.pattern;
uniqueChars = UniqueCharacters(pattern);
int[][] dfa = BuildDFA(pattern);
int k = FindSubstringMatch(dfa, text);
if (k == -1) System.out.println("Substring " + pattern +
" cannot be found in " + text);
else System.out.println(text.substring(k, k+pattern.length()) +
" at position " + k);
}
}
Your expected result for the test1.txt is "ABABAC at position 6"
You need to print out the DFA table.
1 1 3 1 5 1
0 2 0 4 0 6
0 0 0 0 0 0
0 0 0 0 0 0
To Run
>> java SubstringMatching test3.txt
Submission
Write a Readme.txt to describe how to compile and run your program on command
line. Submit Readme.txt and your code via blackboard.