skos/commit
try to factor out some duplicated skos-specific code and move it to this cpack
author | Jacco van Ossenbruggen |
---|---|
Thu Jul 31 14:21:31 2014 +0200 | |
committer | Jacco van Ossenbruggen |
Thu Jul 31 14:21:31 2014 +0200 | |
commit | 8a76cf7ae05f6498a4dd0e9452cf823ff334d488 |
tree | a2bbcd65c18377031250b2250edc5e9f4f46d54c |
parent | 1dde820c83aab1eeb456da14435e51ddd36bcd5e |
Diff style: patch stat
diff --git a/lib/skos/json.pl b/lib/skos/json.pl new file mode 100644 index 0000000..4f53a59 --- /dev/null +++ b/lib/skos/json.pl @@ -0,0 +1,23 @@ +:- module(skos_json, [ + json_all_literal_propvalues/3]). + +:- use_module(library('semweb/rdf_db')). +:- use_module(library('semweb/rdf_label')). + +:- rdf_meta + json_all_literal_propvalues(r, r, -). + +%% json_all_literal_propvalues(URI, Property, Dict) is det. +% +% Dict is a dictionairy with language codes as keys an literal +% values for data property Property as values +json_all_literal_propvalues(R,P,Definitions) :- + findall(Lang-Definition, + ( rdf_has(R, P, DefLit), + literal_text(DefLit,Definition), + ( DefLit = literal(lang(Lang, _)) + -> true + ; Lang=lang_undefined + ) + ), Pairs), + dict_pairs(Definitions, lang, Pairs). diff --git a/lib/skos/util.pl b/lib/skos/util.pl new file mode 100644 index 0000000..6c90d43 --- /dev/null +++ b/lib/skos/util.pl @@ -0,0 +1,49 @@ +:- module(skos_util, [ + skos_notation_ish/2, + skos_all_labels/2, + skos_related_concepts/2 + ]). + +:- use_module(library('semweb/rdf_db')). +:- use_module(library('semweb/rdf_label')). + +%% notation_ish(Concept, NotationIsh) is det. +% +% Unify NotationIsh with a label extend by (notation). +% For notation, use the skos:notation or dc/dcterms:identifier +skos_notation_ish(Concept, NotationIsh) :- + rdf_display_label(Concept, Label), + ( (rdf(Concept, skos:notation, N) + ; rdf_has(Concept, skos:notation, N) + ; rdf_has(Concept, dc:identifier, N) + ) + -> literal_text(N, LT), + format(atom(NotationIsh), '~w (~w)', [Label, LT]) + ; NotationIsh = Label + ). + + +%% skos_all_labels(URI, Labels) is det. +% +% Find all labels using rdf_label/2. +% Note that rdf_label itself is skos hooked... +skos_all_labels(R,Labels) :- + findall(AltLabel, (rdf_label(R,Lit), + literal_text(Lit, AltLabel) + ), + Labels0), + sort(Labels0,Labels). + + +%% skos_related_concepts(?Resource, ?Concepts) is det. +% +% Related Concepts are linked by skos:related to Resource. + +skos_related_concepts(S, Rs) :- + findall(R, skos_related(S, R), Rs0), + sort(Rs0, Rs). + +skos_related(R1, R2) :- + rdf_has(R1, skos:related, R2). +skos_related(R2, R1) :- + rdf_has(R2, skos:related, R1).