-
Notifications
You must be signed in to change notification settings - Fork 29
/
test.pl
70 lines (55 loc) · 1.41 KB
/
test.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
%%%%%%%%%% EXAMPLE LOADING %%%%%%%%%%
load_examples:-
load_pos,
load_neg.
load_pos:-
current_predicate(pos/1),!,
findall(X, pos(X), Pos),
assert_pos_aux(Pos,1).
load_pos.
load_neg:-
current_predicate(neg/1),!,
findall(X, neg(X), Neg),
assert_neg_aux(Neg,-1).
load_neg.
assert_pos_aux([],_).
assert_pos_aux([H|T],I1):-
assertz(pos_index(I1, H)),
I2 is I1+1,
assert_pos_aux(T,I2).
assert_neg_aux([],_).
assert_neg_aux([H|T],I1):-
assertz(neg_index(I1, H)),
I2 is I1-1,
assert_neg_aux(T,I2).
%%%%%%%%%% EXAMPLE TESTING %%%%%%%%%%
ex_index(ID,Atom):-
current_predicate(pos_index/2),
pos_index(ID,Atom).
ex_index(ID,Atom):-
current_predicate(neg_index/2),
neg_index(ID,Atom).
test_ex(Atom):-
functor(Atom,P,A),
current_predicate(P/A),!,
timeout(T),
catch(call_with_time_limit(T, call(Atom)),time_limit_exceeded,false),!.
success_set(Xs):-
findall(ID, (ex_index(ID,Atom),test_ex(Atom)), Xs).
%% ========== FUNCTIONAL CHECKS ==========
non_functional:-
pos(Atom),
non_functional(Atom),!.
%% ========== REDUNDANCY CHECKS ==========
subsumes(C,D) :- \+ \+ (copy_term(D,D2), numbervars(D2,0,_), subset(C,D2)).
subset([], _D).
subset([A|B], D):-
member(A, D),
subset(B,D).
redundant_literal(C1):-
select(_,C1,C2),
subsumes(C1,C2),!.
redundant_clause(P1):-
select(C1,P1,P2),
member(C2,P2),
subsumes(C1,C2),!.