Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: praser languege java

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default praser languege java

    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;
    	}
     
    }
    Last edited by helloworld922; November 13th, 2010 at 02:37 PM.


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: praser languege java

    A forum is not a do-my-homework service. Post your best efforts at tackling this and ask a specific question, and you're almost guaranteed to get help.

    Recommended reading: How To Ask Questions The Smart Way

    db