amalgame/commit
more moving of predicates to better suited locations
author | Jacco van Ossenbruggen |
---|---|
Fri Aug 1 22:34:44 2014 +0200 | |
committer | Jacco van Ossenbruggen |
Fri Aug 1 22:34:44 2014 +0200 | |
commit | 70dec7082a27f36f8621fd1e24a47bd420bced9e |
tree | ca55c4157c4d561a03d1bca34fb1770104f8b3a9 |
parent | b08e8f39a4bfa2b299b2b76d9903e03dd1c3ceca |
Diff style: patch stat
diff --git a/api/correspondence.pl b/api/correspondence.pl index 8da6fe0..77a39e6 100644 --- a/api/correspondence.pl +++ b/api/correspondence.pl @@ -3,20 +3,14 @@ ]). :- use_module(library(lists)). -:- use_module(library(option)). :- use_module(library(http/http_dispatch)). :- use_module(library(http/http_parameters)). :- use_module(library(http/html_write)). :- use_module(library(semweb/rdf_db)). -:- use_module(library(semweb/rdf_label)). -:- use_module(components(label)). -:- use_module(components(graphviz)). - -:- use_module(library(skos/util)). :- use_module(library(amalgame/map)). :- use_module(library(amalgame/expand_graph)). -:- use_module(library(amalgame/util)). +:- use_module(components(amalgame/correspondence)). % http handlers @@ -24,7 +18,10 @@ %% http_correspondence(+Request) % -% Returns HTML with the Context in which the resource occurs +% Returns HTML with the dynamic part of the correspondence detail +% overlay widget. +% +% This is used in both the builder and the evaluater. http_correspondence(Request) :- http_parameters(Request, @@ -84,336 +81,3 @@ find_correspondences(Mapping, Strategy, Source, Target, AllSource, AllTarget, Cs findall(A, member(A, Ms), Cs) ). -html_correspondences([], _) --> !. -html_correspondences([A|As], Options) --> - html_correspondence(A, Options), - html_correspondences(As, Options). - -html_correspondence(align(Source, Target, Evidence), Options) --> - { length(Evidence, EvLength), - option(relations(Relations), Options), - ( option(mode('fill-in'), Options) - -> member(Method, Evidence), - member(relation(Relation), Method), - member(comment(Comment), Method) - ; Comment = '', Relation = undefined - ) - }, - html([div(class('yui3-g'), - [ div(class('yui3-u-1-2'), - \html_resource_context(Source, Evidence)), - div(class('yui3-u-1-2'), - \html_resource_context(Target, Evidence)) - ]), - div(class([manualfixes, 'yui3-g']), - [ div([class([sourcediv, 'yui3-u-1-5'])], - [div([class(sourceuri)], Source), - input([type(hidden), class(original), value(Source)]), - input([type(text), class([skos_ac_field]), name(source)]) - ]), - div([class([relations, 'yui3-u-3-5'])], - \html_relations(Relations, Relation)), - div([class([targetdiv, 'yui3-u-1-5'])], - [div([class(targeturi)], Target), - input([type(hidden), class(original), value(Target)]), - input([type(text), class([skos_ac_field]), name(target)]) - ]), - div(class([comment, 'yui3-u-1']), - ['because: ', input([type(text), name(comment), value(Comment)]) - ]) - ]), - div(class(evcount), - [ '~w individual motivations: '-(EvLength)]), - div(class(evidences), - \html_evidences(Evidence, Source, Target)) - ]). - -html_evidences([],_,_) --> !. -html_evidences([E|Es],Source,Target) --> - { option(method(Method), E, ''), - option(graph(Graph), E, []), - ( option(match(Match), E) - -> format(atom(MatchAtom), ' (~2f)' , [Match]), - Mt = span([class(match)], MatchAtom) - ; Mt = '' - ), - ( option(date(Date), E) - -> At = span([class(date)], [' at: ', Date]) - ; At = '' - ), - ( option(source(MSource), E) - -> format(atom(SrcAtom), ' (on: ~p' , [MSource]), - Src = span([class(source)], SrcAtom) - ; Src = '' - ), - ( option(target(MTarget), E) - -> format(atom(TrgAtom), '/~p)' , [MTarget]), - Trg = span([class(target)], TrgAtom) - ; Trg = '' - ), - ( option(source_stem(SourceStem), E) - -> format(atom(SStemAtom), ' (source stem: ~w)' , [SourceStem]), - Ss = span([class(source_stem)], SStemAtom) - ; Ss = '' - ), - ( option(target_stem(TargetStem), E) - -> format(atom(TStemAtom), ' (target stem: ~w)' , [TargetStem]), - Ts = span([class(target_stem)], TStemAtom) - ; Ts = '' - ), - ( option(score(Score), E) - -> format(atom(ScsAtom), ' (score: ~w)', [Score]), - Scs = span([class(score)], ScsAtom) - ; Scs = '' - ), - ( option(user(User), E) - -> By = span([class(who)], [' by: ', \rdf_link(User)]) - ; By = '' - ), - ( option(comment(Comment), E) - -> Cm = span([class(comment)], [' with comment: ', Comment]) - ; Cm = '' - ) - }, - html(div(class(evidence), - [ div(class(method), ['match: ', Method, By, At, Mt, Src, Trg, Ss, Ts, Scs, Cm]), - div(class('graph yui3-g'), - [ div(class('source yui3-u-1-2'), - \html_evidence_graph(Graph, Source, 'LR')), - div(class('target yui3-u-1-2'), - \html_evidence_graph(Graph, Target, 'RL')) - ]) - ])), - html_evidences(Es,Source,Target). - -html_evidence_graph([],_,_) --> !. -html_evidence_graph(Graph,Node,Layout) --> - graphviz_graph(evidence_graph(Graph,Node), - [shape_hook(ag_api_correspondence:evidence_shape), - label_hook(ag_api_correspondence:evidence_label), - graph_attributes([rankdir(Layout)])]). - - -evidence_graph(Graph, Node, NodeTriples) :- - findall(rdf(S,P,O), - ( member(rdf(S,P,O), Graph), - ( S == Node ; O == Node) - ), - NodeTriples). - - -html_resource_context('',_) --> !. -html_resource_context(URI, _Prov) --> - { rdf_display_label(URI, Label), - skos_all_labels(URI, Alt0), - select(Label, Alt0, Alt), - resource_tree(URI, Tree), - skos_related_concepts(URI, Related), - image_examples(URI, Examples) - }, - html(div(class('resource-info'), - [div(class(label), a([alt(URI), href(URI)], Label)), - div(class(alt), \html_alt_labels(Alt)), - \html_definition(URI), - \html_scope(URI), - \html_resource_tree(Tree), - \html_related_list(Related), - \html_image_examples(Examples) - ])). - -html_relations([], _) --> !. -html_relations([Rel-Label|Rs], Active) --> - { ( Rel == Active - -> Checked = checked - ; Checked = '' - ) - }, - html(span(class(relation), - [input([type(radio), name(relation), value(Rel), Checked]), - ' ', - label(Label) - ])), - html_relations(Rs, Active). - -html_image_examples([]) --> !. -html_image_examples([E|Tail]) --> - { - http_link_to_id(http_thumbnail, [uri(E)], Src) - }, - html(div([class(example)], - [img([src(Src),height(150)])] - )), - html_image_examples(Tail). - - - -image_examples(R, Es) :- - % hack: assume non-literal examples to be image urls ... - findall(E, ( rdf(R, skos:example, E), - \+ E =.. [literal|_] - ), - List), - sort(List, Es). - -%% resource_tree(+Resource, -Tree) -% -% Tree contains the ancesestors and children from Resource. - -resource_tree(R, Tree) :- - Node = node(R, [hit], Children), - rdf_equal(skos:broader, Rel), - ancestor_tree(Node, Rel, Tree, []), - children(R, Rel, Children, []). - -ancestor_tree(Node, Rel, Tree, Options) :- - Node = node(URI,_,_), - rdf_has(URI, Rel, Parent), - URI \== Parent, - ( select_option(sibblings(true), Options, Options1) - -> ancestor_tree(node(Parent, [], [Node|Siblings]), Rel, Tree, Options1), - children(Parent, Rel, Children, Options), - select(node(URI,_,_), Children, Siblings) - ; ancestor_tree(node(Parent, [], [Node]), Rel, Tree, Options) - ). -ancestor_tree(Tree, _Rel, Tree, _). - -children(R, Rel, Children, _Options) :- - findall(node(Child, [], HasChild), - ( rdf_has(Child, Rel, R), - has_child(Child, Rel, HasChild) - ), - Children). - -has_child(R, Rel, true) :- - rdf_has(_, Rel, R), - !. -has_child(_, _, false). - - - -html_alt_labels([]) --> !. -html_alt_labels(Alt) --> - html_label_list(Alt). - -html_label_list([L]) --> - html_label(L). -html_label_list([L|Ls]) --> - html_label(L), - html([', ']), - html_label_list(Ls). - -html_label(L) --> - html(L). - -html_definition(URI) --> - { rdf_lang(URI, skos:definition, Txt) - }, - !, - html_item(definition, Txt). -html_definition(_) --> !. - -html_scope(URI) --> - { rdf_lang(URI, skos:scopeNote, Txt) - }, - !, - html_item(scope, Txt). -html_scope(_) --> !. - - -html_related_list([]) --> !. -html_related_list(Rs) --> - html_item(related, - \html_resource_list(Rs, 3)). - -html_item(Type, Body) --> - html(div(class(Type), - [ div(class(hd), Type), - div(class(bd), Body) - ])). - - -%% html_resource_list(+Resources, +Max) -% -% Emit HTML with a list of resources. - -html_resource_list(Rs, Max) --> - { length(Rs, N), - ( N > Max+2 - -> list_limit(Rs, Max, Visible, Rest) - ; Visible = Rs, - Rest = [] - ) - }, - html([ul(\html_resource_list(Visible)), - \html_more_list(Rest) - ]). - -html_resource_list([]) --> !. -html_resource_list([R|Rs]) --> - html(li(\html_resource(R))), - html_resource_list(Rs). - -html_more_list([]) --> !. -html_more_list(Rs) --> - html(div([div(class(moretoggle), more), - div(class('morelist hidden'), - ul(\html_resource_list(Rs))), - div(class('moretoggle hidden'), less) - ])). - -html_resource(node(R,_,_)) --> !, - rdf_link(R, [resource_format(label)]). -html_resource(R) --> - rdf_link(R, [resource_format(label)]). - -%% html_resource_tree(+Tree:node(uri,attr,children)) -% -% Tree to HTML. - -html_resource_tree(node(_,_,[])) --> !. -html_resource_tree(Tree) --> - html([div(class(hd), hierarchy), - div(class(bd), - ul(\html_tree(Tree))) - ]). - -html_tree(node(R,[hit],Children)) --> - html([li(class(hit), \html_resource(R)), - ul(\html_resource_list(Children, 3)) - ]). - html_tree(node(R,_,Children)) --> - html([li(\html_resource(R)), - ul(\html_tree_children(Children)) - ]). - -html_tree_children([]) --> !. -html_tree_children([C|Cs]) --> - html_tree(C), - html_tree_children(Cs). - - -%% evidence_shape(+Resource, -Shape) -% -% Defines graph node shape for different types of evidence -% resources. - -evidence_shape(literal(_), - [shape(box), - style(filled), - fontsize(10)]) :- - !. -evidence_shape(_, - [fontsize(10)]). - -%% evidence_label(+Resource, +Lang, +MaxLen, -Label) is det. -% -% Defines graph node label for different types of evidence -% resources. -% -evidence_label(Resource, Lang, MaxLen, Label) :- - rdf_display_label(Resource, Lang, Text), - truncate_atom(Text, MaxLen, Label0), - ( rdf_global_id(NS:_Local, Resource) - -> atomic_list_concat([NS, ':', Label0], Label) - ; Label = Label0 - ). diff --git a/components/amalgame/correspondence.pl b/components/amalgame/correspondence.pl index ae2e420..f0b1bc5 100644 --- a/components/amalgame/correspondence.pl +++ b/components/amalgame/correspondence.pl @@ -1,8 +1,19 @@ :- module(ag_component_correspondence, - [ html_correspondence_overlay//0 + [ html_correspondence_overlay//0,% correspondence detail view, static part + html_correspondences//2 % idem, dynamic part ]). - +:- use_module(library(option)). +:- use_module(library(lists)). :- use_module(library(http/html_write)). +:- use_module(library(http/http_dispatch)). + +:- use_module(library(semweb/rdf_db)). +:- use_module(library(semweb/rdf_label)). +:- use_module(components(label)). +:- use_module(components(graphviz)). + +:- use_module(library(skos/util)). +:- use_module(library(amalgame/util)). html_correspondence_options --> html([ 'include all correspondences with the same: ', @@ -33,3 +44,341 @@ html_correspondence_overlay --> ]) ]) ])). + +%% html_correspondences(+Correspondences, +Options)// is det. +% +% Correspondences is a List align/3 terms, Options can be +% +html_correspondences([], _) --> !. +html_correspondences([A|As], Options) --> + html_correspondence(A, Options), + html_correspondences(As, Options). + +html_correspondence(align(Source, Target, Evidence), Options) --> + { length(Evidence, EvLength), + option(relations(Relations), Options, []), + ( option(mode('fill-in'), Options) + -> member(Method, Evidence), + member(relation(Relation), Method), + member(comment(Comment), Method) + ; Comment = '', Relation = undefined + ) + }, + html([div(class('yui3-g'), + [ div(class('yui3-u-1-2'), + \html_resource_context(Source, Evidence)), + div(class('yui3-u-1-2'), + \html_resource_context(Target, Evidence)) + ]), + div(class([manualfixes, 'yui3-g']), + [ div([class([sourcediv, 'yui3-u-1-5'])], + [div([class(sourceuri)], Source), + input([type(hidden), class(original), value(Source)]), + input([type(text), class([skos_ac_field]), name(source)]) + ]), + div([class([relations, 'yui3-u-3-5'])], + \html_relations(Relations, Relation)), + div([class([targetdiv, 'yui3-u-1-5'])], + [div([class(targeturi)], Target), + input([type(hidden), class(original), value(Target)]), + input([type(text), class([skos_ac_field]), name(target)]) + ]), + div(class([comment, 'yui3-u-1']), + ['because: ', input([type(text), name(comment), value(Comment)]) + ]) + ]), + div(class(evcount), + [ '~w individual motivations: '-(EvLength)]), + div(class(evidences), + \html_evidences(Evidence, Source, Target)) + ]). + +html_evidences([],_,_) --> !. +html_evidences([E|Es],Source,Target) --> + { option(method(Method), E, ''), + option(graph(Graph), E, []), + ( option(match(Match), E) + -> format(atom(MatchAtom), ' (~2f)' , [Match]), + Mt = span([class(match)], MatchAtom) + ; Mt = '' + ), + ( option(date(Date), E) + -> At = span([class(date)], [' at: ', Date]) + ; At = '' + ), + ( option(source(MSource), E) + -> format(atom(SrcAtom), ' (on: ~p' , [MSource]), + Src = span([class(source)], SrcAtom) + ; Src = '' + ), + ( option(target(MTarget), E) + -> format(atom(TrgAtom), '/~p)' , [MTarget]), + Trg = span([class(target)], TrgAtom) + ; Trg = '' + ), + ( option(source_stem(SourceStem), E) + -> format(atom(SStemAtom), ' (source stem: ~w)' , [SourceStem]), + Ss = span([class(source_stem)], SStemAtom) + ; Ss = '' + ), + ( option(target_stem(TargetStem), E) + -> format(atom(TStemAtom), ' (target stem: ~w)' , [TargetStem]), + Ts = span([class(target_stem)], TStemAtom) + ; Ts = '' + ), + ( option(score(Score), E) + -> format(atom(ScsAtom), ' (score: ~w)', [Score]), + Scs = span([class(score)], ScsAtom) + ; Scs = '' + ), + ( option(user(User), E) + -> By = span([class(who)], [' by: ', \rdf_link(User)]) + ; By = '' + ), + ( option(comment(Comment), E) + -> Cm = span([class(comment)], [' with comment: ', Comment]) + ; Cm = '' + ) + }, + html(div(class(evidence), + [ div(class(method), ['match: ', Method, By, At, Mt, Src, Trg, Ss, Ts, Scs, Cm]), + div(class('graph yui3-g'), + [ div(class('source yui3-u-1-2'), + \html_evidence_graph(Graph, Source, 'LR')), + div(class('target yui3-u-1-2'), + \html_evidence_graph(Graph, Target, 'RL')) + ]) + ])), + html_evidences(Es,Source,Target). + +html_evidence_graph([],_,_) --> !. +html_evidence_graph(Graph,Node,Layout) --> + graphviz_graph(evidence_graph(Graph,Node), + [shape_hook(ag_api_correspondence:evidence_shape), + label_hook(ag_api_correspondence:evidence_label), + graph_attributes([rankdir(Layout)])]). + + +evidence_graph(Graph, Node, NodeTriples) :- + findall(rdf(S,P,O), + ( member(rdf(S,P,O), Graph), + ( S == Node ; O == Node) + ), + NodeTriples). + + +html_resource_context('',_) --> !. +html_resource_context(URI, _Prov) --> + { rdf_display_label(URI, Label), + skos_all_labels(URI, Alt0), + select(Label, Alt0, Alt), + resource_tree(URI, Tree), + skos_related_concepts(URI, Related), + image_examples(URI, Examples) + }, + html(div(class('resource-info'), + [div(class(label), a([alt(URI), href(URI)], Label)), + div(class(alt), \html_alt_labels(Alt)), + \html_definition(URI), + \html_scope(URI), + \html_resource_tree(Tree), + \html_related_list(Related), + \html_image_examples(Examples) + ])). + +html_relations([], _) --> !. +html_relations([Rel-Label|Rs], Active) --> + { ( Rel == Active + -> Checked = checked + ; Checked = '' + ) + }, + html(span(class(relation), + [input([type(radio), name(relation), value(Rel), Checked]), + ' ', + label(Label) + ])), + html_relations(Rs, Active). + +html_image_examples([]) --> !. +html_image_examples([E|Tail]) --> + { + http_link_to_id(http_thumbnail, [uri(E)], Src) + }, + html(div([class(example)], + [img([src(Src),height(150)])] + )), + html_image_examples(Tail). + + + +image_examples(R, Es) :- + % hack: assume non-literal examples to be image urls ... + findall(E, ( rdf(R, skos:example, E), + \+ E =.. [literal|_] + ), + List), + sort(List, Es). + +%% resource_tree(+Resource, -Tree) +% +% Tree contains the ancesestors and children from Resource. + +resource_tree(R, Tree) :- + Node = node(R, [hit], Children), + rdf_equal(skos:broader, Rel), + ancestor_tree(Node, Rel, Tree, []), + children(R, Rel, Children, []). + +ancestor_tree(Node, Rel, Tree, Options) :- + Node = node(URI,_,_), + rdf_has(URI, Rel, Parent), + URI \== Parent, + ( select_option(sibblings(true), Options, Options1) + -> ancestor_tree(node(Parent, [], [Node|Siblings]), Rel, Tree, Options1), + children(Parent, Rel, Children, Options), + select(node(URI,_,_), Children, Siblings) + ; ancestor_tree(node(Parent, [], [Node]), Rel, Tree, Options) + ). +ancestor_tree(Tree, _Rel, Tree, _). + +children(R, Rel, Children, _Options) :- + findall(node(Child, [], HasChild), + ( rdf_has(Child, Rel, R), + has_child(Child, Rel, HasChild) + ), + Children). + +has_child(R, Rel, true) :- + rdf_has(_, Rel, R), + !. +has_child(_, _, false). + + + +html_alt_labels([]) --> !. +html_alt_labels(Alt) --> + html_label_list(Alt). + +html_label_list([L]) --> + html_label(L). +html_label_list([L|Ls]) --> + html_label(L), + html([', ']), + html_label_list(Ls). + +html_label(L) --> + html(L). + +html_definition(URI) --> + { rdf_lang(URI, skos:definition, Txt) + }, + !, + html_item(definition, Txt). +html_definition(_) --> !. + +html_scope(URI) --> + { rdf_lang(URI, skos:scopeNote, Txt) + }, + !, + html_item(scope, Txt). +html_scope(_) --> !. + + +html_related_list([]) --> !. +html_related_list(Rs) --> + html_item(related, + \html_resource_list(Rs, 3)). + +html_item(Type, Body) --> + html(div(class(Type), + [ div(class(hd), Type), + div(class(bd), Body) + ])). + + +%% html_resource_list(+Resources, +Max) +% +% Emit HTML with a list of resources. + +html_resource_list(Rs, Max) --> + { length(Rs, N), + ( N > Max+2 + -> list_limit(Rs, Max, Visible, Rest) + ; Visible = Rs, + Rest = [] + ) + }, + html([ul(\html_resource_list(Visible)), + \html_more_list(Rest) + ]). + +html_resource_list([]) --> !. +html_resource_list([R|Rs]) --> + html(li(\html_resource(R))), + html_resource_list(Rs). + +html_more_list([]) --> !. +html_more_list(Rs) --> + html(div([div(class(moretoggle), more), + div(class('morelist hidden'), + ul(\html_resource_list(Rs))), + div(class('moretoggle hidden'), less) + ])). + +html_resource(node(R,_,_)) --> !, + rdf_link(R, [resource_format(label)]). +html_resource(R) --> + rdf_link(R, [resource_format(label)]). + +%% html_resource_tree(+Tree:node(uri,attr,children)) +% +% Tree to HTML. + +html_resource_tree(node(_,_,[])) --> !. +html_resource_tree(Tree) --> + html([div(class(hd), hierarchy), + div(class(bd), + ul(\html_tree(Tree))) + ]). + +html_tree(node(R,[hit],Children)) --> + html([li(class(hit), \html_resource(R)), + ul(\html_resource_list(Children, 3)) + ]). + html_tree(node(R,_,Children)) --> + html([li(\html_resource(R)), + ul(\html_tree_children(Children)) + ]). + +html_tree_children([]) --> !. +html_tree_children([C|Cs]) --> + html_tree(C), + html_tree_children(Cs). + + +%% evidence_shape(+Resource, -Shape) +% +% Defines graph node shape for different types of evidence +% resources. + +evidence_shape(literal(_), + [shape(box), + style(filled), + fontsize(10)]) :- + !. +evidence_shape(_, + [fontsize(10)]). + +%% evidence_label(+Resource, +Lang, +MaxLen, -Label) is det. +% +% Defines graph node label for different types of evidence +% resources. +% +evidence_label(Resource, Lang, MaxLen, Label) :- + rdf_display_label(Resource, Lang, Text), + truncate_atom(Text, MaxLen, Label0), + ( rdf_global_id(NS:_Local, Resource) + -> atomic_list_concat([NS, ':', Label0], Label) + ; Label = Label0 + ).