假设我想写一个打招呼的代码,但出于某种原因,我不想打招呼一个叫 John 的人,我想让 GF 生成这种句子。
抽象版
我知道这种结果可以从抽象文件中实现,例如:GreetingFromAbstract.gf
abstract GreetingFromAbstract = {
flags startcat = Sentence;
cat
Relation;
Sentence;
Verb Relation;
Noun Relation;
fun
MySentence : (rel : Relation) -> Verb rel -> Noun rel -> Sentence;
Say : Verb RelA;
Mike : Noun RelA;
John : Noun RelB;
RelA, RelB : Relation;
}
具体文件是这样的:
GreetingFromAbstractEng.gf
concrete GreetingFromAbstractEng of GreetingFromAbstract = open SyntaxEng, ParadigmsEng, IrregEng, Prelude in {
lincat
Sentence = Phr;
Verb = V3;
Noun = N;
Relation = {s : Str};
lin
MySentence _ action person = sayHi (action) (person);
Say = mkV3(say_V) (noPrep) (to_Prep);
Mike = mkN("Mike");
John = mkN("John");
RelA, RelB = {s = ""};
oper
-- Generate the final sentence
sayHi : V3 -> N -> Phr =
\v, n -> mkPhr(mkUtt(mkImp(mkVP
(v)
(mkNP (mkN "hi"))
(mkNP (n)))));
}
谜
但是,假设出于某种原因,我不想从抽象文件而是从具体文件中做到这一点。我希望写名字的人决定向哪个人打招呼,哪个不打招呼。
具体版本
根据我的问题,我写了这段代码:GreetingFromConcrete.gf
abstract GreetingFromConcrete = {
flags startcat = Sentence;
cat
Sentence; Verb; Noun;
fun
MySentence : Verb -> Noun -> Sentence;
Say : Verb;
Mike : Noun;
John : Noun;
}
具体:GreetingFromConcreteEng.gf
concrete GreetingFromConcreteEng of GreetingFromConcrete = open SyntaxEng, ParadigmsEng, IrregEng, Prelude in {
lincat
Sentence = Phr;
Verb = {v : V3 ; rel : Relation};
Noun = {n : N ; rel : Relation};
lin
-- MySentence first judge if these two given variables are a good match
MySentence action person = case <action.rel, person.rel> of {
<RelA, RelA> => sayHi (action.v) (person.n);
<RelB, RelB> => sayHi (action.v) (person.n);
<_, _> => sayHi (action.v) (mkN(nonExist))
};
Say = {v = mkV3(say_V) (noPrep) (to_Prep); rel = RelA};
Mike = {n = mkN("Mike") ; rel = RelA};
John = {n = mkN("John") ; rel = RelB};
param
Relation = RelA | RelB;
oper
-- Generate the final sentence
sayHi : V3 -> N -> Phr =
\v, n -> mkPhr(mkUtt(mkImp(mkVP
(v)
(mkNP (mkN "hi"))
(mkNP (n)))));
}
问题
我的解决方案显然不是最好的解决方案,因为它会导致在使用 command 时生成 50% 的空句子gr | l
,参数越大,情况越糟Relation
。
问题
1-有没有办法强制抽象只给出具体文件中匹配的参数?
2-或者是否有任何可能的方法要求抽象在与具体不匹配时提供另一个参数,而不是仅使用生成空行nonExist
?