2:- use_module(library(logicmoo_cg)).    3
    4
    5cg_graph_value(N,V):- cg(N,Data),cg_formate(Data,V).
    6
    7cg_formate(Data,V):- 
    8     findall(Member,cg_member(Member,Data),Members),
    9     unnumbervars(Members,UMembers),!,
   10     exclude(formed,UMembers,V).
   11
   12formed(frame_var(_, _)).
   13formed(cg_type(_, _)).
   14formed(cg_name(Var, Value)):- =(Var, Value).
   15formed(cg_equal(Var, Value)):- =(Var, Value).
   16% formed(cg_values(E, List)):- member(E,List).
   17%formed(_).
   18
   19cg_member(E,named_graph(_,Data)):- !, cg_member(E,Data).
   20cg_member(E,Data):- is_list(Data),!, member(ED,Data),cg_member(E,ED).
   21cg_member(E,E).
   22
   23
   24id_to_info(ID,(Label + List)):- cgc(ID,simple,Label,_,_),!,
   25   findall(Text,(cg(_,CGRS, _, _),member(cgr(Rel, Args, _),CGRS),
   26          member(ID,Args),id_to_text(cgr(Rel, Args, _),Text)),List).
   27id_to_info(ID,Label):- cg(ID, Rels, More, Data), maplist(id_to_text,Rels,Labels), append([Labels,[more=More],Data],Label),!.
   28id_to_info(ID,complex(Act,MoveBlock)):- 
   29   cgc(ID,complex,Act,_,[fs(name,MoveBlock)|_]),!.
   30
   31
   32
   33id_to_info(ID,C):- id_to_info1(ID,C) *-> true ; id_to_info_all(ID,C).
   34   
   35id_to_info1(ID,C):-
   36        member(C,[cg(ID,_,_,_),reldef(ID,_,_),cgc(ID,_,_,_,_),typedef(ID,_,_), findrels(ID,_Cid,_,_)]), % ,findrels(_,ID,_,_)
   37        call(C),!.                                                                     
   38id_to_info_all(FID,C):-
   39        member(C,[cg(ID,_,_,_),reldef(ID,_,_),cgc(ID,_,_,_,_),typedef(ID,_,_), findrels(ID,_Cid,_,_)]), % ,findrels(_,ID,_,_)
   40        call(C),contains_var(FID,C).
   41
   42% id_to_text(ID,cg(ID)):- cg(ID, _Rels, _More, _Data),!.
   43
   44
   45id_to_text(ID,Label):- cgc(ID, simple, Label,_,_),!.
   46id_to_text(ID,complex(Act,MoveBlock)):-  cgc(ID,complex,Act,_,[fs(name,MoveBlock)|_]),!.
   47id_to_text(ID,cg(Act,MoveBlock)):- cg(ID, _Rels, _More, _Data), cgc(_,complex,Act,[ID],[fs(name,MoveBlock)|_]),!.
   48id_to_text(ID,cg(ID)):- cg(ID, _Rels, _More, _Data),!.
   49id_to_text(cgr(Rel, Args, _),Label):-  maplist(id_to_text,Args,Labels),!, Label =.. [Rel|Labels].
   50id_to_text(ID,LabelOut):- id_to_info(ID,C), id_to_txtra(ID,C,Label), nonvar(Label),Label=LabelOut.
   51
   52id_to_txtra(_ID,C,Label):-  sub_term(Sub,C),compound(Sub), Sub = fs(name, Label),!.
   53id_to_txtra(ID,C,Label):-  C = cgc(ID, _, Label, _, _),!.
   54id_to_txtra(ID,C,Label):-  C = cg(ID, [CGR|_], _, _),
   55  CGR = cgr(Rel, Args, _), maplist(id_to_text,Args,Labels), Label =.. [Rel|Labels].
   56
   57
   58id_to_infos(ID,Set):- findall(Label,id_to_text(ID,Label),Ls1),findall(Label,id_to_info(ID,Label),Ls2),findall(C,id_to_info_all(ID,C),_Ls3),
   59  append([Ls1,Ls2],Ls),!,list_to_set(Ls,Set).
   60
   61
   62id_type(ID,C):- 
   63       (isCG(ID),C=cg;
   64	isTypeDefGraph(ID),C=typedef;
   65	isRelDefGraph(ID),C=reldef;
   66        isConcept(ID),C=concept),!.
   67
   68
   69:- fixup_exports.