-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabels.pl
46 lines (39 loc) · 991 Bytes
/
labels.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
:- module(labels,
[ assert_labels/1 % +Sheet
]).
:- use_module(library(ods/sheet)).
:- use_module(library(ods/data)).
:- meta_predicate
assert_labels(:).
/** <module> Collect and count labels found in a spreadsheet
*/
/*******************************
* FINDING LABELS *
*******************************/
%% assert_labels(?Sheet)
%
% Collect all labels. Each label is represented as a label(Text,
% Count).
assert_labels(Sheet) :-
Sheet = M:SheetName,
findall(Label,
( M:sheet(SheetName, _Style),
cell_type(Sheet,X,Y,string),
cell_value(Sheet,X,Y,Label),
Label \== ''
),
Labels),
msort(Labels, Sorted),
count(Sorted, CountLabel),
keysort(CountLabel, ByCount),
reverse(ByCount, ByCountDown),
forall(member(Count-Label, ByCountDown),
assert_label(M:Label, Count)).
count([], []).
count([H|T0], [C-H|T]) :-
same(H, 1, C, T0, T1),
count(T1, T).
same(H, C0, C, [H|T0], T) :- !,
C1 is C0+1,
same(H, C1, C, T0, T).
same(_, C, C, T, T).