33
34:- module(ods_data,
35 [ assert_table/1, 36 assert_block/1, 37 retract_block/1, 38
39 sheet_object/3, 40 object_union/2, 41 object_id/2, 42 object_data_type/2, 43
44 assert_object_property/2, 45
46 assert_cell_property/4, 47 cell_property/4, 48
49 assert_label/2, 50
51 clean_data/0
52 ]). 53:- use_module(library(error)). 54:- use_module(datasource). 55:- use_module(sheet). 56
57:- meta_predicate
58 assert_table(:),
59 assert_block(:),
60 retract_block(:),
61 sheet_object(:, ?, ?),
62 assert_object_property(:, +),
63 assert_cell_property(:, +, +, +),
64 cell_property(:,?,?,?),
65 assert_label(:,+). 66
67:- module_transparent
68 clean_data/0.
81data(object_property/2).
82data(cell_property/3).
83data(table/5).
84data(block/3).
85data(label/2).
86
87clean_data :-
88 context_module(M),
89 forall(ods_data:data(Name/Arity),
90 ( functor(Head, Name, Arity),
91 retractall(M:Head)
92 )).
93
94
95
103assert_table(M:T) :-
104 assertz(M:T),
105 T = table(TabId, _Type, _MainDS, _HdrDS, Union),
106 ds_sheet(Union, Sheet),
107 forall(ds_inside(Union, X, Y),
108 assert_cell_property(M:Sheet, X, Y, table(TabId))).
114assert_block(M:T) :-
115 assertz(M:T),
116 T = block(BlockId, _Type, DS),
117 ds_sheet(DS, Sheet),
118 forall(ds_inside(DS, X, Y),
119 assert_cell_property(M:Sheet, X, Y, block(BlockId))).
123retract_block(M:BlockId) :-
124 must_be(atom, BlockId),
125 retract(M:block(BlockId, _, _)), !.
126retract_block(M:BlockId) :-
127 existence_error(block, M:BlockId).
137sheet_object(M:Sheet, table, table(TabId, Type, DataDS, HdrDS, Union)) :-
138 ds_sheet(DataDS, Sheet),
139 M:table(TabId, Type, DataDS, HdrDS, Union).
140sheet_object(M:Sheet, block, block(BlockId, Type, DataDS)) :-
141 ds_sheet(DataDS, Sheet),
142 M:block(BlockId, Type, DataDS).
148object_union(table(_TableId, _Type, _DataDS, _HdrDS, Union), Union).
149object_union(block(_BlockId, _Type, DataDS), DataDS).
153object_id(table(TableId, _Type, _DataDS, _HdrDS, _Union), TableId).
154object_id(block(BlockId, _Type, _DataDS), BlockId).
158object_data_type(table(_TableId, Type, _DataDS, _HdrDS, _Union), Type).
159object_data_type(block(_BlockId, Type, _DataDS), Type).
163assert_object_property(M:ObjId, Property) :-
164 ( M:object_property(ObjId, Property)
165 -> true
166 ; assertz(M:object_property(ObjId, Property))
167 ).
168
169
170
179assert_cell_property(M:Sheet, X, Y, Property) :-
180 cell_id(X,Y,CellId),
181 assertz(M:cell_property(Sheet,CellId,Property)).
188cell_property(M:Sheet, X, Y, Property) :-
189 ( nonvar(X), nonvar(Y)
190 -> cell_id(X,Y,Id),
191 M:cell_property(Sheet,Id,Property)
192 ; M:cell_property(Sheet,Id,Property),
193 cell_id(X,Y,Id)
194 ).
195
196
197
205assert_label(M:Label, Count) :-
206 assertz(M:label(Label, Count))
Data store module
Defined relations:
table(TableId, Type, DataDS, HeaderDSList, UnionDS)
block(BlockId, Type, DataDS)
object_property(ObjectId, Property)
cell_property(Sheet, X, Y, Property)
*/