Cases and their implementation (Swedish + general)

15 views
Skip to first unread message

Paula Pawlowski

unread,
Oct 6, 2020, 8:24:40 AM10/6/20
to gf-...@googlegroups.com
Hi GF,

# Specific question

In `scandinavian/PhraseScand.gf` we are able to extract NPs with  `UttNP np = {s = np.s ! nominative} ;`  This will work to create NPs in the `nominative` and `accusative` cases as they are implemented in `scandinavian/CommonScand.gf`:

```
  nominative : NPForm = NPNom ;
  accusative : NPForm = NPAcc ;
 ```
 
What if I want to extract an NP in the genitive case?

I can see that in the NPForms, I don't have the genitive case, but this NPPoss _ _ form which should do the trick for me.
 `NPForm = NPNom | NPAcc | NPPoss GenNum Case ;`
 
 
To be able to use something like `UttNP np = {s = np.s ! nominative} ;` with `NPPoss GenNum Case`, what are my options? Record pattern matching? Or is there no `genitive : NPForm = ...` because this is not possible?


# General question
Ultimately, I want a string that looks like a Swedish word with genitive inflection. There are a few places where I can find cases: `src/swedish/ParadigmsSwe.gf` and `src/scandinavian/CommonScand.gf` (Case, RCase).

Different languages also have different implementations. For the Romance languages we can extract NPs using `UttNP np = {s = (np.s ! Nom).ton} ;` and our cases are implemented in `romance/ResRomance.gf`:

```
  nominative : Case = Nom ;
  accusative : Case = Acc ;
```

What is the reasoning behind these differences? Different developers have different preferences? Some language families favor one implementation and not the other?

Thanks in advance for any tips (documentation, syntax tips, other RGL examples).

Best,
Paula

Inari Listenmaa

unread,
Oct 8, 2020, 8:42:01 AM10/8/20
to Grammatical Framework
Hi Paula,

For your particular use case, you could get away with Extend.GenNP, with the following type signature:

    GenNP       : NP -> Quant ;       -- this man's

The shortest way from Quant to Utt by using the API, seems to be via mkNP and mkUtt:

mkNPQuant -> NP
this
mkUttNP -> Utt
this man
So open ExtendXxx in your grammar, then write mkUtt (mkNP (GenNP your_np)), and there you have a {s : Str} that you can play with. 

There are a few languages where Utt is not a {s : Str}, so for those you can wrap it in mkPhr, like this: mkPhr (mkUtt (mkNP (GenNP your_np))).

I recommend this practice, because it's safe against internal RGL changes.

Alternative is to add more cases to the Paradigms module for different languages. Just like Swedish has already 

  nominative : NPForm = NPNom ;
  accusative : NPForm = NPAcc ;

you can as well add a new NPForm for genitive, and define it as the appropriate NPPoss <some gennum> <some case> value. If you need more, you can always define more: genitive_singular, genitive_plural or whatever. Note that if you only need them from NP, then we know already its number, but if you wanted to have a function from CN to its genitive string, then it might make sense to define genitive_singular and genitive_plural.

What is the reasoning behind these differences? Different developers have different preferences? Some language families favor one implementation and not the other?

The GF RGL has been written by different people over 20 years. Most of it is just personal preferences, or whatever was considered as a good practice at the time of writing, or from which language the developer happened to copy and paste their language from.

I hope this is an answer to your question, but if not, just ask if you need more clarification!

Inari

--

---
You received this message because you are subscribed to the Google Groups "Grammatical Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gf-dev+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gf-dev/CAO%2B7x9cjH9pqtxBOmXXPBTqaJPZE9FB8-r8Px9vpuBUN_cNvmQ%40mail.gmail.com.

Inari Listenmaa

unread,
Oct 22, 2020, 7:53:00 AM10/22/20
to Grammatical Framework
Hi,

One more suggestion to get NPs inflected in cases is to use  mkAdv : Prep -> NP -> Adv and make sure that you have a Prep for every case you want. I have written a bit about this in https://inariksit.github.io/gf/2019/02/17/beyond-API.html#ok-find-another-rgl-api-function  , and in this email I will elaborate on those points.

Export Preps in ParadigmsX

