1:- module(strategy_and_prov_graph_viz_config, []).    2
    3
    4:- use_module(cliopatria(hooks)).    5:- use_module(library(semweb/rdf_db)).    6:- use_module(library(semweb/rdfs)).    7:- use_module(library(semweb/rdf_abstract)).    8
    9:- use_module(library(skos/util)).   10
   11:- rdf_meta
   12        context_triple(r, t),
   13        transitive_context(r).
   14
   15cliopatria:context_graph(URI, RDF) :-
   16	(   rdfs_individual_of(URI, prov:'Entity')
   17	;   rdfs_individual_of(URI, prov:'Activity')
   18	;   rdfs_individual_of(URI, prov:'Agent')
   19	;   skos_is_vocabulary(URI)
   20	;   rdfs_individual_of(URI, amalgame:'Entity')
   21	),
   22	findall(T, prov_context_triple(URI, T), RDF0),
   23	sort(RDF0, RDF1),
   24	minimise_graph(RDF1, RDF2),		% remove inverse/symmetric/...
   25	bagify_graph(RDF2, RDF3, Bags, []),	% Create bags of similar resources
   26	append(RDF3, Bags, RDF),
   27	RDF \= [].
   28
   29cliopatria:context_graph(URI, RDF) :-
   30	rdfs_individual_of(URI, align:'Cell'),
   31	findall(Triple, cell_context_triple(URI, Triple), RDF0),
   32	sort(RDF0, RDF1),
   33	minimise_graph(RDF1, RDF2),		% remove inverse/symmetric/...
   34	bagify_graph(RDF2, RDF3, Bags, []),	% Create bags of similar resources
   35	append(RDF3, Bags, RDF),
   36	RDF \= [].
   37
   38cell_context_triple(URI, rdf(URI, P, E1)):- rdf_has(URI, align:entity1, E1, P).
   39cell_context_triple(URI, rdf(URI, P, E1)):- rdf_has(URI, align:entity2, E1, P).
   40cell_context_triple(URI, rdf(URI, P, E1)):- rdf_has(URI, align:relation, E1, P).
   41cell_context_triple(URI, rdf(Al , P, URI)):- rdf_has(Al, align:map,    URI, P).
   42cell_context_triple(URI, rdf(Other, P, E)):- other(URI, rdf(Other, P, E)).
   43cell_context_triple(URI, rdf(Other, P, R)) :-
   44	other(URI, rdf(Other, _, _)),
   45	rdf_has(Other, align:relation, R, P).
   46
   47other(URI, rdf(Other, P, E1)):-
   48	rdf_has(URI, align:entity1, E1),
   49	rdf_has(Other, align:entity1, E1, P),
   50	Other \= URI.
   51other(URI, rdf(Other, P, E2)):-
   52	rdf_has(URI, align:entity2, E2),
   53	rdf_has(Other, align:entity2, E2, P),
   54	Other \= URI.
   55
   56prov_context_triple(URI, Triple) :-
   57	up(URI, URI, Triples, [URI], 3),
   58	member(Triple, Triples).
   59prov_context_triple(URI, Triple) :-
   60	down(URI, URI, Triples, [URI], 2),
   61	member(Triple, Triples).
   62
   63prov_context_triple(URI, rdf(URI, P, Class)) :-
   64	rdf_has(URI, rdf:type, Class, P),
   65	rdf_global_id(amalgame:_, Class).
   66
   67up(Orig,URI, [rdf(URI, P, Parent)|T], Visited, MaxD) :-
   68	succ(MaxD2, MaxD),
   69	transitive_context(Up),
   70	rdf_has(URI, Up, Parent, P),
   71	\+ blacklist(Orig,Parent),
   72	\+ memberchk(Parent, Visited),
   73	up(Orig, Parent, T, [Parent|Visited], MaxD2).
   74up(_,_, [], _, _).
   75
   76down(Orig, URI, [rdf(Child, P, URI)|T], Visited, MaxD) :-
   77	succ(MaxD2, MaxD),
   78	transitive_context(Up),
   79	rdf_has(Child, Up, URI, P),
   80	\+ blacklist(Orig, Child),
   81	\+ memberchk(Child, Visited),
   82	down(Orig, Child, T, [Child|Visited], MaxD2).
   83down(_,_, [], _, _).
   84
   85transitive_context(owl:versionInfo).
   86transitive_context(prov:used).
   87transitive_context(prov:wasInfluencedBy).
   88
   89blacklist(Orig, Overlap) :-
   90	rdfs_individual_of(Overlap, amalgame:'OverlapMapping'),
   91	\+ rdfs_individual_of(Orig, amalgame:'OverlapMapping'),
   92	\+ rdf_has(_Overlap, prov:wasGeneratedBy,Orig).
   93
   94blacklist(Orig, OverlapProcess) :-
   95	rdf_has(Overlap, prov:wasGeneratedBy, OverlapProcess),
   96	rdfs_individual_of(Overlap, amalgame:'OverlapMapping'),
   97	\+ rdfs_individual_of(Orig, amalgame:'OverlapMapping').
   98
   99
  100% Mapping made with amalgame:
  101cliopatria:node_shape(URI, Shape, _Options) :-
  102	rdf_has(URI, rdf:type, prov:'Entity'),
  103	rdfs_individual_of(URI, amalgame:'Mapping'),
  104	rdf_has(URI, prov:wasInfluencedBy, _),
  105	Shape = [shape('Mdiamond'),fontize('20.00'), style(filled),fillcolor('#FF8888')].
  106% Amalgame process:
  107cliopatria:node_shape(URI, Shape, _Options) :-
  108	rdfs_individual_of(URI, prov:'Activity'),
  109	Shape = [shape('box'), style(filled),fillcolor('#FF8888')].
  110
  111% Mapping (up)loaded, typically not made with amalgame
  112cliopatria:node_shape(URI, Shape, _Options) :-
  113	rdfs_individual_of(URI, amalgame:'LoadedMapping'),
  114	Shape = [shape('Mdiamond'), style(filled),fillcolor('#AAAAAA')].
  115
  116% Vocabulary (up)loaded or made with amalgame
  117cliopatria:node_shape(URI, Shape, _Options) :-
  118	skos_is_vocabulary(URI),
  119	Shape = [shape(box3d),style(filled),fillcolor('#AAAAAA')]