/** Copyright (c) 2018 National Institute of Advanced Industrial Science and Technology(AIST), All Rights Reserved. Author: Yuuji Ichisugi 2018-03-09 CCG semantic analyzer without lambda calculus Tested on SWI-Prolog version 7.6.0 on Windows 10 */ %---------------------------------------------------- % Utilities concatLists([], []). concatLists([L|Ls], R) :- concatLists(Ls, R1), append(L, R1, R). printLists([]). printLists([X|Xs]) :- print(X), nl, printLists(Xs). %---------------------------------------------------- % Semantic Representation Memory % Make memory makeAllM(M) :- Msconj=[[[sconj, '-', '-'],_]], makeAllR(c1,M1), makeAllR(c2,M2), concatLists([Msconj, M1, M2], M). makeAllR(C,M) :- Fs=[size,color,entity], makeAllF(C,agent,Fs,Magent), makeSingleRs(C,[modality,action],Mds), makeAllF(C,patient,Fs,Mpatient), concatLists([Magent,Mds,Mpatient], M). makeSingleRs(C,[],[]). makeSingleRs(C,[R|Rs], [[[C,R,'-'],_] | M]) :- makeSingleRs(C,Rs,M). makeAllF(C,R,[],[]). makeAllF(C,R,[F|Fs],[[[C,R,F],_] | M]) :- makeAllF(C,R,Fs,M). % Access to an element of the Semantic Representation % bind(Memory, Address, Data) %bind(M,A,D) :- print(['bind:', A, D]), nl, fail. bind(M,A,D) :- bind1(M,A,D). %bind1([],A,D) :- print(['error:bind', A,D]), fail. bind1([[A, D]|_],A,D) :- !. bind1([_|Rest],A,D) :- bind1(Rest,A,D). %---------------------------------------------------- % Inference rules. % reduce(Conclusion, Premise1, Premise2) reduce(X, f(X, Y), Y). % X/Y, Y -> X (>) reduce(X, Y, b(X, Y)). % Y, X\Y -> X (<) reduce(f(X, Z), f(X, Y), f(Y, Z)). % X/Y Y/Z -> X/Z (>B) reduce(b(X, Z), b(Y, Z), b(X, Y)). % Y\Z X\Y -> X\Z ( Y/Z (>T and >B) % These two rules are not used by the shift-reduce parser. raiseL(f(T, b(T, X)), X). % X -> T/(T\X) (>T) raiseR(b(T, f(T, X)), X). % X -> T\(T/X) (