📄 migma.pl
字号:
mix_alt2(Rest).
mix_alt([]).
mix_alt([(Name,L1,C)|Qs]):-
%write('dbg mix_alt std'), nl,
min_list(L1,Lmin),
max_list(L1,Lmax),
rnd_list(Lmin,Lmax,LT),
%write('LT='),write(LT),nl,
q(Name,_,Lfix,_),
subtract(LT,Lfix,LT2),
append(LT2,Lfix,L2),
assertz(q2(Name,L2,_,C)),
mix_alt(Qs).
rnd_list(Lmin,Lmax,R):-
Tam is Lmax-Lmin+1,
create_list(0,Tam,R),
rnd_list(Lmin,Lmax,Tam,R).
rnd_list(Lmin,Lmax,_,L):-
%nl,write('------------------------>000'),nl,
fd_all_different(L),
fd_domain(L,Lmin,Lmax),
real_time(A),
set_seed(A),
randomize,
%nl,write('Lmin2='),write(Lmin), nl,write('Lmax2='),write(Lmax),nl,write('L='),write(L),nl,
fd_labeling(L,[variable_method(random)]),
asserta(alb(L)).
% newlist(L1,L2):-
% length(L1,T1),
% X is T1*7,
% perms_creation(L1,X,[R|Rs]),
% length([R|Rs],Len),
% rnd(Len,Num),
% %write('dbg newlist0'), nl,
% newlist(Rs,Num,R,L2).
% newlist([],_,R,R).
% newlist(_,0,R,R).
% newlist([A|B],N,_,R):-
% T is N-1,
% %write('dbg newlist std'), nl,
% newlist(B,T,A,R).
% perms_creation(L,X,R):-
% perms_creation(L,X,[],R).
% perms_creation(_,0,R,R).
% perms_creation(L,N,S,R):-
% T is N-1,
% permutation(L,Lt2),
% %perm2(Lt2a,Lt2),
% Lt2 \= L,
% reverse(Lt2,L2),
% not(member(L2,S)),
% append([L2],S,S2),
% %write('dbg perms_creation'), nl,
% perms_creation(L2,T,S2,R).
rnd(X,B):-
real_time(A),
set_seed(A),
randomize,
random(1,X,B).
%atom_io( Atom) :- io( List ), atom_codes( Atom, List ).
sio(Arq,R):-
io(Arq,L),
conc(L,R).
conc(L,R):-
conc(L,[],R).
conc([],R,R).
conc([A|B],S,R):-
atom_concat(S,A,S2),
conc(B,S2,R).
/*
About io(/2), chars_from_streams(/1) and get_my_byte(/1) predicates:
extract from gnu-prolog maillists (thanks to Detlef Sax)
http://lists.gnu.org/archive/html/users-prolog/2002-10/msg00017.html
*/
io(Arq,List) :-
open(Arq, read, Stream),
add_stream_alias(Stream, fin),
chars_from_stream(List).
chars_from_stream(_) :-
at_end_of_stream(fin),
close(fin).
chars_from_stream([Char| Chars]) :-
get_my_byte(Char),!,
chars_from_stream(Chars).
get_my_byte(C) :-
get_code(fin, C).
not(P):- P,!,fail; true.
/*
About subtract(/3) predicate:
extract from swi-prolog (listing the subtract predicate)
*/
subtract([], _, []) :- !.
subtract([A|B], C, D) :-
memberchk(A, C), !,
subtract(B, C, D).
subtract([A|B], C, [A|D]) :-
subtract(B, C, D).
about:-
write('Migma 0.1.0 - 2004'),nl,
write('by Antonio L Basile (albasile@ime.usp.br)'),nl,
write('GNU General Public License (GPL)'),nl,
write('Migma comes with ABSOLUTELY NO WARRANTY.'),nl,nl.
help:-
write('Usage: migma [options] <input-file>...'),nl,
write('Options:'), nl,
write(' -h, --help print this help and exit'), nl,
write(' --hbr print this help in portuguese and exit'), nl,
write(' -a reorder alternatives (only)'), nl,
write(' -q reorder questions (only)'), nl,
write(' --all reorder alternatives & questions (default)'),nl,
write(' -o <file> place output into file'), nl,
write(' --num <N> number of (generated) different tests'), nl,
write(' --nolatex output without latex format (default: latex)'),nl,
write(' --stats print statistics'), nl,
write(' --audit create validation file'), nl,
write(' --time print execution time'), nl,
write(' --about display about information and exit'), nl,
write('You can use --param or -param (with the same effect) for all the options above.'), nl, nl,
write('On your text (original): '), nl,
write(' begin text (first line) with \\inigab <answer sheet> \\fimgab'),nl,
write(' begin all questions with \\que '),nl,
write(' begin all alternatives that can be changed with \\item '), nl,
write(' begin all fixed alternatives with \\fixo (only last ones supported)'), nl,nl,
write('Example: '),nl,
write(' \\inigab 1c-2a-3c-4b-5e \\fimgab %use this layout (ans-sheet)'),nl,
write(' \\que Choose an irrational animal: '), nl,
write(' \\item the author of this software'), nl,
write(' \\item a student asking for good marks'), nl,
write(' \\item prolog'), nl,
write(' \\item everybody'), nl,
write(' \\fixo none of the above'), nl,
write(' etc...'), nl, nl,
write('Report bugs to albasile@ime.usp.br ;-)'), nl.
ajuda:-
write('Uso: migma [opcoes] <arquivo de entrada>...'),nl,
write('Opcoes:'), nl,
write(' -h, --help mostra este help em ingles e sai'), nl,
write(' --hbr mostra este help e sai'), nl,
write(' -a somente as alternativas mudarao de lugar'), nl,
write(' -q somente as questoes mudarao de lugar'), nl,
write(' --all alternativas & questoes mudarao (default)'),nl,
write(' -o <arquivo> coloca a saida no arq especif'), nl,
write(' --num <N> numero de provas diferentes (geradas)'), nl,
write(' --nolatex nao adiciona formatacao latex (default: latex)'),nl,
write(' --stats mostra estatisticas sobre as provas'), nl,
write(' --audit cria arquivos de validacao'), nl,
write(' --time mostra o tempo de execucao'), nl,
write(' --about mostra <about> e sai'), nl,
write('Tanto faz usar o parametro-- ou o parametro- para as opcoes. '), nl, nl,
write('No seu texto original: '), nl,
write(' comece o texto (primeira linha) com \\inigab <gabarito> \\fimgab'),nl,
write(' comece cada questao com \\que '),nl,
write(' comece cada alternatives que pode mudar de lugar com \\item '), nl,
write(' comece cada alternativa fixa com \\fixo (apenas aceito p/ultima alternat)'), nl,nl,
write('Exemplo: '),nl,
write(' \\inigab 1c-2a-3c-4b-5e \\fimgab %use este layout (gabarito)'),nl,
write(' \\que Escolha um animal irracional: '), nl,
write(' \\item o autor deste software'), nl,
write(' \\item um aluno pedindo nota'), nl,
write(' \\item prolog'), nl,
write(' \\item todos'), nl,
write(' \\fixo nda'), nl,nl,
write(' etc...'), nl, nl,
write('Para informar sobre bugs: albasile@ime.usp.br ;-)'), nl.
stats(L):-
member('-stats',L),
%write('dbg stats0'),nl,
stats_calc(R),
show_stats(R).
stats(L):-
member('--stats',L),
%write('dbg stats0'),nl,
stats_calc(R),
show_stats(R).
stats(_).
stats_calc(R):-
ans_sheet_fix(X),
length(X,Len),
%write('dbg statscalc a'),nl,
stats_calc(0,Len,[],Rx),
reverse(Rx,R).
stats_calc(N,N,R,R).
stats_calc(T,N,S,R):-
T2 is T+1,
findall(X,(ans_sheet_fix(G),nth(T2,G,X)),L),
stats_proc(L,L2),
append([L2],S,S2),
%write('dbg statscalc b'),nl,
stats_calc(T2,N,S2,R).
stats_proc(L,R):-
stats_proc(L,0,0,0,0,0,Rx),
reverse(Rx,R).
stats_proc([],A,B,C,D,E,R):-
append([A],[B],T1),
append([C],[D],T2),
append(T1,T2,T3),
append([E],T3,R).
stats_proc([1|Xs],A,B,C,D,E,R):-
A2 is A+1,
%write('dbg statsproc a'),nl,
stats_proc(Xs,A2,B,C,D,E,R).
stats_proc([2|Xs],A,B,C,D,E,R):-
B2 is B+1,
%write('dbg statsproc b'),nl,
stats_proc(Xs,A,B2,C,D,E,R).
stats_proc([3|Xs],A,B,C,D,E,R):-
C2 is C+1,
%write('dbg statsproc c'),nl,
stats_proc(Xs,A,B,C2,D,E,R).
stats_proc([4|Xs],A,B,C,D,E,R):-
D2 is D+1,
%write('dbg statsproc d'),nl,
stats_proc(Xs,A,B,C,D2,E,R).
stats_proc([5|Xs],A,B,C,D,E,R):-
E2 is E+1,
%write('dbg statsproc e'),nl,
stats_proc(Xs,A,B,C,D,E2,R).
show_stats(L):-
nl,
write('Number of times each letter occurs (per question) - all exams (includes original)'),
nl,
write(' a,b,c,d,e'),
nl,
show_stats(L,0).
show_stats([],_):-
write(' a,b,c,d,e'),
nl.
show_stats([A|B],T):-
T2 is T+1,
write(' question'),
write(T2),
write('='),
write(A),
nl,
%write('dbg showstats'),nl,
show_stats(B,T2).
save_adt(N):-
findall(C,q2(_,_,_,C),Ladt),
sort(Ladt,Ladt2),
asserta(adt(N,Ladt2)).
test_adt:-
argument_list(Args),
member('-audit',Args),
findall((N,Ladt),adt(N,Ladt),L),
last(Args,File),
atom_concat(File,'.audit',Faudit),
open(Faudit,write,Adt),
treat_adt(L,Adt),
close(Adt).
test_adt:-
argument_list(Args),
member('--audit',Args),
findall((N,Ladt),adt(N,Ladt),L),
last(Args,File),
atom_concat(File,'.audit',Faudit),
open(Faudit,write,Adt),
treat_adt(L,Adt),
close(Adt).
test_adt.
treat_adt([],_).
treat_adt([(N,Lans)|Rest],Adt):-
nl(Adt),
write(Adt,'-----------------'),
nl(Adt),
write(Adt,'Test number '),
write(Adt,N),
nl(Adt),
write(Adt,'-----------------'),
nl(Adt),
print_ans(Lans,Adt),
treat_adt(Rest,Adt).
print_ans([],_).
print_ans([A|B],Adt):-
answer(A,Text),
write(Adt,'-->'),
write(Adt,Text),
% nl(Adt),
print_ans(B,Adt).
create_list(Number,List):-
create_list(Number,0,[],List).
create_list(N,N,R,R).
create_list(N,T,S,R):-
T2 is T+1,
append(S,[T2],S2),!,
create_list(N,T2,S2,R).
create_list(A,A,[]).
create_list(T,N,[_|L]):-
T2 is T+1,
create_list(T2,N,L).
/*minimum frequency element in a list (zero inclusive) */
/*elemento que menos ocorre numa lista (neste caso pode ser nula a ocorr阯cia*/
elem_min_ocurr(L,R):-
elem_min_ocurr([1,2,3,4,5],L,R).
elem_min_ocurr([A|_],L,A):-
ocurr(A,L,0).
elem_min_ocurr([A|B],L,R):-
ocurr(A,L,Na),
elem_min_ocurr(B,A,Na,L,R).
elem_min_ocurr([],R,_,_,R).
elem_min_ocurr([A|B],_,Nx,L,R):-
ocurr(A,L,Na),
Na =< Nx,
elem_min_ocurr(B,A,Na,L,R).
elem_min_ocurr([A|B],X,Nx,L,R):-
ocurr(A,L,Na),
Na > Nx,
elem_min_ocurr(B,X,Nx,L,R).
ocurr(_,[],0).
ocurr(X,[X|Y],R):-
ocurr(X,Y,T),
R is T+1.
ocurr(X,[Z|Y],R):-
X \= Z,
ocurr(X,Y,R).
olha:-
argument_list(L),
olha(L,[],R),
write(R).
olha([],R,R).
olha([A|B],S,R):-
atom(A),
write('atom-->'), write(A),nl,
atom_concat(S,A,S2),
olha(B,S2,R).
olha([A|B],S,R):-
number(A),
write('number-->'), write(A),nl,
atom_concat(S,A,S2),
olha(B,S2,R).
testalb:-
findall(X,alb([X,_,_,_,_]),L),
length(L,T),
T<5.
testalb:-
retractall(alb(_)),
asserta(alb([1,2,3,4,5])).
% perm2(L,R):-
% perm2(L,5,R).
% perm2(R,0,R).
% perm2(L,N,R):-
% X is N-1,
% perm(L,T),
% perm2(T,X,R).
split([],[],[]).
split([A],[A],[]).
split([A,B|Zs],[A|As],[B|Bs]):-
split(Zs,As,Bs).
% perm(L,R):-
% length(L,T),
% X is T/2,
% perm(L,X,R).
% perm(L,X,R):-
% divide(L,X,[],L1,L2),
% junta(L1,L2,R).
divide(L2,0,L1,L1,L2).
divide([A|B],X,S1,L1,L2):-
T is X-1,
append([A],S1,Sa),
divide(B,T,Sa,L1,L2).
junta([],[],[]).
junta([],L,L).
junta(L,[],L).
junta([A|As],[B|Bs],[B,A|Zs]):-
junta(As,Bs,Zs).
%gprolog --query-goal '[my_file], my_query(X)'
% bbb(N,R):-
% statistics(runtime,_),
% bbb(N,[],R),
% statistics(runtime,[_,Y]),
% write('time : '), write(Y), nl.
% bbb(0,R,R).
% bbb(N,S,R):- T is N-1, aaa(K), \+ member(K,S), append(S,[K],S2), bbb(T,S2,R).
% bbb(N,S,R):- T is N-1, aaa(K), member(K,S), reverse(K,K2), \+ member(K2,S), append(S,[K2],S2), bbb(T,S2,R).
% save_audit:-
% %convert_q_to_q2,
% argument_list(Args),
% member('-audit',Args),
% findall(File,outfiles(File),L),
% save_audit(L). % listing(q2).
% save_audit:-
% argument_list(Args),
% member('--audit',Args),
% findall(File,outfiles(File),L),
% save_audit(L).
% save_audit.
% save_audit([File|Fs]):-
% save_audit([File|Fs],[],R),
% save_file_audit(File,R).
% save_audit([],R,R).
% save_audit([File|Fs],S,R):-
% initiate,
% io(File,L2),
% read_ans_sheet(L2,Lg),
% ans_sheet(Answer_sheet),
% treats(Lg,Answer_sheet,0,0),
% findall(Answer,(q(_,_,_,C),answer(C,Answer)),L1),
% sort(L1,Lq),
% append(S,Lq,S2),
% %write(Lq),nl,
% save_audit(Fs,S2,R).
% save_file_audit(File,L):-
% atom_concat(File,'.audit',Faudit),
% open(Faudit,write,Adt),
% flattening(L,L2),
% sort(L2,L3),
% write(Adt,'Number of different answers (all exams):'),
% length(L3,Nq),
% write(Adt,Nq),
% nl(Adt),nl(Adt),
% write(Adt,'Correct answers:'),
% nl(Adt),
% print_correct(L3,Adt),
% nl(Adt),
% close(Adt).
% print_correct([],_).
% print_correct([L|Ls],Adt):-
% write(Adt,'--> '),
% write(Adt,L),
% nl(Adt),
% print_correct(Ls,Adt).
% ty(Lu):-
% Lu=[_],
% fd_domain(Lu,1,120),
% real_time(A),
% set_seed(A),
% randomize,
% fd_labeling(Lu,[variable_method(random),value_method(random)]).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -