GrammaticalFramework/GF

Parsing multiple phrases into the same AST

Closed this issue · 4 comments

Apples are a type of fruit
Apples are a kind of fruit
Apples are fruits

...should all be parsed to TypeOf Apple Fruit
I've tried doing this with oper overloading but I'm struggling.
I'm using the resource library.
Any ideas?

You can use variants, as defined here. Here's a dummy sketch, just to give a rough idea:

lin
-- Assume apple and fruit are  { s : Number => Str }
TypeOf apple fruit = { s = variants { 
   apple.s ! Pl ++ "are a type of" ++ fruit.s ! Sg ;
   apple.s ! Pl ++ "are a kind of" ++ fruit.s ! Sg ; 
   apple.s ! Pl ++ "are" ++ fruit.s ! Pl } 
} ;

Ah yes thanks I saw that! But I'm using the resource grammar library. I think I can do with the | operator like this:

Pet = mkCN ((mkN "cat") | (mkN "dog")) ;

Using the RGL or not, doesn't matter: you can write anything inside the variants. This is another dummy example, check the RGL API synopsis for the actual mkX you want.

TypeOf apple fruit = mkS (mkCl apple type_N fruit | mkCl apple kind_N fruit | mkCl apple fruit) ;

Should be the same as

TypeOf apple fruit = variants { 
  mkS (mkCl apple type_N fruit) ;
  mkS (mkCl apple kind_N fruit) ; 
  mkS (mkCl apple fruit) } ;

Amazing thanks!