:- op(500,yfx,&), op(600,yfx,'\/'),
    op(600,xfx,'=>'), op(600,xfx,'<=>').

kleinschreibung(Wort,Klein) :-
    atom(Wort),
    name(Wort,[C|Chars]),
    (member(C,"ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜ")
    ->  K is C+32,           
        name(Klein,[K|Chars])
    ; Klein = Wort).

sem([en(Art,Form), [Vollform]],LamTerm) :-
    wort(Stammform, en(Art,Form), Vollform),
    kleinschreibung(Stammform,EN),
    LamTerm = EN.

sem([rn(Art,Form), [Vollform]],LamTerm) :-
    wort(Stammform, rn(Art,Form), Vollform),
    kleinschreibung(Stammform,Stamm),
    Formel =.. [Stamm,X,Y],
    LamTerm = lam(X,lam(Y,Formel)).

sem([v([nom,akk],Form),[Vollform]],LamTerm) :-
    kleinschreibung(Vollform,VollformKl),
    wort(Stammform,v([nom,akk],Form),VollformKl),
    Formel =.. [Stammform,X,Y],
    LamTerm = lam(X,lam(Y,Formel)).
   
sem([n(Art,Form),[Vollform]],LamTerm) :-
    wort(Stammform, n(Art,Form), Vollform),
    kleinschreibung(Stammform,Stamm),
    Formel =.. [Stamm,X],
    LamTerm = lam(X,Formel).
   
sem([n(Art,Form),[rn(Art,Form),[Vollform]]],LamTerm) :-
    wort(Stammform, rn(Art,Form), Vollform),
    kleinschreibung(Stammform,Stamm),
    Formel =.. [Stamm,X],
    LamTerm = lam(X,Formel).
   
sem([det([quant],_Form),_Vollform],
    lam(N,lam(P,all(X,N*X => P*X)))).

sem([det([indef],_Form),_Vollform],
    lam(N,lam(P,ex(X,N*X & P*X)))).

sem([det([def],[_,pl,_]),[Vollform]],
    lam(N,lam(P, anzahl(X,N*X & P*X,Zahl)))) :-
    anzahl(Vollform,Zahl), !.
sem([det([def], [_,sg,_]),_Vollform],
    lam(N,lam(P,
    ex(Y,all(X,eq(X,Y) <=> N*X) & P*Y)))).

sem([det([qu], _Form),_Vollform],
    lam(N,lam(P,qu(X,N*X & P*X)))).  

sem([a([als(nom)],[komp]),[kleiner]],
    lam(X,lam(Y,(X < Y)))). % Fehlermeldung?
sem([a([als(nom)],[komp]),[größer]],
    lam(X,lam(Y,(Y < X)))). % > kein Grundprädikat

sem([pron([rel],_Form),_Rel], lam(P,lam(X,P*X))).
sem([pron([qu],_Form),_Pron], lam(P,qu(X,P*X))).

sem([poss([rel],[_Gen,_Num,gen]),_Poss],
    lam(RN,lam(P,lam(Y,ex(X,RN*X*Y & P*X))))).
    % nur bei RNsg 
sem([np([_,3,_],[_,_]),
       Det, [n(Art,Form),Vf]], SemNP) :-
    sem(Det,SemDet),
    Vf \= km, sem([n(Art,Form),Vf],SemN),
    normalize(SemDet * SemN,SemNP).

sem([np([def,3,Gen],[Num,Kas]),
       [en([Gen],[Num,Kas]),EN]], SemNP) :-
    sem([en([Gen],[Num,Kas]),EN],SemEN),
    SemNP = lam(P,P*SemEN).
sem([np([def,3,Gen],[Num,_Kas]),
       [det([def],_),_],
       [en([Gen],[Num,nom]),EN]],
    SemNP) :-
    !, sem([en([Gen],[Num,nom]),EN],SemEN),
    SemNP = lam(P,P*SemEN).
