amalgame/commit
Added prebuilder hook to split qualified labels in advance, this should work with existing code in string_match_util.pl, can be turned off by setting amalgame:split_qualified_labels
author | Jacco van Ossenbruggen |
---|---|
Thu May 5 13:05:55 2022 +0200 | |
committer | Jacco van Ossenbruggen |
Thu May 5 13:05:55 2022 +0200 | |
commit | 7f055c98b7a215a46cbd5e986b84e3b2e50a5767 |
tree | 5b7e66d29f8cbb787701a5504cd911b0ce6e163b |
parent | 2938c658ac41f8c64c92cfa4793f1eecfbf34a97 |
Diff style: patch stat
diff --git a/lib/amalgame/hooks/load.pl b/lib/amalgame/hooks/load.pl index 3b6f57f..9e08a46 100644 --- a/lib/amalgame/hooks/load.pl +++ b/lib/amalgame/hooks/load.pl @@ -3,3 +3,4 @@ :- use_module(autocomplete). :- use_module(strategy_backward_compatability). :- use_module(skos_browser). +:- use_module(split_qualified_label). diff --git a/lib/amalgame/hooks/split_qualified_label.pl b/lib/amalgame/hooks/split_qualified_label.pl new file mode 100644 index 0000000..154d7bf --- /dev/null +++ b/lib/amalgame/hooks/split_qualified_label.pl @@ -0,0 +1,73 @@ +:- module(split_qualified_label, []). + +:- use_module(library(settings)). +:- use_module(library(semweb/rdf11)). +:- use_module(library(amalgame/ag_strategy)). +:- use_module(library(amalgame/vocabulary)). +:- use_module(library(ag_modules/string_match_util)). + +:- setting(amalgame:split_qualified_labels, boolean, true, + "Add additional term/qualifier properties for qualified labels"). + +splitted_labels_graph('http://localhost/amalgame/splitted_labels_graph'). + +:- multifile + amalgame:prebuilder/1. + +:- rdf_meta + label_labelxl(r,r). + +% Call split_qualified_labels on all vocabularies in Strategy. +amalgame:prebuilder(Strategy) :- + forall(strategy_vocabulary(Strategy, Vocab), + split_qualified_labels(Vocab) + ). + +%! label_labelxl(?Property, ?PropertyXL) is det. +% +% PropertyXL is the SKOS XL version of Property, or +% amalgame:label if not applicable. + +label_labelxl(skos:prefLabel, skosxl:prefLabel) :- !. +label_labelxl(skos:altLabel, skosxl:altLabel) :- !. +label_labelxl(_, amalgame:label) :- !. + + +%! split_qualified_labels(+Vocab) is det. +% +% Calls split_qualified_labels/1 on all concepts in Vocab. +split_qualified_labels(Vocab) :- + forall(vocab_member(Concept, Vocab), + split_qualified_label(Concept) + ). + +%! split_qualified_label(+Concept) is det. +% +% If Concept has a qualified label in the format +% "Term (Qualifier)"@Lang, a bnode is added with properties +% amalgame:term Term@Lang and +% amalgame:qualifier Qualifier@Lang +% +% If such as bnode already exists, this predicate succeeds without +% adding any triples. + +split_qualified_label(Concept) :- + % Check if not already splitted into a bnode with term (qualifier) + rdf_has(Concept, amalgame:label, LiteralObject), + rdf_is_bnode(LiteralObject), + rdf(LiteralObject, amalgame:term, _), + !. + +split_qualified_label(Concept) :- + skos_has(Concept, amalgame:label, Label@Lang, MatchProp, []), + ( sub_string(Label, Before, _, _, "(") + -> sub_string(Label, 0, Before, _, LabelTermPaddded), + split_string(LabelTermPaddded, "", " ", [LabelTerm]), + split_string(Label, "()", " ", [LabelTerm, Qualifier, ""]), + splitted_labels_graph(Graph), + rdf_create_bnode(LiteralObject), + label_labelxl(MatchProp, MatchPropXL), + rdf_assert(Concept, MatchPropXL, LiteralObject, Graph), + rdf_assert(LiteralObject, amalgame:term, LabelTerm@Lang, Graph), + rdf_assert(LiteralObject, amalgame:qualifier, Qualifier@Lang, Graph) + ; true).