I'm trying to create a program that identifies the subject and verb of a sentence. I use almost the exact same method to determine words that are nouns and words that are verbs, but when I call this method back-to-back it wont work the second time around. For example if I do this:
try {
SA.VerbIdentifier(SA.TokenToArray(INPUT_words));
} catch (Exception e) {
System.out.println("Error reading Verb Text file");
e.printStackTrace();
}
try {
SA.SubjectIdentifier(SA.TokenToArray(INPUT_words));
} catch (Exception e) {
System.out.println("Error reading Subject Text file");
e.printStackTrace();
}
Then the program wont find the subject. If I call the subject method first and the verb method second it wont find the verb. Can someone tell me why?
void SubjectIdentifier(String[] INPUT) throws Exception{
int position = -1;
String[] SubjectFile = {"src/Pronouns.txt","src/Nouns.txt"};
String[] SubjectArray = null;
for(int a = 0; SubjectFile.length > a; a++){
SubjectArray = FileToArray(SubjectFile[a]);
for(int i = 0; INPUT.length > i; i++){
for(int j = 0; SubjectArray.length > j; j++){
if(SubjectArray[j].trim().equalsIgnoreCase((INPUT[i]))){
position = i;
break;
}
}
}
}
Here's the FiletoArray() Method
String[] FileToArray(String file) throws Exception {
String[] words = null;
words = new String[NumberOfWords(file)];
BufferedReader FILE = new BufferedReader(new FileReader(file));
try {
for(int i = 0; words.length > i; i++){
words[i] = FILE.readLine();
}
} catch (Exception done) {
done.printStackTrace();
}
FILE.close();
return words;
}