-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwrites.pl
72 lines (65 loc) · 1.58 KB
/
writes.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
/***
* UNIVPM - Intelligenza Artificiale (a.a. 2020/2021)
* Albero di Decisione binario con diverse politiche di scelta dell'attributo (Gini, Gain, Gainratio)
*
* Conti Edoardo - [email protected]
* Federici Lorenzo - [email protected]
* Melnic Andrian - [email protected]
*
* writes.pl
***/
% debug per stampare termini "in input" su file
debug(A):-
open('debug.txt', append, Out),
write(Out,A),
writeln(Out, ' '),
writeln(Out, ' '),
close(Out).
% stampa albero formattato su terminale
mostra(T) :-
mostra(T,0).
mostra(null,_) :- writeln(' ==> ???').
mostra(l(X),_) :- write(' ==> '),writeln(X).
mostra(t(A,L),I) :-
nl,tab(I),write(A),nl,I1 is I+2,
mostratutto(L,I1).
mostratutto([],_).
mostratutto([V:T|C],I) :-
tab(I),write(V), I1 is I+2,
mostra(T,I1),
mostratutto(C,I).
% stampa albero formattato su file
txt(T,File) :-
exists_file(File),
delete_file(File),
txt(T, File).
txt(T, File) :-
\+ exists_file(File),
open(File, append, Out),
txt(Out, T,0),
close(Out).
txt(Out, null,_) :-
writeln(Out, ' ==> ???').
txt(Out, l(X),_) :-
write(Out, ' ==> '), writeln(Out, X).
txt(Out, t(A,L), I) :-
((I > 0) ->
(writeln(Out, ' '),
tabs(Out, I, 0));
(true)),
write(Out, '|--- '), write(Out, A),
writeln(Out, ' '),
I1 is I+2,
txtTutto(Out, L, I1).
txtTutto(_, [],_).
txtTutto(Out, [V:T|C], I) :-
tabs(Out, I-2, 0),
write(Out, '|--- '), write(Out, V),
I1 is I+2,
txt(Out, T, I1),
txtTutto(Out, C,I).
tabs(Out, I, Counter) :-
write(Out, '|'),
tab(Out, 2),
Counter2 is Counter+1,
(I > 0) -> (I2 is I-2, tabs(Out, I2, Counter2)); !.