首页 > 解决方案 > 变体无法在 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。是否有关于此线程的任何更新,或者是否有比此线程中提供的解决方案更好的解决方案。感谢您的时间和精力。

标签: gf

解决方案


不,在处理变体方面没有更新。但幸运的是,您的代码可以通过一个小修复来提高效率。

VP又大又慢

语法中最大的瓶颈是你有 category VerbPhraseVP来自 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;
}

具体语法在这里。我打开IrregEngand 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

推荐阅读