Hi everybody I am new in java. i try to build the program for phrase-language-lexicon.
this is Tree Builder:
Probabilistic LFG Parser
i need to write same output result in java program. I'v got two text file (lexicon.txt and rules.txt) . lexicon contains words and what those word means in grammar (man-none, bite-verb..etc) in rules file contains rules of position those words in sentience (np-n-v . vp-v ...etc) I need parsing the lexicon file and add it in vector , and parsing entered string from user and add it in vector. after matched above vectors elements for identification words from user-string after match with rules and identification position in sentence . give out print the result ,as in builder tree(s[np[n [man]] vp[v[likes]ad[a]] n[dog]]]. I complicate dump with matching vectors elements....
i bee very appreciate if give me any way how can i do this , or simple examples , o link o same code ...
sorry about my language (english is not my first)
// 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; } }