sem([np([def,3,Gen],[Num,Kas]), 
       [det([def],_),_],
       [n([Gen],[Num,Kas]),N],
       [en([Gen2],[Num,nom]),EN]], SemNP) :-
    !, sem([n([Gen],[Num,Kas]),N],SemN),
    sem([en([Gen2],[Num,nom]),EN],SemEN),
    SemNP = lam(P,SemN*SemEN & P*SemEN).

sem([np([Def,3,Gen],[Num,Kas]),
      [pron([DefP],[Gen,Num,Kas]),Pron]],
    SemNP) :-
    ( DefP = rel, Def = rel(Gen,Num)
    ; DefP = qu, Def = qu ),
    sem([pron([DefP],[Gen,Num,Kas]),Pron],
        SemNP).

sem([np([rel(Gen2,Num2),3,Gen],[sg,Kas]),
       [poss([rel],[Gen2,Num2,gen]),Poss],
       [rn([Gen],[sg,Kas]),RN]],
    SemNP) :-
    sem([poss([rel],[Gen2,Num2,gen]),Poss],
        SemPoss),
    sem([rn([Gen],[sg,Kas]),RN],SemRN),
    normalize(SemPoss*SemRN,SemNP).

sem([np([_,3,_],[_,_]),
       [det([def],_),[Zahlatom]],[n(_,_),[km]]],
    lam(P,P*Zahl)) :-
    anzahl(Zahlatom,Zahl). % Ausnahme: Maß

sem([np([_,3,_],[_,_]),
       Det,[rn(Art,Form),RN],NPgen], Sem) :-
    sem(Det,SemDet),   
    sem([rn(Art,Form),RN],SemRN),
    sem(NPgen,SemNPgen),
    SemN = lam(X,SemNPgen*lam(Y,(SemRN*X)*Y)),
    normalize(SemDet*SemN,Sem).

sem([s([_Def],[_,_,vz]),
      NP1, [v([nom,akk],[3,Num,_,ind]),V], NP2],
    SemS)
:-  sem(NP1,SemNP1), sem(NP2,SemNP2),
    sem([v([nom,akk],[3,Num,_,ind]),V], SemV),
    NP1 = [np([_,3,_],[Num1,Kas1])|_Konst], 
    (Kas1 = nom, Num1 = Num,
        Sem = SemNP1 * lam(X,SemNP2 *
                          lam(Y,SemV * X * Y))
    ; Kas1 = akk,
        Sem = SemNP1 * lam(Y,SemNP2 *
                          lam(X,SemV * X * Y))
    ), normalize(Sem,SemS).
       
sem([s([qu],[_,ind,ve]),
      [v([nom,akk],[3,Num,_,ind]),V], NP1, NP2],
    SemS)
:-
    sem([v([nom,akk],[3,Num,_,ind]),V], SemV),
    sem(NP1,SemNP1), sem(NP2,SemNP2),
    NP1 = [np(_,[Num1,Kas1])|_Konstituenten], 
    (Kas1 = nom, Num1 = Num,
        Sem = SemNP1 * lam(X,SemNP2 *
                          lam(Y,SemV * X * Y))
    ; Kas1 = akk,
        Sem = SemNP1 * lam(Y,SemNP2 *
                          lam(X,SemV * X * Y))
    ), normalize(Sem,SemS).
       
sem([s([qu],[_,ind,ve]),
      [v([sein],[3,Num,_,ind]),_V], NP1, NP2],
    SemS)
:-
    NP1 = [np(_,[Num,nom])|_Konst1],
    NP2 = [np([Def2,3,_],[Num,nom])|_Konst2], 
    sem(NP1,SemNP1),
    sem(NP2,SemNP2), (Def2 = indef ; Def2 = def), 
    Sem = SemNP1*lam(X,SemNP2*lam(Y,eq(X,Y))),
    normalize(Sem,SemS).

sem([s([qu],[_,ind,ve]),
      [v([sein],[3,Num,_,ind]),_], NP1, AP],
    SemS)
:-
    NP1 = [np(_,[Num,nom])|_Konst1],
    AP  = [ap([def],[komp])|_Konst2], 
    sem(NP1,SemNP1), sem(AP,SemAP),
    normalize(SemNP1*SemAP, SemS).

