grammatica-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Grammatica-users] basic question


From: Per Cederberg
Subject: Re: [Grammatica-users] basic question
Date: Fri, 18 Feb 2005 20:02:20 +0100

Hi Leo,

Without a relevant abstract from the grammar it is quite
hard to help with these types of problems. I did find a
small issue, though, that might help explain some of the
mystery:

    System.out.println(parser.parse());
    return parser.parse();

Here you are calling the parse() method twice, which
shouldn't be done. If you wish to first print and then
return the parse tree you should do like this:

    Node node = parser.parse();
    System.out.println(node);
    return node;

The real problem for you, judging from the parser errors,
is that your input doesn't match the grammar. The message
tries to say that the text should have started with either
a PREDICATE or a "\neg" token, which it did not.

Hope this helps. If not, please write again with some of
the grammar visible.

Cheers,

/Per

On fri, 2005-02-18 at 13:46 -0500, Leo Ferres wrote:
> Dear list;
> 
> I'm afraid I've got to ask what I think is a very simple question. So,
> my apologies. I seem to have a problem accessing the parser from my java
> code. The "standalone" parser works, but when I call it, I get an
> "unexpected EOF" error. Here are the details of my implementation:
> 
> try {
>                       parseFOL(myString);
>               } catch (ParserLogException e) {
>                       System.out.println(e.getError(0).getMessage());
>               } catch (ParserCreationException e) {
>                       System.out.println(e.getMessage());
>               }
> 
> myString is a String object. I get no errors in either the packages or
> the classes, but when I put in an expression to be parsed, here's what I
> get for some sample runs:
> 
> input: BLUE(car)
> Sentence(2001)
> unexpected end of file, on line 1 column: 10
> 
> input: (
> unexpected token "(", expected one of <PREDICATE>, or "\neg", on line 1
> column: 1
> 
> input: hello
> unexpected token "hello" <WORD>, expected one of <PREDICATE>, or "\neg",
> on line 1 column: 1,
> 
> so it seems it's accessing the parser no problem, but it stops short of
> giving me the whole parse. If, instead, I run the thing offline
> 
> java -jar grammatica-1.4.jar ./myGrammar.grammar --parse ./test.data,
> 
> I get the right result:
> 
> Parse tree from .\test\test.data:
> Sentence(2001)
>   ComplexSentence(2003)
>     NEGATION(1005): "\neg", line: 1, col: 1
>     Sentence(2001)
>       simpleSentence(2002)
>         PREDICATE(1012): "BLUE", line: 1, col: 6
>         LEFT_PAREN(1008): "(", line: 1, col: 10
>         WORD(1013): "peter", line: 1, col: 11
>         RIGHT_PAREN(1009): ")", line: 1, col: 16
> 
> So the problem seems to be in something like the object (or some
> modification of it) that I'm inputting the parse method. Here's said
> method as I have it implemented:
> 
>       private static Node parseFOL(String input) throws
> ParserCreationException,
>                       ParserLogException {
> 
>               Parser parser=null;
>               parser = new MyGramParser(new StringReader(input));
>               System.out.println(parser.parse());
>               return parser.parse();
>               
>       }
> 
> That should be all for now. Thanks for your help and I'm really enjoying
> your contribution. 
> 
> Best,
> 
> Leo
> 
> Leo Ferres, PhD
> Carleton University, Ottawa, Canada
> 
> 
> 
> _______________________________________________
> Grammatica-users mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/grammatica-users






reply via email to

[Prev in Thread] Current Thread [Next in Thread]