3

我正在为学校项目构建的拉丁语翻译器有问题。我为拉丁语/英语句子创建了语法。我创建了一个谓词 (possiblesentence(Latin,English).),它可以按正确的顺序翻译拉丁句子。然而,由于拉丁句子是按任何顺序排列的,我已经求助于生成一个大的排列列表来找到正确的拉丁语顺序来翻译成英语。这是我的翻译(拉丁语,英语)谓词。这似乎非常低效。有没有更好的方法来做到这一点?

我还有另一个文件,它从 .csv 加载大量谓词,如下所示:

noun("femin","femin",1,f,"woman","women").
verb("port","porta","portav","portat", 1, carry, carrying, carried).

这是我的主要程序:

% Nick's Latin translator

% --------------
% word generator
% --------------

% predicate used to see if any two of the stems join to the ending.

stem_ending_joiner(Stem1,Stem2,Ending,Latin) :-
    (
        append(Stem1,Ending,Latin),
        !
    ;   append(Stem2,Ending,Latin),
        !
    ).

% predicate containing all possible data about nouns including endings
% and such

word_nounx(Latin,Translation,Gender,Case,Number) :-
    noun(Stem1,Stem2,_,Gender,Sgtrans,Pltrans),
    nounending(Ending,Prefix,Number,Case),
    stem_ending_joiner(Stem1,Stem2,Ending,Latin),
    (
        Number = sg,
        Translationw = Sgtrans;
        Number = pl,
        Translationw = Pltrans
    ),
    append(Prefix," ",Prefixspace),
    append(Prefixspace,Translationw,Translation).

% predicate containing all possible data about verbs including endings
% and such
% arguments: Latin,Translation,Tense,Number,Mood,Voice

word_verbx(Latin,Translation,Tense,Number,Mood,Voice,Person) :-
    verb(Stem1,_,_,_,_,Ptrans,_,Pastrans),
    verbending(Ending,Tense,Prefix,Number,Mood,Voice,Person),
    stem_ending_joiner(Stem1,_,Ending,Latin),
    (
        Tense = present,
        Translationw = Ptrans;
        Tense = past,
        Translationw = Pastrans
    ),
    append(Prefix," ",Prefixspace),
    append(Prefixspace,Translationw,Translation).

% -------
% parsing
% -------

word_noun(Latin,Translation,Gender,Case,Number) :-
    word_nounx(Latinx,Translationx,Gender,Case,Number),
    name(Latin,Latinx),
    name(Translation,Translationx).

word_verb(Latin,Translation,Tense,Number,Mood,Voice,Person) :-
    word_verbx(Latinx,Translationx,Tense,Number,Mood,Voice,Person),
    name(Latin,Latinx),
    name(Translation, Translationx).

pnoun(Gender,Case,Number) -->
   [[English,Latin]],
   {word_noun(Latin,English,Gender,Case,Number)}.
nounphrase(Gender,Case,Number) -->
   pnoun(Gender,Case,Number).
pverb(Tense,Number,Mood,Voice,Person) -->
   [[English,Latin]],
   {word_verb(Latin,English,Tense,Number,Mood,Voice,Person)}.
verbphrase(Tense,Number,Mood,Voice,Person,Gender,Case,Nnumber) -->
   pverb(Tense,Number,Mood,Voice,Person),
   nounphrase(Gender,Case,Nnumber).
sentence -->
   nounphrase(_,nom,Number),
   verbphrase(_,Number,_,_,3,_,nom,_).

% Predicates which manipulate lists of list-pairs to get the first and
% last elements of each list.

headofelements([],[]).
headofelements([H|T],[[H|_]|T1]) :-
    headofelements(T,T1).

tailofelements([],[]).
tailofelements([H|T],[[_|H]|T1]) :-
    tailofelements(T,T1).

lastofelements([],[]).
lastofelements([H|T],[X|T1]) :-
    last(X,N),
    H = N,
    lastofelements(T,T1).

% generates possible sentences with the latin and the english.

possible_sentence(X,N) :-
    phrase(sentence,Y),
    lastofelements(X,Y),
    headofelements(N,Y).

translate(Latin,English) :-
    permutation(Latin,X),
    possible_sentence(X,English).

以下是结局:

% --------------------------
% ADJECTIVE ENDINGS
% ------------------------------

adjending("us",sg,nom,m).

% -----------------------------------
% VERBENDINGS
% ------------------------------------

verbending("o",present,"I",sg,_,_,1).
verbending("as",present,"you",sg,_,_,2).
verbending("at",present,"He",sg,_,_,3).
verbending("amus",present,"We",pl,_,_,1).
verbending("atis",present,"You",pl,_,_,2).
verbending("ant",present,"They",pl,_,_,3).


% -----------------------------------
% NOUN ENDINGS
% -----------------------------------

nounending("a","",sg,nom).
nounending("am","",sg,acc).
nounending("ae","of",sg,gen).
nounending("ae","to",sg,dat).
nounending("a","with",sg,abl).
nounending("ae","",pl,nom).
nounending("as","",pl,acc).
nounending("arum","of",pl,gen).
nounending("is","to",pl,dat).
nounending("is","with",pl,abl).
4

1 回答 1

1

拉丁语应该是最喜欢的自由词序依赖解析应用程序。

ProNTo Toolkit 描述这种技术并提供了一些介绍性软件。

顺便说一句,依赖解析器文档使用拉丁语作为主要应用程序域。

于 2014-02-17T18:55:25.440 回答