information retrieval systems

24 views
Skip to first unread message

Joel Reymont

unread,
May 15, 2012, 5:26:04 PM5/15/12
to gf-...@googlegroups.com
Suppose I want to parse and process a request in the form of "Remember
X about Y".

A request "What do you know about X" should print out Y.

X and Y here are simple strings.

Is this possible with GF?

The bits I don't understand are

1) How do I define a grammar where the abstract tree holds strings in
a constructor (Remember String?)

Can I have a type dependent on a String?

2) Assuming my interpreter was Haskell, how do I discover that X is a
meta-variable when the user asks "What do you know about", leaving out
X?

3) How do I linearize "Who are you asking about?" when I discover that
X in #2 is a meta-variable?

Thanks in advance, Joel

P.S. I bought the book but it hasn't arrived yet.

--------------------------------------------------------------------------
AlgoKit: EasyLanguage trading strategies, on the server, w/ Rithmic R|API
---------------------+------------+---------------------------------------
http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
---------------------+------------+---------------------------------------

Aarne Ranta

unread,
May 16, 2012, 3:16:18 AM5/16/12
to gf-...@googlegroups.com
Hello Joel,

The simplest way is to use separate concrete syntaxes for questions and answers:

  fun XY : Request
  lin XY = "What do you know about X"  -- question grammar 
  lin XY = "Y" -- answer grammar

Actually you can get quite far with this idea, because the answer grammar can be e.g. Haskell code with higher-order functions. See for instance the code in

  
which permits the following interaction:

 ./query "which numbers smaller than 200 are prime"
[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199]

Regards

  Aarne.

Joel Reymont

unread,
May 16, 2012, 3:54:08 PM5/16/12
to gf-...@googlegroups.com
Aarne,

How do I detect the presence of unresolved metavariables, though?

Say a user omits "Aarne" in "What do you know about Aarne?".

I would like to respond with "Who do you want to know about"?

Thanks, Joel

On Wed, May 16, 2012 at 8:16 AM, Aarne Ranta <aa...@chalmers.se> wrote:
> Hello Joel,
>
> The simplest way is to use separate concrete syntaxes for questions and
> answers:
>
>   fun XY : Request
>   lin XY = "What do you know about X"  -- question grammar
>   lin XY = "Y" -- answer grammar
>
> Actually you can get quite far with this idea, because the answer grammar
> can be e.g. Haskell code with higher-order functions. See for instance the
> code in
>
>   http://www.digitalgrammars.com/ipl-book/examples/query/
>
> which permits the following interaction:
>
>  ./query "which numbers smaller than 200 are prime"
> [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199]

Joel Reymont

unread,
May 16, 2012, 4:28:32 PM5/16/12
to gf-...@googlegroups.com
Aarne,

More specifically, how do I determine the presence of unresolved
metavariables and linearize them in standalone Haskell code?

Thanks in advance, Joel
--

Krasimir Angelov

unread,
May 16, 2012, 4:33:03 PM5/16/12
to gf-...@googlegroups.com
The Haskell API has the function:

unMeta :: Expr -> Maybe Int

which can tell you whether a given expression is a metavariable or
not. You can traverse the expression recursively for nested
metavariables by using the function:

unApp :: Expr -> Maybe (CId, [Expr])

Regards,
Krasimir


2012/5/16 Joel Reymont <joe...@gmail.com>:

Joel Reymont

unread,
May 16, 2012, 5:10:08 PM5/16/12
to gf-...@googlegroups.com
Thanks Krasimir!

How do you linearize a metavariable once you discover it in Haskell, though?

Assuming that dialogs with GF consist of "filling fields in a form",
how do I fill a hole that I discover?

All in all, I find GF very hard to grok. Hopefully, the book with help
with that, although I already went through the slides and it didn't
help a whole lot.

I'm thinking that GF may be too complex and complicated to build an
English-only agenda (todo list, reminders, etc.) type of service.
Maybe a combination of GLR parser like Dypgen [1] and a basic
pretty-printer for the AST would be simpler.

