Partial Code To Using OpenNLP

Help
2010-07-21
2013-04-16
  • Michael Liguori

    Michael Liguori - 2010-07-21

    Hello,

    I hope someone can help me.  I sent an e-mail to Gann and he directed me here.

    I have found some code out on the web from a partial tutorial from this site:
    http://danielmclaren.net/2007/05/11/getting-started-with-opennlp-natural-language-processing/

    I have had to fix a few dozen errors with this sample, I think,  because of upgrades through OpenNLP development.  I have 1 error left that I'm not too sure about.

    Error:
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    $ /cygdrive/c/Program\ Files/Java/jdk1.6.0_21/bin/javac.exe  mikeTest.java
    mikeTest.java:125: cannot find symbol
    symbol  : constructor Parse(java.lang.String,opennlp.tools.util.Span,java.lang.S
    tring,int)
    location: class opennlp.tools.parser.Parse
        p.insert(new Parse(text, new Span(start, start + tok.length()),
                 ^
    1 error

    Code:
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    // the parent parse instance spans the entire sentence
    Parse p = new Parse(text, new Span(0, text.length()), "INC", 1, null);

    // create a parse object for each token and add it to the parent
    int start = 0;
    for (Iterator ti = tokenList.iterator(); ti.hasNext();)
    {
        String tok = (String) ti.next();
        p.insert(new Parse(text, new Span(start, start + tok.length()),                  // <----- The Error is on this line
    //                       ParserME.TOK_NODE, 0));
                       AbstractBottomUpParser.TOK_NODE, 0));
        start += tok.length() + 1;
    }

    // fetch multiple possible parse trees
    //Parse parses = parser.parse(p,numParses);
    Parse parses = parser.parse(p,start);
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    I'm not sure what I should be doing to replace the constructor.  I just started taking a java course so I'm still a bit new to it.
    Should I be using the cloneRoot function instead of the constructor?

    In: opennlp.tools.parser.Parse;
      public Parse cloneRoot(Parse node, int parseIndex)

    I can handle error fixes, but this is more of a design fix.

    Regards,

    Mike

     
  • Michael Liguori

    Michael Liguori - 2010-07-21

    After taking more of a look, it seems like I can just add a "string type" to the list of arguments.

    Prototype:
    public Parse(String text, Span span, String type, double p, int index);

    Can someone tell me what the "type" should be?  I don't think it is "INC".

     
  • Michael Liguori

    Michael Liguori - 2010-07-21

    Ok, nvm.  I have figured out what went wrong:

    Here is my updated code for that section:
    // the parent parse instance spans the entire sentence
    Parse p = new Parse(text, new Span(0, text.length()), "INC", 1, null);

    // create a parse object for each token and add it to the parent
    int start = 0;
    int myIndex = 0;
    for (Iterator ti = tokenList.iterator(); ti.hasNext();)
    {
        myIndex++;
    String tok = (String) ti.next();
    //public Parse(String text, Span span, String type, double p, int index)
    //public Parse(String text, Span span, String type, double p, Parse h)
    //-----------------
    //    p.insert(new Parse(text, new Span(start, start + tok.length()),
    //    p.insert(new Parse(text, new Span(start, start + tok.length()), "INC",
    //    Parse pInc = new Parse(text, new Span(start, start + tok.length()), "INC", AbstractBottomUpParser.TOK_NODE, 0);
    p.insert( new Parse(text, new Span(start, start + tok.length()),
    AbstractBottomUpParser.TOK_NODE, 0, myIndex));
    //                    AbstractBottomUpParser.TOK_NODE, 0));
        start += tok.length() + 1;
    }

    // fetch multiple possible parse trees
    //Parse parses = parser.parse(p,numParses);
    Parse parses = parser.parse(p,start);

    }

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks