2014-02-17 46 views
3

我的拉丁翻譯器出現問題,我正在爲一個學校項目建立。我爲拉丁/英語句子創建了一個語法。我創建了一個謂詞(可能的句子(拉丁語,英語)),它可以按照正確順序翻譯拉丁語句子。然而,由於拉丁語句子的排列順序不同,所以我採用了一系列排列組合來找到拉丁文翻譯成英語的正確順序。這是我的翻譯(拉丁語,英語)謂語。這看起來效率很低。有沒有更好的方法來做到這一點?非常低效且不雅的代碼

我也有加載一個大集從.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). 

回答

1

拉丁語應該是Free-Word-Order Dependency Parsing的最愛應用程序。

ProNTo工具包描述了這種技術並提供了一些入門級軟件。

順便提一句,dependency parser documentation使用拉丁語作爲主要應用程序域。