sem([s([rel(GenR,NumR)],[Tmp,Mod,vl]),
      NP1,
      NP2, 
      [v([nom,akk],[3,Num,Tmp,Mod]),V]],
    SemS)
:-
    NP1 = [np([rel(GenR,NumR),3,GenR],[_,Kas1])|_], 
    sem(NP1,SemNP1),
    sem([v([nom,akk],[3,Num,Tmp,Mod]),V], SemV),
    sem(NP2,SemNP2),
    ( Kas1 = nom, Sem =
      SemNP1 * lam(X,SemNP2 * lam(Y,SemV * X * Y))
    ; Kas1 = akk, Sem =
      SemNP1 * lam(Y,SemNP2 * lam(X,SemV * X * Y))
    ),
    normalize(Sem,SemS).
       
sem([s([rel(GenR,NumR)],[Temp,ind,vl]),
      NP1, AP, [v([sein],[3,Num,Temp,ind]),_]],
    SemS)
:-
    NP1 = [np([rel(GenR,NumR),3,_],[Num,nom])|_],
    AP  = [ap([def],[komp])|_Konst2], 
    sem(NP1,SemNP1),
    sem(AP,SemAP),
    normalize(SemNP1*SemAP, SemS).

sem([s([rel(GenR,NumR)],[Temp,ind,vl]),
      NP1, NP2, [v([sein],[3,Num,Temp,ind]),_V]],
    SemS)
:-
    NP1 = [np([rel(GenR,NumR),3,_],[Num,nom])|_],
    NP2 = [np([Def2,3,_],[Num,nom])|_Konst2], 
    sem(NP1,SemNP1),
    sem(NP2,SemNP2), (Def2 = indef ; Def2 =def),
    Sem = SemNP1*lam(X,SemNP2*lam(Y,eq(X,Y))),
    normalize(Sem,SemS).

sem([np([_Def,3,Gen],[Num,Kas]),
       DET,
       [n([Gen],[Num,Kas]), N],
       [s([rel(Gen,Num)],[_,_,vl])|Konst]], 
    LamTerm)
:-
    sem(DET,SemDET),
    sem([n([Gen],[Num,Kas]),N],SemN),
    sem([s([rel(Gen,Num)],[_,_,vl])|Konst],SemSREL),
    SemNREL = lam(X,(SemN * X) & (SemSREL * X)),
    normalize(SemDET * SemNREL, LamTerm).
        
sem([ap([def],[komp]),
       [a([als(nom)],[komp]),Adj], [als], NP], 
    SemAP)
:-  sem([a([als(nom)],[komp]),Adj], SemAdj),
    NP = [np([_,3,_],[_,nom])|_],
    sem(NP,SemNP),
    normalize(lam(X,SemNP*lam(Y,SemAdj*X*Y)), SemAP).    
       
sem([np([rel(Gen2,Num2),3,Gen],[pl,Kas]),
       [poss([rel],[Gen2,Num2,gen]),_Poss],
       [rn([Gen],[pl,Kas]),RN]],
    SemNP) :-
    SemPoss = lam(R,lam(P,lam(Y,
                 all(X,R*X*Y => P*X)))),
    sem([rn([Gen],[pl,Kas]),RN],SemRN),
    normalize(SemPoss*SemRN,SemNP).

sem([v([werden],_Form),_Vollform],LamTerm) :-
   LamTerm = lam(TV,lam(Y,ex(X,(TV * X) * Y))).

sem([s([qu],[_,_,ve]),
         [v([werden],Form),PassAux], NP, 
         [v([nom,akk],[part2]),TV]],
    SemS) :-
    sem(NP,SemNP),
    sem([v([werden],Form),PassAux], SemPassAux),
    sem([v([nom,akk],[part2]),TV], SemTV),
    normalize(SemNP * (SemPassAux * SemTV), SemS).

sem([s([_Def],[_,_,vz]),
         NP, [v([werden],Form),PassAux],
         [v([nom,akk],[part2]),V]],
    SemS) :-
    sem(NP,SemNP),
    sem([v([werden],Form),PassAux], SemPassAux),
    sem([v([nom,akk],[part2]),V], SemTV),
    normalize(SemNP * (SemPassAux * SemTV), SemS).

