From fa4fde9d8553a4e05c8724cb9456c7547d80ce02 Mon Sep 17 00:00:00 2001 From: HassanAkbar Date: Thu, 18 Aug 2022 13:57:52 +0500 Subject: [PATCH] Fix concept identifier for rdf format --- _layouts/concept.ttl.html | 12 +++++--- lib/jekyll/geolexica/filters.rb | 16 ++++++++++ spec/unit/jekyll/geolexica/filters_spec.rb | 36 ++++++++++++++++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/_layouts/concept.ttl.html b/_layouts/concept.ttl.html index efe5afe..bf16e88 100644 --- a/_layouts/concept.ttl.html +++ b/_layouts/concept.ttl.html @@ -4,14 +4,16 @@ {%- assign concept = page["eng"] -%} {%- assign rdfprofile = "/api/rdf-profile" -%} {%- assign concept_html = page.representations.html -%} -{%- assign concept_id = concept_html.url -%} +{%- assign concept_id = concept_html.url | extract_concept_id -%} {%- assign english = page["eng"] -%} -# baseURI: "{{ concept_id }}" +{%- assign base_url = site.url | concepts_url -%} +# baseURI: "{{ base_url }}" # imports: http://purl.org/dc/terms/ # imports: https://www.geolexica.org/api/rdf-profile # imports: http://www.w3.org/2004/02/skos/core -@prefix : <{{ concept_id }}> . +@base <{{ base_url }}> . +@prefix : <{{ base_url }}> . @prefix dcterms: . @prefix owl: . @prefix rdf: . @@ -20,13 +22,13 @@ @prefix skos: . @prefix xsd: . -<{{ concept_id }}> +<{{ base_url }}> rdf:type owl:Ontology ; owl:imports dcterms: ; owl:imports <{{ rdfprofile }}> ; owl:imports ; . -:closure +<{{ concept_id }}> rdf:type skos:Concept ; {%- assign authoritative_source = concept.sources | get_authoritative -%} diff --git a/lib/jekyll/geolexica/filters.rb b/lib/jekyll/geolexica/filters.rb index 90d2378..2e8f283 100644 --- a/lib/jekyll/geolexica/filters.rb +++ b/lib/jekyll/geolexica/filters.rb @@ -28,6 +28,22 @@ def display_authoritative_source(input) "#{source}, modified -- #{modification}" end + def concepts_url(base_url) + return if !base_url || base_url.empty? + + if base_url.end_with?("/") + "#{base_url}concepts/" + else + "#{base_url}/concepts/" + end + end + + def extract_concept_id(url) + return if !url || url.empty? + + url.split("/").last + end + REFERENCE_REGEX = /{{(urn:[^,}]*),?([^,}]*),?([^,}]*)?}}/.freeze def resolve_reference_to_links(text) diff --git a/spec/unit/jekyll/geolexica/filters_spec.rb b/spec/unit/jekyll/geolexica/filters_spec.rb index a0d2756..bd17781 100644 --- a/spec/unit/jekyll/geolexica/filters_spec.rb +++ b/spec/unit/jekyll/geolexica/filters_spec.rb @@ -76,6 +76,42 @@ def wrapper.escape_once(str); "!#{str}!"; end end end + describe "#concepts_url" do + subject { wrapper.method(:concepts_url) } + + context "when base_url is nil or empty" do + it { expect(subject.call(nil)).to be_nil } + it { expect(subject.call("")).to be_nil } + end + + context "when base_url ends with `/`" do + let(:base_url) { "https://test-url/" } + + it { expect(subject.call(base_url)).to eq("#{base_url}concepts/") } + end + + context "when base_url do not ends with `/`" do + let(:base_url) { "https://test-url" } + + it { expect(subject.call(base_url)).to eq("#{base_url}/concepts/") } + end + end + + describe "#extract_concept_id" do + subject { wrapper.method(:extract_concept_id) } + + context "when url is nil or empty" do + it { expect(subject.call(nil)).to be_nil } + it { expect(subject.call("")).to be_nil } + end + + context "when url contains id" do + let(:url) { "https://test-url/concepts/147" } + + it { expect(subject.call(url)).to eq("147") } + end + end + describe "#abbreviation?" do subject { wrapper.method(:abbreviation?) }