% Translation
translate_gen(Lan, FS) :-
lan(Lan) ->
Copyright By PowCoder代写 加微信 powcoder
\+ (gen(FS)); write(‘wrong source language’).
translate(Ws) :-
question(q1),
translate_q1(Ws).
translate(Ws) :-
question(q2),
translate_q2(Ws).
translate_q1(Ws) :-
(file_exists(‘.translate_sent.sh’) -> delete_file(‘.translate_sent.sh’);true),
tell(‘.translate_sent.sh’),
(lan(en) -> write(‘/u/csc485h/fall/pub/trale/trale -fsg -c q1_zh.pl -e “ale_flag(another,_,inf),translate_gen(zh,(‘); true),
(lan(zh) -> write(‘/u/csc485h/fall/pub/trale/trale -fsg -c q1_en.pl -e “ale_flag(another,_,inf),translate_gen(en,(‘); true),
\+ \+ (rec(Ws, FS, Res),
my_pp_fs_res_name_only(FS, Res, 0, 0),
write(‘,sem:’),
get_feat(sem, FS, Sem),
my_pp_fs_res(Sem, Res, 0, 0)),
write(‘)),halt”‘) ->
shell(‘bash .translate_sent.sh’),
delete_file(‘.translate_sent.sh’));
delete_file(‘.translate_sent.sh’).
translate_q2(Ws) :-
rec(Ws, FS, Desc, Residue, Index),
get_type(FS, s),
get_feat(logic, FS, Logic),
print_logic(Logic),
present_translation(FS, Res),
ttynl, flush_output,
query_proceed.
present_translation(FS, Res) :-
(file_exists(‘.translate_sent.sh’) -> delete_file(‘.translate_sent.sh’);true),
tell(‘.translate_sent.sh’),
(lan(en) -> write(‘/u/csc485h/fall/pub/trale/trale -fsg -c q2_zh.pl -e “ale_flag(another,_,inf),translate_gen(zh,(‘); true),
(lan(zh) -> write(‘/u/csc485h/fall/pub/trale/trale -fsg -c q2_en.pl -e “ale_flag(another,_,inf),translate_gen(en,(‘); true),
my_pp_fs_res_name_only(FS, Res, 0, 0),
write(‘,sem:’),
get_feat(sem, FS, Sem),
my_pp_fs_res(Sem, Res, 0, 0),
write(‘,logic:’),
get_feat(logic, FS, Logic),
my_pp_fs_res(Logic, Res, 0, 0)),
write(‘)),halt”‘) ->
shell(‘bash .translate_sent.sh’),
delete_file(‘.translate_sent.sh’)
delete_file(‘.translate_sent.sh’).
my_pp_fs_res(FS,Residue,Col,MGType) :-
empty_avl(AssocIn),
filter_iqs(Residue,Iqs,FSResidue),
(ale_flag(residue,show) -> residue_args(FSResidue,ResArgs,[FS]) ; ResArgs = [FS]),
duplicates_list(ResArgs,AssocIn,DupsMid,AssocIn,VisMid,0,NumMid),
duplicates_iqs(Iqs,DupsMid,DupsOut,VisMid,Inf,NumMid,_),
my_pp_fs(FS,MGType,DupsOut,Inf,AssocIn,VisMid2,Col,AssocIn,HDMid).
my_pp_fs(FS,MGType,Dups,Inf,VisIn,VisOut,Col,HDIn,HDOut) :-
deref(FS,_,Type,_),
approps(Type,FRs,_),
build_keyed_feats(FRs,FS,KeyedFeats),
mypp_fs_default(Type,FS,MGType,KeyedFeats,Dups,Inf,VisIn,VisOut,Col,HDIn,HDOut).
my_pp_fs_res_name_only(FS,Residue,Col,MGType) :-
empty_avl(AssocIn),
filter_iqs(Residue,Iqs,FSResidue),
(ale_flag(residue,show) -> residue_args(FSResidue,ResArgs,[FS]) ; ResArgs = [FS]),
duplicates_list(ResArgs,AssocIn,DupsMid,AssocIn,VisMid,0,NumMid),
duplicates_iqs(Iqs,DupsMid,DupsOut,VisMid,Inf,NumMid,_),
my_pp_fs_name_only(FS,MGType,DupsOut,Inf,AssocIn,VisMid2,Col,AssocIn,HDMid).
my_pp_fs_name_only(FS,MGType,Dups,Inf,VisIn,VisOut,Col,HDIn,HDOut) :-
deref(FS,_,Type,_),
approps(Type,FRs,_),
mypp_fs_default(Type,FS,MGType,[],Dups,Inf,VisIn,VisOut,Col,HDIn,HDOut).
mypp_fs_default(Type,FS,MGType,KeyedFeats,Dups,Inf,VisIn,VisOut,Col,HDIn,HDOut) :-
avl_fetch(FS,VisIn,_) ->
VisOut = VisIn,
HDOut = HDIn,
( avl_fetch(FS,Dups,TagNum) ->
write(‘A’), write(TagNum); true
Type == 0 ->
avl_store(FS,VisIn,_,VisOut),
HDOut = HDIn,
( avl_fetch(FS,Dups,TagNum) ->
write(‘A’), write(TagNum); true
no_write_type_flag(MGType) ->
MGType == 0 ->
write(mgsat)
approps(MGType,_,0) ->
write(MGType) % MGType had no features anyway
write(‘mgsat(‘),
write(MGType),
write(‘)’)
avl_store(FS,VisIn,_,VisMid), % print FS if not already visited
no_write_type_flag(Type) ->
my_pp_vs_unwritten(KeyedFeats,Dups,Inf,VisMid,VisOut,Col,HDIn,HDOut)
write(Type),
(KeyedFeats = [] -> true ; comma),
my_pp_vs(KeyedFeats,Dups,Inf,VisMid,VisOut,Col,HDIn,HDOut),
( avl_fetch(FS,Dups,TagNum) ->
write(‘,A’), write(TagNum); true
my_pp_vs([],_,_,Vis,Vis,_,HD,HD).
my_pp_vs([fval(F,V,R)|KFs],Dups,Inf,VisIn,VisOut,Col,HDIn,HDOut) :-
( no_write_feat_flag(F) -> VisMid = VisIn, HDMid = HDIn
; (ale_flag(sparseoutput,on),
avl_fetch(V,Inf,Inform),
var(Inform)) -> VisMid = VisIn, HDMid = HDIn
my_write_feature(F,LengthF),
NewCol is Col + LengthF +1,
my_pp_fs(V,R,Dups,Inf,VisIn,VisMid,NewCol,HDIn,HDMid)
(KFs = [] -> true ; comma),
my_pp_vs(KFs,Dups,Inf,VisMid,VisOut,Col,HDMid,HDOut).
my_pp_vs_unwritten([],_,_,Vis,Vis,_,HD,HD).
my_pp_vs_unwritten([fval(F,V,R)|KFs],Dups,Inf,VisIn,VisOut,Col,HDIn,HDOut):-
( no_write_feat_flag(F) -> VisMid = VisIn, HDMid = HDIn
; (ale_flag(sparseoutput,on),
avl_fetch(V,Inf,Inform),
var(Inform)) -> VisMid = VisIn, HDMid = HDIn
; my_write_feature(F,LengthF),
NewCol is Col + LengthF +1,
my_pp_fs(V,R,Dups,Inf,VisIn,VisMid,NewCol,HDIn,HDMid)
(KFs = [] -> true ; comma),
my_pp_vs(KFs,Dups,Inf,VisMid,VisOut,Col,HDMid,HDOut).
my_write_feature(F,LengthF):-
name(F,NameF), length(NameF,LengthF),
write(‘:’).
comma :- write(‘,’).
lb :- write(‘(‘).
rb :- write(‘)’).
% ================================================================
% Print Logic
% ================================================================
get_parse_tree(Ws, Tree) :- rec(Ws, FS, Desc, Residue, Index),
(ale_lists_defined ->
clause(fcolour(hd,HdPos,_),true),
clause(fcolour(tl,TlPos,_),true),
relink_parse_tree(FS,Ws,Index,Tree,[_FS|TreeFSs],[],HdPos,TlPos);
relink_parse_tree(FS,Ws,Index,Tree,[_FS|TreeFSs],[])).
print_logic(Logic) :-
print_logic(Logic, []).
print_define_scope(Logic, Dict) :-
get_type(Logic, forall),
write(‘∀’),
print_var_dict(Logic, Dict),
write(‘, ‘).
print_define_scope(Logic, Dict) :-
get_type(Logic, exists),
write(‘∃’),
print_var_dict(Logic, Dict),
write(‘, ‘).
print_var(Var, Dict, true) :-
print_var_dict(Var, Dict).
print_var(Var, Dict, false) :-
write(‘, ‘),
print_var_dict(Var, Dict).
print_var_dict(Var1, [Var2|_]) :-
Var1 == Var2,
write(‘x’).
print_var_dict(Var1, [_|[Var2|_]]) :-
Var1 == Var2,
write(‘y’).
print_var_dict(Var1, [_|[_|[Var2|_]]]) :-
Var1 == Var2,
write(‘z’).
print_logic(Logic, Dict) :-
get_type(Logic, scope),
get_feat(var, Logic, Var),
get_feat(rest, Logic, Rest),
append(Dict, [Var], NewDict),
print_define_scope(Var, NewDict),
print_logic(Rest, NewDict),
print_logic(Logic, Dict) :-
get_type(Logic, imply),
get_feat(lhs, Logic, LHS),
get_feat(rhs, Logic, RHS),
print_logic(LHS, Dict),
write(‘ => ‘),
print_logic(RHS, Dict).
print_logic(Logic, Dict) :-
get_type(Logic, and),
get_feat(lhs, Logic, LHS),
get_feat(rhs, Logic, RHS),
print_logic(LHS, Dict),
write(‘ ^ ‘),
print_logic(RHS, Dict).
print_logic(Logic, Dict) :-
% lambda function
get_type(Logic, lambda_func),
get_feat(rest, Logic, Rest),
print_logic(Rest, Dict).
print_logic(Logic, Dict) :-
% functions
get_type(Logic, func),
get_feat(func, Logic, Func),
get_feat(vars, Logic, Vars),
get_type(Func, FuncType),
write(FuncType),
print_list(Vars, Dict, true),
print_list(List, Dict, _) :-
get_type(List, e_list).
print_list(List, Dict, IsFirst) :-
get_type(List, ne_list),
get_feat(hd, List, H),
get_feat(tl, List, T),
print_var(H, Dict, IsFirst),
print_list(T, Dict, false).
prec(Ws) :- \+ \+ (
get_parse_tree(Ws, Tree),
Tree = tree(_, _, FS, _),
get_type(FS, s),
get_feat(logic, FS, Logic),
print_logic(Logic),
ttynl, flush_output,
query_proceed).% Student name: NAME
% Student number: NUMBER
% UTORid: ID
% This code is provided solely for the personal and private use of students
% taking the CSC485H/2501H course at the University of Toronto. Copying for
% purposes other than this use is expressly prohibited. All forms of
% distribution of this code, including but not limited to public repositories on
% GitHub, GitLab, Bitbucket, or any other online platform, whether as given or
% with any changes, are expressly prohibited.
% Authors: and
% All of the files in this directory and all subdirectories are:
% Copyright c 2021 University of Toronto
:- ale_flag(pscompiling, _, parse_and_gen).
:- ensure_loaded(csc485).
question(q1).
bot sub [cate, sem, agr, number, list].
sem sub [n_sem, v_sem].
n_sem sub [cat, dog, professor] intro [count:count].
v_sem sub [see, chase] intro [subj:sem, obj:sem].
cate sub [nominal, verbal] intro [agr:agr, sem:sem].
nominal sub [n, np, det, num] intro [sem:n_sem].
verbal sub [v, vp, s] intro [sem:v_sem, subcat:list].
% Define your agreement
agr intro [].
count sub [one, two, three].
list sub [e_list, ne_list].
ne_list intro [hd:bot, tl:list].
% Specifying the semantics for generation.
semantics sem1.
sem1(sem:S, S) if true.
% Define your Lexicons
% Define your Rules
% Student name: NAME
% Student number: NUMBER
% UTORid: ID
% This code is provided solely for the personal and private use of students
% taking the CSC485H/2501H course at the University of Toronto. Copying for
% purposes other than this use is expressly prohibited. All forms of
% distribution of this code, including but not limited to public repositories on
% GitHub, GitLab, Bitbucket, or any other online platform, whether as given or
% with any changes, are expressly prohibited.
% Authors: and
% All of the files in this directory and all subdirectories are:
% Copyright c 2021 University of Toronto
:- ale_flag(pscompiling, _, parse_and_gen).
:- ensure_loaded(csc485).
question(q1).
bot sub [cate, sem, agr, cl_types].
sem sub [n_sem, v_sem].
n_sem sub [cat, dog, professor] intro [count:count].
v_sem sub [see, chase] intro [subj:sem, obj:sem].
cl_types sub [ge, wei, zhi, tiao].
cate sub [nominal, verbal] intro [agr:agr, sem:sem].
nominal sub [n, np, clp, num, cl] intro [sem:n_sem].
verbal sub [v, vp, s] intro [sem:v_sem, subcat:list].
% Define your agreement
agr intro [].
count sub [one, two, three].
list sub [e_list, ne_list].
ne_list intro [hd:bot, tl:list].
% Specifying the semantics for generation.
semantics sem1.
sem1(sem:S, S) if true.
% Define your Lexical items
% Define your Rules
% Student name: NAME
% Student number: NUMBER
% UTORid: ID
% This code is provided solely for the personal and private use of students
% taking the CSC485H/2501H course at the University of Toronto. Copying for
% purposes other than this use is expressly prohibited. All forms of
% distribution of this code, including but not limited to public repositories on
% GitHub, GitLab, Bitbucket, or any other online platform, whether as given or
% with any changes, are expressly prohibited.
% Authors: and
% All of the files in this directory and all subdirectories are:
% Copyright c 2021 University of Toronto
:- ensure_loaded(csc485).
:- ale_flag(pscompiling, _, parse_and_gen).
question(q2).
bot sub [cat, sem, list, logic, gap_struct, agr].
cat sub [q, det, gappable, has_sem] intro [logic:logic, qstore:list].
has_sem sub [n, gappable] intro [sem:sem].
gappable sub [np, verbal] intro [gap:gap_struct].
verbal sub [v, vp, s] intro [subcat:list].
gap_struct sub [none, np].
sem sub [student, book, read].
list sub [e_list, ne_list].
ne_list intro [hd:bot, tl:list].
logic sub [stmt, nested_logic].
nested_logic sub [scope, lambda_func] intro [rest:logic].
lambda_func intro [lambda:logic].
stmt sub [op, scope, func, var].
op sub [and, imply] intro [lhs:logic, rhs:logic].
func intro [func:sem, vars:list].
scope intro [var:var].
var sub [forall, exists].
qelement intro [l:logic, x:logic].
% Lexical entries (incomplete)
every —> (
% logic:none,
% qstore:[]
% logic:none,
% qstore:[]
book —> (n,
% logic:none,
% qstore:[],
sem:(book, Book)).
student —> (n,
% logic:none,
% qstore:[],
sem:(student, Student)).
read —> (v,
% logic:none,
% qstore:[],
subcat:[], % the subcat list should not be empty
sem:(read, Read)).
% Phrase structure rules (incomplete)
sem_head> (n).
sem_head> (v),
cat> (np).
cat> (np),
sem_head> (vp).
s_gap rule
cat> (Gap),
cat> (np),
sem_head> (vp).
% The empty category:
empty (np, sem:Sem, logic:Logic, qstore:QStore,
gap:(sem:Sem, logic:Logic, qstore:QStore, gap:none)).
% Helper goals
append([],Xs,Xs) if true.
append([H|T1],L2,[H|T2]) if append(T1,L2,T2).
is_empty([]) if true.
% Beta reduction goal
% beta_reduction(X, F, F(X))
beta_reduction((lambda:X, rest:Result), X, Result) if true.
% Quantifier actions
% A Quantifier action can be either apply or store
quantifier_action(Logic, QStore, NewLogic, NewQStore) if
apply(Logic, QStore, NewLogic, NewQStore).
quantifier_action(Logic, QStore, NewLogic, NewQStore) if
store(Logic, QStore, NewLogic, NewQStore).
% Apply, store, and retrieve
apply(Logic, QStore, Logic, QStore) if true.
store(Logic, QStore, (lambda:(F, lambda:X), rest:F), NewQStore) if append([(l:Logic, x:X)], QStore, NewQStore).
retrieve((Empty, []), Logic, Empty, Logic) if true.
retrieve([(l:QLogic, x:X)|T], Logic, T, NewLogic) if beta_reduction(QLogic, (lambda:X, rest:Logic), NewLogic).
% Specifying the semantics for generation.
semantics sem1.
sem1(logic:S, S) if true.
sem1(sem:S, S) if true.
% Some examples
prect_test :- prec([a,student,read,every,book]).
translate_test :- translate([a,student,read,every,book]).
% Student name: NAME
% Student number: NUMBER
% UTORid: ID
% This code is provided solely for the personal and private use of students
% taking the CSC485H/2501H course at the University of Toronto. Copying for
% purposes other than this use is expressly prohibited. All forms of
% distribution of this code, including but not limited to public repositories on
% GitHub, GitLab, Bitbucket, or any other online platform, whether as given or
% with any changes, are expressly prohibited.
% Authors: and
% All of the files in this directory and all subdirectories are:
% Copyright c 2021 University of Toronto
:- ensure_loaded(csc485).
:- ale_flag(pscompiling, _, parse_and_gen).
question(q2).
bot sub [cat, sem, list, logic, gap_struct, agr].
cat sub [gappable, agreeable, dou] intro [logic:logic, qstore:list].
gappable sub [verbal, n, np, n_np_vp] intro [gap:gap_struct, sem:sem].
verbal sub [vp, s, v] intro [subcat:list].
agreeable sub [cl_agreeable, q_agreeable, n_np_vp] intro [agr:agr].
cl_agreeable sub [cl, n] intro [agr:cl_agr].
q_agreeable sub [np_vp, q] intro [agr:q_agr].
n_np_vp sub [n, np_vp].
np_vp sub [np, vp].
n intro [cl:cl].
agr sub [cl_agr, q_agr].
cl_agr sub [ge, ben].
q_agr sub [var].
gap_struct sub [np, none].
sem sub [student, book, read].
list sub [e_list, ne_list].
ne_list intro [hd:bot, tl:list].
logic sub [stmt, nested_logic].
nested_logic sub [scope, lambda_func] intro [rest:logic].
lambda_func intro [lambda:logic].
stmt sub [op, scope, func, var].
op sub [and, imply] intro [lhs:logic, rhs:logic].
func intro [func:sem, vars:list].
scope intro [var:var].
var sub [forall, exists].
qelement intro [l:logic, x:logic].
% Lexical entries (incomplete)
% 每: the universal quantifier
mei —> (q,
% logic:none,
% qstore:[],
agr:forall).
% 一: the existential quantifier
yi —> (q,
% logic:none,
% qstore:[],
agr:exists).
% 个: the classifier for students
ge —> (cl, agr:ge).
% 本: the classifier for books
ben —> (cl, agr:ben).
% 都: the distributive operator
dou —> dou.
shu —> (n,
% logic:none,
% qstore:[],
sem:(book, Book)).
% 学生: student
xuesheng —> (n,
% logic:none,
% qstore:[],
sem:(student, Student)).
% 读过: read
duguo —> (v,
% logic:none,
% qstore:[],
subcat:[], % the subcat list should not be empty
sem:(read, Read)).
% Phrase structure rules (incomplete)
cat> (cl),
sem_head> (n).
sem_head> (v),
cat> (np).
cat> (dou),
sem_head> (vp).
cat> (np),
sem_head> (vp).
s_gap rule
cat> (Gap),
cat> (np),
sem_head> (vp).
% The empty category
empty (np, sem:Sem, logic:Logic, qstore:QStore,
gap:(sem:Sem, logic:Logic, qstore:QStore, gap:none)).
% Helper goals
append([],Xs,Xs) if true.
append([H|T1],L2,[H|T2]) if append(T1,L2,T2).
is_empty([]) if true.
% Beta reduction goal
% beta_reduction(F, X, F(X))
beta_reduction((lambda:X, rest:Result), X, Result) if true.
% Quantifier actions
% A Quantifier action can be either apply or store
quantifier_action(Logic, QStore, NewLogic, NewQStore) if
apply(Logic, QStore, NewLogic, NewQStore).
quantifier_action(Logic, QStore, NewLogic, NewQStore) if
store(Logic, QStore, NewLogic, NewQStore).
% Apply, store, and retrieve
apply(Logic, QStore, Logic, QStore) if true.
store(Logic, QStore, (lambda:(F, lambda:X), rest:F), NewQStore) if append([(l:Logic, x:X)], QStore, NewQStore).
retrieve((Empty, []), Logic, Empty, Logic) if true.
retrieve([(l:QLogic, x:X)|T], Logic, T, NewLogic) if beta_reduction(QLogic, (lambda:X, rest:Logic), NewLogic).
% Your helper goals:
% Specifying the semantics for generation.
semantics sem1.
sem1(logic:S, S) if true.
sem1(sem:S, S) if true.
% Some examples
prect_test :- prec([yi,ge,xuesheng,duguo,mei,ben,shu]).
translate_test :- translate([yi,ge,xuesheng,duguo,mei,ben,shu]).
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com