Still, I'm not giving up on GF just yet.

Thanks, Joel

[1] http://dypgen.free.fr/

Aarne Ranta

unread,
May 17, 2012, 4:52:41 AM5/17/12
to gf-...@googlegroups.com
Hello Joel,

What you need sounds similar to Björn Bringert's pizza dialogue system, which is precisely "filling forms", but with speech:


The main idea there is to use variant linearizations with omissions of arguments; see in particular PizzaEng.gf

The printname judgement form is used for displaying metavariables - essentially, their types.

  Aarne.

Joel Reymont

unread,
May 17, 2012, 6:46:17 PM5/17/12
to gf-...@googlegroups.com
To elaborate on this a bit...

How do I write the grammar to process this request:

Remind me about <a bunch of words not in the grammar, possibly on
multiple lines> a day from now.

I understand how to parse "Remind me about" as well as "a day from now".

How do I grab the text between 'about' and 'a day', though?

This is free text that can be anything and I want to store it in the
Reminder constructor as a Str.

Is this even possible in GF?

Thanks, Joel

On Wed, May 16, 2012 at 8:16 AM, Aarne Ranta <aa...@chalmers.se> wrote:
> Hello Joel,
>
> The simplest way is to use separate concrete syntaxes for questions and
> answers:
>
>   fun XY : Request
>   lin XY = "What do you know about X"  -- question grammar
>   lin XY = "Y" -- answer grammar

Krasimir Angelov

unread,
May 18, 2012, 4:03:59 AM5/18/12
to gf-...@googlegroups.com
2012/5/18 Joel Reymont <joe...@gmail.com>:
> How do I write the grammar to process this request:
>
> Remind me about <a bunch of words not in the grammar, possibly on
> multiple lines>  a day from now.
>
> I understand how to parse "Remind me about" as well as "a day from now".
>
> How do I grab the text between 'about' and 'a day', though?

You can do this by using the String category and a custom Haskell code
which must determine the start and the end of the free text fragment
in some way. There is an example for using this trick for recognizing
proper names in my thesis:

http://www.cse.chalmers.se/~krasimir/phd-thesis.pdf

look at page 48.

Regards,
Krasimir

Joel Reymont

unread,
May 18, 2012, 11:01:50 AM5/18/12
to gf-...@googlegroups.com
Krasimir,

On Fri, May 18, 2012 at 9:03 AM, Krasimir Angelov <kr.an...@gmail.com> wrote:
> You can do this by using the String category and a custom Haskell code
> which must determine the start and the end of the free text fragment
> in some way. There is an example for using this trick for recognizing
> proper names in my thesis:

Thanks for the tip!

What will work, I think, is advancing word by word and trying a parse
each time, until a parse is successful.

I'll need to collect the words that the parser fails on so that I can
stick them into the String category as soon as a parse succeeds.

This would involve stepping back from a successful parse to return the
collected String so that the parse can associate it with the previous
grammar element, then retrying the good parse again.

Am I on the right track? Please correct me if I'm wrong.

Actually, I'm wondering if this would be a good addition to GF. To
specify in the grammar that here comes a String and it goes on until
the next parseable element of the grammar. And the string linearizes
as is, without translation. What do you think?

Thanks, Joel

Krasimir Angelov

unread,
May 18, 2012, 3:42:27 PM5/18/12
to gf-...@googlegroups.com
This is becoming closer to the approach in the robust parser which I
develop. The problem is that this could be quite heavy processing but
your grammar is much smaller so give it try.


2012/5/18 Joel Reymont <joe...@gmail.com>:

Erel Segal Halevi

unread,
May 31, 2012, 9:24:28 AM5/31/12
to gf-...@googlegroups.com
I also think this could be a very useful addition.

Maybe it could be implemented using a regular-expression engine. At least in Joel's specific case, a regular expression could solve this in seconds.
Reply all
Reply to author
Forward
0 new messages