Generating a Possession Genitive Case in GF - gf

I checked the GF library for "’s" as in "My friend’s house", but I couldn't seem to find the right method to create such a relation. May someone guide me on this problem.
Appreciate it 🌹🌹

There's indeed no function for the 's possessive in the core RGL. The closest you can get using just the RGL API is "the house of my friend".
However, there is a module called Extend, which has a function GenNP : NP -> Quant.
So how to use Extend? You have been using the RGL API, where all of the mkX opers are available when you open the Syntax and Paradigms modules. The Extend module is much newer than the core RGL, so its functions are not shown in the synopsis. But you can use them just like you'd use the Syntax and Paradigms modules. Here's an example usage:
resource Test = open SyntaxEng, ParadigmsEng, LexiconEng, ExtendEng in {
oper
-- "the house of my friend"
house1 : NP = mkNP the_Det (mkCN (mkN2 house_N) (mkNP i_Pron friend_N)) ;
-- "my friend's house"
house2 : NP =
let myFriend : NP = mkNP i_Pron friend_N ;
myFriends : Quant = GenNP myFriend ; -- GenNP is from ExtendEng
in mkNP myFriends house_N ;
}
If you have any further questions on how to use Extend, I'll be glad to help!
Copy that into a file called Test.gf, and open your GF shell as you normally do. Then you can import the file with the flag -retain, that allows you to evaluate opers with the cc command. Like this:
(You need to be inside the GF shell, not on the command line)
> i -retain Test.gf
> cc -one house1
the house of my friend
> cc -one house2
my friend's house

If you search the English RGL for implementations of the genitive case (Gen for the most part), you may find something useful for your implementation.
For example, you have addGenitiveS in CompatibilityEng.gf and regGenitiveS in ResEng.gf.
> cc -table ResEng.regGenitiveS "dog"
ResEng.Nom => dog
ResEng.Gen => dog's

Related

Can I do any analysis on spacy display using NER?

When accessing this display in spacy NER, can you add the found entities - in this case any tweets with GPE or LOC - to a new dataframe or do any further analysis on this topic? I thought once I got them into a list I could use geopy to visualive it possibly, any thoughts?
colors = {'LOC': 'linear-gradient(90deg, ~aa9cde, #dc9ce7)', 'GPE' : 'radial-gradient(white, blue)'}
options = {'ents' : ['LOC', 'GPE'],'colors':colors}
spacy.displacy.render(doc, style='ent',jupyter=True, options=options, )
The entities are accessible on the doc object. If you want to get all the ents in the doc object into a list, simply use, doc.ents. For example:
import spacy
content = "Narendra Modi is the Prime Minister of India"
nlp = spacy.load('en_core_web_md')
doc = nlp(content)
print(doc.ents)
should output:
(Narendra Modi, India)
Say, you want to the text (or mention) of the entity and the label of the entity (say, PERSON, GPE, LOC, NORP, etc.) then you can get them as follows:
print([(ent, ent.label_) for ent in doc.ents])
should output:
[(Narendra Modi, 'PERSON'), (India, 'GPE')]
You should be able to use them in other places as you see fit.

Subjunctive mood in Spanish in GF

