1:- module(
    2  jgf,
    3  [
    4    jgf/3,      % +Graph, :NodeLabel_2, -Dict
    5    jgf_reply/2 % +Graph, :NodeLabel_2
    6  ]
    7).

Support for the JSON Graph Format (JGF)

*/

   13:- use_module(library(apply)).   14:- use_module(library(http/http_json)).   15
   16:- meta_predicate
   17    jgf(+, 2, -),
   18    jgf_edge(2, +, -),
   19    jgf_node(2, +, -),
   20    jgf_reply(+, 2).
 jgf(+Graph:compound, :NodeLabel_2, -Dict:dict) is det
   28jgf(
   29  graph(Nodes1,Edges1),
   30  NodeLabel_2,
   31  _{graph: _{directed: true, edges: Edges2, nodes: Nodes2}}
   32):-
   33  maplist(jgf_node(NodeLabel_2), Nodes1, Nodes2),
   34  maplist(jgf_edge(NodeLabel_2), Edges1, Edges2).
 jgf_edge(:NodeLabel_2, +Edge:compound, -Dict:dict) is det
   40jgf_edge(NodeLabel_2, edge(S,P,O), _{label: Label, source: S, target: O}) :-
   41  call(NodeLabel_2, P, Label).
 jgf_node(:NodeLabel_2, +Node, -Dict:dict) is det
   47jgf_node(NodeLabel_2, Node, _{id: Node, label: Label}) :-
   48  call(NodeLabel_2, Node, Label).
 jgf_reply(+Graph:compound, :NodeLabel_2) is det
   54jgf_reply(Graph, NodeLabel_2) :-
   55  jgf(Graph, NodeLabel_2, Dict),
   56  reply_json_dict(Dict, [content_type('application/vnd.jgf+json')])