// Read in a String from the user
// create a parser to test it against
// check each word against the lexicon
// 1. write out the part of speech
// 2. Then check these parts of speech against
// the rules
//as in old example open file, read line from lexicon file and create lex
SOME as:
import java.util.StringTokenizer;
import java.util.Vector;
import java.io.BufferedReader;
import java.io.FileReader;
public class newtoken {
public static void main(String[] args) throws Exception
{
Vector predlo =new Vector();
String s = "THE DOG BITES A MAN";
StringTokenizer st = new StringTokenizer(s, " \t\n\r,.");
while (st.hasMoreTokens())
{
predlo.add(st.nextToken());
}
System.out.println("Thi is a sentence"+predlo);
FileReader fr = new FileReader("lexicon.txt");
BufferedReader br = new BufferedReader(fr);
String line4 = br.readLine();
while (line4!=null)
{
//System.out.println(line4);
String[] tr = line4.split("\\s");
for(int j=0; j<predlo.size(); j++)
if(predlo.elementAt(j).equals(tr[0]))
System.out.println(tr[1]+ " "+"["+predlo.elementAt(j)+"]");
line4 = br.readLine();
}
}
}
output :Thi is a sentence[THE, DOG, BITES, A, MAN]
a [A]
v [BITES]
n [MAN]
n [DOG]
d [THE]
Now need to commpareTo with Node class for praseOfSpeech...
class Node{
String pos;
// np
Node(String s){
pos = s;
}
////////////////////////////////////////////////////
//
////////////////////////////////////////////////////
private String getNode(){
if (!checkPos())
getNode();
//getout/clause pass a parameter in the next call
// perform a 're-write'
else
return pos; // only an entry that is in the PartsOfSpeech vector
// may be returned here
}
////////////////////////////////////////////////////
//
////////////////////////////////////////////////////
public boolean checkPos(){
boolean flag = false;
for(int i =0;i<POS.size();i++) // Go through entire POS vector
if (pos = (String)POS.elementAt(i)) // Check is it there
flag = true; // if so, then return true
return flag;
}
}