Not logged in. · Lost password · Register

PelinGenc
Member since Apr 2018
15 posts
Subject: Assignment 1
Hallo Frederik,

ich habe Problem im "oper" Teil.
Ich habe die mkN und mkAdj so definiert:

   mkN : Str -> Gender=>Str  = \ N -> table {masculine => "der" ; feminine => "die" ; neuter => "das"};
   mkAdj : Adj -> Str= \str -> lin Adj {s= str ++ "e"} ;

und es funktioniert nicht.

ich habe den Logik unter der Notation im Fragment 0.1 /oper nicht verstanden, deswegen kann ich es zum Assignment nicht implementieren.

Kannst du die Notation im Fragment 0.1 /oper (unten)  modular interpretieren?
    mkNP : Str -> NP = \str -> lin NP {s = str; p = Sg};
    mkVP : Str -> Str -> Plurality=>Str = \s1 -> \s2 -> table {Sg => s1; Pl => s2};


Kannst du auch sschreiben was falsch in meiner Definition ist?

Viele Grüße
Pelin
jfschaefer
Member for 2 months
29 posts
Hallo Pelin,

I'll describe the opers from fragment 0.1 in English so that I can potentially reuse it in the future.

Let's start with the motivation for mkNP:
We defined NP to be a record type with two entries - a string and the plurality. In the lexicon, we can therefore introduce noun phrases in the following way:
john = { s = "John"; p = Sg };
mary = { s = "Mary"; p = Sg };
berti = { s = "Berti"; p = Sg };
For a long dictionary that is a lot of copy-pasting and it is not easy to refactor in case we want to change something about NP.
So, instead we create an operation (I think of them as typed macros) that creates these NPs for a string, which allows us to write
mary = mkNP "Mary";

mkNP therefore takes a string produces an NP. Therefore, the type of mkNP is Str -> NP.
Apart from the type, we also need a definition for mkNP.
We use lambda notation for that. The lambda is written as a backslash in GF:
\str -> lin NP { s = str; p = Sg };
in other words: mkNP takes an argument that is a string (we know that from the type). We call this argument str und use it to create an NP.

An operation has therefore the following structure: NAME : TYPE = DEFINITION.
In the case of mkVP, we do basically the same thing, but we get two strings as arguments, which we call s1 and s2.
The type is Str -> Str -> Plurality=>Str, because we use currying. The result type in this case is a table (Plurality=>Str).


Now, about your operations: You probably need to think a bit more about the types of your operations. What kind of arguments do they get and what do the return?
The type of mkAdj indicates that it gets an adjective (Adj) as an argument and then returns a string. Probably it should be the other way around.
For mkN you currently return a table. The type should be something like Str -> Gender -> N, because you get a string ("Elefant") and a gender (masculine) and should create a noun.


I believe that you may not have chosen good types for Adj and N.
I suggest you try to make your grammar work without using any opers (i.e. replace my zebra = mkN "Zebra" neuter with whatever you need for your grammar).
And when that works, you can try to replace the repetitive parts with opers.

I hope this helps :) Feel free to ask follow-up questions.

Viele Grüße
Frederik
PelinGenc
Member since Apr 2018
15 posts
Subject: Problem in lin / AnimalGrammarGer
Hi Frederik,

In my lin / AnimalGrammarGer:

        -- TODO
        makeAdj a = a + "e";
        makeN Adj N = {s= Adj ++ N.s; g=Gender};
        makeNP Art N = Art ! N.g ++ N.s ;       
        makeVP Be Adj = Be ++ Adj;
        makeS NP V =  NP ++ V;

there is an error:

      Happened in linearization of makeN
      type of Gender
      expected: AnimalGrammarGer.Gender
      inferred: PType

It asks type of gender. In makeN, it is independent of gender.
If I write for example g=masculine, it doesn't give an error.
How should I define g= ?

Thanks in advance.
Pelin
jfschaefer
Member for 2 months
29 posts
Hi Pelin,

