3
4:- module(evaluator, [
5 load_tpl/1, 6 load_tpls/1, 7 solve_goal/1, 8 get_sim_equations/1, 9 add_sim_equations/1, 10 update_sim_equations/1, 11 build_block_equations/2 13 ]). 14
15:- use_module(directives). 16:- use_module(utilities). 17:- use_module(flags). 18:- use_module(library(ordsets)). 19
22:- use_module(library(help)). 23:- use_module(library(lists)). 24:- use_module(library(readutil)). 25:- use_module(library(statistics)). 26
28
29:- set_prolog_flag(double_quotes, codes). 30
31
45load_tpl(File) :-
46 retract_all_dyn_predicates,
56 (current_predicate(unload_file/1) ->
57 58 59 current_file(OldFile),
60 (OldFile \== '' ->
61 unload_file(OldFile)
62 ;
63 true
64 ),
65 retract(current_file(OldFile)),
66 assert(current_file(File))
67 ;
68 69 70 71 true
72 ),
73 (File \== '' ->
74 75 consult(File)
76 ;
77 78 79 assert(sim(X, X, 1.0)),
80 assert(frel1(X, X, 1.0)),
81 assert(frel2(X, X, 1.0)),
82 assert(frel3(X, X, 1.0))
83 ).
84
85retract_all_dyn_predicates :-
86 87 retractall(sim(_, _, _)),
88 retractall(sim(_, _, _, _)),
89 retractall(lEqThan(_, _, _)),
90 retractall(gEqThan(_, _, _)),
91 retractall(frel1(_, _, _)),
92 retractall(frel2(_, _, _)),
93 retractall(frel3(_, _, _)).
102load_tpls(File) :-
103 current_file(OldFile),
104 (OldFile \== '' ->
105 unload_file(OldFile)
106 ;
107 true
108 ),
109 (File \== '' ->
110 111 consult(File)
112 ;
113 true
114 ).
125solve_goal(Goal) :-
126 catch((
127 Goal
128 129 ), error(existence_error(procedure, Predicate), context(Context, Extra)), (
130 131 132 133 134 135 get_actual_predicate_definition(Predicate, ActualPredicate),
136 get_actual_predicate_definition(Context, ActualContext),
137 throw(error(existence_error(procedure, ActualPredicate), context(ActualContext, Extra)))
138 )).
148get_sim_equations(Equations) :-
150 nf_setof(sim(Sym1, Sym2, Degree), sim(Sym1, Sym2, Degree), Equations).
157nf_setof(X,Y,Z) :-
158 setof(X,Y,Z),
159 !.
160
161nf_setof(_,_,[]).
172add_sim_equations(Equations) :-
173 add_sim_equations(Equations, _Added).
182add_sim_equations([], Added) :-
183 var(Added),
184 !,
185 Added = no.
186
187add_sim_equations([], _Added). 188
189add_sim_equations([sim(Sym1, Sym2, Value)|MoreEquations], Added) :-
190 sim(Sym1, Sym2, OldValue),
191 OldValue >= Value,
192 193 194 !,
195 add_sim_equations(MoreEquations, Added).
196
197add_sim_equations([sim(Sym1, Sym2, Value)|MoreEquations], Added) :-
198 199 !,
200 assert(sim(Sym1, Sym2, Value)),
201 Added = yes,
202 add_sim_equations(MoreEquations, Added).
203
204add_sim_equations([_|MoreEquations], Added) :-
205 206 !,
207 add_sim_equations(MoreEquations, Added).
219update_sim_equations(Equations) :-
220 update_sim_equations(Equations, _Updated).
229update_sim_equations(Equations, Updated) :-
230 flags:bpl_flags(weak_unification(a3)),
231 !,
232 add_sim_equations(Equations, Updated),
233 retractall(sim(_,_,_,_)),
234 build_block_equations(Equations, _BlockEquations).
235
236update_sim_equations(Equations, Updated) :-
237 add_sim_equations(Equations, Updated).
238
239
240
261build_block_equations(Equations, BlockEquations) :-
262 flags:get_bpl_flag(weak_unification('a3')),
263 flags:get_bpl_flag(ext_block_equs('false')),
264 !,
265 evaluator:add_sim_equations(Equations),
266 evaluator:sim(F,T,D),
267 var(F),
268 retract(evaluator:sim(F,T,D)),
269 gen_rb(BlockEquations),
271 assert(evaluator:sim(F,T,D)).
272
284
285build_block_equations(Equations, BlockEquations) :-
286 flags:get_bpl_flag(weak_unification('a3')),
288 !,
289 290 nf_setof(sim(X,Y,D), member(sim(X,Y,D), Equations), SimEquations),
291 copy_term(SimEquations, CopyEquations), 292 get_sim_equations(StoredEquations),
293 ord_union(StoredEquations, CopyEquations, AllEquations),
294 foreign:ext_block_equs(0, AllEquations, sim, BlockEquations),
295 maplist(assert, BlockEquations).
296
297build_block_equations(_Equations, []).
298
299
314gen_rb(BlockEquations) :-
315 setof(F,T^D^(evaluator:sim(F,T,D)),G), 316 allMaxCliques(G,LC),
317 build_ctrs(LC,Ctrs), 318 gen_entries(Ctrs),
319 setof(sim(F,T,B,D),evaluator:sim(F,T,B,D),BlockEquations),
320 !.
321
322gen_rb([]).
323
324
325build_ctrs(LC,Cout) :-
326 build_ctrs(LC,1,[],Cout).
327
328build_ctrs([],_B,Cin,Cin).
329build_ctrs([Cs|LC],B,Cin,Cout) :-
330 ctrs_from_block(Cs,B,Cin,Cin1),
331 B1 is B+1,
332 build_ctrs(LC,B1,Cin1,Cout).
333
334ctrs_from_block([],_B,Cin,Cin).
335ctrs_from_block([C|Cs],B,Cin,Cout) :-
336 ord_union([C:B],Cin,Cin1),
337 ctrs_from_block(Cs,B,Cin1,Cout).
338
339ord_ctr_member(X,[X|_Xs]).
340ord_ctr_member(X:B,[Y:_|Xs]) :-
341 X@>=Y,
342 ord_ctr_member(X:B,Xs).
343
344gen_entries(Ctrs) :-
345 evaluator:sim(F,T,D),
346 ord_ctr_member(F:B,Ctrs),
347 ord_ctr_member(T:B,Ctrs),
348 assert(evaluator:sim(F,T,B,D)),
349 fail.
350gen_entries(_Ctrs).
351
352
356
359
360
371
372allMaxCliques(LC) :-
373 setof(F,T^D^(evaluator:sim(F,T,D)),Fs),
374 allMaxCliques(Fs,LC).
378allMaxCliques(G,LC) :-
381 setof(C, maxClique(G,C), LC).
384g(LC) :- allMaxCliques([1,2,3,4,5,6],LC).
388maxClique(G, C) :-
389 maxClique(G,[],[], C).
410maxClique([],[],R,OR) :-
411 !, 412 list_to_ord_set(R,OR).
413maxClique(P,X,A,R) :-
414 ord_union(P,X,PX),
415 pivot(PX,U),
416 neighborSet(U,NU),
417 ord_subtract(P,NU,DP),
418 member(V,DP),
419 neighborSet(V,NV),
420 ord_intersection(P,NV,PNV),
421 ord_intersection(X,NV,XNV),
422 maxClique(PNV,XNV,[V|A],R).
423
424
426neighborSet(V,NV) :-
427 setof(N, D^(evaluator:sim(V,N,D)), NV). 429
430
436
437
442pivot(PX,U) :-
443 pivot(PX,0,[],U).
444
445pivot([],_,[A],A).
446pivot([V|Vs],AN,_,U) :-
447 neighborSet(V,NV),
448 length(NV,L),
449 L>AN,
450 !,
451 pivot(Vs,L,[V],U).
452pivot([_|Vs],AN,[A],U) :-
453 pivot(Vs,AN,[A],U).
454
467
468
482weak_unify_a1(Atomic1, Atomic2, Lambda, Degree) :-
483 484 atomic(Atomic1), atomic(Atomic2), !,
485 sim(Atomic1, Atomic2, Degree),
486 Degree >= Lambda.
487
488weak_unify_a1(Term1, Term2, Lambda, Degree) :-
489 490 compound(Term1), compound(Term2), !,
491 Term1 =.. [Functor1|Args1],
492 Term2 =.. [Functor2|Args2],
493 length(Args1, Arity),
494 length(Args2, Arity),
495 sim(Functor1, Functor2, DegreeFunctor),
496 DegreeFunctor >= Lambda,
497 weak_unify_args_a1(Args1, Args2, Lambda, DegreeArgs),
499 t_norm_op(DegreeFunctor, DegreeArgs, Degree).
500
501weak_unify_a1(Term, Variable, _Lambda, 1) :-
502 503 nonvar(Term), var(Variable), !,
504 Variable = Term.
505
506weak_unify_a1(Variable, Term, _Lambda, 1) :-
507 508 var(Variable),
509 Variable = Term.
519weak_unify_args_a1([], [], _Lambda, 1).
520
521weak_unify_args_a1([Arg1|MoreArgs1], [Arg2|MoreArgs2], Lambda, Degree) :-
522 weak_unify_a1(Arg1, Arg2, Lambda, DegreeArg),
523 weak_unify_args_a1(MoreArgs1, MoreArgs2, Lambda, DegreeMoreArgs),
524 t_norm_op(DegreeArg, DegreeMoreArgs, Degree).
526
527
528
532
533
537:- op(750, yfx, '--'). 538
539:- dynamic '--'/2. 540
541
550
551weak_unify_a2(Atomic1, Atomic2, Lambda, Cin, Cout, Degree) :-
552 553 atomic(Atomic1),
554 atomic(Atomic2),
555 !,
556 (Atomic1==Atomic2
557 ->
558 Degree=1,
559 Cout=Cin
560 ;
561 unification_degree_a2(Atomic1, Atomic2, Degree),
562 Degree >= Lambda,
563 sat_a2(Atomic1--Atomic2, Cin, Cout)
564 ).
565
566weak_unify_a2(Term1, Term2, Lambda, Cin, Cout, Degree) :-
567 568 compound(Term1),
569 compound(Term2),
570 !,
571 Term1 =.. [Functor1|Args1],
572 Term2 =.. [Functor2|Args2],
573 length(Args1, Arity),
574 length(Args2, Arity),
575 (Functor1==Functor2
576 ->
577 Cin1=Cin,
578 DegreeFunctor=1
579 ;
580 unification_degree_a2(Functor1, Functor2, DegreeFunctor),
581 DegreeFunctor >= Lambda,
582 sat_a2(Functor1--Functor2, Cin, Cin1)
583 ),
584 weak_unify_args_a2(Args1, Args2, Lambda, Cin1, Cout, DegreeArgs),
586 t_norm_op(DegreeFunctor, DegreeArgs, Degree).
587
588weak_unify_a2(Term, Variable, _Lambda, Cin, Cin, 1) :-
589 590 nonvar(Term),
591 var(Variable),
592 !,
594 Variable = Term.
595
596weak_unify_a2(Variable, Term, _Lambda, Cin, Cin, 1) :-
597 598 var(Variable),
600 Variable = Term.
609weak_unify_args_a2([], [], _Lambda, Cin, Cin, 1).
610
611weak_unify_args_a2([Arg1|MoreArgs1], [Arg2|MoreArgs2], Lambda, Cin, Cout, Degree) :-
612 weak_unify_a2(Arg1, Arg2, Lambda, Cin, Cin1, DegreeArg),
613 weak_unify_args_a2(MoreArgs1, MoreArgs2, Lambda, Cin1, Cout, DegreeMoreArgs),
615 t_norm_op(DegreeArg, DegreeMoreArgs, Degree).
616
623unification_degree_a2(Atomic, Atomic, 1.0). 624
625unification_degree_a2(Atomic1, Atomic2, Degree) :-
626 sim(Atomic1, Atomic2, Degree).
627
628
629
633
634
635
650
651sat_a2(E1--E2, Cin, Cout) :-
652 uniPCS([E1--E2], Cin, Cout), sat_a2_ctrs(Cout).
653
654sat_a2_ctrs(C) :-
655 load_ctrs(C),
656 ((ctrs_path(X,Y), \+sim(X,Y,_D)) 657 ->
658 clear_ctrs,
659 false
660 ;
661 clear_ctrs,
662 true
663 ).
664
665
666
667
671
674
676membPCS(S1--S2, [S1--S2|_]).
677membPCS(S1--S2, [S2--S1|_]).
678membPCS(S1--S2, [_|L]) :- membPCS(S1--S2, L).
679
681subPCS([], _).
682subPCS([S1--S2|R], C) :- membPCS(S1--S2, C), subPCS(R, C).
683
685equalPCS(A, B) :- subPCS(A, B), subPCS(B, A).
686
688uniPCS([], C, C).
689uniPCS([S1--S2|R], C2, C) :- membPCS(S1--S2, C2), !, uniPCS(R, C2, C).
690uniPCS([S1--S2|R], C2, [S1--S2|C]) :- uniPCS(R, C2, C).
691
693interPCS([], _, []).
694interPCS([S1--S2|R], C2, [S1--S2|C]) :- membPCS(S1--S2, C2), !, interPCS(R, C2, C).
695interPCS([_|R], C2, C) :- interPCS(R,C2, C).
696
697
698
701
704load_ctrs([]).
705load_ctrs([X--Y|Cs]) :- assert(X--Y), assert(Y--X), load_ctrs(Cs).
709clear_ctrs:- retractall(_X--_Y).
710
711
715ctrs_path(X,Y) :- ctrs_path(X,Y, _).
716
717ctrs_path(X,Y, P) :- ctrs_path(X,Y,[X],P).
718
719ctrs_path(X,Y, A, [Y|A]) :- X--Y, \+member(Y,A).
720ctrs_path(X,Y, A, P) :- X--Z, \+member(Z,A), ctrs_path(Z,Y,[Z|A],P).
721
722
727
728
742weak_unify_a3(Atomic1, Atomic2, Lambda, Cin, Cout, Degree) :-
743 744 atomic(Atomic1),
745 atomic(Atomic2),
746 !,
747 (Atomic1==Atomic2
748 ->
749 Degree=1.0,
750 Cout=Cin
751 ;
752 unification_degree_a3(Atomic1, Atomic2, Block, Degree),
753 Degree >= Lambda,
754 sat_a3([Atomic1:Block, Atomic2:Block], Cin, Cout)
755 ).
756
757weak_unify_a3(Term1, Term2, Lambda, Cin, Cout, Degree) :-
758 759 compound(Term1),
760 compound(Term2),
761 !,
762 Term1 =.. [Functor1|Args1],
763 Term2 =.. [Functor2|Args2],
764 length(Args1, Arity),
765 length(Args2, Arity),
766 (Functor1==Functor2
767 ->
768 Cin1=Cin,
769 DegreeFunctor=1.0
770 ;
771 unification_degree_a3(Functor1, Functor2, Block, DegreeFunctor),
772 DegreeFunctor >= Lambda,
773 sat_a3([Functor1:Block, Functor2:Block], Cin, Cin1)
774 ),
775 weak_unify_args_a3(Args1, Args2, Lambda, Cin1, Cout, DegreeArgs),
777 t_norm_op(DegreeFunctor, DegreeArgs, Degree).
778
779weak_unify_a3(Term, Variable, _Lambda, Cin, Cin, 1.0) :-
780 781 nonvar(Term),
782 var(Variable),
783 !,
784 Variable = Term.
785
786weak_unify_a3(Variable, Term, _Lambda, Cin, Cin, 1.0) :-
787 788 var(Variable),
789 Variable = Term.
799weak_unify_args_a3([], [], _Lambda, Cin, Cin, 1.0).
800
801weak_unify_args_a3([Arg1|MoreArgs1], [Arg2|MoreArgs2], Lambda, Cin, Cout, Degree) :-
802 weak_unify_a3(Arg1, Arg2, Lambda, Cin, Cin1, DegreeArg),
803 weak_unify_args_a3(MoreArgs1, MoreArgs2, Lambda, Cin1, Cout, DegreeMoreArgs),
805 t_norm_op(DegreeArg, DegreeMoreArgs, Degree).
817unification_degree_a3(Atomic, Atomic, _Block, 1.0). 818
819unification_degree_a3(Atomic1, Atomic2, Block, Degree) :-
820 sim(Atomic1, Atomic2, Block, Degree).
830sat_a3([], Cin, Cin).
831sat_a3([Ctr|Ctrs], Cin, Cout) :-
832 sat_a3_ctr(Ctr, Cin, Cin1),
833 sat_a3(Ctrs, Cin1, Cout).
834
835sat_a3_ctr(Symbol:Block, Cin, Cin) :-
836 get_assoc(Symbol, Cin, Block1),
837 !,
838 Block=Block1.
839sat_a3_ctr(Symbol:Block, Cin, Cout) :-
840 put_assoc(Symbol, Cin, Block, Cout).
841
842
843
856unify_a1(Term1, Term2, Degree) :-
857 flags:get_bpl_flag(lambda_cut(Lambda)),
858 weak_unify_a1(Term1, Term2, Lambda, Degree).
869unify_a2(Term1, Term2, Cin, Cout, Degree) :-
870 flags:get_bpl_flag(lambda_cut(Lambda)),
871 weak_unify_a2(Term1, Term2, Lambda, Cin, Cout, Degree).
872
873unify_a2(Term1, Term2, Degree) :-
874 parser:init_ctr_store([Cin]),
875 unify_a2(Term1, Term2, Cin, _Cout, Degree).
886unify_a3(Term1, Term2, Cin, Cout, Degree) :-
887 flags:get_bpl_flag(lambda_cut(Lambda)),
888 weak_unify_a3(Term1, Term2, Lambda, Cin, Cout, Degree).
889
890unify_a3(Term1, Term2, Degree) :-
891 parser:init_ctr_store([Cin]),
892 unify_a3(Term1, Term2, Cin, _Cout, Degree).
907unify_a1(Term1, Term2, Comparer, Value) :-
908 unify_a1(Term1, Term2, Degree),
909 apply(Comparer, [Degree, Value]),
910 !.
918unify_a2(Term1, Term2, Comparer, Value) :-
919 unify_a2(Term1, Term2, Degree),
920 apply(Comparer, [Degree, Value]),
921 !.
929unify_a3(Term1, Term2, Comparer, Value) :-
930 unify_a3(Term1, Term2, Degree),
931 apply(Comparer, [Degree, Value]),
932 !.
944unify_arguments_a1([]).
945
946unify_arguments_a1([[Term1, Term2, Degree]|MoreProblems]) :-
947 unify_a1(Term1, Term2, Degree),
948 unify_arguments_a1(MoreProblems).
956unify_arguments_a2([]).
957
958unify_arguments_a2([[Term1, Term2, Cin, Cout, Degree]|MoreProblems]) :-
959 unify_a2(Term1, Term2, Cin, Cout, Degree),
960 unify_arguments_a2(MoreProblems).
968unify_arguments_a3([]).
969
970unify_arguments_a3([[Term1, Term2, Cin, Cout, Degree]|MoreProblems]) :-
971 unify_a3(Term1, Term2, Cin, Cout, Degree),
972 unify_arguments_a3(MoreProblems).
973
974
975
987e_frel1(Term1, Term2, Degree) :-
988 flags:get_bpl_flag(lambda_cut(Lambda)),
989 compare_terms(frel1, Term1, Term2, Lambda, Degree).
1002e_frel1(Term1, Term2, Comparer, Value) :-
1003 e_frel1(Term1, Term2, Degree),
1004 apply(Comparer, [Degree, Value]),
1005 !.
1014e_frel2(Term1, Term2, Degree) :-
1015 flags:get_bpl_flag(lambda_cut(Lambda)),
1016 compare_terms(frel2, Term1, Term2, Lambda, Degree).
1029e_frel2(Term1, Term2, Comparer, Value) :-
1030 e_frel2(Term1, Term2, Degree),
1031 apply(Comparer, [Degree, Value]),
1032 !.
1041e_frel3(Term1, Term2, Degree) :-
1042 flags:get_bpl_flag(lambda_cut(Lambda)),
1043 compare_terms(frel3, Term1, Term2, Lambda, Degree).
1056e_frel3(Term1, Term2, Comparer, Value) :-
1057 e_frel3(Term1, Term2, Degree),
1058 apply(Comparer, [Degree, Value]),
1059 !.
1069e_gEqThan(Term1, Term2, Degree) :-
1070 flags:get_bpl_flag(lambda_cut(Lambda)),
1071 compare_terms(gEqThan, Term1, Term2, Lambda, Degree).
1085e_gEqThan(Term1, Term2, Comparer, Value) :-
1086 e_gEqThan(Term1, Term2, Degree),
1087 apply(Comparer, [Degree, Value]),
1088 !.
1098e_lEqThan(Term1, Term2, Degree) :-
1099 flags:get_bpl_flag(lambda_cut(Lambda)),
1100 compare_terms(lEqThan, Term1, Term2, Lambda, Degree).
1114e_lEqThan(Term1, Term2, Comparer, Value) :-
1115 e_lEqThan(Term1, Term2, Degree),
1116 apply(Comparer, [Degree, Value]),
1117 !.
1127compare_terms(Relation, Term1, Term2, _Lambda, Degree) :-
1128 1129 1130 1131 var(Term1), var(Term2), !,
1132 Term1 == Term2,
1133 apply(Relation, [Term1, Term2, Degree]),
1134 var(Term1), var(Term2).
1135
1136compare_terms(Relation, Term1, Term2, Lambda, Degree) :-
1137 1138 atomic(Term1), atomic(Term2), !,
1139 apply(Relation, [Term1, Term2, Degree]),
1140 Degree >= Lambda.
1141
1142compare_terms(Relation, Term1, Term2, Lambda, Degree) :-
1143 1144 compound(Term1), compound(Term2), !,
1145 Term1 =.. [Functor1|Args1],
1146 Term2 =.. [Functor2|Args2],
1147 length(Args1, Arity),
1148 length(Args2, Arity),
1149 apply(Relation, [Functor1, Functor2, DegreeFunctor]),
1150 DegreeFunctor >= Lambda,
1151 compare_args(Args1, Args2, Relation, Lambda, DegreeArgs),
1152 Degree is min(DegreeFunctor, DegreeArgs).
1162compare_args([], [], _Relation, _Lambda, 1).
1163
1164compare_args([Arg1|MoreArgs1], [Arg2|MoreArgs2], Relation, Lambda, Degree) :-
1165 compare_terms(Relation, Arg1, Arg2, Lambda, DegreeArg),
1166 compare_args(MoreArgs1, MoreArgs2, Relation, Lambda, DegreeMoreArgs),
1167 Degree is min(DegreeArg, DegreeMoreArgs). 1168
1169
1170
1184eval_negation(not, Goal, DegreeVars, Degree) :-
1185 1187 (Goal, ! ->
1188 degree_composition(DegreeVars, DegreeGoal),
1189 (DegreeGoal =:= 1 ->
1190 fail
1191 ;
1192 Degree is 1 - DegreeGoal
1193 )
1194 ;
1195 Degree is 1
1196 ).
1197
1198eval_negation(\+, Goal, DegreeVars, Degree) :-
1199 1201 (Goal, ! ->
1202 degree_composition(DegreeVars, DegreeGoal),
1203 (DegreeGoal =:= 1 ->
1204 fail
1205 ;
1206 Degree is 1
1207 )
1208 ;
1209 Degree is 1
1210 ).
1211
1212eval_negation(not, Goal, _BlockConstraints, DegreeVars, Degree) :-
1213 eval_negation(not, Goal, DegreeVars, Degree).
1214
1215eval_negation((\+), Goal, _BlockConstraints, DegreeVars, Degree) :-
1216 eval_negation((\+), Goal, DegreeVars, Degree).
1225over_lambdacut(Degree) :-
1226 flags:get_bpl_flag(lambda_cut(Lambda)),
1227 Degree >= Lambda.
1252
1253degree_composition(List, Degree) :-
1254 degree_composition_aux(List, Degree),
1255 !.
1256
1257degree_composition_aux([], 1).
1258
1259degree_composition_aux([Number|List], Degree) :-
1260 number(Number),
1261 !,
1262 degree_composition_aux(List, PartialDegree),
1263 t_norm_current_op(Number, PartialDegree, Degree).
1264
1265degree_composition_aux([_NotANumber|List], Degree) :-
1266 degree_composition_aux(List, Degree).
1278:- dynamic(t_norm_current_op/3). 1279
1280t_norm_current_op(D1, D2, D) :-
1281 D is min(D1, D2).
1289t_norm_op(yes, D1,D2, D) :- 1290 D is min(D1, D2).
1291t_norm_op(no, D1, D2, D) :-
1292 D is min(D1, D2).
1293t_norm_op(min, D1, D2, D) :-
1294 D is min(D1, D2).
1295t_norm_op(product, D1, D2, D) :-
1296 D is D1*D2.
1298t_norm_op(luka, D1, D2, D) :-
1299 D is max(0, D1+D2-1.0).
1302t_norm_op(drastic, D1, D2, D) :-
1303 (D1=1.0, D=D2, !) ; (D2=1.0, D=D1).
1304t_norm_op(nilpotent, D1, D2, D) :-
1305 (D1+D2>1.0, D is min(D1, D2), !) ; (D1+D2=<1.0, D=0.0).
1306t_norm_op(hamacher, D1, D2, D) :-
1307 (D1=0.0, D2=0.0, D=0.0, !) ; (D1+D2>0.0, D is D1*D2/(D1+D2-D1*D2)).
1317t_norm_op(Degree1, Degree2, Degree) :-
1318 t_norm('~',TNorm),
1319 t_norm_op(TNorm, Degree1, Degree2, Degree).
1331bpl_call(Goal) :-
1332 functor(Goal, Functor, Arity),
1333 current_predicate(Functor/Arity),
1334 1335 !,
1336 Goal.
1337
1347bpl_call(Goal) :-
1348 1349 parser:build_query(Goal, [Query, _DegreeVars]),
1350 1351 Query.
1361bpl_apply(Term, List) :-
1362 Term =.. [Functor|Args],
1363 append(Args, List, NewArgs),
1364 NewTerm =.. [Functor|NewArgs],
1365 bpl_call(NewTerm).
1375bpl_maplist(_Term, []).
1376
1377bpl_maplist(Term, [Item|MoreItems]) :-
1378 Term =.. [Functor|Args],
1379 append(Args, [Item], NewArgs),
1380 NewTerm =.. [Functor|NewArgs],
1381 bpl_call(NewTerm),
1382 bpl_maplist(Term, MoreItems).
1383
1384
1385
1399get_actual_predicate_definition(InternalPredicate, ActualPred/ActualArity) :-
1400 1401 1402 1403 1404 (
1405 InternalPredicate = evaluator:Pred/Arity
1406 ;
1407 InternalPredicate = Pred/Arity
1408 ),
1409 flags:get_bpl_flag(program_prefix(Prefix)),
1410 atom_length(Prefix, PrefixLength),
1411 FullPrefixLength is PrefixLength + 1,
1412 sub_atom(Pred, 0, PrefixLength, _, Prefix),
1413 sub_atom(Pred, FullPrefixLength, _, 0, ActualPredAux),
1414 translator:actual_rule_arity(Arity, ActualArityAux),
1415 (
1416 1417 1418 1419 sub_atom(ActualPredAux, 0, PrefixLength, _, Prefix),
1420 sub_atom(ActualPredAux, FullPrefixLength, _, 0, ActualPred),
1421 translator:actual_rule_arity(ActualArityAux, ActualArity)
1422 ;
1423 ActualPred = ActualPredAux,
1424 ActualArity = ActualArityAux
1425 ),
1426 !.
1427
1428get_actual_predicate_definition(evaluator:Pred/Arity, Pred/Arity) :-
1429 1430 !.
1431
1432get_actual_predicate_definition(Predicate, Predicate).
1433 1434
1435
1436
1448:- dynamic sim/3.
1458:- dynamic sim/4.
1468:- dynamic lEqThan/3.
1478:- dynamic gEqThan/3.
1487:- dynamic frel1/3.
1496:- dynamic frel2/3.
1505:- dynamic frel3/3. 1506
1507
1508
1522:- dynamic current_file/1. 1523
1524current_file('')