-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.pl
68 lines (58 loc) · 1.96 KB
/
loader.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
:- module(loader,[
load_files_from_the_directory/1,
allow_multifile_predicates_for_the_directory/1,
activate_objects_in/1,
possibility_influence/1,
depth_limit/1
]).
:- module_transparent
load_files_from_the_directory/1,
load_files_from_the_list/1,
allow_multifile_predicates_for_the_directory/1,
allow_multifile_for/1,
activate_objects_in/1,
activate_objects_from_files/1,
possibility_asserted_for/1,
possibility_influence/1,
depth_limit/1.
list_of_prolog_files_in_a_directory(Files,Directory) :-
atom_concat(Directory,'/*.pl',Wildcard),
expand_file_name(Wildcard,Files).
load_files_from_the_directory(Directory) :-
list_of_prolog_files_in_a_directory(Files,Directory),
load_files_from_the_list(Files).
load_files_from_the_list([]).
load_files_from_the_list([Head|Tail]) :-
ensure_loaded(Head),
load_files_from_the_list(Tail).
allow_multifile_predicates_for_the_directory(Directory) :-
list_of_prolog_files_in_a_directory(Files,Directory),
allow_multifile_for(Files).
allow_multifile_for([]).
allow_multifile_for([Path|Paths]) :-
file_base_name(Path,File),
file_name_extension(Base,_,File),
file_name_extension(URelation,SArity,Base),
downcase_atom(URelation,Relation),
atom_number(SArity,Arity),
multifile(Relation/Arity),
allow_multifile_for(Paths).
activate_objects_in(Directory) :-
list_of_prolog_files_in_a_directory(Files,Directory),
activate_objects_from_files(Files).
activate_objects_from_files([]).
activate_objects_from_files([Path|Paths]) :-
file_base_name(Path,File),
file_name_extension(Base,_,File),
downcase_atom(Base,Object),
asserta(active(Object)),
possibility_asserted_for(Object),
activate_objects_from_files(Paths).
possibility_asserted_for(Object) :-
knowledgebase:possibility_for(_,Object).
possibility_asserted_for(Object) :-
\+knowledgebase:possibility_for(_,Object),
knowledgebase:asserta(possibility_for(1,Object)).
:- prompt(_,'').
possibility_influence(0.3).
depth_limit(100).