Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix concept identifier for rdf format #185

Merged
merged 1 commit into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions _layouts/concept.ttl.html
Original file line number Diff line number Diff line change
Expand Up @@ -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: <http://purl.org/dc/terms/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
Expand All @@ -20,13 +22,13 @@
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<{{ concept_id }}>
<{{ base_url }}>
rdf:type owl:Ontology ;
owl:imports dcterms: ;
owl:imports <{{ rdfprofile }}> ;
owl:imports <http://www.w3.org/2004/02/skos/core> ;
.
:closure
<{{ concept_id }}>
rdf:type skos:Concept ;

{%- assign authoritative_source = concept.sources | get_authoritative -%}
Expand Down
16 changes: 16 additions & 0 deletions lib/jekyll/geolexica/filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 36 additions & 0 deletions spec/unit/jekyll/geolexica/filters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?) }

Expand Down