g has to be a specific gender. So if you use g=Gender, GF still doesn't know what gender that noun has.
That's why g=masculine works. Then the noun will be masculine. However, not every noun is masculine.
When you use makeN, you combine and adjective (Adj) and a noun (N) into a new noun. For example "klein" and "Löwe" should become "kleine Löwe". Or, more precise "kleine" and {s = "Löwe"; g = masculine} should become {s = "kleine Löwe"; g = masculine}.
In particular, "kleine Löwe" inherits the gender from "Löwe", i.e. the gender should be N.g.
I hope this helps :)
Frederik
PelinGenc
Member since Apr 2018
15 posts
Hi Frederik,

thank you for the previous answer.

I have a new question.

I want to define Adj as when it is used with noun then add "e", and when used after Be, then add nothing. But I have an error :
        In makeN: unsupported token gluing: Adj_0 + "e"

Below is the code:
        makeN Adj N = {s = Adj + "e" ++ N.s; g= N.g};
        makeNP Art N = Art ! N.g ++ N.s ;       
        makeVP Be Adj = Be ++ Adj;
        makeS NP VP =  NP ++ VP;

If I use ++ before "e", then "e" is written separately from the adjective.
Is it possible in makeN to add "e" to the adjective without a space?

Best,
Pelin
jfschaefer
Member for 2 months
29 posts
Hi Pelin,

that's a great question and it touches on a topic that we haven't really discussed yet.

Short answer: You can't use + in the lin section, you can only use it in the oper section.

Longer answer: When you parse a sentence with GF, it sees it as a sequence of tokens.
For example the sentence "die langsame Giraffe" could be split into the token sequence x01 ++ x06 ++ x03, where for example x06 corresponds to "langsame".
At runtime, GF only sees these tokens, not the strings anymore. So the only place where you can change words (like converting "langsam" into "langsame") is at compile time.

So: You can't just say "Adj = Str", Adj actually needs to be a record or a table type and contain both forms ("langsam" and "langsame").

I admit that this is a little confusing.

Best,
Frederik
PelinGenc
Member since Apr 2018
15 posts
Hi Frederik,

your answer solved the problem, thanks.

Now I am having difficulty with the last question.
     --What GF command can you use to translate the German sentence "das kleine Zebra ist schnell"?

I wrote:
     parse -lang=Ger "das kleine Zebra ist schnell" | linearize -lang=Eng
It says:
     No lang

-lang=Eng or -lang=Ger works iff I run the corresponding grammer previously. However in translation I can't run both languages as a previous step.

For example: To run   parse -lang=Ger "das große Zebra ist langsam", I must first run the German grammer part. Otherwise I get an error:
      Unknown language: AnimalLexiconEng

Do you have any idea about this issue?


Best,
Pelin
jfschaefer
Member for 2 months
29 posts
Hi Pelin,

that's a weird bug. I am aware of it, but so far I failed to fix it. I'll give it another try :)

One work-around would be to use the normal GF-shell:

1. From the notebook you can export the grammar files with the command "export AnimalLexiconEng" etc.
2. You can start the GF shell in the command line with the command "gf"
3. You can import the grammars with "import AnimalLexiconEng.gf" and "import AnimalLexiconGer.gf"
4. Then you can type any command you want and hopefully don't have the same issue.

If there are any technical difficulties with this, we should discuss them on Wednesday.

Best,
Frederik
jfschaefer
Member for 2 months
29 posts
Hi,

one more remark on the "Unknown Language" issue:
This problem also exists in the normal GF shell. Here is roughly what happens:
1. Import AnimalLexiconEng. This sets the abstract syntax to AnimalLexicon.
2. Import AnimalGrammarGer. The new abstract syntax has to be AnimalGrammar, which means that anything up to here gets discarded (in particular AnimalLexiconEng).
3. Import AnimalLexiconGer. The new abstract syntax has to be AnimalLexicon, which means that anything up to here gets discarded. But since AnimalLexiconGer imports AnimalGrammarGer, that functionality is reimported.

The work-around is to skip the import of AnimalGrammarGer by simple executing the cell for AnimalLexiconEng and the cell for AnimalGrammarGer manually and then doing the translation.
We should add some functionality to the GF-Kernel for that.

Best,
Frederik
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Datenschutz | Kontakt
Powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2011 by Yves Goergen