12:- if(( ( \+ ((current_prolog_flag(logicmoo_include,Call),Call))) )). 13:- module(mpred_type_naming,
14 [ convertOneSpawnArg/4,
15 convertSpawnArgs/4,
16 convertToInstance/3,
17 createByNameMangle/3,
18 createByNameMangle0/3,
19 createByNameMangle_compound/3,
20 create_from_type/3,
21 create_meta/4,
22 get_source_suffix/2,
23 27 modality/3,
28 doSpawn/1,
29 doSpawn_modal/2,
30 doSpawn_f_args/3,
31 spawnOneSpawnArg/4,
32 40 mpred_type_naming_file/0
41 ]). 42
44:- endif. 45
46:- set_how_virtualize_file(bodies). 47
48:- thread_local(t_l:current_source_suffix/1). 49
50
54:- was_export(create_meta/4). 57
64create_meta(SuggestedName,SuggestedClass,BaseClass,SystemName):-
65 must_det(split_name_type(SuggestedName,SystemName,NewSuggestedClass)),
66 ignore(SuggestedClass=NewSuggestedClass),
67 assert_subclass_safe(SuggestedClass,BaseClass),
68 assert_subclass_safe(NewSuggestedClass,BaseClass),
69 assert_isa_safe(SystemName,BaseClass),
70 assert_isa_safe(SystemName,NewSuggestedClass),
71 assert_isa_safe(SystemName,SuggestedClass).
72
73
74
81createByNameMangle(Name,IDA,InstAO):-must(createByNameMangle0(Name,IDA,InstAO)),!.
82
83
90createByNameMangle0(S,I,C):-is_list(S),toCamelAtom1(S,A),!,createByNameMangle0(A,I,C).
91createByNameMangle0(S,I,C):-string(S),!,string_to_atom(S,A),!,createByNameMangle0(A,I,C).
92createByNameMangle0(OType,Name,Type):-compound(OType),!,must(createByNameMangle_compound(OType,Name,Type)),!.
93createByNameMangle0(Name,_,_Type):- \+ atom(Name),!,trace_or_throw(todo(not_atom_createByNameMangle(Name))).
95createByNameMangle0(OType,Name,Type):-create_from_type(OType,Name,Type),!.
96createByNameMangle0(Suggest,Name,Type):- once(split_name_type(Suggest,Name,Type)),(Suggest==Name;Suggest==Type),assert_isa(Name,Type),!.
97createByNameMangle0(Name,I,C):-ereq(mudKeyword(W,KW)),string_equal_ci(Name,KW),!,createByNameMangle0(W,I,C).
98createByNameMangle0(Name,IDA,Name):- gensym(Name,IDA), englishServerInterface([actCreate,Name,IDA]).
99
100
101toCamelAtom1([A],O):-nonvar(A),!,toPropercase(A,O),!.
102toCamelAtom1([A|List],O):-!,toPropercase(A,AO),toCamelAtom1(List,LO),atom_concat(AO,LO,O).
103toCamelAtom1(A,O):-toPropercase(A,O),!.
104
105
112createByNameMangle_compound(Name,Name,Type):- Name=..[Type|Props],assert_isa(Name,Type),locally(t_l:deduceArgTypes(_),padd(Name,Props)).
113createByNameMangle_compound(Name,Inst,Type):- functor_catch(Name,Type,A),must(A==1),assert_isa(Name,Type),Name=Inst.
114
115
116
117
124get_source_suffix(_NameNeedsNum,SS):- fail,
125 source_location(F,_),!,file_directory_name(F,DN),
126 directory_source_sufix(DN,SS),!,
127 asserta_if_new(t_l:current_source_suffix(SS)).
128get_source_suffix(_NameNeedsNum,SS):- t_l:current_source_suffix(SS),!.
129get_source_suffix(_NameNeedsNum,'7').
130
131:- volatile(lmcache:tmp_directory_source_sufix/2). 132:- dynamic(lmcache:tmp_directory_source_sufix/2). 133directory_source_sufix(DN,SSM):- lmcache:tmp_directory_source_sufix(DN,SSM),!.
134directory_source_sufix(DN,SSM):- make_directory_source_sufix(DN,SSM),!,
135 asserta(lmcache:tmp_directory_source_sufix(DN,SSM)),!.
136
137make_directory_source_sufix(DN,SSM):-
138 file_base_name(DN,SS),
139 atomic_list_concat(REV,'_',SS),reverse(REV,[SS1|_]),
140 141 atomic_list_concat(['_',SS1,8],SSM),!.
142
143
144clip_source_suffix(TypeStemNum,TypeStem):- get_source_suffix(TypeStem,SS), atom_concat(TypeStem,SS,TypeStemNum),!.
145clip_source_suffix(TypeStem,TypeStem):-!.
146
153create_from_type(InstOrType,Name,Type):- sanity(var(Name)),
154 must_det_l((
155 guess_type_name(InstOrType,Type),
156 guess_inst_name(InstOrType,Type,Name),
157 assert_isa(Type,tSet),
158 assert_isa(Name,Type))),!.
159
160guess_type_name(InstOrType,InstOrType):- isa_asserted(InstOrType,tCol),!.
161guess_type_name(InstOrType,InstOrType):- atom_concat('t',_,InstOrType),!.
162guess_type_name(InstOrType,Type):-
163 i_name(InstOrType,TypeStemNum),
164 clip_source_suffix(TypeStemNum,TypeStem),
165 atom_concat('t',TypeStem,Type).
166
167guess_inst_name(InstOrType,Type,InstOrType):- atom_concat('t',Type,InstOrType),!.
168guess_inst_name(Type,Type,Name):-
169 i_name('i',Type,NameNeedsNum),
170 get_source_suffix(NameNeedsNum,SS),
171 atom_concat(NameNeedsNum,SS,Name),!.
172guess_inst_name(Inst,_Type,Inst).
173
174
175
179
180
187modality(mdefault, [usually],[]).
188modality(~ , [cannot],[can]).
189modality(mdefault,[sometimes],[]).
190modality(can,[can],[be]).
191modality(possibly,[either],[]).
192modality(~,[not],[]).
193modality(~,[never],[]).
200doSpawn((A,B)):- must_be(nonvar,A),!,doSpawn(A),doSpawn(B).
201doSpawn(Class==>Fact):-!,mpred_post(Class==>{doSpawn(Fact)}).
202doSpawn(ClassFact):-
203 fully_expand(clause(assert,doSpawn),ClassFact,ClassFactO),!,
204 doSpawn_modal(t,ClassFactO).
205
206
213doSpawn_modal(_Modality,ClassFact):-
214 ClassFact=..[FunctArgType,Name],
215 modality(FunctArgType,_,_),!,
216 must(doSpawn_modal(FunctArgType,Name)).
217
218doSpawn_modal(Modality,ClassFact):- ClassFact=..[FunctArgType,Name],
219 call_u(tSet(FunctArgType)),
220 must_det((
221 createByNameMangle(Name,Inst,TypeA),
222 assert_isa(TypeA,tCol),assert_isa(Inst,FunctArgType),assert_isa(Inst,TypeA),
223 fully_expand(clause(assert,doSpawn),t(Modality,genls(TypeA,FunctArgType)),TO),
224 add_on_start(TO))).
225
226
227doSpawn_modal(Modality,ClassFact):- ClassFact=..[Funct|InstADeclB],
228 must_det(doSpawn_f_args(Modality,Funct,InstADeclB)).
229
230
237doSpawn_f_args(Modality,Funct,List):-
238 must_det((
239 convertSpawnArgs(Funct,1,List,NewList),
240 Later =.. [Funct|NewList],
241 fully_expand(clause(assert,doSpawn),t(Modality,Later),TO),
242 add_on_start(TO))),!.
243 244
245
246definitional(X):- \+ compound(X),!,fail.
247definitional(isa(_,_)).
248definitional(genls(_,_)).
249definitional(t(TO)):- !, definitional(TO).
250definitional(Compound):- functor(Compound,F,A), (A=1;if_defined(definitionalProp(F),fail)).
251
252add_on_start(t(TO)):- nonvar(TO),!,add_on_start(TO).
253add_on_start(TO):- definitional(TO),!,mpred_post(TO).
254add_on_start(TO):- call_u(mpred_post(onStart(TO))).
255
262convertSpawnArgs(_,_,[],[]).
263convertSpawnArgs(Funct,N,[A|List],[O|NewList]):-
264 must(convertOneSpawnArg(Funct,N,A,O)),!,
265 N2 is N + 1,
266 convertSpawnArgs(Funct,N2,List,NewList),!.
267
268
275convertOneSpawnArg(_,_,O,O):-string(O),!.
276convertOneSpawnArg(_,_,O,O):-number(O),!.
277convertOneSpawnArg(_,_,nospawn(O),O):-!.
278convertOneSpawnArg(Funct,N,isInstFn(A),O):-spawnOneSpawnArg(Funct,N,A,O).
279convertOneSpawnArg(Funct,N,A,O):-spawnOneSpawnArg(Funct,N,A,O).
280
281
288spawnOneSpawnArg(Funct,N,Name,Inst):-
289 N == 1, call_u(tCol(Funct)),
290 must(convertToInstance(Name,Funct,Inst)),!.
291
292spawnOneSpawnArg(Funct,N,Name,Inst):-
293 must(argIsa(Funct,N,FunctArgType)),!,
294 must(convertToInstance(Name,FunctArgType,Inst)),!.
295
296
303convertToInstance(Name,FunctArgType,Inst):- call_u(isa(Name,FunctArgType)),!,Inst=Name.
304convertToInstance(Name,COLTHING,TypeA):- a(ttTypeType,COLTHING),createByNameMangle(Name,_,TypeA),assert_isa(TypeA,COLTHING).
305convertToInstance(Name,COLTHING,TypeA):- call_u(genls(COLTHING,tCol)),createByNameMangle(Name,_,TypeA),assert_isa(TypeA,COLTHING).
306convertToInstance(Name,FunctArgType,Inst):- createByNameMangle(Name,Inst,TypeA),
307 assert_isa(Inst,FunctArgType),
308 call_u(mpred_post(genls(TypeA,FunctArgType))),!.
309
310:- fixup_exports. 311
312mpred_type_naming_file