:- eval(consult("utils.prova")).

:- eval(parse(scop,des,"/prova/des.txt")).
:- eval(parse(scop,cla,"/prova/cla.txt")).

% Database locations
location(database,scop,"jdbc:mysql://localhost/scop","username","password").

% SCOP: Populate
parse(DBName,Type,File) :-
	dbopen(DBName,DB),
	fopen(File,Reader),
	read_enum(Reader,Line),
	db_import(DB,DBName,Type,Line).
db_import(DB,scop,des,Line) :-
	tokenize_list(Line,"\t",[T|Ts]),
	sql_insert(DB,des,[id,type,sccs,sid,description],[T|Ts]).
db_import(DB,scop,cla,Line) :-
	tokenize_list(Line,"\t",[Sid,Pid,DDefs,Sccs,PX,Trace]),
	tokenize_enum(DDefs,",",DDef),
	parse_list(DDef,"(?:(\w*):|)(-?\d*\w?)-?(\d*)",[T|Ts]),
	sql_insert(DB,subchain,[px,chain_id,begin,end],[PX,T|Ts]).
db_import(DB,scop,cla,Line) :-
	tokenize_list(Line,"\t",[Sid,Pid,DDefs,Sccs,PX,Trace]),
	parse_nv(Trace,"(?:(\w+)=(\w+),?)",[N|Ns],[V|Vs]),
	sql_insert(DB,cla,[sid,pdb_id,sccs,N|Ns],[Sid,Pid,Sccs,V|Vs]).