sem([s([_Def],[_,_,vl]),
         NP, [v([nom,akk],[part2]),V],  
         [v([werden],Form),PassAux]],
    SemS) :-
    sem(NP,SemNP),
    sem([v([werden],Form),PassAux], SemPassAux),
    sem([v([nom,akk],[part2]),V], SemTV),
    normalize(SemNP * (SemPassAux * SemTV), SemS).

sem([s([qu],[_,_,ve]),
         [v([werden],_Form),_PassAux],
         NP, von, NPsbj,
         [v([nom,akk],[part2]),TV]],
    SemS) :-
    sem(NP,SemNP),
    NPsbj = [np([_Def2,_Pers2,_Gen2],[_Num2,dat]) | _],
    sem(NPsbj,SemNPsbj),
    sem([v([nom,akk],[part2]),TV], SemTV),
    normalize(SemNP * lam(Y,SemNPsbj
                      * lam(X,(SemTV*X)*Y)), SemS).

sem([s([_Def],[_,_,vz]),
         NPobj,
         [v([werden],_Form),_PassAux],
         von, NPsbj,
         [v([nom,akk],[part2]),TV]],
    SemS) :-
    sem(NPobj,SemNPobj),
    NPsbj = [np([_Def2,_Pers2,_Gen2],[_Num2,dat]) | _],
    sem(NPsbj,SemNPsbj),
    sem([v([nom,akk],[part2]),TV], SemTV),
    normalize(SemNPobj * lam(Y,SemNPsbj
                         * lam(X,(SemTV*X)*Y)), SemS).

sem([s([_Def],[_,_,vl]),
         NP, von, NPsbj,
         [v([nom,akk],[part2]),TV],
         [v([werden],_Form),_PassAux]],
    SemS) :-
    sem(NP,SemNP),
    NPsbj = [np([_Def2,_Pers2,_Gen2],[_Num2,dat]) | _],
    sem(NPsbj,SemNPsbj),
    sem([v([nom,akk],[part2]),TV], SemTV),
    normalize(SemNP * lam(Y,SemNPsbj
                      * lam(X,(SemTV*X)*Y)), SemS).

sem([s([rel(GenR,NumR)],[Temp,Mod,vl]),
     NPrel, NPteil,
     [v([sein],[3,Num2,Temp,Mod]),_Verb],
     [s([rel(Gen2,Num2)],[Temp2,Mod2,vl])|Cs]],
    SemS) :-
   NPrel = [np([rel(GenR,NumR),3,_],[_Num,_nom])|_],
   NPteil = [np([Def2,3,Gen2],
                [Num2,nom])/s([rel(Gen2,Num2)],
                              [Temp2,Mod2,vl])|_],
   (Def2 = indef ; Def2 = def),
   sem(NPrel,SemNPrel),
   sem(NPteil,SemNPteil), 
   sem([s([rel(Gen2,Num2)],[Temp2,Mod2,vl])|Cs],SemRelS),
   Sem = SemNPrel*lam(X,(SemNPteil*SemRelS)
                         * lam(Y,eq(X,Y))),
   normalize(Sem,SemS).

sem([s([rel(_GenR,_NumR)],[Temp,Mod,vl]),
     NPrel, NPteil, 
     [v([nom,akk],[3,Num,Temp,Mod]),TV],
     RelS],
    SemS) :-
    NPteil = [np([_Def2,3,Gen2],
                 [Num2,_Kas2])/s([rel(Gen2,Num2)],
                                [Temp2,Mod2,vl])|_],
    RelS = [s([rel(Gen2,Num2)],[Temp2,Mod2,vl])|_Cs],
    sem(NPrel,SemNPrel),
    sem(NPteil,SemNPteil),
    sem(RelS,SemRelS),
    sem([v([nom,akk],[3,Num,Temp,Mod]),TV],SemTV),
    Sem = SemNPrel*lam(X,(SemNPteil*SemRelS)
                              * lam(Y,(SemTV * X) * Y)),
    normalize(Sem,SemS).