For instance, in ParadigmsSpa you have these options for Prep: http://www.grammaticalframework.org/lib/doc/synopsis/index.html#toc120 

accusativePrepdirect object
genitivePreppreposition "de" and its contractions
dativePreppreposition "a" and its contractions
Any other preposition in Spanish either doesn't merge with article (sobre el …) or is a compound preposition using one of the merging prepositions (antes del …).


Export Cases and casePrep : Case -> Prep in ParadigmsX

Some languages have a function like the following Finnish casePrep (http://www.grammaticalframework.org/lib/doc/synopsis/index.html#toc97):

casePrepCase -> Prepjust case, e.g. adessive
and all cases exported in Paradigms, so that you can write this to get a NP inflected in ablative:

mkAdv (casePrep ablative) (mkNP (mkN "talo"))

Create your own casePrep

Many languages don't have these functions in their Paradigms module, so if you want to use them, you need to write them yourself (or create an issue and ask someone else to do it). If you want to do it like it's done for Finnish, you need two things:
- export the cases in ParadigmsX. Like this https://github.com/GrammaticalFramework/gf-rgl/blob/master/src/finnish/ParadigmsFin.gf#L47-L58 in the visible part of the API, and like this https://github.com/GrammaticalFramework/gf-rgl/blob/master/src/finnish/ParadigmsFin.gf#L395-L415 in the hidden part (i.e. after the --.).
- Create a function casePrep : Case -> Prep. Here's an example for Finnish: https://github.com/GrammaticalFramework/gf-rgl/blob/master/src/finnish/ParadigmsFin.gf#L442-L443 Note that it may already exist, but isn't exported in Paradigms, so check the Res module of the language you're working on.

How to start doing this for some language X? The most important clues are CatX, to see the lincat of Prep, and AdverbX, to see the implementation of PrepNP. For instance, in the Scandinavian functor, we actually have this hardcoded situation:

PrepNP prep np = {s = prep.s ++ np.s ! accusative} ;

The preposition doesn't affect which case is chosen, it's always accusative. Changing that behaviour would be a bigger change in the Scandinavian functor, and that's not something many people would be willing to do. So for Swedish, the solution with the least hassle is to add an UttGenNP to Extend. 

Let's take another language, say Hungarian. Hungarian actually has already casePrep, but let's imagine for a moment it doesn't have it yet. 

This is the lincat for Prep (defined as Adposition in ResHun):

Adposition : Type = {
    pr : Str ; -- Preposition
    s : Str ;  -- Postposition
    c : Case ;
    } ;

And this is how PrepNP is implemented (using the oper applyAdp from ResHun, simplified):

applyAdp : Adposition -> NounPhrase -> Str = \adp,np ->
  adp.pr ++ np.s ! adp.c ++ adp.s ;

The crucial information here is np.s ! adp.c --- the case inherent in the Prep is used to choose the form from the NP. So now, all you need to do to create your casePrep for, say, superessive, is to produce a record that is {s = [] ; pr = [] ; c = Sup}. Preposition and postposition fields contain just an empty string, and the c field contains the case parameter Sup. I haven't exported the Hungarian cases in ParadigmsHun (because I'm lazy), so you need to either export them yourself following the example for Finnish, or use the raw internal parameters. If you don't export the cases in ParadigmsHun, then this is what the application grammar code would look like:

concrete MyGrammarHun of MyGrammar = … ** open (R=ResHun), SyntaxHun, ParadigmsHun in {

myAblativeAdv = mkAdv (casePrep R.Abl) (mkNP (mkN "ház")) ;
}

And if you do, then it's the same except you can skip opening (R=ResHun) and write mkAdv (casePrep ablative) (mkNP (mkN "ház")) instead. 

If you find that you don't need cases for anything other than preps, you can skip the casePrep : Case -> Prep step and just export the cases as Preps, like in the Spanish grammar. You just need to do this in ParadigmsX:

  nominative  : Prep ; -- e.g. "house"
  genitive    : Prep ; -- e.g. "house's"

And define them like this

nominative = lin Prep {c = NPCase Nom ; s = <[],[],\\_ => []>} ; -- or whatever internals the Prep of your language has

(or rather using an internal casePrep oper, instead of repeating the non-variable part in the 14 times. :-P)

Inari
Reply all
Reply to author
Forward
0 new messages