/* ========================================================================== */
/*                 LOADING BACKGROUND KNOWLEDGE AND EXAMPLES                  */
/* ========================================================================== */

:- module(manage_examples2,
          [
             get_domains/3,
             erase_examples_test/0,
             erase_examples/0,
             erase_background/0,
             get_examples/4,
             get_examples_test/4,
             load_examples_file/1,
             load_background_file/1,
             load_test_file/1
          ]
         ). 

/* ========================================================================== */


:- dynamic train:loaded_examples, test:loaded_examples, bk:loaded_background.


 :- getenv('LEAR_DIR', Lear),
    atom_concat(Lear, '/utilities_lear11.pl', Utilities),
    use_module(Utilities).
 

/* ======================= LOADING AND ERASING EXAMPLES ===================== */


   /* return domains related with the current example */
get_domains(Num, Mode, LDomains) :-
   get_learn_mode(Learn_mode),
   Learn_mode:domains(Num, Mode, LDomains).


   /* erase all data relative to the training examples */
 erase_examples :-
   train:retract(loaded_examples),
   train:retract(examplesP(_)),
   train:retract(examplesN(_)),
   train:retract(tabs(pos, _)),
   train:retract(tabs(neg,_)),
   train:retractall(domains(_, _, _)),
   train:retractall(target(_, _, _)). 


   /* erase all data relative to the test examples */
 erase_examples_test :-
   test:retract(loaded_examples),
   test:retract(examplesP(_)),
   test:retract(examplesN(_)),
   test:retract(tabs(pos, _)),
   test:retract(tabs(neg,_)),
   test:retractall(domains(_, _, _)),
   test:retractall(target(_, _, _)). 
   
   

   /* erase all data relative to the background knowledge */
erase_background :-
   bk:retract(target_relation(_)),
   bk:retract(loaded_background),
   bk:retractall(mode(_)),
   bk:retract(types_instantiable(_)),
   bk:retract(types_under_oi(_)).  


get_examples(LPos, LTab_pos, LNeg, LTab_neg) :-
        train:examplesP(LPos),
        train:tabs(pos, LTab_pos),
        train:examplesN(LNeg),
        train:tabs(neg, LTab_neg),
        !.
        
get_examples(_, _, _, _) :-
        writeln('there is no example !'),
        write('use load_examples_background(FileName) to get them.').
        
        
get_examples_test(LPos, LTab_pos, LNeg, LTab_neg) :-
        test:examplesP(LPos),
        test:tabs(pos, LTab_pos),
        test:examplesN(LNeg),
        test:tabs(neg,LTab_neg),
        !.
        
get_examples_test(_, _, _,_ ) :-
        writeln('there is no example for test!'),
        write('use load_examples_test(FileName) to get them.'). 


load_examples_background(File_name) :-
        load_background_file(File_name),
        load_examples_file(File_name).  
        
        
load_background_file(_File_name) :-     
        bk:loaded_background,
        !.
        
load_background_file(File_name) :-      
        atom_concat(File_name, '.bkg', Background_file),
        bk:consult(Background_file).
        
        
load_examples_file(_File_name) :-       
        train:loaded_examples,
        !.      
               
load_examples_file(File_name) :-
        atom_concat(File_name, '.pl', Example_file),
        train:consult(Example_file).

        
load_test_file(_File_name) :-       
        test:loaded_examples,
        !.      
        
load_test_file(File_name) :-
        atom_concat(File_name, '.pl', Examples_test),
        test:consult(Examples_test).

/* ========================== FIN DU LISTING ================================ */