sem([np([_Def,3,Gen],
        [Num,_Kas])/s([rel(Gen,Num)],[Temp,Mod,vl]),
     Det,N,RelS],
    SemNP) :-
    RelS = [s([rel(Gen,Num)],
              [Temp,Mod,vl])/s([rel(Gen,Num)],
                               [Temp,Mod,vl])|_Cs],
    sem(Det,SemDet), sem(N,SemN),
    SemNPE = lam(Q, SemDet * lam(X, SemN*X & Q*X)),
    normalize(SemNPE,SemNP).

sem([s([rel(Gen,Num)],
       [Temp,Mod,vl])/s([rel(Gen,Num)],[Temp,Mod,vl])],
    lam(P,P)).

sem([a([equ,Grad],[pos|Form]),[Vollform]],LamTerm) :- 
    wort(Stammform,a([equ,Grad],[pos|Form]),Vollform),
    dim(Stammform,_Pol,Dim),
    LamTerm = lam(N,lam(X, N*X & quant(Dim,X,Stammform))).
sem([ap([indef],[pos|Form]),A], SemAP) :-
    A = [a([equ,_Grad],[pos|Form]),[_Vollform]],
    sem(A,SemAP).
sem([a([dim,Grad],[pos|Form]),[Vollform]],LamTerm) :-
    poldim([a([dim,Grad],[pos|Form]),[Vollform]],Pol,Dim),
    LamTerm = [Pol,Dim].

quant(Dim,Objekt,Grad) :- datenbank:quant(Dim,Objekt,Grad).
dim(Adjektiv,Pol,Dim)  :- datenbank:dim(Adjektiv,Pol,Dim).
skala(Dim,Skala) :- datenbank:skala(Dim,Skala).
poldim([a([dim,Grad],Form),[Vollform]],Pol,Dim) :-
    wort(Stammform,a([dim,Grad],Form),Vollform),
    datenbank:dim(Stammform,Pol,Dim).
sem([a([dim,+grad],[komp]),[Vollform]],LamTerm) :-
    poldim([a([dim,+grad],[komp]),[Vollform]],Pol,Dim),
    skala(Dim,Skala),
    ( Pol = +, LamTerm =
      lam(C,lam(V,lam(X,ex(G,quant(Dim,X,G)
                             & (Skala:gt(G,C+V))))))
    ; Pol = -, LamTerm =
      lam(C,lam(V,lam(X,ex(G,quant(Dim,X,G)
                             & (Skala:lt(G+C,V))))))
    ).

sem([ap([def],[komp]),
     [a([dim,+grad],[komp]),[Vollform]], [als],
     [np([Def2,3,_Gen2],[_Num,nom]) | Cs]],Sem) :-
    sem([a([dim,+grad],[komp]),[Vollform]],SemA),
    sem([np([Def2,3,_Gen2],[_Num,nom])|Cs],SemNP),
    poldim([a([dim,+grad],[komp]),[Vollform]],_Pol,Dim),
    SemAP = lam(X, SemNP * lam(Y,ex(G,(quant(Dim,Y,G)
                                      & SemA*0*G*X)))),
    normalize(SemAP,Sem).

sem([s([qu],[Temp,Mod,ve]),
     [v([sein],[3,Num,Temp,Mod]),[_Vollform]],
     [np([Def1,3,_Gen1],[Num,nom])|CsNP],
     [ap([def],[Komp])|CsAP]],SemS) :-
    sem([np([Def1,3,_Gen1],[Num,nom])|CsNP],SemNP),
    sem([ap([def],[Komp])|CsAP],SemAP),
    normalize(SemNP*SemAP,SemS).

sem([s([_DefS],[Temp,Mod,vz]),
     [np([Def1,3,_Gen1],[Num,nom])|CsNP],
     [v([sein],[3,Num,Temp,Mod]),[_Vollform]],
     [ap([def],[Komp])|CsAP]],SemS) :-
    sem([np([Def1,3,_Gen1],[Num,nom])|CsNP],SemNP),
    sem([ap([def],[Komp])|CsAP],SemAP),
    normalize(SemNP*SemAP,SemS).

