gf - 变体无法在 GF 上编译
问题描述
我构建了一个程序来从一个命令树生成不同的动词。
摘要文件:
abstract Test = {
flags startcat = Utterance;
cat
Utterance; Imperative; Verb; VerbPhrase;
fun
-- verb phrase
Play_VP : VerbPhrase;
-- Imp
Play_Imp : VerbPhrase -> Imperative;
-- Utt
Sentence : Imperative -> Utterance;}
具体文件:
concrete TestEng of Test = open SyntaxEng, TestEngSrc, ParadigmsEng in {
lincat
Utterance = Utt;
Imperative = Imp;
VerbPhrase = VP;
Verb = V;
lin
-- verb phrase
Play_VP = mkVP ( variants{ mkV(play_Str) ; put_on_V });
--Imp
Play_Imp verbPhrase = mkImp(verbPhrase);
--Utt
Sentence imperative = mkUtt(imperative);}
最后是源文件:
resource TestEngSrc = open ParadigmsEng, SyntaxEng in {
oper
-- verb string
play_Str : Str = variants{ "broadcast" ; "play"
; "replay" ; "see" ; "view" ; "watch" ; "show"};
-- verb
play_V : V = variants {mkV(play_Str) ; put_on_V };
-- verb part
put_on_V : V = partV (mkV "put") "on";}
我在 GitHub 上搜索了 GF 线程,以确定这个问题是个人问题还是一般问题,但我发现了这个页面: https ://github.com/GrammaticalFramework/GF/issues/32 其中提到了一个解决方案将在较新的版本中提供GF。是否有关于此线程的任何更新,或者是否有比此线程中提供的解决方案更好的解决方案。感谢您的时间和精力。
解决方案
不,在处理变体方面没有更新。但幸运的是,您的代码可以通过一个小修复来提高效率。
VP又大又慢
语法中最大的瓶颈是你有 category VerbPhrase
,VP
来自 RGL 的 lincat。它对最终用户不可见,但一个 VP 包含近 3000 个字段。如果你想看,在 GF shell 中试试这个:
> i -retain TestEngSrc.gf
> cc mkVP play_V
... lots of output
我不知道编译的确切细节,但是对于具有 8 个变体的 VP,编译器会卡住。
如何修正你的语法
如果你知道你只会在祈使句中使用动词,你可以完全跳过 VP 阶段,直接从动词创建祈使句。RGL 类别V
要好得多,而不是约 3000 个字段,它有 6 个。因此,如果您将语法更改为此,它会立即编译。我将名称更改为 Test2,因此您可以与旧名称进行比较。
abstract Test2 = {
flags startcat = Utterance;
cat
Utterance; Imperative; Verb;
fun
-- Verb
Play_V : Verb ;
-- Imp
Play_Imp : Verb -> Imperative;
-- Utt
Sentence : Imperative -> Utterance;
}
具体语法在这里。我打开IrregEng
and LexiconEng
,因为那里已经定义了一些动词。
concrete Test2Eng of Test2 = open SyntaxEng, ParadigmsEng, IrregEng, LexiconEng in {
lincat
Utterance = Utt;
Imperative = Imp;
Verb = V;
lin
--Verb
-- broadcast_V, see_V, show_V are in IrregEng. play_V is in LexiconEng.
Play_V = play_V|replay_V|broadcast_V|see_V|show_V|view_V|watch_V|put_on_V ;
--Imp
Play_Imp verb = mkImp verb ;
--Utt
Sentence imperative = mkUtt imperative ;
oper
replay_V : V = mkV "replay" ;
view_V : V = mkV "view" ;
watch_V : V = mkV "watch" ;
put_on_V : V = partV put_V "on"; -- put_V is in IrregEng
}
在 GF shell 中进行测试,按预期工作:
Test2> p "replay"
Sentence (Play_Imp Play_V)
Test2> p "watch"
Sentence (Play_Imp Play_V)
Test2> gt | l -treebank -all
Test2: Sentence (Play_Imp Play_V)
Test2Eng: play
Test2Eng: replay
Test2Eng: broadcast
Test2Eng: see
Test2Eng: show
Test2Eng: view
Test2Eng: watch
Test2Eng: put on
推荐阅读
- reactjs - 如何避免将调度作为道具传递给需要它的组件,但通过 connect() 接收调度?
- java - 如何反序列化仅具有 ID 或对象本身的对象?
- javascript - 在这种情况下如何让 Discord bot 编辑嵌入消息?
- javascript - 按动态列进行角度过滤
- javascript - 需要自定义 Node Red Editor Client CSS 和 JS,在哪里可以找到有关 node-red-editor 源代码的文档?
- javascript - 在多个按钮上有一个活动状态切换器
- python - 我可以在 python selenium ChromeDriver 选项中添加哪个首选项以允许不安全下载?
- python - 如何使用 python 获取我的计算机空闲(空闲时间)多长时间?
- python - 为机器学习收集数据(财务数据)
- javascript - 如何从第 3 方 JavaScript 代码中提取此 OFFERID 值并将其用于不同的第 3 方函数?