[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [Grammatica-users] basic question
From: |
Leo Ferres |
Subject: |
RE: [Grammatica-users] basic question |
Date: |
Sat, 19 Feb 2005 11:23:00 -0500 |
Per,
it worked just great. Thank you very much. My next question is, I guess, the
next logical step of a newbie.
How can I access each of the individual nodes of the generated tree? I'd
like to do something like
0 Sentence
1 simpleSentence
2 PREDICATE "BLUE"
3 (
4 WORD "boy"
5 )
node.get(2) to get the "PREDICATE "BLUE"" string.
I appreciate all your help so far and I hope my questions help create a KB
for new grammatica/java users!
Leo
|-----Original Message-----
|From: address@hidden
|[mailto:address@hidden
|On Behalf Of Per Cederberg
|Sent: Saturday, February 19, 2005 3:56 AM
|To: address@hidden
|Subject: Re: [Grammatica-users] basic question
|
|
|The results you are getting are actually both correct and
|expected... :-)
|
|Thing is, the toString() method in the Node subclasses does
|not print the whole parse tree, just the node itself. So in
|the first case you most certainly have a complete parse tree
|like this:
|
| Sentence
| simpleSentence
| PREDICATE "BLUE"
| (
| WORD "boy"
| )
|
|You can use the printTo() method if you wish to print the
|whole parse tree. Like this:
|
| node.printTo(System.out);
|
|Hope this helps!
|
|/Per
|
|On fri, 2005-02-18 at 14:46 -0500, Leo Ferres wrote:
|> Dear Per and J.;
|>
|> That was a prompt reply, thank you.
|>
|> As per your suggestions, I've both added a "newline" at the end of
|> myString:
|>
|> myString=myString + "\n";
|>
|> and I've corrected the (horrible) programming mistake that Per pointed
|> out. The method now reads:
|>
|> private static Node parseFOL(String input) throws
|> ParserCreationException,
|> ParserLogException {
|>
|> Parser parser=null;
|> parser = new MyGramParser(new StringReader(input));
|> Node node=parser.parse();
|> System.out.println(node);
|> return node;
|>
|> }
|>
|> It still doesn't work, though now, no error is printed. Here's a sample
|> run:
|>
|> The latter one is expected, the first one is not. Here it is:
|>
|> FOL:> BLUE(boy)
|> [Fri Feb 18 14:33:32 EST 2005]: Parsing BLUE(boy)...
|> Sentence(2001)
|> FOL:> BLUE(
|> [Fri Feb 18 14:33:40 EST 2005]: Parsing BLUE(...
|> unexpected end of file, on line 2 column: 1
|> FOL:>
|>
|> And here's my toy grammar:
|>
|> %header%
|>
|> GRAMMARTYPE = "LL"
|>
|> DESCRIPTION = "A grammar for a simple FOL language."
|>
|> AUTHOR = "Leo Ferres, <lferres at ccs dot carleton dot ca>"
|> VERSION = "1.0"
|> DATE = "February 2005"
|>
|> LICENSE = "Permission is granted to copy this document verbatim in
|>
|> any
|> medium, provided that this copyright notice is left
|>
|> intact."
|>
|> COPYRIGHT = "Copyright (c) 2005 Leo Ferres for the HOTLab. All rights
|>
|> reserved."
|>
|> %tokens%
|>
|> EXISTENTIAL = "\exists"
|> CONJUNCTION = "\wedge"
|> UNIVERSAL = "\forall"
|> DISJUNCTION = "\vee"
|> NEGATION = "\neg"
|> TRUTH = "True"
|> FALSITY = "False"
|> LEFT_PAREN = "("
|> RIGHT_PAREN = ")"
|> ARGUMENT_SEPARATOR = ","
|> NUMBER = <<[0-9]+>>
|> PREDICATE = <<[A-Z]+>>
|> WORD = <<[a-z]+>>
|> WHITESPACE = <<[ \t\n\r]+>> %ignore%
|>
|> %productions%
|>
|> Sentence = simpleSentence | ComplexSentence ;
|>
|> simpleSentence = PREDICATE "(" WORD ")" ;
|>
|> ComplexSentence = NEGATION Sentence ;
|>
|> I appreciate your help.
|>
|> Best regards,
|>
|> Leo
|
|
|
|
|_______________________________________________
|Grammatica-users mailing list
|address@hidden
|http://lists.nongnu.org/mailman/listinfo/grammatica-users