sem([s([rel(_,_)],[Temp,Mod,vl]),
     [np([Def1,3,_Gen1],[Num,nom])|CsNP],
     [ap([def],[Komp])|CsAP],
     [v([sein],[3,Num,Temp,Mod]),[_Vollform]]
    ],SemS) :-
    sem([np([Def1,3,_Gen1],[Num,nom])|CsNP],SemNP),
    sem([ap([def],[Komp])|CsAP],SemAP),
    normalize(SemNP*SemAP,SemS).

sem([s([def],[Temp,Mod,vl]),
     [np([Def1,3,_Gen1],[Num,nom])|CsNP],
     [ap([def],[Komp])|CsAP],
     [v([sein],[3,Num,Temp,Mod]),[_Vollform]]
    ],SemS) :-
    sem([np([Def1,3,_Gen1],[Num,nom])|CsNP],SemNP),
    sem([ap([def],[Komp])|CsAP],SemAP),
    normalize(SemNP*SemAP,SemS).

% Objekt X ist DimApos = DimAkomp als der Druchschnitt der N
semAabs([a([dim,Grad],[pos|Form]),[Vollform]],LamTerm) :-
    poldim([a([dim,Grad],[pos|Form]),[Vollform]],Pol,Dim),
    LamTerm = lam(N,lam(X,vglNorm(Pol,Dim,X,N))).
vglNorm(Pol,Dim,X,N) :- 
    normalize(qu(Y,N*Y),Qu), antworten(Qu,Ys), 
    maplist(quant(Dim),[X|Ys],[G|Gs]),
    skala(Dim,Skala), Skala:vglNorm(Pol,G,Gs).
% Sollte das wahr(vglNorm(Pol,Dim,X,N)) :- .. sein?
% Obj X ist mindestens Faktor mal so DimAPos wie Obj Y
semAfak([a([dim,Grad],[pos|Form]),[Vollform]],LamTerm) :-
    poldim([a([dim,Grad],[pos|Form]),[Vollform]],Pol,Dim),
    LamTerm = lam(F,lam(X,lam(Y,vglEqFak(Pol,Dim,X,Y,F)))).
vglEqFak(Pol,Dim,X,Y,Faktor) :- 
    quant(Dim,X,GradX),
    quant(Dim,Y,GradY),
    skala(Dim,Skala),
    Skala:vglEqFak(Pol,GradX,GradY,Faktor).

% Obj X ist mindestens Grad G DimAPos
vglEqG(Pol,Dim,X,G) :- 
    quant(Dim,X,GradX),
    skala(Dim,Skala),
    Skala:vglEqG(Pol,GradX,G).
semAgrd([a([dim,+grad],[pos|Form]),[Vollform]],LamTerm) :-
    poldim([a([dim,+grad],[pos|Form]),[Vollform]],Pol,Dim),
    LamTerm = lam(D,lam(X,vglEqG(Pol,Dim,X,D))).

sem([ap([indef],[pos|Form]),A],SemAP) :-
    A = [a([dim,_Grad],[pos|Form]),[_Vollform]],
    sem(A,[Pol,Dim]),
    SemAP = lam(N,lam(X, N*X & vglNorm(Pol,Dim,X,N))).

sem([ap([Def],[pos|Form]),GP,A],SemAP) :-
    GP = [gp([Def],[])|_KonstGP], sem(GP,SemGP),
    A = [a([dim,+grad],[pos|Form]),[_Vollform]],
    sem(A,[Pol,Dim]), 
    normalize(SemGP*Pol*Dim, SemAP).

sem([gp([def],[]),[anzahl(Zahl),_],[einheit,_E]],SemGP) :-
    SemGP = lam(Pol,lam(Dim,lam(G,lam(X,vglEqG(Pol,Dim,X,G)))*Zahl)).
sem([gp([indef],[]),[sehr]],SemGP) :-
    SemGP = lam(Pol,lam(Dim,lam(N,lam(X,vglRelNorm(Pol,Dim,X,N))))).
sem([gp([qu],[]),[wie]],SemGP) :-
    SemGP = lam(Pol,lam(Dim,qu(G,lam(X,quant(Dim,X,G))))).
