Search code examples
gf

Conjunction for Verb Phrase on GF


Problem

I'm trying to generate the sentence It's sunny on Monday and rainy on Tuesday on GF using RGL. I looked for a method to generate this sentence on the RGL page, but I couldn't find anything that might help with this. Checked Extend.gf on GitHub for more information about GF, and I found these three lines:

    MkVPS      : Temp -> Pol -> VP -> VPS ;  -- hasn't slept
    ConjVPS    : Conj -> [VPS] -> VPS ;      -- has walked and won't sleep
    PredVPS    : NP   -> VPS -> S ;          -- she [has walked and won't sleep]

They seemed promising at first glance, but when I tried implementing them on a real code, it seems like I misused [VPS]. My code:

mkPhr(PredVPS
        (it_NP)
        (ConjVPS
            (and_Conj)
            (MkVPS
                (mkTemp (futureTense) (simultaneousAnt))
                (positivePol)
                (mkVP
                    (mkVP (mkA "sunny"))
                    (SyntaxEng.mkAdv (on_Prep) (mkNP (mkN ("Monday"))))))
            (MkVPS
                (mkTemp (futureTense) (simultaneousAnt))
                (positivePol)
                (mkVP
                    (mkVP (mkA "rainy"))
                    (SyntaxEng.mkAdv (on_Prep) (mkNP (mkN ("Tuesday"))))))));

But I ran into this error, which obviously a problem with the defined variable and the expected one.

missing record fields: s1, s2 type of MkVPS (mkTemp futureTense simultaneousAnt) positivePol (AdvVP ((\a -> UseComp (CompAP (PositA a))) (regA "rainy")) (PrepNP on_Prep ((\n -> MassNP (UseN n)) (regN "Monday"))))
      expected: {s1 : ResEng.Agr => Str; s2 : ResEng.Agr => Str}
      inferred: {s : ResEng.Agr => Str; lock_VPS : {}}

Question

What is the correct way to use [VPS]?


Solution

  • Clarification on lists

    Just like with other list categories C, you need to use a constructor that takes two (or more) Cs and creates a [C].

    For categories that are in the RGL API, there are convenience opers of type mkC : Conj -> C -> C -> C, but under the hood, those opers also need to call the proper constructors for [C]. (The constructors are called BaseC and ConsC, and you can read more on lists here.)

    How to use conjunctions with VPSs

    So VPS is not in the API, so there is no convenience oper with type signature Conj -> VPS -> VPS -> VPS. Instead, you need to call BaseVPS explicitly. Here is working code, I cut your long expression into smaller pieces.

    resource VPS = open SyntaxEng, ParadigmsEng, ExtendEng in {
      oper
        -- Lexicon
        sunny_A : A = mkA "sunny" ;
        rainy_A : A = mkA "rainy" ;
        monday_N : N  = mkN "Monday" ;
        tuesday_N : N  = mkN "Tuesday" ;
    
        -- Helper functions
        adj_on_day : A -> N -> VP = \a,n ->
          mkVP (mkVP a) (SyntaxEng.mkAdv on_Prep (mkNP n)) ;
        sunny_on_Monday_VP  : VP = adj_on_day sunny_A monday_N ;
        rainy_on_Tuesday_VP : VP = adj_on_day rainy_A tuesday_N ;
    
        tenseVPS : Tense -> VP -> VPS = \tns,vp -> 
          MkVPS (mkTemp tns simultaneousAnt) positivePol vp ;
        futureVPS = tenseVPS futureTense ;
        pastVPS = tenseVPS pastTense ;
    
        -- Constructing the phrase
        -- lin: "it will be sunny on Monday and will be rainy on Tuesday"
        futFutPhrase : Phr =
          mkPhr (
            PredVPS it_NP
                    (ConjVPS -- : Conj -> [VPS] -> VPS
                       and_Conj -- : Conj
                       (BaseVPS -- : VPS -> VPS -> [VPS]
                         (futureVPS sunny_on_Monday_VP)  -- : VPS
                         (futureVPS rainy_on_Tuesday_VP) -- : VPS
                       )
                    )
          ) ;
    
        -- lin: "it was sunny on Monday and will be rainy on Tuesday"
        pastFutPhrase : Phr =
          mkPhr (
            PredVPS it_NP
                    (ConjVPS -- : Conj -> [VPS] -> VPS
                       and_Conj -- : Conj
                       (BaseVPS -- : VPS -> VPS -> [VPS]
                         (pastVPS sunny_on_Monday_VP)    -- : VPS
                         (futureVPS rainy_on_Tuesday_VP) -- : VPS
                       )
                    )
          ) ;
    }
    

    And it works like this:

    $ gf
    Languages:
    > i -retain VPS.gf
    > cc -one futFutPhrase
    it will be sunny on Monday and will be rainy on Tuesday
    > cc -one pastFutPhrase
    it was sunny on Monday and will be rainy on Tuesday
    

    So the tenses are repeated in both cases, because the conjunction is on the VPS level, not on the AP level.

    How to create the phrase you wanted

    If you want to have ellipsis, "it will be sunny on Monday and rainy on Tuesday", you will need to attach the Adv "on Monday" to the AP "sunny" using AdvAP, then do an AP conjunction, turn that AP into VP, and then use that VP in a Cl as you normally would. Here is code, a separate file from the previous:

    resource APConj = open SyntaxEng, ParadigmsEng, (A=AdjectiveEng) in {
      oper
        -- Lexicon
        sunny_A : A = mkA "sunny" ;
        rainy_A : A = mkA "rainy" ;
        monday_N : N  = mkN "Monday" ;
        tuesday_N : N  = mkN "Tuesday" ;
    
        -- Helper functions
        adj_on_day : A -> N -> AP = \a,n ->
          A.AdvAP (mkAP a) (SyntaxEng.mkAdv on_Prep (mkNP n)) ;
        sunny_on_Monday_AP  : AP = adj_on_day sunny_A monday_N ;
        rainy_on_Tuesday_AP : AP = adj_on_day rainy_A tuesday_N ;
    
        -- Constructing the phrase
    
        sunnyRainyEllipsisPhrase : Phr =
          mkPhr (
            mkCl (
              mkVP (mkAP and_Conj sunny_on_Monday_AP rainy_on_Tuesday_AP)
              )
          ) ;
    }
    

    Works like this:

    $ gf
    Languages:
    > i -retain APConj.gf 
    > cc -one sunnyRainyEllipsisPhrase
    it is sunny on Monday and rainy on Tuesday