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.

Page 2 of 2 FirstFirst 12
Results 26 to 30 of 30

Thread: Matrix Generator

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,105
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Matrix Generator

    Is it defined to throw an exception? If so, put it in try/catch for that exception.
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Junior Member
    Join Date
    Apr 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Matrix Generator

    Ok...finally now it is giving an output.

    [OUTPUT]
    layers that fly that food . that fly sneaks{}
    [/OUTPUT]


    Now the problem is the tagging part is not working (noun,verb or verbnoun) The tagger needs to tag each word in a sentence.

    import java.util.HashMap;
    import java.util.Map;
    import org.junit.Test;
     
     public class Tagger 
     {
          public HashMap my_member_variable = new HashMap();
         public static void main (String args[])
            {
                 Tagger tag = new Tagger();
     
    		// Access member variable of tag
                    System.out.println ("layers that fly that food . that fly sneaks" +
                            tag.my_member_variable );
            }
     	String tagset;
     	String corpus;
     	Map<String, String> lexicon;
     	String lexiconString;
            //private String HashMap;
     	@Test
     	public void testTagger() {
               //System.out.println(tag("layers that fly that food . that fly sneaks ."));
     	}
     
     
     
     	private void initData() {
     	    lexicon = new HashMap<String, String>();
     	    lexicon.put("fly", "vn");
     	    lexicon.put("layers", "vn");
     	    lexicon.put("sneaks", "v");
     	    lexicon.put("food", "n");
     	    lexicon.put("that", "det,rp");
     	    lexicon.put(".", "period");
     	    StringBuilder lexBuf = new StringBuilder();
     	    for (String word : lexicon.keySet()) {
                StringBuilder append = lexBuf.append(word).append(" ");
     	    }
     	    lexiconString = lexBuf.toString();
     	    tagset = "det rp vn v n period";
     	    corpus = "that fly layers. that fly sneaks. that, that sneaks food" +
     	    		"layers. that fly layers that food. layers.";
     	}
     
     
     	public String tag(String input) {
     	    initData();
     	    ViterbiHMM hmm = new ViterbiHMM(tagset, lexiconString, input, lexicon,
     	            corpus, true);
     	    String[] in = input.split(" ");
     	    String[] re = hmm.mostProbableSequence().split(" ");
     	    StringBuilder buf = new StringBuilder();
     	    for (int i = 0; i < in.length; i++) {
                StringBuilder append = buf.append(in[i]).append(":").append(re[i]).append(" ");
     	    }
     	    return buf.toString();
     	}
    }

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,105
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Matrix Generator

    Please post the program's output and add some comments to it that describes what is wrong with the output and show what the output should be.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Junior Member
    Join Date
    Apr 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Matrix Generator

    The output is printing out the training set which is pre- programmed in the code. Which is this:

    layers that fly that food . that fly sneaks


    The output should actually be something like this:

    layers/vn that fly/vn that food/n . that/det,rp fly sneaks

    This part of the code initialize the lexicon, the tagset and the untagged corpus
    private void initData() {
     	    lexicon = new HashMap<String, String>();
     	    lexicon.put("fly", "vn");
     	    lexicon.put("layers", "vn");
     	    lexicon.put("sneaks", "v");
     	    lexicon.put("food", "n");
     	    lexicon.put("that", "det,rp");
     	    lexicon.put(".", "period");
     	    StringBuilder lexBuf = new StringBuilder();
     	    for (String word : lexicon.keySet()) {
                StringBuilder append = lexBuf.append(word).append(" ");
     	    }
     	    lexiconString = lexBuf.toString();
     	    tagset = "det rp vn v n period";
     	    corpus = "that fly layers. that fly sneaks. that, that sneaks food" +
     	    		"layers. that fly layers that food. layers.";
     	}

    This part of the code adds the POS tag for every word in the input and returns that tagged string using the most probable tag set for the input.
    public String tag(String input) {
        initData();
        ViterbiHMM hmm = new ViterbiHMM(tagset, lexiconString, input, lexicon,
                corpus, true);
        String[] in = input.split(" ");
        String[] re = hmm.mostProbableSequence().split(" ");
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < in.length; i++) {
            buf.append(in[i] + ":" + re[i] + " ");
        }
        return buf.toString();
    }

  5. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,105
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Matrix Generator

    Are the methods being called? Add some println statements to each method and constructor to print a message when it is executed so you can see if the methods are being executed.
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. help with GUI password generator
    By semicolon in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 30th, 2011, 12:22 PM
  2. Replies: 0
    Last Post: January 25th, 2011, 12:24 AM
  3. FLash generator app
    By axell in forum Java Theory & Questions
    Replies: 0
    Last Post: July 28th, 2010, 05:38 AM
  4. Java password generator program to generate 8 random integers
    By Lizard in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 16th, 2009, 07:49 AM
  5. [SOLVED] Random number method implementation
    By big_c in forum Java Theory & Questions
    Replies: 2
    Last Post: April 15th, 2009, 01:10 PM