sem([gp([qu],[]),[wieviele],[einheit,E]],SemGP) :-
    SemGP = lam(Pol,lam(Dim,qu(G,lam(X,quant(Dim,X,G))))).

vglRelNorm(Pol,Dim,X,N) :- 
    normalize(qu(Y,N*Y),Qu), antworten(Qu,Ys), 
    maplist(quant(Dim),[X|Ys],[G|Gs]),
    skala(Dim,Skala), Skala:vglRelNorm(Pol,G,Gs).

sem([s([qu],[Temp,Mod,vz]),
     [ap([qu],[pos])|CsAP],
     [v([sein],[3,Num,Temp,Mod]),_],
     [np([Def,3,_Gen1],[Num,nom])|CsNP]
    ],SemS) :-
    sem([ap([qu],[pos])|CsAP],qu(G,SemAP)),
    sem([np([Def,3,_Gen1],[Num,nom])|CsNP],SemNP),
    normalize(qu(G,SemNP * SemAP),SemS).
sem([ap([def],[pos]),
     [so],[a([dim,Grad],[pos]),[Vollform]],
     [wie],[np(_Art2,_Form2)|_Konst]], SemAP) :-
    semAfak([a([dim,Grad],[pos]),[Vollform]],SemAF),
    sem([np(_Art2,_Form2)|_Konst],SemNP),
    LamTerm = lam(X,SemNP * lam(Y,SemAF * 1 * X * Y)),
    normalize(LamTerm,SemAP).

sem([ap([Def],[pos]), [fp([Def],[])|KonstF],
     [so], [a([dim,Grad],[pos]),[Vollform]],
     [wie],[np(_Art2,_Form2)|_Konst]], SemAP) :-
    semAfak([a([dim,Grad],[pos]),[Vollform]],SemAF),
    sem([np(_Art2,_Form2)|_Konst],SemNP),

    sem([fp([Def],[])|KonstF],F),
    LamTerm = lam(X,SemNP * lam(Y,SemAF * F * X * Y)),
    normalize(LamTerm,SemAP).

sem([fp([def],[]),[anzahl(N),_Atom],[mal]],N).
sem([fp([def],[]),[doppelt]],2).
sem([fp([def],[]),[halb]],0.5).
sem([fp([def],[]),[ein],[drittel]],0.3).
sem([fp([def],[]),[zwei],[drittel]],0.6).
   
semAgrd([a([dim,Grad],[komp|Form]),[Vollform]],LamTerm) :-
    poldim([a([dim,Grad],[komp|Form]),[Vollform]],Pol,Dim),
    LamTerm = lam(D,lam(X,lam(Y,vglEqDiff(Pol,Dim,X,Y,D)))).

% Obj X ist mindestens um die Differenz D DimPos-er als Obj Y
vglEqDiff(Pol,Dim,X,Y,Diff) :- 
    quant(Dim,X,GradX),
    quant(Dim,Y,GradY),
    skala(Dim,Skala),
    Skala:vglEqDiff(Pol,GradX,GradY,Diff).

sem([np(_Art,_Form),Det,AP,N],SemNP) :-
   sem(Det,SemDet),
   AP = [ap([DefAP],[Komp|_])|CsAP],
   sem(N,SemN),
   sem(AP,SemAP),
   ( DefAP = def,
       NP = lam(X,(SemN*X) & (SemAP*X))
   ; DefAP = indef,
       NP = lam(X, (SemAP*SemN)*X)
   ),
   normalize(SemDet * NP, SemNP).

% Sequenz von attr.APs:
sem([ap([DefAP],[pos|_])|CsAP],SemAP) :-
   reverse(CsAP,[[ap(Def2,Komp2)|Cs2]|CsRev]),
   sem([ap(Def2,Komp2)|Cs2],SemAP2),
   reverse(CsRev,CsAP1),
   sem([ap([DefAP],[pos|_])|CsAP1],SemAP1),
   normalize(lam(N,lam(X,SemAP1*(SemAP2*N)*X)),SemAP).

