Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/CSV-data-manipulation/Prolog/csv-data-manipulation.pro
Normal file
22
Task/CSV-data-manipulation/Prolog/csv-data-manipulation.pro
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
test :- augment('test.csv', 'test.out.csv').
|
||||
|
||||
% augment( +InFileName, +OutFileName)
|
||||
augment(InFile, OutFile) :-
|
||||
open(OutFile, write, OutStream),
|
||||
( ( csv_read_file_row(InFile, Row, [line(Line)]),
|
||||
% Row is of the form row( Item1, Item2, ....).
|
||||
addrow(Row, Out),
|
||||
csv_write_stream(OutStream, [Out], []),
|
||||
fail
|
||||
)
|
||||
; close(OutStream)
|
||||
).
|
||||
|
||||
% If the first item in a row is an integer, then append the sum;
|
||||
% otherwise append 'SUM':
|
||||
addrow( Term, NewTerm ) :-
|
||||
Term =.. [F | List],
|
||||
List = [X|_],
|
||||
(integer(X) -> sum_list(List, Sum) ; Sum = 'SUM'),
|
||||
append(List, [Sum], NewList),
|
||||
NewTerm =.. [F | NewList].
|
||||
Loading…
Add table
Add a link
Reference in a new issue