-
Notifications
You must be signed in to change notification settings - Fork 2
/
list_utils.pl
92 lines (57 loc) · 2.18 KB
/
list_utils.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
Copyright (C) 2015 Nicola Dileo, Tommaso Viterbo
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
% Module: list_utils.pl
% --------
%
% This module contains the predicate to manage a list. In this system
% a list contains couple with rule identifier and rule salience
difference(L,[],L).
difference(L1,[H|L2],L3) :-
not(member(H,L1)),
difference(L1,L2,L3).
difference(L1,[H|L2],L3) :-
member(H,L1),
nth0(_,L1,H,L4),
difference(L4,L2,L3).
extractSubList([],_,[]) :- !.
extractSubList([Item|_],Item,[Item]) :- !.
extractSubList([ItemX|Rest],Item,ListOut) :-
extractSubList(Rest,Item,ListOutX),
append([ItemX],ListOutX,ListOut),
!.
insertRule(RuleID-Salience,[],[RuleID-Salience]) :- !.
insertRule(RuleID-Salience,[RuleIDX-SalienceX|Rest],[RuleID-Salience,RuleIDX-SalienceX|Rest]) :-
Salience < SalienceX,
!.
insertRule(RuleID-Salience,[RuleIDX-Salience|Rest],[RuleID-Salience,RuleIDX-Salience|Rest]) :-
RuleID < RuleIDX,
!.
insertRule(RuleID-Salience,[RuleIDX-SalienceX|Rest],[RuleIDX-SalienceX|Others]) :-
insertRule(RuleID-Salience,Rest,Others).
memberRule(RuleID, [RuleID-_|_]) :- !.
memberRule(RuleID, [_-_|Rest]) :-
memberRule(RuleID,Rest).
sortDiagnosis([],[]).
sortDiagnosis([Diag-CF|Rest],Sorted) :-
partition(Rest,CF,Left,Right),
sortDiagnosis(Left,LeftS),
sortDiagnosis(Right,RightS),
append(LeftS,[Diag-CF|RightS],Sorted).
partition([DiagX-CFX|Rest],CF,[DiagX-CFX|Ls],Rs) :-
CFX > CF,
partition(Rest,CF,Ls,Rs).
partition([],_,[],[]).
partition([DiagX-CFX|Rest],CF,Ls,[DiagX-CFX|Rs]) :-
CFX =< CF,
partition(Rest,CF,Ls,Rs).