What is the correct grammar tree in GF for generating sentences in Spanish:
a) that contain subjunctive mood.
b) which the subject is a sentence too.
an example:
me gusta que mi jefe no trabaje hoy
Let's construct this piece by piece.
bossDoesntWork_S : S = mkS negativePol (mkCl (mkNP i_Pron boss_N) work_V) ;
Checking out the table, we see that both indicative and subjunctive are retained.
> cc -table bossDoesntWork_S
s . CommonRomance.Indic => mi jefe no trabaja
s . CommonRomance.Conjunct => mi jefe no trabaje
So now we need to give this as an argument to some VS, which forces out the subjunctive. Let's construct one—there is a ready-made constructor in ParadigmsSpa, called subjVS : V -> VS.
likeThat_VS : VS = subjVS like_V ;
Now let's test that:
> cc -one mkS ( mkCl (mkNP i_Pron) likeThat_VS bossDoesntWork_S)
yo gusto que mi jefe no trabaje
The subjunctive is correct, but unfortunately, the dative agreement isn't working properly. That's a known issue, and I have tried to fix it, but adding it on top, in a way that everything works properly, makes the whole grammar just really slow. (I wonder if it was more feasible, if Spanish didn't use the Romance functor, but that's not something I'm willing to try. :-P)
The complete grammar
So, the subjunctive part of this is easy. Here's a grammar for you to try out.
resource Subjunctive = open SyntaxSpa, LexiconSpa, ParadigmsSpa in {
oper
likeThat_VS : VS = subjVS like_V ;
bossDoesntWork_S : S = mkS negativePol (mkCl (mkNP i_Pron boss_N) work_V) ;
-- lexicon
like_V : V = <like_V2 : V> ; --treat LexiconSpa.like_V2 as V
work_V : V = mkV "trabajar" ;
}
Note on dative verbs
So what to do with dative verbs? For V2, you can just flip the subject and the object. But for VS, it's trickier, and would require ~ugly~creative hacks.
For now, I would suggest postprocessing, as in this answer. The good side with a dative verb as a VS is that the verb will always inflect in 3rd person singular, so you don't have the situation like "me gustas tu" vs. "me gustan ustedes". You can safely postprocess "yo gusto que" into "me gusta que".
If the RGL is fixed to include proper handling of dative verbs, I'll update this answer.

How to trace Grammatical Framework parse: example WordNet imports badly

I am trying to use WordNetEng concrete grammar https://github.com/GrammaticalFramework/gf-wordnet which, as I understand - uses all the standard grammar features (from the GF base installation), but greatly expands lexicon. My GF installation is working, e.g.:
> import C:\Workspace-Data\GF\AllEng.gfo
linking ... OK
Languages: AllEng
3031 msec
AllEngAbs> parse "turtle is good"
The parser failed at token 1: "turtle"
31 msecAllEngAbs> parse "dog is good"
PredVPS (MassNP (UseN dog_N)) (MkVPS (TTAnt TPres ASimul) PPos (UseComp (CompAP (PositA good_A))))
PredVPS (MassNP (UseN dog_N)) (MkVPS (TTAnt TPres ASimul) PPos (UseComp (CompNP (AdjAsNP (PositA good_A)))))
...
But I can import WordNetEng, but it does not recognize nor the turtle, nor other common words, including dog:
AllEngAbs> import C:\Workspace-Data\GF\WordNetEng.gf
linking ... OK
Languages: WordNetEng
5468 msec
WordNet> parse "tortoise is good"
The parser failed at token 1: "tortoise"
4234 msec
WordNet> parse "dog is good"
The parser failed at token 1: "dog"
0 msec
What is wrong? How GF can import the grammar (quite complex set of files) and then can not parse the simplest sentences? How can I debug this and correct this? Thanks!
Maybe there is option to list all the grammatical categories or terminals that have been imported in the session, e.g. in that way I could see whther the "tortoise" is imported or not?
I tried to generate random sentences, but there is strange error:
WordNet> gr
no trees found
0 msec
The WordNet lexicon is just a lexicon. It uses the categories from the standard RGL, but not the rest of the RGL functions. This is the abstract syntax:
abstract WordNet = Cat ** {
fun a_bomb_N : N ;
...
fun zymotic_2_A : A ;
}
So your result is completely expected.
Parse with RGL+WordNet
If you want to parse with the RGL and the WordNet lexicon, you can use the Parse module in the same repo, gf-wordnet/Parse.gf.
A warning though, that grammar can be very ambiguous. Most of the ambiguity comes from the fact that the every word has several versions, but you can also experiment with commenting out ParseExtend and see if that contributes to the multiple parses.
Use it like this:
$ gf ParseEng.gf
Parse> p "I am a human"
PhrUtt NoPConj (UttS (UseCl (TTAnt TPres ASimul) PPos (PredVP (UsePron iFem_Pron) (UseComp (CompCN (UseN human_N)))))) NoVoc
PhrUtt NoPConj (UttS (UseCl (TTAnt TPres ASimul) PPos (PredVP (UsePron iFem_Pron) (UseComp (CompNP (DetCN (DetQuant IndefArt NumSg) (UseN human_N))))))) NoVoc
PhrUtt NoPConj (UttS (UseCl (TTAnt TPres ASimul) PPos (PredVP (UsePron i_Pron) (UseComp (CompCN (UseN human_N)))))) NoVoc
PhrUtt NoPConj (UttS (UseCl (TTAnt TPres ASimul) PPos (PredVP (UsePron i_Pron) (UseComp (CompNP (DetCN (DetQuant IndefArt NumSg) (UseN human_N))))))) NoVoc
But it will still be ambiguous, because some of the words belong to lots of different synsets (20 synsets for the word good), and a long sentence may contain several such words.
Use WordNet lexicon in an application grammar
If you write an application grammar, you can always open WordNet in it, like any other module. For instance, to recreate the Foods example from the tutorial, we could write the parametrised module (functor) FoodsI.gf like this instead:
incomplete concrete FoodsI of Foods = open Syntax, WordNet in {
lincat
Phrase = Cl ;
Item = NP ;
Kind = CN ;
Quality = AP ;
lin
Is item quality = mkCl item quality ;
This kind = mkNP this_Det kind ;
That kind = mkNP that_Det kind ;
These kind = mkNP these_Det kind ;
Those kind = mkNP those_Det kind ;
QKind quality kind = mkCN quality kind ;
Very quality = mkAP very_AdA quality ;
Wine = mkCN wine_1_N ; -- All these from WordNet
Fish = mkCN fish_2_N ;
...
}
and instantiate it for a concrete language like this
concrete FoodsEng of Foods = FoodsI with
(Syntax = SyntaxEng),
(LexFoods = WordNetEng) ;

The relative clause (which) in GF

"Play Toy Story which was published last year"
Sentence = mkUtt( mkImp (mkVP
(mkV2 "play")
(mkNP (mkCN
(mkCN (mkN "Toy Story"))
(mkS pastTense simultaneousAnt(mkCl (mkVP
(mkV2 "publish")
(mkNP (mkCN (mkN "last yser")))
)))
))
));
When creating a relative clause sentence in GF it always the syntax S for sentence will add that between the two of the sentences is there is any way to replace that with which.
First of all, the structure you made isn't a relative clause, but this structure:
mkCN : CN -> S -> CN -- rule that she sleeps
Relative clause has the type RS in the RGL.
How to construct an actual RS
Here I build the RS gradually. Feel free to put these steps back to a single expression, if you wish so, but I find it clearer to to things like this.
oper
last_year_Adv : Adv = ParadigmsEng.mkAdv "last year" ;
published_last_year_VP : VP = mkVP (passiveVP (mkV2 "publish")) last_year_Adv ;
which_is_published_last_year_RCl : RCl = mkRCl which_RP published_last_year_VP ;
which_was_published_last_year_RS : RS = mkRS pastTense which_is_published_last_year_RCl ;
lin
play_TS = mkUtt (mkImp (mkVP
(mkV2 "play")
(mkNP
(mkNP (mkPN "Toy Story"))
which_was_published_last_year_RS)
)
) ;
Now when we test it on the GF shell, we see that despite the name, which_RP is actually "that".
> l play_TS
play Toy Story , that was published last year
How to change "that" into "which"
The first thing to check when you want to create a new lexical item is Paradigms module. Unfortunately, there is no mkRP for English. Things like relative pronouns are usually thought of as closed class: there's only a small, fixed amount of them. Other examples of closed classes are basic numerals (you can't just make up a new integer between 4 and 5!) and determiners. Contrast this to open classes like nouns, verbs and adjectives, those pop up all the time. For open classes, Paradigms modules have many options. But not for closed classes, like relative pronouns.
So if Paradigms doesn't help, the next thing to check is the language-specific Extra module.
Check language-specific Extra modules
If you have the RGL source on your own computer, you can just go to the directory gf-rgl/src/english and grep for which. Or you can use the RGL browser to search for interesting functions.
And there is indeed a relative pronoun in ExtraEng, also called which_RP. (There is also one called who_which_RP.) So now you can do these modifications in your grammar:
concrete MyGrammarEng of MyGrammar =
open SyntaxEng,
ParadigmsEng,
ExtraEng -- Need to open ExtraEng in the concrete!
in ** {
-- … as usual, except for
oper
which_is_published_last_year_RCl : RCl =
mkRCl ExtraEng.which_RP -- Use the ExtraEng.which_RP!
published_last_year_VP ;
And the rest of the code is like before. This produces the result you want.
> l play_TS
play Toy Story , which was published last year
Last-resort hack
So you have looked in all possible modules and found nothing. Consider making it into an issue in the gf-rgl repository, if it's something that's clearly wrong or missing.
But in any case, here's a general, unsafe hack to quickly construct what you want.
First, let's look at the lincat of RP in CatEng, {s : RCase => Str ; a : RAgr}. Then let's look at its implementation in RelativeEng. There you see also the explanation why it's always "that": unlike who and which, "that" works for animate and inanimate NPs.
So I would do this to force the string "which":
oper
myWhich_RP : RP = which_RP ** {s = table {_ => "which"}} ;
The ** syntax means record extension. We use all other fields from the original which_RP, but in the s field, we put a table whose all branches contain the string "which". (You can read more about this technique in my blog.)
Then we use the newly defined myWhich_RP in forming the relative clause:
oper
which_is_published_last_year_RCl : RCl = mkRCl myWhich_RP published_last_year_VP ;
This works too, but it's unsafe, because whenever the RGL changes, any code that touches the raw implementation may break.

adding (|) functionality to determiner on GF

On GF writing sentences' tree often encounter many options where multiple prepositions could be used in the same tree such as
Download it on my phone
Download it to my phone
Download it onto my phone
... and the list goes on and on.
this kind of problem could be solved as below
(on_Prep|to_Prep|...)
But in some situations, this problem occurs with determiners such as
Eat the food
Eat food
I know the meaning of the above sentences is not exactly the same but is there any way to accomplish such a goal?
I tried the following but it seemed unlogical.
mkNP
(the_Det|)
(mkN ("food"))
I also tried to add an empty string for determiner such as mkDet (mkDigits (""))
but unfortunately, the above two ways seem not smart enough.😁😁
Your general approach with using | is correct.
There is no empty determiner, but rather another overload instance of mkNP. There's one with a determiner (so Det -> N -> NP) and another without, just N -> NP. So you can do this:
eat_food_VP : VP =
mkVP eat_V2 (mkNP the_Det food_N | mkNP food_N) ;