From b42f3f3eab3e3b19878c8cdc708f8b1b0ffe387e Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Wed, 24 Oct 2018 22:27:10 +0200 Subject: [PATCH 01/85] Revert "Undo named graph feature" This reverts commit 2a09429b71a4c052e00b8fa84fd44385c5f0391c. --- lib/jekyll-rdf.rb | 1 + lib/jekyll/rdf_main_generator.rb | 1 + test/cases/remoteGraphs/Gemfile | 4 ++ test/cases/remoteGraphs/_config.yml | 13 ++++ test/cases/remoteGraphs/_data/Prefixes.pref | 3 + .../remoteGraphs/_data/knowledge-base.ttl | 27 +++++++++ test/cases/remoteGraphs/_layouts/default.html | 12 ++++ .../_layouts/exampleInstance.html | 8 +++ .../remoteGraphs/remoteCollectionTest.html | 19 ++++++ .../remoteGraphs/remoteContainerTest.html | 19 ++++++ test/cases/remoteGraphs/remoteMainTest.html | 19 ++++++ test/cases/remoteGraphs/remoteQueryTest.html | 19 ++++++ test/cases/remoteGraphs/test_remote.rb | 60 +++++++++++++++++++ 13 files changed, 205 insertions(+) create mode 100644 test/cases/remoteGraphs/Gemfile create mode 100644 test/cases/remoteGraphs/_config.yml create mode 100644 test/cases/remoteGraphs/_data/Prefixes.pref create mode 100644 test/cases/remoteGraphs/_data/knowledge-base.ttl create mode 100644 test/cases/remoteGraphs/_layouts/default.html create mode 100644 test/cases/remoteGraphs/_layouts/exampleInstance.html create mode 100644 test/cases/remoteGraphs/remoteCollectionTest.html create mode 100644 test/cases/remoteGraphs/remoteContainerTest.html create mode 100644 test/cases/remoteGraphs/remoteMainTest.html create mode 100644 test/cases/remoteGraphs/remoteQueryTest.html create mode 100644 test/cases/remoteGraphs/test_remote.rb diff --git a/lib/jekyll-rdf.rb b/lib/jekyll-rdf.rb index dd0ac188..2a768a14 100644 --- a/lib/jekyll-rdf.rb +++ b/lib/jekyll-rdf.rb @@ -31,6 +31,7 @@ require 'sparql' require 'set' require 'addressable/uri' +require 'cgi' require 'pp' require 'jekyll/helper/rdf_types' diff --git a/lib/jekyll/rdf_main_generator.rb b/lib/jekyll/rdf_main_generator.rb index 974dadbc..c143dc2d 100644 --- a/lib/jekyll/rdf_main_generator.rb +++ b/lib/jekyll/rdf_main_generator.rb @@ -54,6 +54,7 @@ def generate(site) else graph = @config['remote']['endpoint'].strip end + graph << "?default-graph-uri=#{CGI::escape(@config['remote']['default_graph'])}" unless @config['remote']['default_graph'].nil? elsif(!@config['path'].nil?) graph = RDF::Graph.load( File.join( site.config['source'], @config['path'])) else diff --git a/test/cases/remoteGraphs/Gemfile b/test/cases/remoteGraphs/Gemfile new file mode 100644 index 00000000..4d519ca0 --- /dev/null +++ b/test/cases/remoteGraphs/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +group :jekyll_plugins do + gem 'jekyll-rdf', :path => '../../../' +end diff --git a/test/cases/remoteGraphs/_config.yml b/test/cases/remoteGraphs/_config.yml new file mode 100644 index 00000000..b008260a --- /dev/null +++ b/test/cases/remoteGraphs/_config.yml @@ -0,0 +1,13 @@ +baseurl: "/instance" # the subpath of your site, e.g. /blog +url: "http://remote-endpoint.org/" # the base hostname & protocol for your site +# Build settings +markdown: kramdown +plugins: +- jekyll-rdf +jekyll_rdf: + remote: + endpoint: "http://localhost:3030/remote/query" + default_graph: "http://localhost:3030/remote/data/graph1" + restriction: "SELECT ?resourceUri WHERE {?resourceUri ?p }" + instance_template_mappings: + "http://remote-endpoint.org/instance/resource": "exampleInstance" diff --git a/test/cases/remoteGraphs/_data/Prefixes.pref b/test/cases/remoteGraphs/_data/Prefixes.pref new file mode 100644 index 00000000..feb6ac34 --- /dev/null +++ b/test/cases/remoteGraphs/_data/Prefixes.pref @@ -0,0 +1,3 @@ +PREFIX rdf: +PREFIX rdfs: +PREFIX remote: diff --git a/test/cases/remoteGraphs/_data/knowledge-base.ttl b/test/cases/remoteGraphs/_data/knowledge-base.ttl new file mode 100644 index 00000000..e5c8db36 --- /dev/null +++ b/test/cases/remoteGraphs/_data/knowledge-base.ttl @@ -0,0 +1,27 @@ +@prefix rdf: . +@prefix rdfs: . +@prefix remote: . + +remote:resource remote:predicate remote:render . +remote:resource remote:predicate2 remote:queryItem0 , + remote:queryItem1 , + remote:queryItem2 . + +remote:collection a rdf:List . +remote:collection rdf:first remote:colItem1 . +remote:collection rdf:rest remote:colHolder1 . +remote:colHolder1 rdf:first remote:colItem2 . +remote:colHolder1 rdf:rest remote:colHolder2 . +remote:colHolder2 rdf:first remote:colItem3 . +remote:colHolder2 rdf:rest remote:colHolder3 . +remote:colHolder3 rdf:first remote:colItem4 . +remote:colHolder3 rdf:rest remote:colHolder4 . +remote:colHolder4 rdf:first remote:colItem5 . +remote:colHolder4 rdf:rest rdf:nil . + +remote:Container a rdfs:Container . +remote:Container rdf:_1 remote:conItem1 . +remote:Container rdf:_2 remote:conItem2 . +remote:Container rdf:_3 remote:conItem3 . +remote:Container rdf:_4 remote:conItem4 . +remote:Container rdf:_5 remote:conItem5 . diff --git a/test/cases/remoteGraphs/_layouts/default.html b/test/cases/remoteGraphs/_layouts/default.html new file mode 100644 index 00000000..96137a3e --- /dev/null +++ b/test/cases/remoteGraphs/_layouts/default.html @@ -0,0 +1,12 @@ +--- +--- + + + + +
+

This is made with jekyll-rdf

+ {{content}} +
+ + diff --git a/test/cases/remoteGraphs/_layouts/exampleInstance.html b/test/cases/remoteGraphs/_layouts/exampleInstance.html new file mode 100644 index 00000000..655a2ea8 --- /dev/null +++ b/test/cases/remoteGraphs/_layouts/exampleInstance.html @@ -0,0 +1,8 @@ +--- +layout: default +rdf_prefix_path: _data/Prefixes.pref +--- +
+
This page is mapped to:
+ {{page.rdf}} +
diff --git a/test/cases/remoteGraphs/remoteCollectionTest.html b/test/cases/remoteGraphs/remoteCollectionTest.html new file mode 100644 index 00000000..d03c01a6 --- /dev/null +++ b/test/cases/remoteGraphs/remoteCollectionTest.html @@ -0,0 +1,19 @@ +--- +rdf_prefix_path: _data/Prefixes.pref +--- + + + + Remote Collection Test + + + + +
+ {%- assign contain = "remote:collection" | rdf_collection -%} + {%- for item in contain -%} + {{ item }}
+ {%- endfor -%} +
+ + diff --git a/test/cases/remoteGraphs/remoteContainerTest.html b/test/cases/remoteGraphs/remoteContainerTest.html new file mode 100644 index 00000000..d21f3c73 --- /dev/null +++ b/test/cases/remoteGraphs/remoteContainerTest.html @@ -0,0 +1,19 @@ +--- +rdf_prefix_path: _data/Prefixes.pref +--- + + + + Remote Container Test + + + + +
+ {%- assign contain = "remote:Container" | rdf_container -%} + {%- for item in contain -%} + {{ item }}
+ {%- endfor -%} +
+ + diff --git a/test/cases/remoteGraphs/remoteMainTest.html b/test/cases/remoteGraphs/remoteMainTest.html new file mode 100644 index 00000000..583ea00a --- /dev/null +++ b/test/cases/remoteGraphs/remoteMainTest.html @@ -0,0 +1,19 @@ +--- +rdf_prefix_path: _data/Prefixes.pref +--- + + + + Remote SPARQL Endpoint Test + + + + +
+ {%- assign resource = "remote:resource" | rdf_get -%} + {{resource}}
+ {%- assign result = resource | rdf_property: "remote:predicate" -%} + {{result}} +
+ + diff --git a/test/cases/remoteGraphs/remoteQueryTest.html b/test/cases/remoteGraphs/remoteQueryTest.html new file mode 100644 index 00000000..0ce9096d --- /dev/null +++ b/test/cases/remoteGraphs/remoteQueryTest.html @@ -0,0 +1,19 @@ +--- +rdf_prefix_path: _data/Prefixes.pref +--- + + + + Remote Query Test + + + + +
+ {%- assign results = "SELECT ?o WHERE { remote:resource remote:predicate2 ?o }" | sparql_query -%} + {%- for item in results -%} + {{ item.o }}
+ {%- endfor -%} +
+ + diff --git a/test/cases/remoteGraphs/test_remote.rb b/test/cases/remoteGraphs/test_remote.rb new file mode 100644 index 00000000..4b82cff9 --- /dev/null +++ b/test/cases/remoteGraphs/test_remote.rb @@ -0,0 +1,60 @@ +require 'test_helper' +require 'rest_client' + +class TestGeneral < Test::Unit::TestCase + include RSpec::Matchers + include RdfTestUtility + RestClient.post('http://localhost:3030/remote/upload', :graph => "http://localhost:3030/remote/data/graph1", :name_of_file_param => File.new(File.join(File.dirname(__FILE__), "_data/knowledge-base.ttl"))) + context "A remote sparql endpoint on a specified default graph" do + should "keep rdf_get and rdf_property usable" do + setup_jekyll File.dirname(__FILE__) + file = File.read(File.join(@source, "_site/remoteMainTest.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + + assert_equal "http://remote-endpoint.org/instance/resource", content[0] + assert_equal "http://remote-endpoint.org/instance/render", content[1] + end + + should "keep rdf_container usable" do + setup_jekyll File.dirname(__FILE__) + file = File.read(File.join(@source, "_site/remoteContainerTest.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + + assert_equal "http://remote-endpoint.org/instance/conItem1", content[0] + assert_equal "http://remote-endpoint.org/instance/conItem2", content[1] + assert_equal "http://remote-endpoint.org/instance/conItem3", content[2] + assert_equal "http://remote-endpoint.org/instance/conItem4", content[3] + assert_equal "http://remote-endpoint.org/instance/conItem5", content[4] + end + + should "keep rdf_collection usable" do + setup_jekyll File.dirname(__FILE__) + file = File.read(File.join(@source, "_site/remoteCollectionTest.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + + assert_equal "http://remote-endpoint.org/instance/colItem1", content[0] + assert_equal "http://remote-endpoint.org/instance/colItem2", content[1] + assert_equal "http://remote-endpoint.org/instance/colItem3", content[2] + assert_equal "http://remote-endpoint.org/instance/colItem4", content[3] + assert_equal "http://remote-endpoint.org/instance/colItem5", content[4] + end + + should "keep sparql_query usable" do + setup_jekyll File.dirname(__FILE__) + file = File.read(File.join(@source, "_site/remoteQueryTest.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + + assert(content.any? {|resource| resource.to_s.eql? "http://remote-endpoint.org/instance/queryItem0"}, "answerset does not contain 'http://remote-endpoint.org/instance/queryItem0'") + assert(content.any? {|resource| resource.to_s.eql? "http://remote-endpoint.org/instance/queryItem1"}, "answerset does not contain 'http://remote-endpoint.org/instance/queryItem1'") + assert(content.any? {|resource| resource.to_s.eql? "http://remote-endpoint.org/instance/queryItem2"}, "answerset does not contain 'http://remote-endpoint.org/instance/queryItem2'") + end + end +end From 014d82b7f71f3d1c8aa21919ba68e57d7c701eee Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Tue, 27 Nov 2018 17:13:16 +0100 Subject: [PATCH 02/85] Forward version --- CHANGELOG.md | 2 ++ jekyll-rdf.gemspec | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60075f90..bdd4ca46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [3.1.1] - ??? + ## [3.1.0] - 2018-11-27 ### Added - Allow building sites from a (remote) SPARQL endpoint by setting `remote:\n endpoint: ` in the `_config.yml`. (Currently only querying the default default-graph ;-). Specifying the default graph, with `FROM` resp. `default-graph-uri` will come in the future, https://github.com/white-gecko/jekyll-rdf/pull/220.) diff --git a/jekyll-rdf.gemspec b/jekyll-rdf.gemspec index 352481ae..c1fe4ec2 100644 --- a/jekyll-rdf.gemspec +++ b/jekyll-rdf.gemspec @@ -1,4 +1,4 @@ -VERSION = '3.1.0' +VERSION = '3.1.1' RELEASE_VERSION = case when ENV['TRAVIS'] && ENV['TRAVIS_BRANCH'].match(/^master$/i) then "#{VERSION}" when ENV['TRAVIS'] && ENV['TRAVIS_BRANCH'].match(/^develop$/i) then "#{VERSION}-#{ENV['TRAVIS_BRANCH']}.#{ENV['TRAVIS_BUILD_NUMBER']}" From 1c4106d08ca6f9b583a5818a21caacc10cedeef7 Mon Sep 17 00:00:00 2001 From: Nime Date: Mon, 3 Dec 2018 19:36:35 +0100 Subject: [PATCH 03/85] adept code to sparql default-graph feature --- lib/jekyll/rdf_main_generator.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/rdf_main_generator.rb b/lib/jekyll/rdf_main_generator.rb index c143dc2d..cc54f847 100644 --- a/lib/jekyll/rdf_main_generator.rb +++ b/lib/jekyll/rdf_main_generator.rb @@ -54,14 +54,17 @@ def generate(site) else graph = @config['remote']['endpoint'].strip end - graph << "?default-graph-uri=#{CGI::escape(@config['remote']['default_graph'])}" unless @config['remote']['default_graph'].nil? + if @config['remote']['default_graph'].nil? + sparql = SPARQL::Client.new(graph) + else + sparql = SPARQL::Client.new(graph, { :graph => @config['remote']['default_graph'] }) + end elsif(!@config['path'].nil?) - graph = RDF::Graph.load( File.join( site.config['source'], @config['path'])) + sparql = SPARQL::Client.new(RDF::Graph.load( File.join( site.config['source'], @config['path']))) else Jekyll.logger.error("No sparql endpoint defined. Jumping out of jekyll-rdf processing.") return false end - sparql = SPARQL::Client.new(graph) Jekyll::JekyllRdf::Helper::RdfHelper::sparql = sparql Jekyll::JekyllRdf::Helper::RdfHelper::site = site From e9dae6ee75390e27d6e7c4f94b6ab4bd7da24dd4 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Tue, 4 Dec 2018 11:08:29 +0100 Subject: [PATCH 04/85] Set dependency to sparql-client >= 3.0.1 and remove cgi dependency --- jekyll-rdf.gemspec | 2 +- lib/jekyll-rdf.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/jekyll-rdf.gemspec b/jekyll-rdf.gemspec index eaaa1e86..33b06842 100644 --- a/jekyll-rdf.gemspec +++ b/jekyll-rdf.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |s| s.license = 'MIT' s.add_runtime_dependency 'net-http-persistent', '~> 2.9' # https://github.com/white-gecko/jekyll-rdf/issues/197 s.add_runtime_dependency 'linkeddata', '~> 2.0' - s.add_runtime_dependency 'sparql', '~> 2.2', '>= 2.2.1' + s.add_runtime_dependency 'sparql-client', '~> 3.0', '>= 3.0.1' s.add_runtime_dependency 'jekyll', '~> 3.1' s.add_development_dependency 'rake', '~> 10.4' s.add_development_dependency 'rest-client', '~> 1.8' diff --git a/lib/jekyll-rdf.rb b/lib/jekyll-rdf.rb index 2a768a14..dd0ac188 100644 --- a/lib/jekyll-rdf.rb +++ b/lib/jekyll-rdf.rb @@ -31,7 +31,6 @@ require 'sparql' require 'set' require 'addressable/uri' -require 'cgi' require 'pp' require 'jekyll/helper/rdf_types' From b9938ae290b3e73e7d23b37453046b02c56dbc16 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Tue, 4 Dec 2018 11:14:35 +0100 Subject: [PATCH 05/85] Simplify test docker setup --- .travis.yml | 4 +--- Dockerfile | 4 ---- 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 Dockerfile diff --git a/.travis.yml b/.travis.yml index dac99bb8..1ad88d18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,9 +10,7 @@ matrix: allow_failures: - rvm: ruby-head before_install: -- docker pull stain/jena-fuseki -- docker build -t remote_sparql . -- docker run -p 3030:3030 -e ADMIN_PASSWORD=admin -d remote_sparql:latest +- docker run -p 3030:3030 -d stain/jena-fuseki:latest ./fuseki-server --mem /remote script: - bundle exec rake test deploy: diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index c1019053..00000000 --- a/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM stain/jena-fuseki - -CMD ./fuseki-server --mem /remote - From 98762e1ccda0a441799d44ba780c8299fd61ad5a Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Tue, 4 Dec 2018 11:21:07 +0100 Subject: [PATCH 06/85] Depend on newer rest client to prevent cypher issue --- jekyll-rdf.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jekyll-rdf.gemspec b/jekyll-rdf.gemspec index 33b06842..4d67e93e 100644 --- a/jekyll-rdf.gemspec +++ b/jekyll-rdf.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'sparql-client', '~> 3.0', '>= 3.0.1' s.add_runtime_dependency 'jekyll', '~> 3.1' s.add_development_dependency 'rake', '~> 10.4' - s.add_development_dependency 'rest-client', '~> 1.8' + s.add_development_dependency 'rest-client', '~> 2.0', '>= 2.0.1' s.add_development_dependency 'coveralls', '~> 0.8' s.add_development_dependency 'test-unit', '~> 3.0' s.add_development_dependency 'shoulda-context', '~> 1.1' From 1911fd624dfdc772be01feaa3dcad2fc74f7f416 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Tue, 4 Dec 2018 11:31:04 +0100 Subject: [PATCH 07/85] Add new ruby version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1ad88d18..9aade6ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ -sudo: required language: ruby services: - docker rvm: - 2.2.4 - 2.3.0 +- 2.5.3 - ruby-head matrix: allow_failures: From cfa4e72e5dcd93e767ef3dcdc14287d14a8f15cb Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Tue, 15 Jan 2019 18:43:57 +0100 Subject: [PATCH 08/85] Update LICENSE --- LICENSE | 1 + 1 file changed, 1 insertion(+) diff --git a/LICENSE b/LICENSE index ac9bc47a..a776f13f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,6 @@ MIT License +Copyright (c) 2016-2019 Sebastian Zänker, Natanael Arndt Copyright (c) 2016 Elias Saalmann, Christian Frommert, Simon Jakobi, Arne Jonas Präger, Maxi Bornmann, Georg Hackel, Eric Füg From 7905d7f469d2eb14b5d4c23710e5c923670a2243 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Fri, 25 Jan 2019 13:41:53 +0100 Subject: [PATCH 09/85] Fix test_sci_math, the time value is just hour:min If the year is requested from an hour:min string than the current year is returned, which changed to 2019 lately. --- test/cases/sciMath/math_filters.html | 1 - test/cases/sciMath/test_sci_math.rb | 27 +++++++++++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/test/cases/sciMath/math_filters.html b/test/cases/sciMath/math_filters.html index 0d56f46d..fccfcba9 100644 --- a/test/cases/sciMath/math_filters.html +++ b/test/cases/sciMath/math_filters.html @@ -31,7 +31,6 @@ {{ number | at_least: 12 }}
{{ number | at_least: 8 }}
{{ nnumber | abs }}
- {{ time | date: "%Y" }}
{{ time | date: "%H" }}
{{ time | date: "%M" }}
{{ date | date: "%Y" }}
diff --git a/test/cases/sciMath/test_sci_math.rb b/test/cases/sciMath/test_sci_math.rb index f2464d58..ccdde815 100644 --- a/test/cases/sciMath/test_sci_math.rb +++ b/test/cases/sciMath/test_sci_math.rb @@ -27,20 +27,19 @@ class TestSciMath < Test::Unit::TestCase # assert "12".eql?(content[11]), "Wrong result on liquid standard math filter: at_least" # assert "10".eql?(content[12]), "Wrong result on liquid standard math filter: at_least" assert "3".eql?(content[13]), "Wrong result on liquid standard math filter: abs" - assert "2018".eql?(content[14]), "Wrong result on liquid standard date filter: xsd:time %Y" - assert "12".eql?(content[15]), "Wrong result on liquid standard date filter: xsd:time %H" - assert "45".eql?(content[16]), "Wrong result on liquid standard date filter: xsd:time %M" - assert "2018".eql?(content[17]), "Wrong result on liquid standard date filter: xsd:date %Y" - assert "06".eql?(content[18]), "Wrong result on liquid standard date filter: xsd:date %m" - assert "2018".eql?(content[19]), "Wrong result on liquid standard date filter: xsd:dateTime %Y" - assert "06".eql?(content[20]), "Wrong result on liquid standard date filter: xsd:dateTime %m" - assert "12".eql?(content[21]), "Wrong result on liquid standard date filter: xsd:dateTime %H" - assert "2018".eql?(content[22]), "Wrong result on liquid standard date filter: xsd:dateTime (Zone: Z) %Y" - assert "12".eql?(content[23]), "Wrong result on liquid standard date filter: xsd:dateTime (Zone: Z) %H" - assert "42".eql?(content[24]), "Wrong result on liquid standard date filter: xsd:dateTime (Zone: Z) %M" - assert "2018".eql?(content[25]), "Wrong result on liquid standard date filter: xsd:dateTime (Zone: +02:00) %Y" - assert "12".eql?(content[26]), "Wrong result on liquid standard date filter: xsd:dateTime (Zone: +02:00) %H" - assert "42".eql?(content[27]), "Wrong result on liquid standard date filter: xsd:dateTime (Zone: +02:00) %M" + assert "12".eql?(content[14]), "Wrong result on liquid standard date filter: xsd:time %H" + assert "45".eql?(content[15]), "Wrong result on liquid standard date filter: xsd:time %M" + assert "2018".eql?(content[16]), "Wrong result on liquid standard date filter: xsd:date %Y" + assert "06".eql?(content[17]), "Wrong result on liquid standard date filter: xsd:date %m" + assert "2018".eql?(content[18]), "Wrong result on liquid standard date filter: xsd:dateTime %Y" + assert "06".eql?(content[19]), "Wrong result on liquid standard date filter: xsd:dateTime %m" + assert "12".eql?(content[20]), "Wrong result on liquid standard date filter: xsd:dateTime %H" + assert "2018".eql?(content[21]), "Wrong result on liquid standard date filter: xsd:dateTime (Zone: Z) %Y" + assert "12".eql?(content[22]), "Wrong result on liquid standard date filter: xsd:dateTime (Zone: Z) %H" + assert "42".eql?(content[23]), "Wrong result on liquid standard date filter: xsd:dateTime (Zone: Z) %M" + assert "2018".eql?(content[24]), "Wrong result on liquid standard date filter: xsd:dateTime (Zone: +02:00) %Y" + assert "12".eql?(content[25]), "Wrong result on liquid standard date filter: xsd:dateTime (Zone: +02:00) %H" + assert "42".eql?(content[26]), "Wrong result on liquid standard date filter: xsd:dateTime (Zone: +02:00) %M" end should "test different math filters on scinitfic notation" do From 8b673cbeeb0b8bd18f9f0d17775a715798985fec Mon Sep 17 00:00:00 2001 From: Nime Date: Sun, 2 Dec 2018 21:46:36 +0100 Subject: [PATCH 10/85] cleaned up code around template mapping --- lib/jekyll/drops/rdf_resource_class.rb | 26 +++++++++------------- lib/jekyll/helper/rdf_class_extraction.rb | 27 +++++++++++++++-------- lib/jekyll/rdf_main_generator.rb | 2 +- lib/jekyll/rdf_template_mapper.rb | 4 ++-- 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/lib/jekyll/drops/rdf_resource_class.rb b/lib/jekyll/drops/rdf_resource_class.rb index 19138ec7..bd47be32 100644 --- a/lib/jekyll/drops/rdf_resource_class.rb +++ b/lib/jekyll/drops/rdf_resource_class.rb @@ -31,23 +31,18 @@ module Drops #:nodoc: # Represents an RDF resource class to the Liquid template engine # class RdfResourceClass < RdfResource - @subClasses = [] - @lock = -1 - @subClassHierarchyValue = 0 - attr_accessor :lock - attr_accessor :template - attr_accessor :alternativeTemplates - attr_accessor :subClasses - attr_accessor :subClassHierarchyValue - attr_reader :sparql + attr_reader :lock + attr_reader :template + attr_reader :alternativeTemplates + attr_reader :subClasses + attr_reader :subClassHierarchyValue - def initialize(term, sparql) + def initialize(term) super(term) @subClasses = [] @lock = -1 @subClassHierarchyValue = 0 @alternativeTemplates = [] - @sparql = sparql end def multiple_templates? @@ -56,7 +51,8 @@ def multiple_templates? def find_direct_subclasses query = "SELECT ?s WHERE{ ?s #{@term.to_ntriples}}" - selection = @sparql.query(query).map{ |solution| solution.s.to_s} + selection = Jekyll::JekyllRdf::Helper::RdfHelper::sparql. + query(query).map{ |solution| solution.s.to_s} return selection end @@ -69,17 +65,17 @@ def propagate_template(template, lock) @lock=lock @template=template @alternativeTemplates.clear() - subClasses.each{|sub| sub.propagate_template(template ,lock+1)} + @subClasses.each{|sub| sub.propagate_template(template ,lock+1)} elsif(@lock==lock) @alternativeTemplates.push(template) - subClasses.each{|sub| sub.propagate_template(template ,lock+1)} + @subClasses.each{|sub| sub.propagate_template(template ,lock+1)} end end def traverse_hierarchy_value(predecessorHierarchyValue) if(@subClassHierarchyValue + 1 >= predecessorHierarchyValue) #avoid loops @subClassHierarchyValue += 1 - subClasses.each{|sub| sub.traverse_hierarchy_value(@subClassHierarchyValue)} + @subClasses.each{|sub| sub.traverse_hierarchy_value(@subClassHierarchyValue)} end end end diff --git a/lib/jekyll/helper/rdf_class_extraction.rb b/lib/jekyll/helper/rdf_class_extraction.rb index b1470f5d..2c01aea2 100644 --- a/lib/jekyll/helper/rdf_class_extraction.rb +++ b/lib/jekyll/helper/rdf_class_extraction.rb @@ -2,20 +2,29 @@ module Jekyll module JekyllRdf module Helper module RdfClassExtraction + private - def search_for_classes(sparql) - class_recognition_query = "SELECT DISTINCT ?resourceUri WHERE{ {?resourceUri ?o} UNION{ ?s ?resourceUri} UNION{ ?s ?resourceUri}}" - class_search_results = sparql.query(class_recognition_query).map{ |sol| sol[:resourceUri] }.reject do |s| # Reject literals - s.class <= RDF::Literal - end.select do |s| # Select URIs and blank nodes in case of include_blank - s.class <=RDF::Node || s.class <= RDF::URI - end + def create_class_map + create_resource_class(search_for_classes) + end + + def search_for_classes + class_recognition_query = "SELECT DISTINCT ?resourceUri WHERE{ " << + "{?resourceUri ?o}" << + " UNION{ ?s ?resourceUri}" << + " UNION{ ?s ?resourceUri}}" + class_search_results = Jekyll::JekyllRdf::Helper::RdfHelper::sparql. + query(class_recognition_query). + map{ |sol| sol[:resourceUri] }.reject do |s| # Reject literals + s.class <= RDF::Literal + end return class_search_results end - def create_resource_class(class_search_results, sparql) + def create_resource_class(class_search_results) class_search_results.each do |uri| - @classResources[uri.to_s]=Jekyll::JekyllRdf::Drops::RdfResourceClass.new(uri, sparql) + @classResources[uri.to_s]=Jekyll::JekyllRdf::Drops:: + RdfResourceClass.new(uri) end @classResources.each{|key, value| diff --git a/lib/jekyll/rdf_main_generator.rb b/lib/jekyll/rdf_main_generator.rb index 4fec1679..c0f7ed11 100644 --- a/lib/jekyll/rdf_main_generator.rb +++ b/lib/jekyll/rdf_main_generator.rb @@ -82,7 +82,7 @@ def generate(site) parse_resources(resources) - mapper = Jekyll::RdfTemplateMapper.new(@config['instance_template_mappings'], @config['class_template_mappings'], @config['default_template'], sparql) + mapper = Jekyll::RdfTemplateMapper.new(@config['instance_template_mappings'], @config['class_template_mappings'], @config['default_template']) prepare_pages(site, mapper) diff --git a/lib/jekyll/rdf_template_mapper.rb b/lib/jekyll/rdf_template_mapper.rb index b48e9158..f3c59c96 100644 --- a/lib/jekyll/rdf_template_mapper.rb +++ b/lib/jekyll/rdf_template_mapper.rb @@ -37,13 +37,13 @@ class RdfTemplateMapper # # * +resources_to_templates+ - A Hash mapping a type resource to a template name # * +default_template+ - Default template name - def initialize(resources_to_templates, classes_to_templates, default_template, sparql) + def initialize(resources_to_templates, classes_to_templates, default_template) @resources_to_templates = resources_to_templates @default_template = default_template @classes_to_templates = classes_to_templates @classResources = {} @warnings = {} - create_resource_class(search_for_classes(sparql), sparql) + create_class_map assign_class_templates(classes_to_templates) end From 409a4a6e990e5e51d953682602cc304e41e23cc5 Mon Sep 17 00:00:00 2001 From: Nime Date: Mon, 3 Dec 2018 23:47:20 +0100 Subject: [PATCH 11/85] hashing warnings onto class mappings --- lib/jekyll/drops/rdf_resource_class.rb | 46 +++++++++---- lib/jekyll/helper/rdf_class_extraction.rb | 79 ++++++++++++++++++++++- lib/jekyll/rdf_template_mapper.rb | 48 ++++---------- 3 files changed, 126 insertions(+), 47 deletions(-) diff --git a/lib/jekyll/drops/rdf_resource_class.rb b/lib/jekyll/drops/rdf_resource_class.rb index bd47be32..3ef00d90 100644 --- a/lib/jekyll/drops/rdf_resource_class.rb +++ b/lib/jekyll/drops/rdf_resource_class.rb @@ -32,23 +32,38 @@ module Drops #:nodoc: # class RdfResourceClass < RdfResource attr_reader :lock - attr_reader :template + attr_reader :dist #distance to next class with template + attr_accessor :template + attr_accessor :path attr_reader :alternativeTemplates attr_reader :subClasses attr_reader :subClassHierarchyValue + attr_accessor :base # important for template mapping + # true if _config.yml assigned this class a template - def initialize(term) + def initialize(term, base = false) super(term) + @base = base @subClasses = [] @lock = -1 @subClassHierarchyValue = 0 @alternativeTemplates = [] + @stop_object = StopObject.new end def multiple_templates? !@alternativeTemplates.empty? end + def find_direct_superclasses + return @superclasses unless @superclasses.nil? + query = "SELECT ?s WHERE{ #{@term.to_ntriples} ?s }" + selection = Jekyll::JekyllRdf::Helper::RdfHelper::sparql. + query(query).map{ |solution| solution.s.to_s} + @superclasses = selection + return selection + end + def find_direct_subclasses query = "SELECT ?s WHERE{ ?s #{@term.to_ntriples}}" selection = Jekyll::JekyllRdf::Helper::RdfHelper::sparql. @@ -60,16 +75,23 @@ def add_subclass(resource) @subClasses << resource end - def propagate_template(template, lock) - if(@lock>lock||@lock==-1) - @lock=lock - @template=template - @alternativeTemplates.clear() - @subClasses.each{|sub| sub.propagate_template(template ,lock+1)} - elsif(@lock==lock) - @alternativeTemplates.push(template) - @subClasses.each{|sub| sub.propagate_template(template ,lock+1)} - end + #def propagate_template(template, lock) + # if(@lock>lock||@lock==-1) + # @lock=lock + # @template=template + # @alternativeTemplates.clear() + # @subClasses.each{|sub| sub.propagate_template(template ,lock+1)} + # elsif(@lock==lock) + # @alternativeTemplates.push(template) + # @subClasses.each{|sub| sub.propagate_template(template ,lock+1)} + # end + #end + + def propagate_template(dist) + return if @path.nil? + @dist = dist + @path.template = @template + @path.propagate_template(dist +1) end def traverse_hierarchy_value(predecessorHierarchyValue) diff --git a/lib/jekyll/helper/rdf_class_extraction.rb b/lib/jekyll/helper/rdf_class_extraction.rb index 2c01aea2..4e4b3e9b 100644 --- a/lib/jekyll/helper/rdf_class_extraction.rb +++ b/lib/jekyll/helper/rdf_class_extraction.rb @@ -39,12 +39,77 @@ def assign_class_templates(classes_to_templates) @classResources.default = StopObject.new classes_to_templates.each{|key, value| @classResources[key].propagate_template(value,0) - @classResources[key].traverse_hierarchy_value(0); + @classResources[key].traverse_hierarchy_value(0) } @classResources.default = nil end end + ## + # TODO -hashing + # -reset lock for each call + # -make sure each class is added only once to class_list + def request_class_template class_list + #hash template and determine if we used these classes before + #start searching + lock = -1 + count = 0 + next_increase = -1 + min_template_lock = @stop_object #ruby does not have MAX_VALUE + min_template = nil + class_list.map!{|uri| + @classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass(uri) + } + class_list.each{|class_resource| + if(next_increase <= count) # the next level of the breadth-first search + lock += 1 + next_increase = class_list.length + end + class_resource.find_direct_superclasses.each{ |uri| + @classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass(uri) + if(!@classResources[uri].template.nil?) # do not search in paths you previously found + @classResources[uri].path = class_resource + if @classResources[uri].base + @classResources[uri].propagate_template(0) + return @classResources[uri] + elsif min_template_lock > (lock + @classResources[uri].dist) # you found a branche that was used earlier + min_template = @classResources[uri].template + min_template_lock = lock + @classResources[uri].dist + end + elsif(@classResources[uri].lock > class_resource.lock) + class_list.push(@classResources[uri]) + @classResources[uri].path = class_resource + end + } + count += 1 + return min_template if (min_template_lock <= lock) + } + end + + + def clean_alternative_tmpl + @classResources.each{|key, value| + consistence_templates(value) if value.multiple_templates? + } + end + + ## + # Add a warning for a class having multiple possible templates + # The warnings are then later displayed with print_warnings + # + def consistence_templates(classRes) + hash_str = classRes.alternativeTemplates.push(classRes.template). + sort!.join(", ") + begin + @consistence[hash_str] = [] + @consistence[hash_str].push(classRes.template) + @consistence[hash_str].push([]) + end if @consistence[hash_str].nil? + classRes.template = @consistence[hash_str][0] + @consistence[hash_str][1].push(classRes) # using a hash ensures that a warning is printed only once for each combination of templates + # and for each resource at most once + end + class StopObject #unfortunately next does not work in this setup, it avoids to have "if" in every iteration def propagate_template(template, lock) return @@ -53,6 +118,18 @@ def propagate_template(template, lock) def traverse_hierarchy_value(predecessorHierarchyValue) return end + + def > + true + end + + def <= + false + end + + def < + false + end end end end diff --git a/lib/jekyll/rdf_template_mapper.rb b/lib/jekyll/rdf_template_mapper.rb index f3c59c96..d3e254fe 100644 --- a/lib/jekyll/rdf_template_mapper.rb +++ b/lib/jekyll/rdf_template_mapper.rb @@ -42,9 +42,10 @@ def initialize(resources_to_templates, classes_to_templates, default_template) @default_template = default_template @classes_to_templates = classes_to_templates @classResources = {} - @warnings = {} - create_class_map + @consistence = {} #ensures that the same template is chosen for each combination of templates + #create_class_map assign_class_templates(classes_to_templates) + clean_alternative_tmpl end ## @@ -55,43 +56,22 @@ def map(resource) tmpl = @resources_to_templates ? @resources_to_templates[resource.term.to_s] : nil lock = -1 hier = -1 - duplicate_level_templ = [] - resource.direct_classes.each do |classUri| - classRes = @classResources[classUri] - if((classRes.lock <= lock || lock == -1) && !classRes.template.nil?) - if(classRes.subClassHierarchyValue > hier) - lock = classRes.lock - tmpl = classRes.template - hier = classRes.subClassHierarchyValue - duplicate_level_templ.clear.push(tmpl) - if(classRes.multiple_templates?) - duplicate_level_templ.concat(classRes.alternativeTemplates) - end - elsif(classRes.subClassHierarchyValue == hier) - duplicate_level_templ.push(classRes.template) - end - end unless classRes.nil? - end if(tmpl.nil?) - add_warning(duplicate_level_templ.uniq, resource.iri) if (duplicate_level_templ.length > 1) && (Jekyll.env.eql? "development") + request_class_template(resource.direct_classes) #TODO: check empty? + #resource.direct_classes.each do |classUri| + # classRes = @classResources[classUri] + # if((classRes.lock <= lock || lock == -1) && !classRes.template.nil? && (classRes.subClassHierarchyValue > hier)) + # lock = classRes.lock + # tmpl = classRes.template + # hier = classRes.subClassHierarchyValue + # end unless classRes.nil? + #end if(tmpl.nil?) return tmpl unless tmpl.nil? return @default_template end - ## - # Add a warning for a resource having multiple possible templates - # The warnings are then later displayed with print_warnings - # - def add_warning(keys, iri) - keys.sort! - key = keys.join(', ') - @warnings[key] = [] if @warnings[key].nil? # using a hash ensures that a warning is printed only once for each combination of templates - # and for each resource at most once - @warnings[key].push(iri) unless @warnings[key].include? iri - end - def print_warnings - @warnings.delete_if{ |key, iris| - Jekyll.logger.warn("Warning: multiple possible templates for resources #{iris.join(", ")}\nPossible Templates: #{key}") + @consistence.each{ |key, template_class_store| + Jekyll.logger.warn("Warning: multiple possible templates for resources #{template_class_store[1].join(", ")}\nPossible Templates: #{key}") true } end From 6206975bd6757ccdfd0b290461dc35604516a3f8 Mon Sep 17 00:00:00 2001 From: Nime Date: Mon, 17 Dec 2018 01:09:21 +0100 Subject: [PATCH 12/85] added the new template-mapping system (unclean) --- lib/jekyll/drops/rdf_resource_class.rb | 32 +++++++-- lib/jekyll/helper/rdf_class_extraction.rb | 82 ++++++++++++----------- lib/jekyll/rdf_template_mapper.rb | 9 +-- 3 files changed, 75 insertions(+), 48 deletions(-) diff --git a/lib/jekyll/drops/rdf_resource_class.rb b/lib/jekyll/drops/rdf_resource_class.rb index 3ef00d90..93665b43 100644 --- a/lib/jekyll/drops/rdf_resource_class.rb +++ b/lib/jekyll/drops/rdf_resource_class.rb @@ -31,8 +31,8 @@ module Drops #:nodoc: # Represents an RDF resource class to the Liquid template engine # class RdfResourceClass < RdfResource - attr_reader :lock - attr_reader :dist #distance to next class with template + attr_writer :lock + attr_reader :distance #distance to next class with template attr_accessor :template attr_accessor :path attr_reader :alternativeTemplates @@ -46,9 +46,10 @@ def initialize(term, base = false) @base = base @subClasses = [] @lock = -1 + @lockNumber = 0 @subClassHierarchyValue = 0 @alternativeTemplates = [] - @stop_object = StopObject.new + @distance = 0 end def multiple_templates? @@ -87,11 +88,16 @@ def add_subclass(resource) # end #end - def propagate_template(dist) + def propagate_template(distance) return if @path.nil? - @dist = dist + @distance = distance @path.template = @template - @path.propagate_template(dist +1) + @path.propagate_template(distance +1) + end + + def get_path_root + return self if @path.nil? + @path.get_path_root end def traverse_hierarchy_value(predecessorHierarchyValue) @@ -100,6 +106,20 @@ def traverse_hierarchy_value(predecessorHierarchyValue) @subClasses.each{|sub| sub.traverse_hierarchy_value(@subClassHierarchyValue)} end end + + def added? lock_number + if @lock_number != lock_number + @lock_number = lock_number # used to recognize different searchpasses of request_class_template + @lock = -1 + false + else + true + end + end + + def lock + @lock + end end end end diff --git a/lib/jekyll/helper/rdf_class_extraction.rb b/lib/jekyll/helper/rdf_class_extraction.rb index 4e4b3e9b..bc26c268 100644 --- a/lib/jekyll/helper/rdf_class_extraction.rb +++ b/lib/jekyll/helper/rdf_class_extraction.rb @@ -21,71 +21,85 @@ def search_for_classes return class_search_results end - def create_resource_class(class_search_results) - class_search_results.each do |uri| - @classResources[uri.to_s]=Jekyll::JekyllRdf::Drops:: - RdfResourceClass.new(uri) - end - - @classResources.each{|key, value| - value.find_direct_subclasses.each{|s| - value.add_subclass(@classResources[s]) + def create_resource_class(classes_to_templates) + if(classes_to_templates.is_a?(Hash)) + classes_to_templates.each{|uri, template| + @classResources[uri] = Jekyll::JekyllRdf::Drops:: + RdfResourceClass.new(RDF::URI(uri), true) + @classResources[uri].template = template } - } + end end def assign_class_templates(classes_to_templates) if(classes_to_templates.is_a?(Hash)) - @classResources.default = StopObject.new classes_to_templates.each{|key, value| - @classResources[key].propagate_template(value,0) + @classResources[key].propagate_template(value, 0) @classResources[key].traverse_hierarchy_value(0) } - @classResources.default = nil end end ## # TODO -hashing - # -reset lock for each call - # -make sure each class is added only once to class_list - def request_class_template class_list + # +reset lock for each call + # +make sure each class is added only once to class_list + def request_class_template direct_classes #hash template and determine if we used these classes before #start searching lock = -1 count = 0 next_increase = -1 + lock_number = rand min_template_lock = @stop_object #ruby does not have MAX_VALUE - min_template = nil - class_list.map!{|uri| - @classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass(uri) + min_class = nil + class_list = direct_classes.map{|uri| + @classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass.new(RDF::URI(uri)) } class_list.each{|class_resource| if(next_increase <= count) # the next level of the breadth-first search + if ((min_template_lock <= lock) && (lock >= 1)) # if (distance to next template is smaller than current search radius) && (we checked all immediate classes) + min_class.propagate_template(min_class.distance) + return extract_template(min_class) + end lock += 1 next_increase = class_list.length end + + unless class_resource.template.nil? + return class_resource.template + end + class_resource.find_direct_superclasses.each{ |uri| - @classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass(uri) + @classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass.new(RDF::URI(uri)) if(!@classResources[uri].template.nil?) # do not search in paths you previously found @classResources[uri].path = class_resource if @classResources[uri].base - @classResources[uri].propagate_template(0) - return @classResources[uri] - elsif min_template_lock > (lock + @classResources[uri].dist) # you found a branche that was used earlier - min_template = @classResources[uri].template - min_template_lock = lock + @classResources[uri].dist + min_template_lock = lock + min_class = @classResources[uri] + elsif min_template_lock > (lock + @classResources[uri].distance) # you found a branch that was used earlier + min_template_lock = lock + @classResources[uri].distance + min_class = @classResources[uri] end - elsif(@classResources[uri].lock > class_resource.lock) + elsif(!@classResources[uri].added?(lock_number) && @classResources[uri].lock > class_resource.lock) # not a previously searched resource without a template class_list.push(@classResources[uri]) @classResources[uri].path = class_resource + @classResources[uri].lock = lock end } count += 1 - return min_template if (min_template_lock <= lock) } + + unless min_class.nil? + return extract_template(min_class) + end + return nil end + def extract_template class_resource + class_resource.propagate_template(class_resource.distance) + return class_resource.get_path_root.template + end def clean_alternative_tmpl @classResources.each{|key, value| @@ -111,23 +125,15 @@ def consistence_templates(classRes) end class StopObject #unfortunately next does not work in this setup, it avoids to have "if" in every iteration - def propagate_template(template, lock) - return - end - - def traverse_hierarchy_value(predecessorHierarchyValue) - return - end - - def > + def > object true end - def <= + def <= object false end - def < + def < object false end end diff --git a/lib/jekyll/rdf_template_mapper.rb b/lib/jekyll/rdf_template_mapper.rb index d3e254fe..acdb3e0f 100644 --- a/lib/jekyll/rdf_template_mapper.rb +++ b/lib/jekyll/rdf_template_mapper.rb @@ -40,12 +40,13 @@ class RdfTemplateMapper def initialize(resources_to_templates, classes_to_templates, default_template) @resources_to_templates = resources_to_templates @default_template = default_template - @classes_to_templates = classes_to_templates @classResources = {} @consistence = {} #ensures that the same template is chosen for each combination of templates + @stop_object = StopObject.new + #create_class_map - assign_class_templates(classes_to_templates) - clean_alternative_tmpl + create_resource_class(classes_to_templates) + #clean_alternative_tmpl end ## @@ -56,7 +57,7 @@ def map(resource) tmpl = @resources_to_templates ? @resources_to_templates[resource.term.to_s] : nil lock = -1 hier = -1 - request_class_template(resource.direct_classes) #TODO: check empty? + tmpl = request_class_template(resource.direct_classes) if tmpl.nil? #TODO: check empty? #resource.direct_classes.each do |classUri| # classRes = @classResources[classUri] # if((classRes.lock <= lock || lock == -1) && !classRes.template.nil? && (classRes.subClassHierarchyValue > hier)) From 5bbbd58795149c9fda04f1a079363a2c3a1cd73a Mon Sep 17 00:00:00 2001 From: Nime Date: Mon, 17 Dec 2018 02:11:14 +0100 Subject: [PATCH 13/85] made mapping prefer more exact layout --- lib/jekyll/drops/rdf_resource_class.rb | 1 + lib/jekyll/helper/rdf_class_extraction.rb | 14 +++++++++----- lib/jekyll/rdf_template_mapper.rb | 2 +- test/cases/classHierarchy/test_class_hierarchy.rb | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/jekyll/drops/rdf_resource_class.rb b/lib/jekyll/drops/rdf_resource_class.rb index 93665b43..c28b5e92 100644 --- a/lib/jekyll/drops/rdf_resource_class.rb +++ b/lib/jekyll/drops/rdf_resource_class.rb @@ -91,6 +91,7 @@ def add_subclass(resource) def propagate_template(distance) return if @path.nil? @distance = distance + return unless @path.template.nil? @path.template = @template @path.propagate_template(distance +1) end diff --git a/lib/jekyll/helper/rdf_class_extraction.rb b/lib/jekyll/helper/rdf_class_extraction.rb index bc26c268..cc1265ed 100644 --- a/lib/jekyll/helper/rdf_class_extraction.rb +++ b/lib/jekyll/helper/rdf_class_extraction.rb @@ -44,7 +44,7 @@ def assign_class_templates(classes_to_templates) # TODO -hashing # +reset lock for each call # +make sure each class is added only once to class_list - def request_class_template direct_classes + def request_class_template direct_classes, test #hash template and determine if we used these classes before #start searching lock = -1 @@ -55,6 +55,8 @@ def request_class_template direct_classes min_class = nil class_list = direct_classes.map{|uri| @classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass.new(RDF::URI(uri)) + @classResources[uri].path = nil + @classResources[uri] } class_list.each{|class_resource| if(next_increase <= count) # the next level of the breadth-first search @@ -66,14 +68,16 @@ def request_class_template direct_classes next_increase = class_list.length end - unless class_resource.template.nil? - return class_resource.template + Jekyll.logger.info "checking #{class_resource}" if test + if !class_resource.template.nil? && min_template_lock > lock - 1 + class_resource.distance + min_template_lock = lock - 1 + min_class = class_resource end class_resource.find_direct_superclasses.each{ |uri| @classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass.new(RDF::URI(uri)) + @classResources[uri].path = class_resource if(!@classResources[uri].template.nil?) # do not search in paths you previously found - @classResources[uri].path = class_resource if @classResources[uri].base min_template_lock = lock min_class = @classResources[uri] @@ -83,7 +87,7 @@ def request_class_template direct_classes end elsif(!@classResources[uri].added?(lock_number) && @classResources[uri].lock > class_resource.lock) # not a previously searched resource without a template class_list.push(@classResources[uri]) - @classResources[uri].path = class_resource + Jekyll.logger.info "found #{@classResources[uri]}" if test @classResources[uri].lock = lock end } diff --git a/lib/jekyll/rdf_template_mapper.rb b/lib/jekyll/rdf_template_mapper.rb index acdb3e0f..bbfd9037 100644 --- a/lib/jekyll/rdf_template_mapper.rb +++ b/lib/jekyll/rdf_template_mapper.rb @@ -57,7 +57,7 @@ def map(resource) tmpl = @resources_to_templates ? @resources_to_templates[resource.term.to_s] : nil lock = -1 hier = -1 - tmpl = request_class_template(resource.direct_classes) if tmpl.nil? #TODO: check empty? + tmpl = request_class_template(resource.direct_classes, (resource.to_s.eql? "http://example.org/instance/baseRes")) if tmpl.nil? #TODO: check empty? #resource.direct_classes.each do |classUri| # classRes = @classResources[classUri] # if((classRes.lock <= lock || lock == -1) && !classRes.template.nil? && (classRes.subClassHierarchyValue > hier)) diff --git a/test/cases/classHierarchy/test_class_hierarchy.rb b/test/cases/classHierarchy/test_class_hierarchy.rb index 320cd49f..52c312a8 100644 --- a/test/cases/classHierarchy/test_class_hierarchy.rb +++ b/test/cases/classHierarchy/test_class_hierarchy.rb @@ -12,7 +12,7 @@ class TestClassHierarchy < Test::Unit::TestCase entry.strip end assert_equal "http://example.org/instance/baseRes", content[0] - assert_equal "Master", content[1] + assert_equal "LowerMaster", content[1] content = [] file = File.read(File.join(@source, "_site/advaRes.html")) From fe4878be19960b503dee1801e01f18a3caf84245 Mon Sep 17 00:00:00 2001 From: Nime Date: Tue, 18 Dec 2018 14:17:09 +0100 Subject: [PATCH 14/85] added Hashing --- lib/jekyll/drops/rdf_resource_class.rb | 37 ++------------ lib/jekyll/helper/rdf_class_extraction.rb | 61 +++++++++++++---------- lib/jekyll/rdf_template_mapper.rb | 15 +----- 3 files changed, 41 insertions(+), 72 deletions(-) diff --git a/lib/jekyll/drops/rdf_resource_class.rb b/lib/jekyll/drops/rdf_resource_class.rb index c28b5e92..c5a2bb0e 100644 --- a/lib/jekyll/drops/rdf_resource_class.rb +++ b/lib/jekyll/drops/rdf_resource_class.rb @@ -31,7 +31,7 @@ module Drops #:nodoc: # Represents an RDF resource class to the Liquid template engine # class RdfResourceClass < RdfResource - attr_writer :lock + attr_accessor :lock attr_reader :distance #distance to next class with template attr_accessor :template attr_accessor :path @@ -65,29 +65,6 @@ def find_direct_superclasses return selection end - def find_direct_subclasses - query = "SELECT ?s WHERE{ ?s #{@term.to_ntriples}}" - selection = Jekyll::JekyllRdf::Helper::RdfHelper::sparql. - query(query).map{ |solution| solution.s.to_s} - return selection - end - - def add_subclass(resource) - @subClasses << resource - end - - #def propagate_template(template, lock) - # if(@lock>lock||@lock==-1) - # @lock=lock - # @template=template - # @alternativeTemplates.clear() - # @subClasses.each{|sub| sub.propagate_template(template ,lock+1)} - # elsif(@lock==lock) - # @alternativeTemplates.push(template) - # @subClasses.each{|sub| sub.propagate_template(template ,lock+1)} - # end - #end - def propagate_template(distance) return if @path.nil? @distance = distance @@ -108,20 +85,16 @@ def traverse_hierarchy_value(predecessorHierarchyValue) end end - def added? lock_number + def add? lock_number if @lock_number != lock_number @lock_number = lock_number # used to recognize different searchpasses of request_class_template @lock = -1 - false - else true + else + false end end - - def lock - @lock - end - end + end #RdfResourceClass end end end diff --git a/lib/jekyll/helper/rdf_class_extraction.rb b/lib/jekyll/helper/rdf_class_extraction.rb index cc1265ed..f802c13e 100644 --- a/lib/jekyll/helper/rdf_class_extraction.rb +++ b/lib/jekyll/helper/rdf_class_extraction.rb @@ -31,21 +31,12 @@ def create_resource_class(classes_to_templates) end end - def assign_class_templates(classes_to_templates) - if(classes_to_templates.is_a?(Hash)) - classes_to_templates.each{|key, value| - @classResources[key].propagate_template(value, 0) - @classResources[key].traverse_hierarchy_value(0) - } - end - end - ## - # TODO -hashing - # +reset lock for each call - # +make sure each class is added only once to class_list - def request_class_template direct_classes, test + # TODO -make sure each class is added only once to class_list + def request_class_template direct_classes #hash template and determine if we used these classes before + hash_str = direct_classes.sort!.join(", ") + return @template_cache[hash_str] unless @template_cache[hash_str].nil? #start searching lock = -1 count = 0 @@ -58,17 +49,18 @@ def request_class_template direct_classes, test @classResources[uri].path = nil @classResources[uri] } + alternatives = [] + class_list.each{|class_resource| if(next_increase <= count) # the next level of the breadth-first search if ((min_template_lock <= lock) && (lock >= 1)) # if (distance to next template is smaller than current search radius) && (we checked all immediate classes) - min_class.propagate_template(min_class.distance) - return extract_template(min_class) + return extract_template(find_highlevel_inheritance(min_class, alternatives), hash_str) end + alternatives.clear() lock += 1 next_increase = class_list.length end - Jekyll.logger.info "checking #{class_resource}" if test if !class_resource.template.nil? && min_template_lock > lock - 1 + class_resource.distance min_template_lock = lock - 1 min_class = class_resource @@ -76,18 +68,26 @@ def request_class_template direct_classes, test class_resource.find_direct_superclasses.each{ |uri| @classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass.new(RDF::URI(uri)) - @classResources[uri].path = class_resource if(!@classResources[uri].template.nil?) # do not search in paths you previously found if @classResources[uri].base - min_template_lock = lock - min_class = @classResources[uri] + if(min_class.nil?) + min_template_lock = lock + min_class = @classResources[uri] + else + alternatives.push @classResources[uri] + end + @classResources[uri].path = class_resource # <- this might be valnuable to cyclic inheritance in the graph elsif min_template_lock > (lock + @classResources[uri].distance) # you found a branch that was used earlier + @classResources[uri].base # note template but search further unitl (min_template_lock <= lock) && (lock >= 1) is satisfied + @classResources[uri].path = class_resource # <- this might be valnuable to cyclic inheritance in the graph min_template_lock = lock + @classResources[uri].distance min_class = @classResources[uri] + elsif min_template_lock == (lock + @classResources[uri].distance) + alternatives.push @classResources[uri] end - elsif(!@classResources[uri].added?(lock_number) && @classResources[uri].lock > class_resource.lock) # not a previously searched resource without a template + elsif(@classResources[uri].add?(lock_number) && @classResources[uri].lock > class_resource.lock) # not a previously searched resource without a template + @classResources[uri].path = class_resource # <- this might be valnuable to cyclic inheritance in the graph class_list.push(@classResources[uri]) - Jekyll.logger.info "found #{@classResources[uri]}" if test @classResources[uri].lock = lock end } @@ -95,20 +95,27 @@ def request_class_template direct_classes, test } unless min_class.nil? - return extract_template(min_class) + return extract_template(find_highlevel_inheritance(min_class, alternatives), hash_str) end return nil end - def extract_template class_resource + def extract_template class_resource, hash_str class_resource.propagate_template(class_resource.distance) - return class_resource.get_path_root.template + return (@template_cache[hash_str] = class_resource.get_path_root.template) end - def clean_alternative_tmpl - @classResources.each{|key, value| - consistence_templates(value) if value.multiple_templates? + def find_highlevel_inheritance current_best, class_list #check at the end of the search for direct inheritance on highest level + class_list.each{|resource| + resource.find_direct_superclasses.each{|uri| + @classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass.new(RDF::URI(uri)) + @classResources[uri].path = resource + } if resource.base } + while(class_list.include?(current_best.path)) # this is valnuable to cyclic inheritance + current_best = current_best.path + end + current_best end ## diff --git a/lib/jekyll/rdf_template_mapper.rb b/lib/jekyll/rdf_template_mapper.rb index bbfd9037..94a1ce38 100644 --- a/lib/jekyll/rdf_template_mapper.rb +++ b/lib/jekyll/rdf_template_mapper.rb @@ -42,11 +42,10 @@ def initialize(resources_to_templates, classes_to_templates, default_template) @default_template = default_template @classResources = {} @consistence = {} #ensures that the same template is chosen for each combination of templates + @template_cache = {} @stop_object = StopObject.new - #create_class_map create_resource_class(classes_to_templates) - #clean_alternative_tmpl end ## @@ -55,17 +54,7 @@ def initialize(resources_to_templates, classes_to_templates, default_template) # Returns the template name of one of the +resource+'s types, if available. Returns the default template name otherwise. def map(resource) tmpl = @resources_to_templates ? @resources_to_templates[resource.term.to_s] : nil - lock = -1 - hier = -1 - tmpl = request_class_template(resource.direct_classes, (resource.to_s.eql? "http://example.org/instance/baseRes")) if tmpl.nil? #TODO: check empty? - #resource.direct_classes.each do |classUri| - # classRes = @classResources[classUri] - # if((classRes.lock <= lock || lock == -1) && !classRes.template.nil? && (classRes.subClassHierarchyValue > hier)) - # lock = classRes.lock - # tmpl = classRes.template - # hier = classRes.subClassHierarchyValue - # end unless classRes.nil? - #end if(tmpl.nil?) + tmpl = request_class_template(resource.direct_classes) if tmpl.nil? && !resource.direct_classes.empty? return tmpl unless tmpl.nil? return @default_template end From 65fa8e4007a14373da066250e029cb5d4eb4f62c Mon Sep 17 00:00:00 2001 From: Nime Date: Tue, 15 Jan 2019 00:36:01 +0100 Subject: [PATCH 15/85] hookup warning system --- lib/jekyll/helper/rdf_class_extraction.rb | 28 +++++++++++++++-------- lib/jekyll/rdf_template_mapper.rb | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/jekyll/helper/rdf_class_extraction.rb b/lib/jekyll/helper/rdf_class_extraction.rb index f802c13e..350317ab 100644 --- a/lib/jekyll/helper/rdf_class_extraction.rb +++ b/lib/jekyll/helper/rdf_class_extraction.rb @@ -33,7 +33,9 @@ def create_resource_class(classes_to_templates) ## # TODO -make sure each class is added only once to class_list - def request_class_template direct_classes + def request_class_template resource + return nil if resource.direct_classes.empty? + direct_classes = resource.direct_classes #hash template and determine if we used these classes before hash_str = direct_classes.sort!.join(", ") return @template_cache[hash_str] unless @template_cache[hash_str].nil? @@ -54,7 +56,7 @@ def request_class_template direct_classes class_list.each{|class_resource| if(next_increase <= count) # the next level of the breadth-first search if ((min_template_lock <= lock) && (lock >= 1)) # if (distance to next template is smaller than current search radius) && (we checked all immediate classes) - return extract_template(find_highlevel_inheritance(min_class, alternatives), hash_str) + return extract_template(find_highlevel_inheritance(min_class, alternatives, resource), hash_str) end alternatives.clear() lock += 1 @@ -95,7 +97,7 @@ def request_class_template direct_classes } unless min_class.nil? - return extract_template(find_highlevel_inheritance(min_class, alternatives), hash_str) + return extract_template(find_highlevel_inheritance(min_class, alternatives, resource), hash_str) end return nil end @@ -105,7 +107,7 @@ def extract_template class_resource, hash_str return (@template_cache[hash_str] = class_resource.get_path_root.template) end - def find_highlevel_inheritance current_best, class_list #check at the end of the search for direct inheritance on highest level + def find_highlevel_inheritance current_best, class_list, resource #check at the end of the search for direct inheritance on highest level class_list.each{|resource| resource.find_direct_superclasses.each{|uri| @classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass.new(RDF::URI(uri)) @@ -113,26 +115,32 @@ def find_highlevel_inheritance current_best, class_list #check at the end of t } if resource.base } while(class_list.include?(current_best.path)) # this is valnuable to cyclic inheritance + slice = class_list.index(current_best) + class_list.slice!(slice) unless slice.nil? # parent alternatives are no real alternatives current_best = current_best.path end - current_best + return consistence_templates(current_best, class_list, resource) unless class_list.empty? + return current_best end ## # Add a warning for a class having multiple possible templates # The warnings are then later displayed with print_warnings # - def consistence_templates(classRes) - hash_str = classRes.alternativeTemplates.push(classRes.template). + def consistence_templates(classRes, alternatives, resource) + hash_str = alternatives.push(classRes). + map {|x| + x.template + }. sort!.join(", ") begin @consistence[hash_str] = [] - @consistence[hash_str].push(classRes.template) + @consistence[hash_str].push(classRes) @consistence[hash_str].push([]) end if @consistence[hash_str].nil? - classRes.template = @consistence[hash_str][0] - @consistence[hash_str][1].push(classRes) # using a hash ensures that a warning is printed only once for each combination of templates + @consistence[hash_str][1].push(resource) # using a hash ensures that a warning is printed only once for each combination of templates # and for each resource at most once + @consistence[hash_str][0] end class StopObject #unfortunately next does not work in this setup, it avoids to have "if" in every iteration diff --git a/lib/jekyll/rdf_template_mapper.rb b/lib/jekyll/rdf_template_mapper.rb index 94a1ce38..4e0e346b 100644 --- a/lib/jekyll/rdf_template_mapper.rb +++ b/lib/jekyll/rdf_template_mapper.rb @@ -54,7 +54,7 @@ def initialize(resources_to_templates, classes_to_templates, default_template) # Returns the template name of one of the +resource+'s types, if available. Returns the default template name otherwise. def map(resource) tmpl = @resources_to_templates ? @resources_to_templates[resource.term.to_s] : nil - tmpl = request_class_template(resource.direct_classes) if tmpl.nil? && !resource.direct_classes.empty? + tmpl = request_class_template(resource) if tmpl.nil? return tmpl unless tmpl.nil? return @default_template end From d3a9c12ac2312f641a046711716efa20f1ee65c5 Mon Sep 17 00:00:00 2001 From: Nime Date: Mon, 28 Jan 2019 20:39:58 +0100 Subject: [PATCH 16/85] remove junk --- lib/jekyll/helper/rdf_class_extraction.rb | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/lib/jekyll/helper/rdf_class_extraction.rb b/lib/jekyll/helper/rdf_class_extraction.rb index 0b91945b..0a9143ba 100644 --- a/lib/jekyll/helper/rdf_class_extraction.rb +++ b/lib/jekyll/helper/rdf_class_extraction.rb @@ -4,23 +4,6 @@ module Helper module RdfClassExtraction private - def create_class_map - create_resource_class(search_for_classes) - end - - def search_for_classes - class_recognition_query = "SELECT DISTINCT ?resourceUri WHERE{ " << - "{?resourceUri ?o}" << - " UNION{ ?s ?resourceUri}" << - " UNION{ ?s ?resourceUri}}" - class_search_results = Jekyll::JekyllRdf::Helper::RdfHelper::sparql. - query(class_recognition_query). - map{ |sol| sol[:resourceUri] }.reject do |s| # Reject literals - s.class <= RDF::Literal - end - return class_search_results - end - def create_resource_class(classes_to_templates) if(classes_to_templates.is_a?(Hash)) classes_to_templates.each{|uri, template| @@ -32,7 +15,7 @@ def create_resource_class(classes_to_templates) end ## - # TODO -make sure each class is added only once to class_list + # returns to a RdfResource a template through its rdf:type def request_class_template resource return nil if resource.direct_classes.empty? direct_classes = resource.direct_classes @@ -151,10 +134,6 @@ def > object def <= object false end - - def < object - false - end end end end From e028a03783ba8876e6a0742d1c4d7f16db913e04 Mon Sep 17 00:00:00 2001 From: Nime Date: Mon, 28 Jan 2019 20:19:25 +0100 Subject: [PATCH 17/85] fix: better solution classified as alternatives --- lib/jekyll/helper/rdf_class_extraction.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/jekyll/helper/rdf_class_extraction.rb b/lib/jekyll/helper/rdf_class_extraction.rb index 350317ab..0b91945b 100644 --- a/lib/jekyll/helper/rdf_class_extraction.rb +++ b/lib/jekyll/helper/rdf_class_extraction.rb @@ -72,15 +72,15 @@ def request_class_template resource @classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass.new(RDF::URI(uri)) if(!@classResources[uri].template.nil?) # do not search in paths you previously found if @classResources[uri].base - if(min_class.nil?) + if(!min_class.nil? && min_template_lock == lock) #min_class could contain a previously found class with equal distance + alternatives.push @classResources[uri] + else min_template_lock = lock min_class = @classResources[uri] - else - alternatives.push @classResources[uri] end @classResources[uri].path = class_resource # <- this might be valnuable to cyclic inheritance in the graph elsif min_template_lock > (lock + @classResources[uri].distance) # you found a branch that was used earlier - @classResources[uri].base # note template but search further unitl (min_template_lock <= lock) && (lock >= 1) is satisfied + # note template but search further unitl (min_template_lock <= lock) && (lock >= 1) is satisfied @classResources[uri].path = class_resource # <- this might be valnuable to cyclic inheritance in the graph min_template_lock = lock + @classResources[uri].distance min_class = @classResources[uri] From 435717e78d9623e4622753f37e5776f88ed16705 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 28 Jan 2019 15:57:28 +0100 Subject: [PATCH 18/85] fix heading in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e7c03c76..b8025a32 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# jekyll-rdf +# Jekyll RDF A [Jekyll plugin](https://jekyllrb.com/docs/plugins/) for including RDF data in your static site. From 61bfe205332f73a33180da491c12024efa33d7c0 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Tue, 29 Jan 2019 17:18:13 +0100 Subject: [PATCH 19/85] Update links to match new repo location --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b8025a32..955fa275 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ A [Jekyll plugin](https://jekyllrb.com/docs/plugins/) for including RDF data in your static site. [![Gem Version](https://badge.fury.io/rb/jekyll-rdf.svg)](https://badge.fury.io/rb/jekyll-rdf) -[![Build Status](https://travis-ci.org/white-gecko/jekyll-rdf.svg?branch=develop)](https://travis-ci.org/white-gecko/jekyll-rdf) -[![Coverage Status](https://coveralls.io/repos/github/white-gecko/jekyll-rdf/badge.svg?branch=develop)](https://coveralls.io/github/white-gecko/jekyll-rdf?branch=develop) +[![Build Status](https://travis-ci.org/AKSW/jekyll-rdf.svg?branch=develop)](https://travis-ci.org/AKSW/jekyll-rdf) +[![Coverage Status](https://coveralls.io/repos/github/AKSW/jekyll-rdf/badge.svg?branch=develop)](https://coveralls.io/github/AKSW/jekyll-rdf?branch=develop) The API Documentation is available at [RubyDoc.info](http://www.rubydoc.info/gems/jekyll-rdf/). @@ -664,7 +664,7 @@ http://www.ifi.uio.no/INF3580/simpsons#Maggie ## Installation from source To install the project with the git-repository you will need `git` on your system. The first step is just cloning the repository: ``` -git clone git@github.com:white-gecko/jekyll-rdf.git +git clone git@github.com:AKSW/jekyll-rdf.git ``` A folder named `jekyll-rdf` will be automatically generated. You need to switch into this folder and compile the ruby gem to finish the installation: ``` From 882296b9bd41b9c5d47d8abe795f440d481ead02 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Thu, 31 Jan 2019 10:22:54 +0100 Subject: [PATCH 20/85] Update remaining repo paths --- CHANGELOG.md | 2 ++ jekyll-rdf.gemspec | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdd4ca46..b238f70e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [3.1.1] - ??? +### changed +- Repository moved from https://github.com/white-gecko/jekyll-rdf/ to https://github.com/AKSW/jekyll-rdf/ ## [3.1.0] - 2018-11-27 ### Added diff --git a/jekyll-rdf.gemspec b/jekyll-rdf.gemspec index 4befbeab..d6ac3e51 100644 --- a/jekyll-rdf.gemspec +++ b/jekyll-rdf.gemspec @@ -13,9 +13,9 @@ Gem::Specification.new do |s| s.authors = ['Elias Saalmann', 'Christian Frommert', 'Simon Jakobi', 'Arne Jonas Präger', 'Maxi Bornmann', 'Georg Hackel', 'Eric Füg', 'Sebastian Zänker', 'Natanael Arndt', 'Simon Bin', 'Jan Beckert'] s.email = 'arndt@informatik.uni-leipzig.de' s.files = Dir['lib/**/*.rb'] - s.homepage = 'https://github.com/white-gecko/jekyll-rdf' + s.homepage = 'https://github.com/AKSW/jekyll-rdf' s.license = 'MIT' - s.add_runtime_dependency 'net-http-persistent', '~> 2.9' # https://github.com/white-gecko/jekyll-rdf/issues/197 + s.add_runtime_dependency 'net-http-persistent', '~> 2.9' # https://github.com/AKSW/jekyll-rdf/issues/197 s.add_runtime_dependency 'linkeddata', '~> 2.0' s.add_runtime_dependency 'sparql-client', '~> 3.0', '>= 3.0.1' s.add_runtime_dependency 'jekyll', '~> 3.1' From 38c54b0ac476658e6e19604f1a18a2ffc365e728 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Thu, 31 Jan 2019 10:24:39 +0100 Subject: [PATCH 21/85] Update version number to install in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b8025a32..149b27cf 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Add Jekyll-RDF to the plugins section: ``` group :jekyll_plugins do - gem "jekyll-rdf", '~> 3.0.0.pre.a' + gem "jekyll-rdf", '~> 3.1.0' … end ``` From b63c318d005743f14e55f9e8e774b74c20eb1337 Mon Sep 17 00:00:00 2001 From: Nime Date: Sun, 3 Feb 2019 19:57:45 +0100 Subject: [PATCH 22/85] move rdf_page_to_resource.rb and rdf_resolve_prefix.rb to lib/jekyll/helper/ --- lib/jekyll-rdf.rb | 3 +- lib/jekyll/filters/rdf_page_to_resource.rb | 34 -------- lib/jekyll/filters/rdf_resolve_prefix.rb | 60 -------------- lib/jekyll/helper/rdf_filter_helper.rb | 94 ++++++++++++++++++++++ lib/jekyll/rdf_main_generator.rb | 2 +- 5 files changed, 96 insertions(+), 97 deletions(-) delete mode 100644 lib/jekyll/filters/rdf_page_to_resource.rb delete mode 100644 lib/jekyll/filters/rdf_resolve_prefix.rb create mode 100644 lib/jekyll/helper/rdf_filter_helper.rb diff --git a/lib/jekyll-rdf.rb b/lib/jekyll-rdf.rb index 8624c59c..e26c7dc1 100644 --- a/lib/jekyll-rdf.rb +++ b/lib/jekyll-rdf.rb @@ -51,15 +51,14 @@ require 'jekyll/helper/rdf_class_extraction' require 'jekyll/helper/rdf_page_helper' require 'jekyll/helper/rdf_generator_helper' +require 'jekyll/helper/rdf_filter_helper' require 'jekyll/hooks/rdf_page_pointer' -require 'jekyll/filters/rdf_resolve_prefix' require 'jekyll/filters/rdf_sparql_query' require 'jekyll/filters/rdf_property' require 'jekyll/filters/rdf_collection' require 'jekyll/filters/rdf_container' require 'jekyll/filters/rdf_get' require 'jekyll/filters/rdf_debug_message' -require 'jekyll/filters/rdf_page_to_resource' Liquid::Template.register_filter(Jekyll::JekyllRdf::Filter) diff --git a/lib/jekyll/filters/rdf_page_to_resource.rb b/lib/jekyll/filters/rdf_page_to_resource.rb deleted file mode 100644 index 1f8f0c9e..00000000 --- a/lib/jekyll/filters/rdf_page_to_resource.rb +++ /dev/null @@ -1,34 +0,0 @@ -module Jekyll - module JekyllRdf - module Filter - private - def rdf_page_to_resource(input) - return Jekyll::JekyllRdf::Helper::RdfHelper::page.data['rdf'] if rdf_substitude_nil?(input) - return input['rdf'] if rdf_page_to_resource?(input) - return input - end - - def rdf_page_to_resource?(input) - return input.class <= Hash && input.key?("template") && input.key?("url") && input.key?("path") &&!input["rdf"].nil? - end - - def rdf_substitude_nil?(input) - return (!Jekyll::JekyllRdf::Helper::RdfHelper::page.data['rdf'].nil?)&&input.nil? - end - - def valid_resource?(input) - return (input.class <= String || input.class <= Jekyll::JekyllRdf::Drops::RdfResource) - end - - def to_string_wrap(input) - if(input.class <= Jekyll::JekyllRdf::Drops::RdfResource) - return input.term.to_ntriples - elsif(input.class <= String) - return rdf_resolve_prefix(input) - else - return false - end - end - end - end -end diff --git a/lib/jekyll/filters/rdf_resolve_prefix.rb b/lib/jekyll/filters/rdf_resolve_prefix.rb deleted file mode 100644 index 7f3300a1..00000000 --- a/lib/jekyll/filters/rdf_resolve_prefix.rb +++ /dev/null @@ -1,60 +0,0 @@ -## -# MIT License -# -# Copyright (c) 2016 Elias Saalmann, Christian Frommert, Simon Jakobi, -# Arne Jonas Präger, Maxi Bornmann, Georg Hackel, Eric Füg -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# - -module Jekyll - module JekyllRdf - module ResolvePrefixes - private - def rdf_resolve_prefix(predicate) - if(predicate[0] == "<" && predicate[-1] == ">") - # iri - return predicate - end - # qname - arr = predicate.split(":", 2) - if((arr[1].include? (":")) || (arr[1][0..1].eql?("//"))) - raise UnMarkedUri.new(predicate, Jekyll::JekyllRdf::Helper::RdfHelper::page.data['template']) #TODO .data['template'] is only defined on RdfPages - end - if(!Jekyll::JekyllRdf::Helper::RdfHelper::prefixes["rdf_prefixes"].nil?) - if(!Jekyll::JekyllRdf::Helper::RdfHelper::prefixes["rdf_prefix_map"][arr[0]].nil?) - return "<#{arr[1].prepend(Jekyll::JekyllRdf::Helper::RdfHelper::prefixes["rdf_prefix_map"][arr[0]])}>" - else - raise NoPrefixMapped.new(predicate, Jekyll::JekyllRdf::Helper::RdfHelper::page.data['template'], arr[0]) #TODO .data['template'] is only defined on RdfPages - end - else - raise NoPrefixesDefined.new(predicate, Jekyll::JekyllRdf::Helper::RdfHelper::page.data['template']) #TODO .data['template'] is only defined on RdfPages - end - end - end - end -end - -module Jekyll - module JekyllRdf - module Filter - include Jekyll::JekyllRdf::ResolvePrefixes - end - end -end diff --git a/lib/jekyll/helper/rdf_filter_helper.rb b/lib/jekyll/helper/rdf_filter_helper.rb new file mode 100644 index 00000000..715c7186 --- /dev/null +++ b/lib/jekyll/helper/rdf_filter_helper.rb @@ -0,0 +1,94 @@ +## +# MIT License +# +# Copyright (c) 2016 Elias Saalmann, Christian Frommert, Simon Jakobi, +# Arne Jonas Präger, Maxi Bornmann, Georg Hackel, Eric Füg +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +module Jekyll + module JekyllRdf + module Helper + module FilterHelper + private + def rdf_page_to_resource(input) + return Jekyll::JekyllRdf::Helper::RdfHelper::page.data['rdf'] if rdf_substitude_nil?(input) + return input['rdf'] if rdf_page_to_resource?(input) + return input + end + + def rdf_page_to_resource?(input) + return input.class <= Hash && input.key?("template") && input.key?("url") && input.key?("path") &&!input["rdf"].nil? + end + + def rdf_substitude_nil?(input) + return (!Jekyll::JekyllRdf::Helper::RdfHelper::page.data['rdf'].nil?)&&input.nil? + end + + def valid_resource?(input) + return (input.class <= String || input.class <= Jekyll::JekyllRdf::Drops::RdfResource) + end + + def to_string_wrap(input) + if(input.class <= Jekyll::JekyllRdf::Drops::RdfResource) + return input.term.to_ntriples + elsif(input.class <= String) + return rdf_resolve_prefix(input) + else + return false + end + end + end + + module PrefixSolver + private + def rdf_resolve_prefix(predicate) + if(predicate[0] == "<" && predicate[-1] == ">") + # iri + return predicate + end + # qname + arr = predicate.split(":", 2) + if((arr[1].include? (":")) || (arr[1][0..1].eql?("//"))) + raise UnMarkedUri.new(predicate, Jekyll::JekyllRdf::Helper::RdfHelper::page.data['template']) #TODO .data['template'] is only defined on RdfPages + end + if(!Jekyll::JekyllRdf::Helper::RdfHelper::prefixes["rdf_prefixes"].nil?) + if(!Jekyll::JekyllRdf::Helper::RdfHelper::prefixes["rdf_prefix_map"][arr[0]].nil?) + return "<#{arr[1].prepend(Jekyll::JekyllRdf::Helper::RdfHelper::prefixes["rdf_prefix_map"][arr[0]])}>" + else + raise NoPrefixMapped.new(predicate, Jekyll::JekyllRdf::Helper::RdfHelper::page.data['template'], arr[0]) #TODO .data['template'] is only defined on RdfPages + end + else + raise NoPrefixesDefined.new(predicate, Jekyll::JekyllRdf::Helper::RdfHelper::page.data['template']) #TODO .data['template'] is only defined on RdfPages + end + end + end + end + end +end + +module Jekyll + module JekyllRdf + module Filter + include Jekyll::JekyllRdf::Helper::FilterHelper + include Jekyll::JekyllRdf::Helper::PrefixSolver + end + end +end diff --git a/lib/jekyll/rdf_main_generator.rb b/lib/jekyll/rdf_main_generator.rb index 4fec1679..bf8acee4 100644 --- a/lib/jekyll/rdf_main_generator.rb +++ b/lib/jekyll/rdf_main_generator.rb @@ -33,7 +33,7 @@ class RdfMainGenerator < Jekyll::Generator safe true priority :highest include Jekyll::JekyllRdf::Helper::RdfGeneratorHelper - include Jekyll::JekyllRdf::ResolvePrefixes + include Jekyll::JekyllRdf::Helper::PrefixSolver ## # #generate performs the enrichment of a Jekyll::Site with rdf triples From 1d132144092d4141c45b898d3fa287c8aaeb8d71 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 4 Feb 2019 14:40:24 +0100 Subject: [PATCH 23/85] Add comment for find_highlevel_inheritance method and move comment in consistence_templates inline --- lib/jekyll/helper/rdf_class_extraction.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/helper/rdf_class_extraction.rb b/lib/jekyll/helper/rdf_class_extraction.rb index 0a9143ba..c234f3db 100644 --- a/lib/jekyll/helper/rdf_class_extraction.rb +++ b/lib/jekyll/helper/rdf_class_extraction.rb @@ -90,7 +90,13 @@ def extract_template class_resource, hash_str return (@template_cache[hash_str] = class_resource.get_path_root.template) end - def find_highlevel_inheritance current_best, class_list, resource #check at the end of the search for direct inheritance on highest level + ## + # Check at the end of the search for direct inheritance on highest level. + # + # +current_best+ ? + # +class_list+ is the list of clases that the +resource+ is assigned to. + # +resource+ is the resource. + def find_highlevel_inheritance current_best, class_list, resource class_list.each{|resource| resource.find_direct_superclasses.each{|uri| @classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass.new(RDF::URI(uri)) @@ -121,8 +127,8 @@ def consistence_templates(classRes, alternatives, resource) @consistence[hash_str].push(classRes) @consistence[hash_str].push([]) end if @consistence[hash_str].nil? - @consistence[hash_str][1].push(resource) # using a hash ensures that a warning is printed only once for each combination of templates - # and for each resource at most once + # using a hash ensures that a warning is printed only once for each combination of templates and for each resource at most once + @consistence[hash_str][1].push(resource) @consistence[hash_str][0] end From 79b0ba868a42e11e052f8dcf2f12a1078fe24c29 Mon Sep 17 00:00:00 2001 From: Nime Date: Mon, 28 Jan 2019 20:39:58 +0100 Subject: [PATCH 24/85] remove junk --- lib/jekyll/drops/rdf_resource_class.rb | 17 ----------------- lib/jekyll/helper/rdf_class_extraction.rb | 23 +---------------------- 2 files changed, 1 insertion(+), 39 deletions(-) diff --git a/lib/jekyll/drops/rdf_resource_class.rb b/lib/jekyll/drops/rdf_resource_class.rb index c5a2bb0e..56d33587 100644 --- a/lib/jekyll/drops/rdf_resource_class.rb +++ b/lib/jekyll/drops/rdf_resource_class.rb @@ -35,27 +35,17 @@ class RdfResourceClass < RdfResource attr_reader :distance #distance to next class with template attr_accessor :template attr_accessor :path - attr_reader :alternativeTemplates - attr_reader :subClasses - attr_reader :subClassHierarchyValue attr_accessor :base # important for template mapping # true if _config.yml assigned this class a template def initialize(term, base = false) super(term) @base = base - @subClasses = [] @lock = -1 @lockNumber = 0 - @subClassHierarchyValue = 0 - @alternativeTemplates = [] @distance = 0 end - def multiple_templates? - !@alternativeTemplates.empty? - end - def find_direct_superclasses return @superclasses unless @superclasses.nil? query = "SELECT ?s WHERE{ #{@term.to_ntriples} ?s }" @@ -78,13 +68,6 @@ def get_path_root @path.get_path_root end - def traverse_hierarchy_value(predecessorHierarchyValue) - if(@subClassHierarchyValue + 1 >= predecessorHierarchyValue) #avoid loops - @subClassHierarchyValue += 1 - @subClasses.each{|sub| sub.traverse_hierarchy_value(@subClassHierarchyValue)} - end - end - def add? lock_number if @lock_number != lock_number @lock_number = lock_number # used to recognize different searchpasses of request_class_template diff --git a/lib/jekyll/helper/rdf_class_extraction.rb b/lib/jekyll/helper/rdf_class_extraction.rb index 0b91945b..0a9143ba 100644 --- a/lib/jekyll/helper/rdf_class_extraction.rb +++ b/lib/jekyll/helper/rdf_class_extraction.rb @@ -4,23 +4,6 @@ module Helper module RdfClassExtraction private - def create_class_map - create_resource_class(search_for_classes) - end - - def search_for_classes - class_recognition_query = "SELECT DISTINCT ?resourceUri WHERE{ " << - "{?resourceUri ?o}" << - " UNION{ ?s ?resourceUri}" << - " UNION{ ?s ?resourceUri}}" - class_search_results = Jekyll::JekyllRdf::Helper::RdfHelper::sparql. - query(class_recognition_query). - map{ |sol| sol[:resourceUri] }.reject do |s| # Reject literals - s.class <= RDF::Literal - end - return class_search_results - end - def create_resource_class(classes_to_templates) if(classes_to_templates.is_a?(Hash)) classes_to_templates.each{|uri, template| @@ -32,7 +15,7 @@ def create_resource_class(classes_to_templates) end ## - # TODO -make sure each class is added only once to class_list + # returns to a RdfResource a template through its rdf:type def request_class_template resource return nil if resource.direct_classes.empty? direct_classes = resource.direct_classes @@ -151,10 +134,6 @@ def > object def <= object false end - - def < object - false - end end end end From 8b3897eed1754e55217f582b01c946c187628cd4 Mon Sep 17 00:00:00 2001 From: Nime Date: Sat, 9 Feb 2019 15:04:13 +0100 Subject: [PATCH 25/85] added documentation to the templating routine --- lib/jekyll/drops/rdf_resource_class.rb | 17 +++++++++++- lib/jekyll/helper/rdf_class_extraction.rb | 33 ++++++++++++++++++++--- lib/jekyll/rdf_template_mapper.rb | 3 +++ 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/lib/jekyll/drops/rdf_resource_class.rb b/lib/jekyll/drops/rdf_resource_class.rb index 56d33587..fd30b8b5 100644 --- a/lib/jekyll/drops/rdf_resource_class.rb +++ b/lib/jekyll/drops/rdf_resource_class.rb @@ -46,6 +46,9 @@ def initialize(term, base = false) @distance = 0 end + ## + # Returns all classes from which +term+ directly inherited + # def find_direct_superclasses return @superclasses unless @superclasses.nil? query = "SELECT ?s WHERE{ #{@term.to_ntriples} ?s }" @@ -55,6 +58,10 @@ def find_direct_superclasses return selection end + ## + # Propagate the current template to the parent of the breadth-first search + # in RdfClassExtraction.request_class_template. + # def propagate_template(distance) return if @path.nil? @distance = distance @@ -63,14 +70,22 @@ def propagate_template(distance) @path.propagate_template(distance +1) end + ## + # Returns the beginning of the path leading to the found template + # def get_path_root return self if @path.nil? @path.get_path_root end + ## + # Checks if this instance was already added to the breadth-first search + # in RdfClassExtraction.request_class_template. + # def add? lock_number if @lock_number != lock_number - @lock_number = lock_number # used to recognize different searchpasses of request_class_template + # used to recognize different searchpasses of request_class_template + @lock_number = lock_number @lock = -1 true else diff --git a/lib/jekyll/helper/rdf_class_extraction.rb b/lib/jekyll/helper/rdf_class_extraction.rb index 0a9143ba..39149cae 100644 --- a/lib/jekyll/helper/rdf_class_extraction.rb +++ b/lib/jekyll/helper/rdf_class_extraction.rb @@ -4,6 +4,12 @@ module Helper module RdfClassExtraction private + + ## + # Instantiate all rdf:class'es with an template mapped in +classes_to_templates+. + # +classes_to_templates+ A hash that contains string representations of class resources + # as keys and maps these to a template. + # def create_resource_class(classes_to_templates) if(classes_to_templates.is_a?(Hash)) classes_to_templates.each{|uri, template| @@ -15,7 +21,9 @@ def create_resource_class(classes_to_templates) end ## - # returns to a RdfResource a template through its rdf:type + # Returns to a RdfResource a template through its rdf:type + # +resource+ the resource a template is searched for. + # def request_class_template resource return nil if resource.direct_classes.empty? direct_classes = resource.direct_classes @@ -85,11 +93,20 @@ def request_class_template resource return nil end + ## + # Returns the template stored in the input resource +class_resource+ + # and caches it with +hash_str+ as key. + # def extract_template class_resource, hash_str class_resource.propagate_template(class_resource.distance) return (@template_cache[hash_str] = class_resource.get_path_root.template) end + ## + # Returns the most specific class resource from +class_list+ based on + # +current_best+. + # +resource+ is the original input of request_class_template. + # def find_highlevel_inheritance current_best, class_list, resource #check at the end of the search for direct inheritance on highest level class_list.each{|resource| resource.find_direct_superclasses.each{|uri| @@ -97,9 +114,11 @@ def find_highlevel_inheritance current_best, class_list, resource #check at th @classResources[uri].path = resource } if resource.base } - while(class_list.include?(current_best.path)) # this is valnuable to cyclic inheritance + # this is valnuable to cyclic inheritance + while(class_list.include?(current_best.path)) slice = class_list.index(current_best) - class_list.slice!(slice) unless slice.nil? # parent alternatives are no real alternatives + # parent alternatives are no real alternatives + class_list.slice!(slice) unless slice.nil? current_best = current_best.path end return consistence_templates(current_best, class_list, resource) unless class_list.empty? @@ -109,6 +128,9 @@ def find_highlevel_inheritance current_best, class_list, resource #check at th ## # Add a warning for a class having multiple possible templates # The warnings are then later displayed with print_warnings + # +classRes+ and +alternatives+ make up a list of class resources which + # are all equally valid choices for request_class_template + # +resource+ is the original input of request_class_template. # def consistence_templates(classRes, alternatives, resource) hash_str = alternatives.push(classRes). @@ -126,7 +148,10 @@ def consistence_templates(classRes, alternatives, resource) @consistence[hash_str][0] end - class StopObject #unfortunately next does not work in this setup, it avoids to have "if" in every iteration + ## + # used to escape loops without an if-statement + # + class StopObject def > object true end diff --git a/lib/jekyll/rdf_template_mapper.rb b/lib/jekyll/rdf_template_mapper.rb index 4e0e346b..b5951f3f 100644 --- a/lib/jekyll/rdf_template_mapper.rb +++ b/lib/jekyll/rdf_template_mapper.rb @@ -59,6 +59,9 @@ def map(resource) return @default_template end + ## + # outputs all warnings prepared by RdfClassExtraction.consistence_templates + # def print_warnings @consistence.each{ |key, template_class_store| Jekyll.logger.warn("Warning: multiple possible templates for resources #{template_class_store[1].join(", ")}\nPossible Templates: #{key}") From fa30e5ee2a513a763e3aa71defc333d1dc51fe8c Mon Sep 17 00:00:00 2001 From: Nime Date: Sun, 3 Feb 2019 23:46:44 +0100 Subject: [PATCH 26/85] resources get rendered attribute --- lib/jekyll/drops/rdf_resource.rb | 11 +++ test/cases/renderedAttribute/Gemfile | 4 ++ test/cases/renderedAttribute/_config.yml | 11 +++ .../renderedAttribute/_data/Prefixes.pref | 2 + .../_data/knowledge-base.ttl | 13 ++++ .../renderedAttribute/_layouts/default.html | 12 ++++ test/cases/renderedAttribute/rendered.html | 69 +++++++++++++++++++ .../test_rendered_attribute.rb | 26 +++++++ 8 files changed, 148 insertions(+) create mode 100644 test/cases/renderedAttribute/Gemfile create mode 100644 test/cases/renderedAttribute/_config.yml create mode 100644 test/cases/renderedAttribute/_data/Prefixes.pref create mode 100644 test/cases/renderedAttribute/_data/knowledge-base.ttl create mode 100644 test/cases/renderedAttribute/_layouts/default.html create mode 100644 test/cases/renderedAttribute/rendered.html create mode 100644 test/cases/renderedAttribute/test_rendered_attribute.rb diff --git a/lib/jekyll/drops/rdf_resource.rb b/lib/jekyll/drops/rdf_resource.rb index 7fdce008..3013a974 100644 --- a/lib/jekyll/drops/rdf_resource.rb +++ b/lib/jekyll/drops/rdf_resource.rb @@ -216,6 +216,17 @@ def inspect return "#" end + ## + # Returns a true if this resource has a Jekyll::Page representation. + # + def rendered? + return @rendered unless @rendered.nil? + @rendered = Jekyll::JekyllRdf::Helper::RdfHelper.site.pages.any?{|page| + (filedir.eql? page.dir) && (filename.eql? page.name) + } + return @rendered + end + #checks if a query solution contains a language or type tag and returns those in a hash private def check_solution(solution) diff --git a/test/cases/renderedAttribute/Gemfile b/test/cases/renderedAttribute/Gemfile new file mode 100644 index 00000000..4d519ca0 --- /dev/null +++ b/test/cases/renderedAttribute/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +group :jekyll_plugins do + gem 'jekyll-rdf', :path => '../../../' +end diff --git a/test/cases/renderedAttribute/_config.yml b/test/cases/renderedAttribute/_config.yml new file mode 100644 index 00000000..3f084ddc --- /dev/null +++ b/test/cases/renderedAttribute/_config.yml @@ -0,0 +1,11 @@ +baseurl: "/instance" # the subpath of your site, e.g. /blog +url: "http://example.org/" # the base hostname & protocol for your site +# Build settings +markdown: kramdown +plugins: +- jekyll-rdf +jekyll_rdf: + path: "_data/knowledge-base.ttl" + restriction: "SELECT ?resourceUri WHERE {?resourceUri ?p }" + default_template: "default" + diff --git a/test/cases/renderedAttribute/_data/Prefixes.pref b/test/cases/renderedAttribute/_data/Prefixes.pref new file mode 100644 index 00000000..d13eaa49 --- /dev/null +++ b/test/cases/renderedAttribute/_data/Prefixes.pref @@ -0,0 +1,2 @@ +PREFIX eg: +PREFIX egs: diff --git a/test/cases/renderedAttribute/_data/knowledge-base.ttl b/test/cases/renderedAttribute/_data/knowledge-base.ttl new file mode 100644 index 00000000..349949fc --- /dev/null +++ b/test/cases/renderedAttribute/_data/knowledge-base.ttl @@ -0,0 +1,13 @@ +@prefix eg: . +@prefix egs: . + +eg:resource1 eg:predicate eg:rendered . +eg:resource2 eg:predicate eg:rendered . +eg:resource3 eg:predicate eg:rendered . + +eg:resource4 eg:predicate eg:notRendered . +eg:resource5 eg:predicate eg:notRendered . +eg:resource6 eg:predicate eg:notRendered . + +egs:resource7 eg:predicate eg:rendered . +egs:resource8 eg:predicate eg:notRendered . diff --git a/test/cases/renderedAttribute/_layouts/default.html b/test/cases/renderedAttribute/_layouts/default.html new file mode 100644 index 00000000..d83fc027 --- /dev/null +++ b/test/cases/renderedAttribute/_layouts/default.html @@ -0,0 +1,12 @@ +--- +--- + + + + +
+

This is made with jekyll-rdf

+ {{page.rdf}} +
+ + diff --git a/test/cases/renderedAttribute/rendered.html b/test/cases/renderedAttribute/rendered.html new file mode 100644 index 00000000..0e5562f4 --- /dev/null +++ b/test/cases/renderedAttribute/rendered.html @@ -0,0 +1,69 @@ +--- +--- + + + + TODO supply a title + + + + +
+ {%- assign resource1 = "" | rdf_get -%} + {%- assign resource2 = "" | rdf_get -%} + {%- assign resource3 = "" | rdf_get -%} + {%- assign resource4 = "" | rdf_get -%} + {%- assign resource5 = "" | rdf_get -%} + {%- assign resource6 = "" | rdf_get -%} + {%- assign resource7 = "" | rdf_get -%} + {%- assign resource8 = "" | rdf_get -%} + {%- if resource1.rendered? -%} + true + {%- else -%} + false + {%- endif -%} +
+ {%- if resource2.rendered? -%} + true + {%- else -%} + false + {%- endif -%} +
+ {%- if resource3.rendered? -%} + true + {%- else -%} + false + {%- endif -%} +
+ {%- if resource4.rendered? -%} + true + {%- else -%} + false + {%- endif -%} +
+ {%- if resource5.rendered? -%} + true + {%- else -%} + false + {%- endif -%} +
+ {%- if resource6.rendered? -%} + true + {%- else -%} + false + {%- endif -%} +
+ {%- if resource7.rendered? -%} + true + {%- else -%} + false + {%- endif -%} +
+ {%- if resource8.rendered? -%} + true + {%- else -%} + false + {%- endif -%} +
+ + diff --git a/test/cases/renderedAttribute/test_rendered_attribute.rb b/test/cases/renderedAttribute/test_rendered_attribute.rb new file mode 100644 index 00000000..216fa978 --- /dev/null +++ b/test/cases/renderedAttribute/test_rendered_attribute.rb @@ -0,0 +1,26 @@ +require 'test_helper' + +class TestRenderedAttribute < Test::Unit::TestCase + include RdfTestUtility + context "cases/renderedAttribute" do + setup do + setup_jekyll File.dirname(__FILE__) + end + + should "" do + content = [] + file = File.read(File.join(@source, "_site/rendered.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + assert "true".eql?(content[0]), "Resource 1 should be true, but it is #{content[0]}" + assert "true".eql?(content[1]), "Resource 2 should be true, but it is #{content[1]}" + assert "true".eql?(content[2]), "Resource 3 should be true, but it is #{content[2]}" + assert "false".eql?(content[3]), "Resource 4 should be false, but it is #{content[3]}" + assert "false".eql?(content[4]), "Resource 5 should be false, but it is #{content[4]}" + assert "false".eql?(content[5]), "Resource 6 should be false, but it is #{content[5]}" + assert "true".eql?(content[6]), "Resource 7 should be false, but it is #{content[6]}" + assert "false".eql?(content[7]), "Resource 8 should be false, but it is #{content[7]}" + end + end +end From 7a5a52c990ec9c9a04ad72e95ba50b304ab48988 Mon Sep 17 00:00:00 2001 From: Nime Date: Sun, 10 Feb 2019 16:22:44 +0100 Subject: [PATCH 27/85] rudimentary support for construction query --- lib/jekyll-rdf.rb | 1 + lib/jekyll/filters/rdf_construct_query.rb | 63 +++++++++++++++++++ test/cases/constructQueries/Gemfile | 4 ++ test/cases/constructQueries/_config.yml | 11 ++++ .../constructQueries/_data/Prefixes.pref | 5 ++ .../constructQueries/_data/knowledge-base.ttl | 9 +++ .../constructQueries/_layouts/default.html | 12 ++++ .../_layouts/exampleInstance.html | 8 +++ .../constructQueries/_layouts/person.html | 15 +++++ test/cases/constructQueries/constructs.html | 23 +++++++ .../test_construct_queries.rb | 29 +++++++++ 11 files changed, 180 insertions(+) create mode 100644 lib/jekyll/filters/rdf_construct_query.rb create mode 100644 test/cases/constructQueries/Gemfile create mode 100644 test/cases/constructQueries/_config.yml create mode 100644 test/cases/constructQueries/_data/Prefixes.pref create mode 100644 test/cases/constructQueries/_data/knowledge-base.ttl create mode 100644 test/cases/constructQueries/_layouts/default.html create mode 100644 test/cases/constructQueries/_layouts/exampleInstance.html create mode 100644 test/cases/constructQueries/_layouts/person.html create mode 100644 test/cases/constructQueries/constructs.html create mode 100644 test/cases/constructQueries/test_construct_queries.rb diff --git a/lib/jekyll-rdf.rb b/lib/jekyll-rdf.rb index e26c7dc1..87562bbf 100644 --- a/lib/jekyll-rdf.rb +++ b/lib/jekyll-rdf.rb @@ -58,6 +58,7 @@ require 'jekyll/filters/rdf_collection' require 'jekyll/filters/rdf_container' require 'jekyll/filters/rdf_get' +require 'jekyll/filters/rdf_construct_query' require 'jekyll/filters/rdf_debug_message' diff --git a/lib/jekyll/filters/rdf_construct_query.rb b/lib/jekyll/filters/rdf_construct_query.rb new file mode 100644 index 00000000..039f6bf2 --- /dev/null +++ b/lib/jekyll/filters/rdf_construct_query.rb @@ -0,0 +1,63 @@ +## +# MIT License +# +# Copyright (c) 2016 Elias Saalmann, Christian Frommert, Simon Jakobi, +# Arne Jonas Präger, Maxi Bornmann, Georg Hackel, Eric Füg +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +module Jekyll + module JekyllRdf + ## + # Internal module to hold the medthod #sparql_query + # + module Filter + + ## + # Executes a CONSTRUCT query. The supplied query is augmented by replacing each occurence of '?resourceUri' by the URI of the context RDF resource. + # Returns an Array of bindings. Each binding is a Hash mapping variables to their values. + # + # * +input+ - the context RDF resource + # * +query+ - the SPARQL query + # + def construct_query(resource = nil, query) + query = query.clone #sometimes liquid wont reinit static strings in for loops + if(rdf_substitude_nil?(resource)) + query.gsub!('?resourceUri', "<#{Jekyll::JekyllRdf::Helper::RdfHelper::page.data['rdf'].term}>") + elsif(resource.class <= Array) + resource.each_with_index do |uri, index| + return unless valid_resource?(uri) + if(uri.class <= Jekyll::JekyllRdf::Drops::RdfResource) + query.gsub!("?resourceUri_#{index}", uri.term.to_ntriples) + else + query.gsub!("?resourceUri_#{index}", "#{rdf_resolve_prefix(uri.to_s)}") + end + end + else + return unless valid_resource?(resource) + query.gsub!('?resourceUri', to_string_wrap(resource)) + end if query.include? '?resourceUri' #the only purpose of the if statement is to substitute ?resourceUri + new_graph = Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(query) + Jekyll::JekyllRdf::Helper::RdfHelper::sparql.insert_data(new_graph) + return nil + end + end + end +end diff --git a/test/cases/constructQueries/Gemfile b/test/cases/constructQueries/Gemfile new file mode 100644 index 00000000..4d519ca0 --- /dev/null +++ b/test/cases/constructQueries/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +group :jekyll_plugins do + gem 'jekyll-rdf', :path => '../../../' +end diff --git a/test/cases/constructQueries/_config.yml b/test/cases/constructQueries/_config.yml new file mode 100644 index 00000000..6b9d1b9a --- /dev/null +++ b/test/cases/constructQueries/_config.yml @@ -0,0 +1,11 @@ +baseurl: "/instance" # the subpath of your site, e.g. /blog +url: "http://example.org/" # the base hostname & protocol for your site +# Build settings +markdown: kramdown +plugins: +- jekyll-rdf +jekyll_rdf: + path: "_data/knowledge-base.ttl" + restriction: "SELECT ?resourceUri WHERE {?resourceUri ?p }" + default_template: "default" + diff --git a/test/cases/constructQueries/_data/Prefixes.pref b/test/cases/constructQueries/_data/Prefixes.pref new file mode 100644 index 00000000..f59c9317 --- /dev/null +++ b/test/cases/constructQueries/_data/Prefixes.pref @@ -0,0 +1,5 @@ +PREFIX rdf: +PREFIX rdfs: +PREFIX xsd: +PREFIX foaf: +PREFIX eg: diff --git a/test/cases/constructQueries/_data/knowledge-base.ttl b/test/cases/constructQueries/_data/knowledge-base.ttl new file mode 100644 index 00000000..966d1c34 --- /dev/null +++ b/test/cases/constructQueries/_data/knowledge-base.ttl @@ -0,0 +1,9 @@ +@prefix eg: . + +eg:resource1 eg:construct eg:goConstruct . +eg:resource2 eg:construct eg:goConstruct . +eg:resource3 eg:construct eg:goConstruct . + +eg:resource4 eg:construct eg:noConstruct . +eg:resource5 eg:construct eg:noConstruct . +eg:resource6 eg:construct eg:noConstruct . diff --git a/test/cases/constructQueries/_layouts/default.html b/test/cases/constructQueries/_layouts/default.html new file mode 100644 index 00000000..96137a3e --- /dev/null +++ b/test/cases/constructQueries/_layouts/default.html @@ -0,0 +1,12 @@ +--- +--- + + + + +
+

This is made with jekyll-rdf

+ {{content}} +
+ + diff --git a/test/cases/constructQueries/_layouts/exampleInstance.html b/test/cases/constructQueries/_layouts/exampleInstance.html new file mode 100644 index 00000000..655a2ea8 --- /dev/null +++ b/test/cases/constructQueries/_layouts/exampleInstance.html @@ -0,0 +1,8 @@ +--- +layout: default +rdf_prefix_path: _data/Prefixes.pref +--- +
+
This page is mapped to:
+ {{page.rdf}} +
diff --git a/test/cases/constructQueries/_layouts/person.html b/test/cases/constructQueries/_layouts/person.html new file mode 100644 index 00000000..30e3bf3b --- /dev/null +++ b/test/cases/constructQueries/_layouts/person.html @@ -0,0 +1,15 @@ +--- +layout: default +rdf_prefix_path: _data/Prefixes.pref +--- +
+
+ name: +
+ {{page.rdf | rdf_property: "foaf:name"}} +
+
+ age: +
+ {{page.rdf | rdf_property: "foaf:age"}} +
diff --git a/test/cases/constructQueries/constructs.html b/test/cases/constructQueries/constructs.html new file mode 100644 index 00000000..eee67efe --- /dev/null +++ b/test/cases/constructQueries/constructs.html @@ -0,0 +1,23 @@ +--- +--- + + + + A demonstration of Construct queries + + + + + {%- assign cquery = "CONSTRUCT {?x } where {?x }" -%} + {%- assign test = cquery | construct_query -%} + {%- assign query = "SELECT ?res {?res }" -%} + {%- assign results = query | sparql_query -%} + +
+ {%- for result in results -%} + {{result.res}} +
+ {%- endfor -%} +
+ + diff --git a/test/cases/constructQueries/test_construct_queries.rb b/test/cases/constructQueries/test_construct_queries.rb new file mode 100644 index 00000000..11f10524 --- /dev/null +++ b/test/cases/constructQueries/test_construct_queries.rb @@ -0,0 +1,29 @@ +require 'test_helper' + +class TestSciMath < Test::Unit::TestCase + include RdfTestUtility + context "cases/constructQueries" do + setup do + setup_jekyll File.dirname(__FILE__) + end + + should "work with construction queries" do + content = [] + file = File.read(File.join(@source, "_site/constructs.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + assert_equal 3, content.length + assert (content[0].eql?("http://example.org/instance/resource1") || content[0].eql?("http://example.org/instance/resource2") || content[0].eql?("http://example.org/instance/resource3")), "The
should contain http://example.org/instance/resource1, http://example.org/instance/resource2 and http://example.org/instance/resource3 at first position.\n It was: >#{content[0]}<." + assert (content[1].eql?("http://example.org/instance/resource1") || content[1].eql?("http://example.org/instance/resource2") || content[1].eql?("http://example.org/instance/resource3")), "The
should contain http://example.org/instance/resource1, http://example.org/instance/resource2 and http://example.org/instance/resource3 at second position.\n It was: >#{content[1]}<." + assert (content[2].eql?("http://example.org/instance/resource1") || content[2].eql?("http://example.org/instance/resource2") || content[2].eql?("http://example.org/instance/resource3")), "The
should contain http://example.org/instance/resource1, http://example.org/instance/resource2 and http://example.org/instance/resource3 at third position.\n It was: >#{content[2]}<." + assert content.include?("http://example.org/instance/resource1"), "The
should include http://example.org/instance/resource1." + assert content.include?("http://example.org/instance/resource2"), "The
should include http://example.org/instance/resource2." + assert content.include?("http://example.org/instance/resource3"), "The
should include http://example.org/instance/resource3." + #assert_equal "", content[3] + assert !content.include?("http://example.org/instance/resource4"), "The
should not include http://example.org/instance/resource4." + assert !content.include?("http://example.org/instance/resource5"), "The
should not include http://example.org/instance/resource5." + assert !content.include?("http://example.org/instance/resource6"), "The
should not include http://example.org/instance/resource6." + end + end +end From 0a089d39464a8c35e836d43310cce0566dd2f4fa Mon Sep 17 00:00:00 2001 From: Nime Date: Sun, 10 Feb 2019 16:37:55 +0100 Subject: [PATCH 28/85] created general query preparation --- lib/jekyll/filters/rdf_construct_query.rb | 18 ++---------------- lib/jekyll/filters/rdf_sparql_query.rb | 21 ++------------------- lib/jekyll/helper/rdf_filter_helper.rb | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/lib/jekyll/filters/rdf_construct_query.rb b/lib/jekyll/filters/rdf_construct_query.rb index 039f6bf2..3402ea71 100644 --- a/lib/jekyll/filters/rdf_construct_query.rb +++ b/lib/jekyll/filters/rdf_construct_query.rb @@ -38,22 +38,8 @@ module Filter # * +query+ - the SPARQL query # def construct_query(resource = nil, query) - query = query.clone #sometimes liquid wont reinit static strings in for loops - if(rdf_substitude_nil?(resource)) - query.gsub!('?resourceUri', "<#{Jekyll::JekyllRdf::Helper::RdfHelper::page.data['rdf'].term}>") - elsif(resource.class <= Array) - resource.each_with_index do |uri, index| - return unless valid_resource?(uri) - if(uri.class <= Jekyll::JekyllRdf::Drops::RdfResource) - query.gsub!("?resourceUri_#{index}", uri.term.to_ntriples) - else - query.gsub!("?resourceUri_#{index}", "#{rdf_resolve_prefix(uri.to_s)}") - end - end - else - return unless valid_resource?(resource) - query.gsub!('?resourceUri', to_string_wrap(resource)) - end if query.include? '?resourceUri' #the only purpose of the if statement is to substitute ?resourceUri + query = prepare_query(resource, query) + return if query.nil? new_graph = Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(query) Jekyll::JekyllRdf::Helper::RdfHelper::sparql.insert_data(new_graph) return nil diff --git a/lib/jekyll/filters/rdf_sparql_query.rb b/lib/jekyll/filters/rdf_sparql_query.rb index f7d105a7..8cc96f98 100644 --- a/lib/jekyll/filters/rdf_sparql_query.rb +++ b/lib/jekyll/filters/rdf_sparql_query.rb @@ -38,25 +38,8 @@ module Filter # * +query+ - the SPARQL query # def sparql_query(resource = nil, query) - query = query.clone #sometimes liquid wont reinit static strings in for loops - if(rdf_substitude_nil?(resource)) - query.gsub!('?resourceUri', "<#{Jekyll::JekyllRdf::Helper::RdfHelper::page.data['rdf'].term}>") - elsif(resource.class <= Array) - resource.each_with_index do |uri, index| - return unless valid_resource?(uri) - if(uri.class <= Jekyll::JekyllRdf::Drops::RdfResource) - query.gsub!("?resourceUri_#{index}", uri.term.to_ntriples) - else - query.gsub!("?resourceUri_#{index}", "#{rdf_resolve_prefix(uri.to_s)}") - end - end - else - return unless valid_resource?(resource) - query.gsub!('?resourceUri', to_string_wrap(resource)) - end if query.include? '?resourceUri' #the only purpose of the if statement is to substitute ?resourceUri - unless Jekyll::JekyllRdf::Helper::RdfHelper::prefixes["rdf_prefixes"].nil? - query = query.prepend(" ").prepend(Jekyll::JekyllRdf::Helper::RdfHelper::prefixes["rdf_prefixes"]) - end + query = prepare_query(resource, query) + return if query.nil? begin result = Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(query).map do |solution| hsh = solution.to_h diff --git a/lib/jekyll/helper/rdf_filter_helper.rb b/lib/jekyll/helper/rdf_filter_helper.rb index 715c7186..abcb31f8 100644 --- a/lib/jekyll/helper/rdf_filter_helper.rb +++ b/lib/jekyll/helper/rdf_filter_helper.rb @@ -55,6 +55,29 @@ def to_string_wrap(input) return false end end + + def prepare_query(resource = nil, query) + query = query.clone #sometimes liquid wont reinit static strings in for loops + if(rdf_substitude_nil?(resource)) + query.gsub!('?resourceUri', "<#{Jekyll::JekyllRdf::Helper::RdfHelper::page.data['rdf'].term}>") + elsif(resource.class <= Array) + resource.each_with_index do |uri, index| + return nil unless valid_resource?(uri) + if(uri.class <= Jekyll::JekyllRdf::Drops::RdfResource) + query.gsub!("?resourceUri_#{index}", uri.term.to_ntriples) + else + query.gsub!("?resourceUri_#{index}", "#{rdf_resolve_prefix(uri.to_s)}") + end + end + else + return nil unless valid_resource?(resource) + query.gsub!('?resourceUri', to_string_wrap(resource)) + end if query.include? '?resourceUri' #the only purpose of the if statement is to substitute ?resourceUri + unless Jekyll::JekyllRdf::Helper::RdfHelper::prefixes["rdf_prefixes"].nil? + query = query.prepend(" ").prepend(Jekyll::JekyllRdf::Helper::RdfHelper::prefixes["rdf_prefixes"]) + end + return query + end end module PrefixSolver From e7cfa4091f94ef8e6fbd39ab76c6ca7005d02a84 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Tue, 12 Feb 2019 17:19:11 +0100 Subject: [PATCH 29/85] Add failing test MWE for prefixes not available for posts --- test/cases/prefixesInPosts/Gemfile | 4 ++++ test/cases/prefixesInPosts/_config.yml | 9 +++++++++ .../cases/prefixesInPosts/_data/Prefixes.pref | 6 ++++++ .../prefixesInPosts/_data/knowledge-base.ttl | 5 +++++ test/cases/prefixesInPosts/_layouts/post.html | 9 +++++++++ .../_posts/2019-02-12-Blogpost.md | 5 +++++ test/cases/prefixesInPosts/test_prefixes.rb | 19 +++++++++++++++++++ 7 files changed, 57 insertions(+) create mode 100644 test/cases/prefixesInPosts/Gemfile create mode 100644 test/cases/prefixesInPosts/_config.yml create mode 100644 test/cases/prefixesInPosts/_data/Prefixes.pref create mode 100644 test/cases/prefixesInPosts/_data/knowledge-base.ttl create mode 100644 test/cases/prefixesInPosts/_layouts/post.html create mode 100644 test/cases/prefixesInPosts/_posts/2019-02-12-Blogpost.md create mode 100644 test/cases/prefixesInPosts/test_prefixes.rb diff --git a/test/cases/prefixesInPosts/Gemfile b/test/cases/prefixesInPosts/Gemfile new file mode 100644 index 00000000..4d519ca0 --- /dev/null +++ b/test/cases/prefixesInPosts/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +group :jekyll_plugins do + gem 'jekyll-rdf', :path => '../../../' +end diff --git a/test/cases/prefixesInPosts/_config.yml b/test/cases/prefixesInPosts/_config.yml new file mode 100644 index 00000000..9b0d44e6 --- /dev/null +++ b/test/cases/prefixesInPosts/_config.yml @@ -0,0 +1,9 @@ +baseurl: "/instance" +url: "http://example.org/" + +plugins: +- jekyll-rdf +jekyll_rdf: + path: "_data/knowledge-base.ttl" + restriction: "SELECT ?resourceUri WHERE {?resourceUri ?p ?o}" + diff --git a/test/cases/prefixesInPosts/_data/Prefixes.pref b/test/cases/prefixesInPosts/_data/Prefixes.pref new file mode 100644 index 00000000..cc553e69 --- /dev/null +++ b/test/cases/prefixesInPosts/_data/Prefixes.pref @@ -0,0 +1,6 @@ +PREFIX rdf: +PREFIX rdfs: +PREFIX xsd: +PREFIX foaf: +PREFIX eg: +PREFIX dc: diff --git a/test/cases/prefixesInPosts/_data/knowledge-base.ttl b/test/cases/prefixesInPosts/_data/knowledge-base.ttl new file mode 100644 index 00000000..858c180d --- /dev/null +++ b/test/cases/prefixesInPosts/_data/knowledge-base.ttl @@ -0,0 +1,5 @@ +@prefix rdf: . +@prefix rdfs: . +@prefix dc: . + + dc:title "My Jekyll RDF Blog" . diff --git a/test/cases/prefixesInPosts/_layouts/post.html b/test/cases/prefixesInPosts/_layouts/post.html new file mode 100644 index 00000000..76ecd041 --- /dev/null +++ b/test/cases/prefixesInPosts/_layouts/post.html @@ -0,0 +1,9 @@ + + + {% assign root = "" | rdf_get %} +

{{ root | rdf_property: "dc:title" }}

+
+ {{ content }} +
+ + diff --git a/test/cases/prefixesInPosts/_posts/2019-02-12-Blogpost.md b/test/cases/prefixesInPosts/_posts/2019-02-12-Blogpost.md new file mode 100644 index 00000000..3552de9e --- /dev/null +++ b/test/cases/prefixesInPosts/_posts/2019-02-12-Blogpost.md @@ -0,0 +1,5 @@ +--- +layout: post +--- + +This is a Blogpost diff --git a/test/cases/prefixesInPosts/test_prefixes.rb b/test/cases/prefixesInPosts/test_prefixes.rb new file mode 100644 index 00000000..930af04d --- /dev/null +++ b/test/cases/prefixesInPosts/test_prefixes.rb @@ -0,0 +1,19 @@ +require 'test_helper' + +class TestPrefixes < Test::Unit::TestCase + context "load_prefixes form RdfPageHelper" do + include RdfTestUtility + should "map prefixes from the file given through rdf_prefix_path in template frontmatter also for posts" do + setup_jekyll File.dirname(__FILE__) + + content = [] + file = File.read(File.join(@source, "_site/2019/02/12/Blogpost.html")) + content = file[/\(.|\s)*\<\/body\>/][6..-6].strip.split("\n").map do |entry| + entry.strip + end + + assert_equal "

My Jekyll RDF Blog

", content[0] + assert_equal "

This is a Blogpost

", content[2] + end + end +end From 7f947301020ede5f9ffb6d67646e67284c90844b Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Tue, 12 Feb 2019 17:22:18 +0100 Subject: [PATCH 30/85] Add prefix declaration --- test/cases/prefixesInPosts/_layouts/post.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/cases/prefixesInPosts/_layouts/post.html b/test/cases/prefixesInPosts/_layouts/post.html index 76ecd041..405c543b 100644 --- a/test/cases/prefixesInPosts/_layouts/post.html +++ b/test/cases/prefixesInPosts/_layouts/post.html @@ -1,3 +1,6 @@ +--- +rdf_prefix_path: _data/Prefixes.pref +--- {% assign root = "" | rdf_get %} From eb38df8edf98dfa3a16537c0827406c00fb25627 Mon Sep 17 00:00:00 2001 From: Nime Date: Thu, 14 Feb 2019 17:33:50 +0100 Subject: [PATCH 31/85] bugfixes for templatemapping --- lib/jekyll/drops/rdf_resource_class.rb | 2 +- lib/jekyll/helper/rdf_class_extraction.rb | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/jekyll/drops/rdf_resource_class.rb b/lib/jekyll/drops/rdf_resource_class.rb index fd30b8b5..2b85c0e2 100644 --- a/lib/jekyll/drops/rdf_resource_class.rb +++ b/lib/jekyll/drops/rdf_resource_class.rb @@ -63,8 +63,8 @@ def find_direct_superclasses # in RdfClassExtraction.request_class_template. # def propagate_template(distance) - return if @path.nil? @distance = distance + return if @path.nil? return unless @path.template.nil? @path.template = @template @path.propagate_template(distance +1) diff --git a/lib/jekyll/helper/rdf_class_extraction.rb b/lib/jekyll/helper/rdf_class_extraction.rb index 39149cae..32670f29 100644 --- a/lib/jekyll/helper/rdf_class_extraction.rb +++ b/lib/jekyll/helper/rdf_class_extraction.rb @@ -43,10 +43,9 @@ def request_class_template resource @classResources[uri] } alternatives = [] - class_list.each{|class_resource| if(next_increase <= count) # the next level of the breadth-first search - if ((min_template_lock <= lock) && (lock >= 1)) # if (distance to next template is smaller than current search radius) && (we checked all immediate classes) + if ((min_template_lock <= lock) && (lock >= 0)) # if (distance to next template is smaller than current search radius) && (we checked all immediate classes) return extract_template(find_highlevel_inheritance(min_class, alternatives, resource), hash_str) end alternatives.clear() @@ -78,7 +77,7 @@ def request_class_template resource elsif min_template_lock == (lock + @classResources[uri].distance) alternatives.push @classResources[uri] end - elsif(@classResources[uri].add?(lock_number) && @classResources[uri].lock > class_resource.lock) # not a previously searched resource without a template + elsif(@classResources[uri].add?(lock_number)) # not a previously searched resource without a template @classResources[uri].path = class_resource # <- this might be valnuable to cyclic inheritance in the graph class_list.push(@classResources[uri]) @classResources[uri].lock = lock From 4d2f2efff42e08bce6764647890521f478635c52 Mon Sep 17 00:00:00 2001 From: Nime Date: Thu, 14 Feb 2019 17:37:13 +0100 Subject: [PATCH 32/85] edit template mapping tests --- test/cases/classHierarchy/_config.yml | 12 +++--- .../classHierarchy/_data/knowledge-base.ttl | 39 +++++++++++++------ .../{LowerMaster.html => breathingAir.html} | 2 +- .../{Supreme.html => foodFromWater.html} | 2 +- .../_layouts/{Advanced.html => landBorn.html} | 2 +- .../_layouts/{Master.html => layingEggs.html} | 2 +- .../classHierarchy/test_class_hierarchy.rb | 33 +++++++++------- 7 files changed, 58 insertions(+), 34 deletions(-) rename test/cases/classHierarchy/_layouts/{LowerMaster.html => breathingAir.html} (92%) rename test/cases/classHierarchy/_layouts/{Supreme.html => foodFromWater.html} (92%) rename test/cases/classHierarchy/_layouts/{Advanced.html => landBorn.html} (93%) rename test/cases/classHierarchy/_layouts/{Master.html => layingEggs.html} (93%) diff --git a/test/cases/classHierarchy/_config.yml b/test/cases/classHierarchy/_config.yml index 9642e2a3..bfdf280d 100644 --- a/test/cases/classHierarchy/_config.yml +++ b/test/cases/classHierarchy/_config.yml @@ -1,12 +1,12 @@ -baseurl: "/instance" # the subpath of your site, e.g. /blog -url: "http://example.org/" # the base hostname & protocol for your site +baseurl: "/instance/" # the subpath of your site, e.g. /blog +url: "http://animals.org" # the base hostname & protocol for your site plugins: - jekyll-rdf jekyll_rdf: path: "_data/knowledge-base.ttl" restriction: "SELECT ?resourceUri WHERE {?resourceUri ?o}" class_template_mappings: - "http://example.org/instance/Supreme": "Supreme" - "http://example.org/instance/Master": "Master" - "http://example.org/instance/lowerMaster": "LowerMaster" - "http://example.org/instance/advanced": "Advanced" + "http://animals.org/classification/landBorn": "landBorn" + "http://animals.org/classification/layingEggs": "layingEggs" + "http://animals.org/classification/foodFromWater": "foodFromWater" + "http://animals.org/classification/breathingAir": "breathingAir" diff --git a/test/cases/classHierarchy/_data/knowledge-base.ttl b/test/cases/classHierarchy/_data/knowledge-base.ttl index 1af2045a..38f07b7e 100644 --- a/test/cases/classHierarchy/_data/knowledge-base.ttl +++ b/test/cases/classHierarchy/_data/knowledge-base.ttl @@ -1,15 +1,32 @@ @prefix rdfs: . -@prefix eg: . +@prefix an: . +@prefix ani: . -eg:baseClass rdfs:subClassOf eg:Master . -eg:advanced rdfs:subClassOf eg:baseClass . -eg:baseClass rdfs:subClassOf eg:lowerMaster . -eg:lowerMaster rdfs:subClassOf eg:Master . -eg:lowerMaster rdfs:subClassOf eg:Supreme . -eg:Master rdfs:subClassOf eg:Supreme . +an:landBorn rdfs:subClassOf an:animal . +an:birds rdfs:subClassOf an:animal . +an:swimming rdfs:subClassOf an:animal . -eg:baseRes a eg:baseClass . -eg:advaRes a eg:advanced . -eg:suprRes a eg:Supreme . -eg:mastRes a eg:Master . +an:4orMoreLimbs rdfs:subClassOf an:landBorn . +an:walkingUpright rdfs:subClassOf an:4orMoreLimbs . +an:layingEggs rdfs:subClassOf an:birds . +an:scalyFeets rdfs:subClassOf an:layingEggs . +an:keratinousScalyFeets rdfs:subClassOf an:scalyFeets . + +an:foodFromWater rdfs:subClassOf an:swimming . +an:waterFiltering rdfs:subClassOf an:foodFromWater . +an:waterHunting rdfs:subClassOf an:foodFromWater . +an:landWaterLiving rdfs:subClassOf an:waterHunting . + +an:breathingAir rdfs:subClassOf an:foodFromWater . + +ani:ape a an:walkingUpright . +ani:Lizard a an:4orMoreLimbs . +ani:Lizard a an:keratinousScalyFeets . +ani:Lizard a an:landWaterLiving . +ani:Penguins a an:keratinousScalyFeets . +ani:Penguins a an:landWaterLiving . +ani:Fish a an:waterHunting . +ani:Fish a an:foodFromWater . +ani:Whale a an:breathingAir . +ani:Whale a an:foodFromWater . diff --git a/test/cases/classHierarchy/_layouts/LowerMaster.html b/test/cases/classHierarchy/_layouts/breathingAir.html similarity index 92% rename from test/cases/classHierarchy/_layouts/LowerMaster.html rename to test/cases/classHierarchy/_layouts/breathingAir.html index 8ed9d087..50303895 100644 --- a/test/cases/classHierarchy/_layouts/LowerMaster.html +++ b/test/cases/classHierarchy/_layouts/breathingAir.html @@ -8,7 +8,7 @@
{{page.rdf}}
- LowerMaster + breathingAir
diff --git a/test/cases/classHierarchy/_layouts/Supreme.html b/test/cases/classHierarchy/_layouts/foodFromWater.html similarity index 92% rename from test/cases/classHierarchy/_layouts/Supreme.html rename to test/cases/classHierarchy/_layouts/foodFromWater.html index ac7555bb..d8c6e9d1 100644 --- a/test/cases/classHierarchy/_layouts/Supreme.html +++ b/test/cases/classHierarchy/_layouts/foodFromWater.html @@ -8,7 +8,7 @@
{{page.rdf}}
- Supreme + foodFromWater
diff --git a/test/cases/classHierarchy/_layouts/Advanced.html b/test/cases/classHierarchy/_layouts/landBorn.html similarity index 93% rename from test/cases/classHierarchy/_layouts/Advanced.html rename to test/cases/classHierarchy/_layouts/landBorn.html index 05f4abff..d73db2ef 100644 --- a/test/cases/classHierarchy/_layouts/Advanced.html +++ b/test/cases/classHierarchy/_layouts/landBorn.html @@ -8,7 +8,7 @@
{{page.rdf}}
- Advanced + landBorn
diff --git a/test/cases/classHierarchy/_layouts/Master.html b/test/cases/classHierarchy/_layouts/layingEggs.html similarity index 93% rename from test/cases/classHierarchy/_layouts/Master.html rename to test/cases/classHierarchy/_layouts/layingEggs.html index 42d58ea8..4474bfd3 100644 --- a/test/cases/classHierarchy/_layouts/Master.html +++ b/test/cases/classHierarchy/_layouts/layingEggs.html @@ -8,7 +8,7 @@
{{page.rdf}}
- Master + layingEggs
diff --git a/test/cases/classHierarchy/test_class_hierarchy.rb b/test/cases/classHierarchy/test_class_hierarchy.rb index 52c312a8..a620518b 100644 --- a/test/cases/classHierarchy/test_class_hierarchy.rb +++ b/test/cases/classHierarchy/test_class_hierarchy.rb @@ -7,37 +7,44 @@ class TestClassHierarchy < Test::Unit::TestCase setup_jekyll File.dirname(__FILE__) content = [] - file = File.read(File.join(@source, "_site/baseRes.html")) + file = File.read(File.join(@source, "_site/Fish.html")) content = file[/\
(.|\s)*\<\/div>/][21..-7].strip.split("
").map do |entry| entry.strip end - assert_equal "http://example.org/instance/baseRes", content[0] - assert_equal "LowerMaster", content[1] + assert_equal "http://animals.org/instance/Fish", content[0] + assert_equal "foodFromWater", content[1] content = [] - file = File.read(File.join(@source, "_site/advaRes.html")) + file = File.read(File.join(@source, "_site/Lizard.html")) content = file[/\
(.|\s)*\<\/div>/][21..-7].strip.split("
").map do |entry| entry.strip end - assert_equal "http://example.org/instance/advaRes", content[0] - assert_equal "Advanced", content[1] + assert_equal "http://animals.org/instance/Lizard", content[0] + assert_equal "landBorn", content[1] content = [] - file = File.read(File.join(@source, "_site/mastRes.html")) + file = File.read(File.join(@source, "_site/Penguins.html")) content = file[/\
(.|\s)*\<\/div>/][21..-7].strip.split("
").map do |entry| entry.strip end - assert_equal "http://example.org/instance/mastRes", content[0] - assert_equal "Master", content[1] + assert_equal "http://animals.org/instance/Penguins", content[0] + assert (("foodFromWater".eql? content[1]) || ("layingEggs".eql? content[1])) content = [] - file = File.read(File.join(@source, "_site/suprRes.html")) + file = File.read(File.join(@source, "_site/Whale.html")) content = file[/\
(.|\s)*\<\/div>/][21..-7].strip.split("
").map do |entry| entry.strip end - assert_equal "http://example.org/instance/suprRes", content[0] - assert_equal "Supreme", content[1] - #subclasshier... used in map -> problem: subclasses do not get the same template | class to class is not influenced by classHier... only instance to class + assert_equal "http://animals.org/instance/Whale", content[0] + assert_equal "breathingAir", content[1] + + content = [] + file = File.read(File.join(@source, "_site/ape.html")) + content = file[/\
(.|\s)*\<\/div>/][21..-7].strip.split("
").map do |entry| + entry.strip + end + assert_equal "http://animals.org/instance/ape", content[0] + assert_equal "landBorn", content[1] end end end From a897d580252898eaf67420a9d5100d870f026d0d Mon Sep 17 00:00:00 2001 From: Nime Date: Fri, 15 Feb 2019 14:40:13 +0100 Subject: [PATCH 33/85] fixing empty prefixes for posts --- lib/jekyll/hooks/rdf_page_pointer.rb | 12 ++++++++++++ test/cases/prefixesInPosts/_config.yml | 2 ++ 2 files changed, 14 insertions(+) diff --git a/lib/jekyll/hooks/rdf_page_pointer.rb b/lib/jekyll/hooks/rdf_page_pointer.rb index 60940f7f..53532e5a 100644 --- a/lib/jekyll/hooks/rdf_page_pointer.rb +++ b/lib/jekyll/hooks/rdf_page_pointer.rb @@ -38,5 +38,17 @@ end Jekyll::Hooks.register :posts, :pre_render do |page, payload| + prefix_path = page.data["rdf_prefix_path"] + # posts frontmatter does not contain values from layout frontmatters + prefix_path ||= payload.layout["rdf_prefix_path"] + if(page.data["rdf_prefixes"].nil? && !prefix_path.nil?) + Jekyll::JekyllRdf::Helper::RdfHelper.load_prefixes( + File.join( + page.path[0..-(page.relative_path.length + 1)], + prefix_path + ), + page.data + ) + end Jekyll::JekyllRdf::Helper::RdfHelper::page = page end \ No newline at end of file diff --git a/test/cases/prefixesInPosts/_config.yml b/test/cases/prefixesInPosts/_config.yml index 9b0d44e6..c965ee0b 100644 --- a/test/cases/prefixesInPosts/_config.yml +++ b/test/cases/prefixesInPosts/_config.yml @@ -6,4 +6,6 @@ plugins: jekyll_rdf: path: "_data/knowledge-base.ttl" restriction: "SELECT ?resourceUri WHERE {?resourceUri ?p ?o}" + instance_template_mappings: + "http://example.org/blog" : "post" From 94d7267aecaa1c28f3424626811db42ad4d8f7bb Mon Sep 17 00:00:00 2001 From: Nime Date: Fri, 15 Feb 2019 15:24:34 +0100 Subject: [PATCH 34/85] merged sparql_query and construct_query --- lib/jekyll-rdf.rb | 1 - lib/jekyll/filters/rdf_construct_query.rb | 49 --------------------- lib/jekyll/filters/rdf_sparql_query.rb | 7 ++- test/cases/constructQueries/constructs.html | 2 +- 4 files changed, 7 insertions(+), 52 deletions(-) delete mode 100644 lib/jekyll/filters/rdf_construct_query.rb diff --git a/lib/jekyll-rdf.rb b/lib/jekyll-rdf.rb index 87562bbf..e26c7dc1 100644 --- a/lib/jekyll-rdf.rb +++ b/lib/jekyll-rdf.rb @@ -58,7 +58,6 @@ require 'jekyll/filters/rdf_collection' require 'jekyll/filters/rdf_container' require 'jekyll/filters/rdf_get' -require 'jekyll/filters/rdf_construct_query' require 'jekyll/filters/rdf_debug_message' diff --git a/lib/jekyll/filters/rdf_construct_query.rb b/lib/jekyll/filters/rdf_construct_query.rb deleted file mode 100644 index 3402ea71..00000000 --- a/lib/jekyll/filters/rdf_construct_query.rb +++ /dev/null @@ -1,49 +0,0 @@ -## -# MIT License -# -# Copyright (c) 2016 Elias Saalmann, Christian Frommert, Simon Jakobi, -# Arne Jonas Präger, Maxi Bornmann, Georg Hackel, Eric Füg -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# - -module Jekyll - module JekyllRdf - ## - # Internal module to hold the medthod #sparql_query - # - module Filter - - ## - # Executes a CONSTRUCT query. The supplied query is augmented by replacing each occurence of '?resourceUri' by the URI of the context RDF resource. - # Returns an Array of bindings. Each binding is a Hash mapping variables to their values. - # - # * +input+ - the context RDF resource - # * +query+ - the SPARQL query - # - def construct_query(resource = nil, query) - query = prepare_query(resource, query) - return if query.nil? - new_graph = Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(query) - Jekyll::JekyllRdf::Helper::RdfHelper::sparql.insert_data(new_graph) - return nil - end - end - end -end diff --git a/lib/jekyll/filters/rdf_sparql_query.rb b/lib/jekyll/filters/rdf_sparql_query.rb index 8cc96f98..3730e2b6 100644 --- a/lib/jekyll/filters/rdf_sparql_query.rb +++ b/lib/jekyll/filters/rdf_sparql_query.rb @@ -41,7 +41,12 @@ def sparql_query(resource = nil, query) query = prepare_query(resource, query) return if query.nil? begin - result = Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(query).map do |solution| + result = Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(query) + if (result.class == RDF::Graph) + Jekyll::JekyllRdf::Helper::RdfHelper::sparql.insert_data(result) + return nil + end + result.map! do |solution| hsh = solution.to_h hsh.update(hsh){ |k,v| Jekyll::JekyllRdf::Drops::RdfTerm.build_term_drop(v, Jekyll::JekyllRdf::Helper::RdfHelper::site, true).add_necessities(Jekyll::JekyllRdf::Helper::RdfHelper::site, Jekyll::JekyllRdf::Helper::RdfHelper::page)} hsh.collect{|k,v| [k.to_s, v]}.to_h diff --git a/test/cases/constructQueries/constructs.html b/test/cases/constructQueries/constructs.html index eee67efe..0eeb1ded 100644 --- a/test/cases/constructQueries/constructs.html +++ b/test/cases/constructQueries/constructs.html @@ -9,7 +9,7 @@ {%- assign cquery = "CONSTRUCT {?x } where {?x }" -%} - {%- assign test = cquery | construct_query -%} + {%- assign test = cquery | sparql_query -%} {%- assign query = "SELECT ?res {?res }" -%} {%- assign results = query | sparql_query -%} From 6f88ef56604d51b7235b1fc9ce34f54042861435 Mon Sep 17 00:00:00 2001 From: Nime Date: Fri, 15 Feb 2019 16:43:32 +0100 Subject: [PATCH 35/85] serialize graph objects --- lib/jekyll/filters/rdf_sparql_query.rb | 3 ++- lib/jekyll/helper/rdf_filter_helper.rb | 18 ++++++++++++++++++ test/cases/constructQueries/constructs.html | 1 + .../constructQueries/test_construct_queries.rb | 7 +++++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/filters/rdf_sparql_query.rb b/lib/jekyll/filters/rdf_sparql_query.rb index 3730e2b6..56aa6877 100644 --- a/lib/jekyll/filters/rdf_sparql_query.rb +++ b/lib/jekyll/filters/rdf_sparql_query.rb @@ -44,7 +44,8 @@ def sparql_query(resource = nil, query) result = Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(query) if (result.class == RDF::Graph) Jekyll::JekyllRdf::Helper::RdfHelper::sparql.insert_data(result) - return nil + result.extend Jekyll::JekyllRdf::Helper::GraphSerializer + return result end result.map! do |solution| hsh = solution.to_h diff --git a/lib/jekyll/helper/rdf_filter_helper.rb b/lib/jekyll/helper/rdf_filter_helper.rb index abcb31f8..e8fe8f5c 100644 --- a/lib/jekyll/helper/rdf_filter_helper.rb +++ b/lib/jekyll/helper/rdf_filter_helper.rb @@ -103,6 +103,24 @@ def rdf_resolve_prefix(predicate) end end end + + module GraphSerializer + def to_liquid + return to_nquads + end + + def to_nquads + return statements.map{|state| + state.to_nquads + }.join("\n") + end + + def to_ntriples + return statements.map{|state| + state.to_ntriples + }.join("\n") + end + end end end end diff --git a/test/cases/constructQueries/constructs.html b/test/cases/constructQueries/constructs.html index 0eeb1ded..e9ada23b 100644 --- a/test/cases/constructQueries/constructs.html +++ b/test/cases/constructQueries/constructs.html @@ -18,6 +18,7 @@ {{result.res}}
{%- endfor -%} + {{ test }}
diff --git a/test/cases/constructQueries/test_construct_queries.rb b/test/cases/constructQueries/test_construct_queries.rb index 11f10524..1afcf81c 100644 --- a/test/cases/constructQueries/test_construct_queries.rb +++ b/test/cases/constructQueries/test_construct_queries.rb @@ -13,17 +13,20 @@ class TestSciMath < Test::Unit::TestCase content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| entry.strip end - assert_equal 3, content.length + assert_equal 4, content.length assert (content[0].eql?("http://example.org/instance/resource1") || content[0].eql?("http://example.org/instance/resource2") || content[0].eql?("http://example.org/instance/resource3")), "The
should contain http://example.org/instance/resource1, http://example.org/instance/resource2 and http://example.org/instance/resource3 at first position.\n It was: >#{content[0]}<." assert (content[1].eql?("http://example.org/instance/resource1") || content[1].eql?("http://example.org/instance/resource2") || content[1].eql?("http://example.org/instance/resource3")), "The
should contain http://example.org/instance/resource1, http://example.org/instance/resource2 and http://example.org/instance/resource3 at second position.\n It was: >#{content[1]}<." assert (content[2].eql?("http://example.org/instance/resource1") || content[2].eql?("http://example.org/instance/resource2") || content[2].eql?("http://example.org/instance/resource3")), "The
should contain http://example.org/instance/resource1, http://example.org/instance/resource2 and http://example.org/instance/resource3 at third position.\n It was: >#{content[2]}<." assert content.include?("http://example.org/instance/resource1"), "The
should include http://example.org/instance/resource1." assert content.include?("http://example.org/instance/resource2"), "The
should include http://example.org/instance/resource2." assert content.include?("http://example.org/instance/resource3"), "The
should include http://example.org/instance/resource3." - #assert_equal "", content[3] assert !content.include?("http://example.org/instance/resource4"), "The
should not include http://example.org/instance/resource4." assert !content.include?("http://example.org/instance/resource5"), "The
should not include http://example.org/instance/resource5." assert !content.include?("http://example.org/instance/resource6"), "The
should not include http://example.org/instance/resource6." + nquads = content[3].split("\n\n") + assert (nquads.include? " ."), "the return graph should contain >>> <<<" + assert (nquads.include? " ."), "the return graph should contain >>> <<<" + assert (nquads.include? " ."), "the return graph should contain >>> <<<" end end end From a0c0565372f1adf6cd5aa5405df0012c045a168f Mon Sep 17 00:00:00 2001 From: Nime Date: Mon, 25 Feb 2019 15:43:07 +0100 Subject: [PATCH 36/85] correcting classHierarchy tests --- test/cases/classHierarchy/_data/knowledge-base.ttl | 2 +- test/cases/classHierarchy/test_class_hierarchy.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/test/cases/classHierarchy/_data/knowledge-base.ttl b/test/cases/classHierarchy/_data/knowledge-base.ttl index 38f07b7e..2693f802 100644 --- a/test/cases/classHierarchy/_data/knowledge-base.ttl +++ b/test/cases/classHierarchy/_data/knowledge-base.ttl @@ -27,6 +27,6 @@ ani:Lizard a an:landWaterLiving . ani:Penguins a an:keratinousScalyFeets . ani:Penguins a an:landWaterLiving . ani:Fish a an:waterHunting . -ani:Fish a an:foodFromWater . +ani:Fish a an:waterFiltering . ani:Whale a an:breathingAir . ani:Whale a an:foodFromWater . diff --git a/test/cases/classHierarchy/test_class_hierarchy.rb b/test/cases/classHierarchy/test_class_hierarchy.rb index a620518b..6df1cd4c 100644 --- a/test/cases/classHierarchy/test_class_hierarchy.rb +++ b/test/cases/classHierarchy/test_class_hierarchy.rb @@ -45,6 +45,11 @@ class TestClassHierarchy < Test::Unit::TestCase end assert_equal "http://animals.org/instance/ape", content[0] assert_equal "landBorn", content[1] + + #Jekyll.logger.error "methods: #{Jekyll.logger.methods.sort.join("\n")}" + #Jekyll.logger.error Jekyll.logger.inspect + #Jekyll.logger.error "any1?: #{Jekyll.logger.messages.any? {|message| !!(message =~ /.*Warning: multiple possible templates for resources.*Penguins.*/)}}" + #Jekyll.logger.error "any2?: #{Jekyll.logger.messages.any? {|message| !!(message =~ /.*Warning: multiple possible templates for resources.*fish.*/)}}" end end end From 8aeab4d77ff914d2b6bc141130110e91db3dad5b Mon Sep 17 00:00:00 2001 From: Nime Date: Mon, 25 Feb 2019 16:47:34 +0100 Subject: [PATCH 37/85] classHierarchy check warn messages --- lib/jekyll/helper/rdf_class_extraction.rb | 4 ++-- test/cases/classHierarchy/test_class_hierarchy.rb | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/jekyll/helper/rdf_class_extraction.rb b/lib/jekyll/helper/rdf_class_extraction.rb index 32670f29..0c7d853f 100644 --- a/lib/jekyll/helper/rdf_class_extraction.rb +++ b/lib/jekyll/helper/rdf_class_extraction.rb @@ -63,7 +63,7 @@ def request_class_template resource if(!@classResources[uri].template.nil?) # do not search in paths you previously found if @classResources[uri].base if(!min_class.nil? && min_template_lock == lock) #min_class could contain a previously found class with equal distance - alternatives.push @classResources[uri] + alternatives.push @classResources[uri] unless min_class.eql? @classResources[uri] else min_template_lock = lock min_class = @classResources[uri] @@ -75,7 +75,7 @@ def request_class_template resource min_template_lock = lock + @classResources[uri].distance min_class = @classResources[uri] elsif min_template_lock == (lock + @classResources[uri].distance) - alternatives.push @classResources[uri] + alternatives.push @classResources[uri] unless min_class.eql? @classResources[uri] end elsif(@classResources[uri].add?(lock_number)) # not a previously searched resource without a template @classResources[uri].path = class_resource # <- this might be valnuable to cyclic inheritance in the graph diff --git a/test/cases/classHierarchy/test_class_hierarchy.rb b/test/cases/classHierarchy/test_class_hierarchy.rb index 6df1cd4c..c08840b6 100644 --- a/test/cases/classHierarchy/test_class_hierarchy.rb +++ b/test/cases/classHierarchy/test_class_hierarchy.rb @@ -4,7 +4,12 @@ class TestClassHierarchy < Test::Unit::TestCase include RdfTestUtility context "the class-template-mapping system" do should "map the right template to the right class in consideration to its super classes" do + error_holder = $stderr + Jekyll.logger.log_level = :warn + $stderr = StringIO.new setup_jekyll File.dirname(__FILE__) + Jekyll.logger.log_level = :error + $stderr = error_holder content = [] file = File.read(File.join(@source, "_site/Fish.html")) @@ -46,10 +51,8 @@ class TestClassHierarchy < Test::Unit::TestCase assert_equal "http://animals.org/instance/ape", content[0] assert_equal "landBorn", content[1] - #Jekyll.logger.error "methods: #{Jekyll.logger.methods.sort.join("\n")}" - #Jekyll.logger.error Jekyll.logger.inspect - #Jekyll.logger.error "any1?: #{Jekyll.logger.messages.any? {|message| !!(message =~ /.*Warning: multiple possible templates for resources.*Penguins.*/)}}" - #Jekyll.logger.error "any2?: #{Jekyll.logger.messages.any? {|message| !!(message =~ /.*Warning: multiple possible templates for resources.*fish.*/)}}" + assert Jekyll.logger.messages.any? {|message| !!(message =~ /.*Warning: multiple possible templates for resources.*Penguins.*/)}, "This warning should have been thrown >>>Warning: multiple possible templates for resources http://animals.org/instance/Penguins Possible Templates: foodFromWater, layingEggs<<<" + assert !Jekyll.logger.messages.any? {|message| !!(message =~ /.*Warning: multiple possible templates for resources.*Fish.*/)}, "This warning should not have been thrown >>>Warning: multiple possible templates for resources http://animals.org/instance/Fish Possible Templates: ***<<<" end end end From 02ebf4d56ee728fd8330f9314dc8b725a988e283 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 25 Feb 2019 17:25:24 +0100 Subject: [PATCH 38/85] Update changelog, add new features to README, and fix typos --- CHANGELOG.md | 5 +++++ README.md | 17 +++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b238f70e..0e1d958c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [3.1.1] - ??? ### changed - Repository moved from https://github.com/white-gecko/jekyll-rdf/ to https://github.com/AKSW/jekyll-rdf/ +- Add posibility to specify the default graph on a SPARQL endpoint +- Some updates in the test/build system +- Update some dependencies +- Minor code cleanup +- New `resource.rendered` attribute to check if a page is rendered in the present site for this resource. ## [3.1.0] - 2018-11-27 ### Added diff --git a/README.md b/README.md index c8803457..9869d3bc 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ You can restrict the resources selected to be built by adding a SPARQL query as restriction: "SELECT ?resourceUri WHERE { ?resourceUri }" ``` -There are 3 pre-defined keywords for restrictions implemented: +There are 3 predefined keywords for restrictions implemented: * `subjects` will load all subject URIs * `predicates` will load all predicate URIs * `objects` will load all object URIs @@ -146,7 +146,7 @@ jekyll_rdf: ## Building the Jekyll Site Running `jekyll build` will render the RDF resources to the `_site/…` directory. Running `jekyll serve` will render the RDF resources and provide you with an instant HTTP-Server usually accessible at `http://localhost:4000/`. -RDF resources whose IRIs don't start with the configured jekyll `url` and `baseurl` are rendered to the `_site/rdfsites/…` subdirectory. +RDF resources whose IRIs don't start with the configured jekyll `url` and `baseurl` are rendered to the `_site/rdfsites/…` sub directory. ## Defining Templates To make use of the RDF data, create one or more files (e.g `rdf_index.html` or `person.html`) in the `_layouts`-directory. For each resource a page will be rendered. See example below: @@ -342,8 +342,12 @@ Return the URL of the page representing this RdfResource. Return the path to the page representing this RdfResource. Use it with care. ### Resource.covered -This method is relevant for rendering pages for IRIs containing a fragment identifier (`http://superresource#anchor`). -This method returns true for the super-resource (`http://superresource`) if it is actually described in the given knowledgebase. +This attribute is relevant for rendering pages for IRIs containing a fragment identifier (`http://superresource#anchor`). +This attribute is true for the super-resource (`http://superresource`) if it is actually described in the given knowledgebase. + +### Resource.rendered +This attribute tells if the respective instance of a resource is rendered within the context of the current site generation. +Usage: `{% if resource.rendered? %}…{% endif %}`. ### Resource.inspect Returns a verbose String representing this resource. @@ -649,8 +653,9 @@ http://www.ifi.uio.no/INF3580/simpsons#Maggie |Name|Parameter|Default|Description|Example| |--- |--- |--- |--- |--- | |path|Relative path to the RDF-File|no default|Specifies the path to the RDF file from where you want to render the website|```path: "rdf-data/simpsons.ttl"```| -|remote|Section to specify a remote data source|no default|Has to contain the `endpoint` key. The `remote` paramter overrides the `path` parameter.|| +|remote|Section to specify a remote data source|no default|Has to contain the `endpoint` key. The `remote` parameter overrides the `path` parameter.|| |remote > endpoint|SPARQL endpoint to get the data from|no default|Specifies the URL to the SPARQL endpoint from where you want to render the website|```remote: endpoint: "http://localhost:5000/sparql/"```| +|remote > default_graph|Select a default graph on the endpoint|no default|Specifies the IRI to the named graph to select from the SPARQL endpoint|```remote: endpoint: "http://localhost:5000/sparql/" default_graph: "http://example.org/"```| |language|Language-Tag as String|no default|Specifies the preferred language when you select objects using our Liquid filters|```language: "en"```| |include_blank|Boolean-Expression|false|Specifies whether blank nodes should also be rendered or not|```include_blank: true```| |restriction|SPARQL-Query as String or subjects/objects/predicates|no default|Restricts the resource-selection with a given SPARQL-Query to the results bound to the special variable `?resourceUri` or the three keywords `subjects` (only subject URIs), `objects`, `predicates`|```restriction: "SELECT ?resourceUri WHERE { ?resourceUri }"```| @@ -679,7 +684,7 @@ bundle exec rake test ``` ## Test page -Everytime the tests are executed, the Jekyll page inside of `test/source` gets processed. Start a slim web server to watch the results in web browser, e.g. Pythons `SimpleHTTPServer` (Python 2, for Python 3 it's `http.server`): +Every time the tests are executed, the Jekyll page inside of `test/source` gets processed. Start a slim web server to watch the results in web browser, e.g. Pythons `SimpleHTTPServer` (Python 2, for Python 3 it's `http.server`): ``` cd test/source/_site python -m SimpleHTTPServer 8000 From e86712587f7e1ab745b1dd8e5164beef92a72b7e Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 25 Feb 2019 17:35:57 +0100 Subject: [PATCH 39/85] Add documentation for baseiri config. Fix #241. --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9869d3bc..e01b3c6f 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ jekyll new my_page cd my_page ``` -Further there are some parameters required in your `_config.yml` for `jekyll-rdf`. I.e. the `url` and `baseurl` parameters are used for including the resource pages into the root of the site, the plug-in has to be configured, and the path to the RDF file has to be present. +Further, there are some parameters required in your `_config.yml` for `jekyll-rdf`. I.e. the `url` and `baseurl` parameters are used for including the resource pages into the root of the site, the plug-in has to be configured, and the path to the RDF file has to be present. ```yaml baseurl: "/simpsons" @@ -85,6 +85,20 @@ jekyll_rdf: "http://example.org/simpsons/Abraham": "abraham.html" ``` +### Base Path Specification +The `url` + `baseurl` are used by Jekyll RDF to identify relative to which URL it should build the RDF resource pages. +In the example above this means that a resource with the IRI `` is rendered to the path `/Bart.html`. +Also other features and plugins for Jekyll depend on these two parameters. +If for any case the two parameters differ from the base path that Jekyll RDF should assume, it is possible to set the parameter `baseiri` in the `jekyll_rdf` section. + +```yaml +baseurl: "/simpsons" +url: "https://beispiel.com" + +jekyll_rdf: + baseiri: "http://example.org/" +``` + ### Map resources to templates It is possible to map a specific class (resp. RDF-type) or individual resources to a template. ```yaml @@ -146,7 +160,7 @@ jekyll_rdf: ## Building the Jekyll Site Running `jekyll build` will render the RDF resources to the `_site/…` directory. Running `jekyll serve` will render the RDF resources and provide you with an instant HTTP-Server usually accessible at `http://localhost:4000/`. -RDF resources whose IRIs don't start with the configured jekyll `url` and `baseurl` are rendered to the `_site/rdfsites/…` sub directory. +RDF resources whose IRIs don't start with the configured jekyll `url` and `baseurl` (resp. `baseiri`) are rendered to the `_site/rdfsites/…` sub directory. ## Defining Templates To make use of the RDF data, create one or more files (e.g `rdf_index.html` or `person.html`) in the `_layouts`-directory. For each resource a page will be rendered. See example below: From 3a5949845dcb8ef2261a043affac6b9adf7591a5 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Tue, 26 Feb 2019 11:41:39 +0100 Subject: [PATCH 40/85] Add new template system to changelog and fix typos --- CHANGELOG.md | 3 ++- README.md | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e1d958c..5720c056 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [3.1.1] - ??? ### changed - Repository moved from https://github.com/white-gecko/jekyll-rdf/ to https://github.com/AKSW/jekyll-rdf/ -- Add posibility to specify the default graph on a SPARQL endpoint +- Add possibility to specify the default graph on a SPARQL endpoint - Some updates in the test/build system - Update some dependencies - Minor code cleanup - New `resource.rendered` attribute to check if a page is rendered in the present site for this resource. +- Update class-template selection to be straightforward ## [3.1.0] - 2018-11-27 ### Added diff --git a/README.md b/README.md index e01b3c6f..9628f7c3 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ The API Documentation is available at [RubyDoc.info](http://www.rubydoc.info/gem As a prerequisite for *Jekyll RDF* you of course need to install [*Jekyll*](https://jekyllrb.com/). Please take a look at the installations instructions at https://jekyllrb.com/docs/installation/. -If you already have a working Jekyll installation you can add the the Jekyll-RDF plugin. +If you already have a working Jekyll installation you can add the Jekyll-RDF plugin. Probably you already using [Bundler](https://bundler.io/) and there is a [`Gemfile`](https://bundler.io/gemfile.html) in your Jekyll directory. Add Jekyll-RDF to the plugins section: @@ -141,7 +141,7 @@ A file `_data/restriction.txt` cool have the following content: ``` In the `_config.yml` you specify the file with the key `restriction_file`. -If both, a `restriction_file` and a `restriction`, are specified JekyllRDF will build pages for the union of the both. +If both, a `restriction_file` and a `restriction`, are specified Jekyll RDF will build pages for the union of the both. ### Blank Nodes Furthermore you can decide if you want to render blank nodes or not. You just need to add `include_blank`to `_config.yml`: @@ -160,7 +160,7 @@ jekyll_rdf: ## Building the Jekyll Site Running `jekyll build` will render the RDF resources to the `_site/…` directory. Running `jekyll serve` will render the RDF resources and provide you with an instant HTTP-Server usually accessible at `http://localhost:4000/`. -RDF resources whose IRIs don't start with the configured jekyll `url` and `baseurl` (resp. `baseiri`) are rendered to the `_site/rdfsites/…` sub directory. +RDF resources whose IRIs don't start with the configured Jekyll `url` and `baseurl` (resp. `baseiri`) are rendered to the `_site/rdfsites/…` sub directory. ## Defining Templates To make use of the RDF data, create one or more files (e.g `rdf_index.html` or `person.html`) in the `_layouts`-directory. For each resource a page will be rendered. See example below: @@ -285,8 +285,8 @@ The template for `ex:Resource`: ``` ### Custom SPARQL Query -We implemented a liquid filter `sparql_query` to run custom SPARQL queries. Each occurence of `?resourceUri` gets replaced with the current URI. -*Caution:* You have to separate query and resultset variables because of Liquids concepts. Example: +We implemented a liquid filter `sparql_query` to run custom SPARQL queries. Each occurrence of `?resourceUri` gets replaced with the current URI. +*Caution:* You have to separate query and result set variables because of Liquids concepts. Example: ```html {% assign query = 'SELECT ?sub ?pre WHERE { ?sub ?pre ?resourceUri }' %} {% assign resultset = page.rdf | sparql_query: query %} @@ -357,7 +357,7 @@ Return the path to the page representing this RdfResource. Use it with care. ### Resource.covered This attribute is relevant for rendering pages for IRIs containing a fragment identifier (`http://superresource#anchor`). -This attribute is true for the super-resource (`http://superresource`) if it is actually described in the given knowledgebase. +This attribute is true for the super-resource (`http://superresource`) if it is actually described in the given knowledge base. ### Resource.rendered This attribute tells if the respective instance of a resource is rendered within the context of the current site generation. @@ -397,7 +397,7 @@ http://www.ifi.uio.no/INF3580/simpsons - `` is a boolean value (`true`, `false`). **Description:** Returns the object, of the triple ` ?object`. -The returned object can by any of the kind, resource, literal, or blanknode. +The returned object can by any of the kind, resource, literal, or blank node. **Example (default):** ``` @@ -454,7 +454,7 @@ The returned object can by any of the kind, resource, literal, or blanknode. **Description:** Same as rdf_property, but in inverse direction. It returns the subject, of the triple `?subject `. -The returned object can by any of the kind, resource, or blanknode. +The returned object can by any of the kind, resource, or blank node. **Examples (default):** ``` From 434eead93c9b05851a6579b9f3731a75ee232ef8 Mon Sep 17 00:00:00 2001 From: Nime Date: Sun, 3 Mar 2019 17:36:28 +0100 Subject: [PATCH 41/85] load prefixes for post with theme templates --- lib/jekyll-rdf.rb | 1 + lib/jekyll/helper/rdf_hook_helper.rb | 38 ++++++++++++++++++++++++++++ lib/jekyll/hooks/rdf_page_pointer.rb | 15 ++++++++--- 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 lib/jekyll/helper/rdf_hook_helper.rb diff --git a/lib/jekyll-rdf.rb b/lib/jekyll-rdf.rb index e26c7dc1..2a76d31a 100644 --- a/lib/jekyll-rdf.rb +++ b/lib/jekyll-rdf.rb @@ -52,6 +52,7 @@ require 'jekyll/helper/rdf_page_helper' require 'jekyll/helper/rdf_generator_helper' require 'jekyll/helper/rdf_filter_helper' +require 'jekyll/helper/rdf_hook_helper' require 'jekyll/hooks/rdf_page_pointer' require 'jekyll/filters/rdf_sparql_query' require 'jekyll/filters/rdf_property' diff --git a/lib/jekyll/helper/rdf_hook_helper.rb b/lib/jekyll/helper/rdf_hook_helper.rb new file mode 100644 index 00000000..89782030 --- /dev/null +++ b/lib/jekyll/helper/rdf_hook_helper.rb @@ -0,0 +1,38 @@ +## +# MIT License +# +# Copyright (c) 2017 Sebastian Zänker +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +module Jekyll + module JekyllRdf + module Helper + module RdfHookHelper + def search_prefix_definition layout, rdf_prefix_path + if(rdf_prefix_path.eql? layout.data["rdf_prefix_path"]) + return layout.instance_variable_get(:@base_dir) + end + return search_prefix_definition layout.site.layouts[layout.data["layout"]], rdf_prefix_path + end + end + end + end +end diff --git a/lib/jekyll/hooks/rdf_page_pointer.rb b/lib/jekyll/hooks/rdf_page_pointer.rb index 53532e5a..526d51f4 100644 --- a/lib/jekyll/hooks/rdf_page_pointer.rb +++ b/lib/jekyll/hooks/rdf_page_pointer.rb @@ -38,17 +38,24 @@ end Jekyll::Hooks.register :posts, :pre_render do |page, payload| + include Jekyll::JekyllRdf::Helper::RdfHookHelper prefix_path = page.data["rdf_prefix_path"] # posts frontmatter does not contain values from layout frontmatters - prefix_path ||= payload.layout["rdf_prefix_path"] - if(page.data["rdf_prefixes"].nil? && !prefix_path.nil?) + if(prefix_path.nil?) + prefix_path = payload.layout["rdf_prefix_path"] + base_path = search_prefix_definition page.site.layouts[page.data["layout"]], prefix_path + else + base_path = page.path[0..-(page.relative_path.length + 1)] + end + + if(page.data["rdf_prefixes"].nil? && !(prefix_path.nil? || base_path.nil?)) Jekyll::JekyllRdf::Helper::RdfHelper.load_prefixes( File.join( - page.path[0..-(page.relative_path.length + 1)], + base_path, prefix_path ), page.data ) end Jekyll::JekyllRdf::Helper::RdfHelper::page = page -end \ No newline at end of file +end From f76145de24b2b4102daae9ac884056fa22e6132a Mon Sep 17 00:00:00 2001 From: Nime Date: Sun, 3 Mar 2019 19:54:37 +0100 Subject: [PATCH 42/85] fix: renders all resources if restriction is empty --- lib/jekyll/rdf_main_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/rdf_main_generator.rb b/lib/jekyll/rdf_main_generator.rb index 01688844..ba5b5a2b 100644 --- a/lib/jekyll/rdf_main_generator.rb +++ b/lib/jekyll/rdf_main_generator.rb @@ -75,7 +75,7 @@ def generate(site) resources = [] resources = resources + extract_resources(@config['restriction'], @config['include_blank'], sparql) unless @config['restriction'].nil? resources = resources + extract_list_resources(File.join(site.config['source'], @config['restriction_file'])) unless @config['restriction_file'].nil? - resources = resources + extract_resources(nil, @config['include_blank'], sparql) if resources.length == 0 # subject + predicate + object should only be extracted if there is neither a restriction or restriction_file + resources = resources + extract_resources(nil, @config['include_blank'], sparql) if @config['restriction'].nil? && @config['restriction_file'].nil? # subject + predicate + object should only be extracted if there is neither a restriction or restriction_file resources.uniq! unless @config['restriction'].nil? || @config['restriction_file'].nil? site.data['sparql'] = sparql site.data['resources'] = [] From 1f9d5779b5aed2f6a9d8308f537d5db64f0b686d Mon Sep 17 00:00:00 2001 From: Nime Date: Wed, 20 Feb 2019 14:43:27 +0100 Subject: [PATCH 43/85] exposed graph serialization to liquid --- lib/jekyll-rdf.rb | 1 + lib/jekyll/drops/rdf_graph.rb | 56 +++++++++++++++++++ lib/jekyll/filters/rdf_sparql_query.rb | 3 +- lib/jekyll/helper/rdf_filter_helper.rb | 18 ------ .../constructQueries/_data/Prefixes.pref | 5 -- .../_layouts/exampleInstance.html | 8 --- .../constructQueries/_layouts/person.html | 15 ----- test/cases/constructQueries/constructs.html | 9 ++- .../test_construct_queries.rb | 12 +++- 9 files changed, 75 insertions(+), 52 deletions(-) create mode 100644 lib/jekyll/drops/rdf_graph.rb delete mode 100644 test/cases/constructQueries/_data/Prefixes.pref delete mode 100644 test/cases/constructQueries/_layouts/exampleInstance.html delete mode 100644 test/cases/constructQueries/_layouts/person.html diff --git a/lib/jekyll-rdf.rb b/lib/jekyll-rdf.rb index e26c7dc1..a20daf67 100644 --- a/lib/jekyll-rdf.rb +++ b/lib/jekyll-rdf.rb @@ -43,6 +43,7 @@ require 'jekyll/drops/rdf_literal' require 'jekyll/drops/rdf_resource' require 'jekyll/drops/rdf_resource_class' +require 'jekyll/drops/rdf_graph' require 'jekyll/exceptions/NoPrefixMapped' require 'jekyll/exceptions/NoPrefixesDefined' require 'jekyll/exceptions/UnMarkedUri' diff --git a/lib/jekyll/drops/rdf_graph.rb b/lib/jekyll/drops/rdf_graph.rb new file mode 100644 index 00000000..a6fcafe0 --- /dev/null +++ b/lib/jekyll/drops/rdf_graph.rb @@ -0,0 +1,56 @@ +## +# MIT License +# +# Copyright (c) 2016 Elias Saalmann, Christian Frommert, Simon Jakobi, +# Arne Jonas Präger, Maxi Bornmann, Georg Hackel, Eric Füg +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +module Jekyll #:nodoc: + module JekyllRdf #:nodoc: + module Drops #:nodoc: + class RdfGraph < Liquid::Drop + attr_reader :graph + + def initialize(graph) + @graph = graph + end + + def to_s + to_nquads + end + + def to_nquads + result = @graph.statements.map{|state| + state.to_nquads + }.join("") + return result + end + + def to_ntriples + result = @graph.statements.map{|state| + state.to_ntriples + }.join("") + return result + end + end + end + end +end diff --git a/lib/jekyll/filters/rdf_sparql_query.rb b/lib/jekyll/filters/rdf_sparql_query.rb index 56aa6877..8bdccb44 100644 --- a/lib/jekyll/filters/rdf_sparql_query.rb +++ b/lib/jekyll/filters/rdf_sparql_query.rb @@ -44,8 +44,7 @@ def sparql_query(resource = nil, query) result = Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(query) if (result.class == RDF::Graph) Jekyll::JekyllRdf::Helper::RdfHelper::sparql.insert_data(result) - result.extend Jekyll::JekyllRdf::Helper::GraphSerializer - return result + return Jekyll::JekyllRdf::Drops::RdfGraph.new(result) end result.map! do |solution| hsh = solution.to_h diff --git a/lib/jekyll/helper/rdf_filter_helper.rb b/lib/jekyll/helper/rdf_filter_helper.rb index e8fe8f5c..abcb31f8 100644 --- a/lib/jekyll/helper/rdf_filter_helper.rb +++ b/lib/jekyll/helper/rdf_filter_helper.rb @@ -103,24 +103,6 @@ def rdf_resolve_prefix(predicate) end end end - - module GraphSerializer - def to_liquid - return to_nquads - end - - def to_nquads - return statements.map{|state| - state.to_nquads - }.join("\n") - end - - def to_ntriples - return statements.map{|state| - state.to_ntriples - }.join("\n") - end - end end end end diff --git a/test/cases/constructQueries/_data/Prefixes.pref b/test/cases/constructQueries/_data/Prefixes.pref deleted file mode 100644 index f59c9317..00000000 --- a/test/cases/constructQueries/_data/Prefixes.pref +++ /dev/null @@ -1,5 +0,0 @@ -PREFIX rdf: -PREFIX rdfs: -PREFIX xsd: -PREFIX foaf: -PREFIX eg: diff --git a/test/cases/constructQueries/_layouts/exampleInstance.html b/test/cases/constructQueries/_layouts/exampleInstance.html deleted file mode 100644 index 655a2ea8..00000000 --- a/test/cases/constructQueries/_layouts/exampleInstance.html +++ /dev/null @@ -1,8 +0,0 @@ ---- -layout: default -rdf_prefix_path: _data/Prefixes.pref ---- -
-
This page is mapped to:
- {{page.rdf}} -
diff --git a/test/cases/constructQueries/_layouts/person.html b/test/cases/constructQueries/_layouts/person.html deleted file mode 100644 index 30e3bf3b..00000000 --- a/test/cases/constructQueries/_layouts/person.html +++ /dev/null @@ -1,15 +0,0 @@ ---- -layout: default -rdf_prefix_path: _data/Prefixes.pref ---- -
-
- name: -
- {{page.rdf | rdf_property: "foaf:name"}} -
-
- age: -
- {{page.rdf | rdf_property: "foaf:age"}} -
diff --git a/test/cases/constructQueries/constructs.html b/test/cases/constructQueries/constructs.html index e9ada23b..7753b4ba 100644 --- a/test/cases/constructQueries/constructs.html +++ b/test/cases/constructQueries/constructs.html @@ -12,13 +12,18 @@ {%- assign test = cquery | sparql_query -%} {%- assign query = "SELECT ?res {?res }" -%} {%- assign results = query | sparql_query -%} -
{%- for result in results -%} - {{result.res}} + {{ result.res }}
{%- endfor -%} {{ test }} +
+ {%- assign nquads = test.to_nquads -%} + {{ nquads }} +
+ {%- assign ntriples = test.to_ntriples -%} + {{ ntriples }}
diff --git a/test/cases/constructQueries/test_construct_queries.rb b/test/cases/constructQueries/test_construct_queries.rb index 1afcf81c..e78fdaa9 100644 --- a/test/cases/constructQueries/test_construct_queries.rb +++ b/test/cases/constructQueries/test_construct_queries.rb @@ -13,7 +13,7 @@ class TestSciMath < Test::Unit::TestCase content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| entry.strip end - assert_equal 4, content.length + assert_equal 6, content.length assert (content[0].eql?("http://example.org/instance/resource1") || content[0].eql?("http://example.org/instance/resource2") || content[0].eql?("http://example.org/instance/resource3")), "The
should contain http://example.org/instance/resource1, http://example.org/instance/resource2 and http://example.org/instance/resource3 at first position.\n It was: >#{content[0]}<." assert (content[1].eql?("http://example.org/instance/resource1") || content[1].eql?("http://example.org/instance/resource2") || content[1].eql?("http://example.org/instance/resource3")), "The
should contain http://example.org/instance/resource1, http://example.org/instance/resource2 and http://example.org/instance/resource3 at second position.\n It was: >#{content[1]}<." assert (content[2].eql?("http://example.org/instance/resource1") || content[2].eql?("http://example.org/instance/resource2") || content[2].eql?("http://example.org/instance/resource3")), "The
should contain http://example.org/instance/resource1, http://example.org/instance/resource2 and http://example.org/instance/resource3 at third position.\n It was: >#{content[2]}<." @@ -23,10 +23,18 @@ class TestSciMath < Test::Unit::TestCase assert !content.include?("http://example.org/instance/resource4"), "The
should not include http://example.org/instance/resource4." assert !content.include?("http://example.org/instance/resource5"), "The
should not include http://example.org/instance/resource5." assert !content.include?("http://example.org/instance/resource6"), "The
should not include http://example.org/instance/resource6." - nquads = content[3].split("\n\n") + nquads = content[3].split("\n") assert (nquads.include? " ."), "the return graph should contain >>> <<<" assert (nquads.include? " ."), "the return graph should contain >>> <<<" assert (nquads.include? " ."), "the return graph should contain >>> <<<" + nquads = content[4].split("\n") + assert (nquads.include? " ."), "the return graph should contain >>> <<<" + assert (nquads.include? " ."), "the return graph should contain >>> <<<" + assert (nquads.include? " ."), "the return graph should contain >>> <<<" + ntriples = content[5].split("\n") + assert (ntriples.include? " ."), "the return graph should contain >>> <<<" + assert (ntriples.include? " ."), "the return graph should contain >>> <<<" + assert (ntriples.include? " ."), "the return graph should contain >>> <<<" end end end From 59ad2564a54ac65db83d3962bc418c3878ec951d Mon Sep 17 00:00:00 2001 From: Nime Date: Mon, 25 Feb 2019 11:20:28 +0100 Subject: [PATCH 44/85] added comments to general helper --- lib/jekyll/helper/rdf_general_helper.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/jekyll/helper/rdf_general_helper.rb b/lib/jekyll/helper/rdf_general_helper.rb index f71c4e5a..c709ef12 100644 --- a/lib/jekyll/helper/rdf_general_helper.rb +++ b/lib/jekyll/helper/rdf_general_helper.rb @@ -105,8 +105,7 @@ def self.pathiri= path def self.pathiri @@baseiri end - end - - end - end -end + end #RdfHelper + end #Helper + end #JekyllRdf +end #Jekyll From f5241e17854afe9aa709d839bea4e93128706483 Mon Sep 17 00:00:00 2001 From: Nime Date: Mon, 25 Feb 2019 14:33:12 +0100 Subject: [PATCH 45/85] resources are only produced once --- lib/jekyll/filters/rdf_get.rb | 2 +- lib/jekyll/filters/rdf_property.rb | 4 ++-- lib/jekyll/helper/rdf_general_helper.rb | 20 ++++++++++++++++ lib/jekyll/helper/rdf_generator_helper.rb | 4 ++-- test/RdfTestUtility.rb | 2 ++ test/cases/uniqueResources/Gemfile | 4 ++++ test/cases/uniqueResources/_config.yml | 11 +++++++++ .../cases/uniqueResources/_data/Prefixes.pref | 2 ++ .../uniqueResources/_data/knowledge-base.ttl | 4 ++++ .../uniqueResources/_layouts/default.html | 12 ++++++++++ .../uniqueResources/test_unique_resources.rb | 23 +++++++++++++++++++ .../uniqueResources/uniqueResources.html | 22 ++++++++++++++++++ 12 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 test/cases/uniqueResources/Gemfile create mode 100644 test/cases/uniqueResources/_config.yml create mode 100644 test/cases/uniqueResources/_data/Prefixes.pref create mode 100644 test/cases/uniqueResources/_data/knowledge-base.ttl create mode 100644 test/cases/uniqueResources/_layouts/default.html create mode 100644 test/cases/uniqueResources/test_unique_resources.rb create mode 100644 test/cases/uniqueResources/uniqueResources.html diff --git a/lib/jekyll/filters/rdf_get.rb b/lib/jekyll/filters/rdf_get.rb index b191296a..f0c56b18 100644 --- a/lib/jekyll/filters/rdf_get.rb +++ b/lib/jekyll/filters/rdf_get.rb @@ -43,7 +43,7 @@ def rdf_get(request_uri) else exists = false || exists #take care of compatibility with virtuoso end - Jekyll::JekyllRdf::Drops::RdfResource.new(RDF::URI(request_uri[1..-2]), Jekyll::JekyllRdf::Helper::RdfHelper::site, Jekyll::JekyllRdf::Helper::RdfHelper::page, exists) + Jekyll::JekyllRdf::Helper::RdfHelper.resources(request_uri[1..-2], exists) end end end diff --git a/lib/jekyll/filters/rdf_property.rb b/lib/jekyll/filters/rdf_property.rb index 29d5c015..65022f9a 100644 --- a/lib/jekyll/filters/rdf_property.rb +++ b/lib/jekyll/filters/rdf_property.rb @@ -74,7 +74,7 @@ def filter_statements(n_triples, predicate, inverse = false, lang = nil) query = "SELECT ?s WHERE{ ?s #{predicate} #{n_triples} }" result = client.query(query).map do |solution| subject = RDF::URI(solution.s) - Jekyll::JekyllRdf::Drops::RdfResource.new(subject, Jekyll::JekyllRdf::Helper::RdfHelper::site, Jekyll::JekyllRdf::Helper::RdfHelper::page, true) + Jekyll::JekyllRdf::Helper::RdfHelper.resources(subject, true) end else query = "SELECT ?o ?dt ?lit ?lang WHERE{ #{n_triples} #{predicate} ?o BIND(datatype(?o) AS ?dt) BIND(isLiteral(?o) AS ?lit) BIND(lang(?o) AS ?lang) #{lang_query} }" @@ -95,7 +95,7 @@ def dist_literal_resource(solution) result = Jekyll::JekyllRdf::Drops::RdfLiteral.new(object) else object = RDF::URI(solution.o) - result = Jekyll::JekyllRdf::Drops::RdfResource.new(object, Jekyll::JekyllRdf::Helper::RdfHelper::site, Jekyll::JekyllRdf::Helper::RdfHelper::page, true) + result = Jekyll::JekyllRdf::Helper::RdfHelper.resources(object, true) end return result end diff --git a/lib/jekyll/helper/rdf_general_helper.rb b/lib/jekyll/helper/rdf_general_helper.rb index c709ef12..7dbee570 100644 --- a/lib/jekyll/helper/rdf_general_helper.rb +++ b/lib/jekyll/helper/rdf_general_helper.rb @@ -32,6 +32,9 @@ module Helper module RdfHelper @@prefixes = {} @@usePage = false + @@resources = {} + @@site = nil + @@page = nil def self.sparql= sparql @@sparql = sparql @@ -105,6 +108,23 @@ def self.pathiri= path def self.pathiri @@baseiri end + + def self.resources uri, exists = false + resource = @@resources[uri.to_s] + if resource.nil? + resource = Jekyll::JekyllRdf::Drops::RdfResource.new(RDF::URI(uri.to_s), @@site, @@page, exists) + @@resources[uri.to_s] = resource + end + return resource + end + + def self.reinitialize + @@prefixes.clear + @@usePage = false + @@resources.clear + @@site = nil + @@page = nil + end end #RdfHelper end #Helper end #JekyllRdf diff --git a/lib/jekyll/helper/rdf_generator_helper.rb b/lib/jekyll/helper/rdf_generator_helper.rb index e3443372..6346862f 100644 --- a/lib/jekyll/helper/rdf_generator_helper.rb +++ b/lib/jekyll/helper/rdf_generator_helper.rb @@ -20,7 +20,7 @@ def parse_resources (resources) @pageResources={}; @blanknodes=[] resources.each do |uri| - resource = Jekyll::JekyllRdf::Drops::RdfResource.new(uri, nil, nil, true) + resource = Jekyll::JekyllRdf::Helper::RdfHelper.resources(uri, true) if(uri.instance_of? RDF::URI) uriString = uri.to_s if((uriString.include? "#") && (uriString.index("#") < (uriString.length - 1))) #sorting in uris with a # @@ -41,7 +41,7 @@ def parse_resources (resources) end # give parents to orphaned resources @pageResources.each_key{|key| - @pageResources[key]['./'] = Jekyll::JekyllRdf::Drops::RdfResource.new(RDF::URI(key)) if @pageResources[key]['./'].nil? + @pageResources[key]['./'] = Jekyll::JekyllRdf::Helper::RdfHelper.resources(key) if @pageResources[key]['./'].nil? } end diff --git a/test/RdfTestUtility.rb b/test/RdfTestUtility.rb index e028a389..e2b70cd3 100644 --- a/test/RdfTestUtility.rb +++ b/test/RdfTestUtility.rb @@ -3,6 +3,7 @@ def setup_jekyll path @source = path config = Jekyll.configuration(YAML.load_file(File.join(@source, '_config.yml')).merge!({'source' => @source, 'destination' => File.join(@source, "_site")})) site = Jekyll::Site.new(config) + Jekyll::JekyllRdf::Helper::RdfHelper.reinitialize site.process end @@ -10,6 +11,7 @@ def setup_site_jekyll path @source = path config = Jekyll.configuration(YAML.load_file(File.join(@source, '_config.yml')).merge!({'source' => @source, 'destination' => File.join(@source, "_site")})) @site = Jekyll::Site.new(config) + Jekyll::JekyllRdf::Helper::RdfHelper.reinitialize @site.process end end \ No newline at end of file diff --git a/test/cases/uniqueResources/Gemfile b/test/cases/uniqueResources/Gemfile new file mode 100644 index 00000000..4d519ca0 --- /dev/null +++ b/test/cases/uniqueResources/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +group :jekyll_plugins do + gem 'jekyll-rdf', :path => '../../../' +end diff --git a/test/cases/uniqueResources/_config.yml b/test/cases/uniqueResources/_config.yml new file mode 100644 index 00000000..a1e219dd --- /dev/null +++ b/test/cases/uniqueResources/_config.yml @@ -0,0 +1,11 @@ +baseurl: "/instance" # the subpath of your site, e.g. /blog +url: "http://example.org/" # the base hostname & protocol for your site +# Build settings +markdown: kramdown +plugins: +- jekyll-rdf +jekyll_rdf: + path: "_data/knowledge-base.ttl" + restriction: "SELECT ?resourceUri WHERE {?resourceUri ?p ?o}" + default_template: "default" + diff --git a/test/cases/uniqueResources/_data/Prefixes.pref b/test/cases/uniqueResources/_data/Prefixes.pref new file mode 100644 index 00000000..cd1928d9 --- /dev/null +++ b/test/cases/uniqueResources/_data/Prefixes.pref @@ -0,0 +1,2 @@ +PREFIX eg: + diff --git a/test/cases/uniqueResources/_data/knowledge-base.ttl b/test/cases/uniqueResources/_data/knowledge-base.ttl new file mode 100644 index 00000000..5c782582 --- /dev/null +++ b/test/cases/uniqueResources/_data/knowledge-base.ttl @@ -0,0 +1,4 @@ +@prefix eg: . + +eg:resource eg:predicate eg:object . + diff --git a/test/cases/uniqueResources/_layouts/default.html b/test/cases/uniqueResources/_layouts/default.html new file mode 100644 index 00000000..96137a3e --- /dev/null +++ b/test/cases/uniqueResources/_layouts/default.html @@ -0,0 +1,12 @@ +--- +--- + + + + +
+

This is made with jekyll-rdf

+ {{content}} +
+ + diff --git a/test/cases/uniqueResources/test_unique_resources.rb b/test/cases/uniqueResources/test_unique_resources.rb new file mode 100644 index 00000000..2cd18ec2 --- /dev/null +++ b/test/cases/uniqueResources/test_unique_resources.rb @@ -0,0 +1,23 @@ +require 'test_helper' + +class TestRenderedAttribute < Test::Unit::TestCase + include RdfTestUtility + context "cases/uniqueResources" do + setup do + setup_jekyll File.dirname(__FILE__) + end + + should "create only one resource" do + content = [] + file = File.read(File.join(@source, "_site/uniqueResources.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + assert_equal "http://example.org/instance/resource", content[0] + assert_equal "http://example.org/instance/resource", content[1] + assert_equal "http://example.org/instance/resource", content[2] + resources = Jekyll::JekyllRdf::Helper::RdfHelper.class_variable_get(:@@resources) + assert resources.length.eql? 1 + end + end +end \ No newline at end of file diff --git a/test/cases/uniqueResources/uniqueResources.html b/test/cases/uniqueResources/uniqueResources.html new file mode 100644 index 00000000..dc003baf --- /dev/null +++ b/test/cases/uniqueResources/uniqueResources.html @@ -0,0 +1,22 @@ +--- +--- + + + + This Resource should be instantiated only once! + + + + + {%- assign resource1 = "" | rdf_get -%} + {%- assign resource2 = "" | rdf_get -%} + {%- assign resource3 = "" | rdf_get -%} +
+ {{resource1}} +
+ {{resource2}} +
+ {{resource3}} +
+ + From 79013280755053b14bff4d8818722044d7213784 Mon Sep 17 00:00:00 2001 From: Nime Date: Mon, 11 Mar 2019 18:08:20 +0100 Subject: [PATCH 46/85] resource.covered gets lazy loaded --- lib/jekyll/drops/rdf_resource.rb | 22 +++++++++++++------ lib/jekyll/drops/rdf_term.rb | 2 +- lib/jekyll/filters/rdf_get.rb | 9 +------- lib/jekyll/filters/rdf_property.rb | 4 ++-- lib/jekyll/helper/rdf_general_helper.rb | 12 ++++++++-- lib/jekyll/helper/rdf_generator_helper.rb | 2 +- test/cases/filter/test_rdf_filters.rb | 2 +- .../uniqueResources/test_unique_resources.rb | 2 +- 8 files changed, 32 insertions(+), 23 deletions(-) diff --git a/lib/jekyll/drops/rdf_resource.rb b/lib/jekyll/drops/rdf_resource.rb index 3013a974..9bdf69eb 100644 --- a/lib/jekyll/drops/rdf_resource.rb +++ b/lib/jekyll/drops/rdf_resource.rb @@ -42,11 +42,6 @@ class RdfResource < RdfTerm # attr_accessor :page - ## - # - # - attr_reader :covered - ## # # @@ -55,7 +50,7 @@ class RdfResource < RdfTerm ## # # - def initialize(term, site = nil, page = nil, covered = false) + def initialize(term, site = nil, page = nil) super(term) if(site.is_a?(Jekyll::Site)) @site = site @@ -64,7 +59,6 @@ def initialize(term, site = nil, page = nil, covered = false) @page = page end @subResources = {} - @covered = covered @iri = term.to_s @blank = false begin @@ -87,6 +81,20 @@ def ready? return (@site.is_a?(Jekyll::Site)||@page.is_a?(Jekyll::Page)) end + ## + # Returns true if the resource base containes this resource + # + def covered + return @covered unless @covered.nil? + ask_exist = "ASK WHERE {{#{term.to_ntriples} ?p ?o}UNION{?s #{term.to_ntriples} ?o}UNION{?s ?p #{term.to_ntriples}}} " + @covered = Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(ask_exist) + if(@covered.instance_of? RDF::Literal::Boolean) + @covered = @covered.true? + else + @covered = false || @covered #take care of compatibility with virtuoso + end + end + ## # Return a list of Jekyll::JekyllRdf::Drops::RdfStatements whose subject, predicate or object is the RDF resource represented by the receiver # diff --git a/lib/jekyll/drops/rdf_term.rb b/lib/jekyll/drops/rdf_term.rb index 42346ad3..3c0e9c13 100644 --- a/lib/jekyll/drops/rdf_term.rb +++ b/lib/jekyll/drops/rdf_term.rb @@ -90,7 +90,7 @@ def ===(other_obj) def self.build_term_drop(term, site, covered) case term when RDF::URI, RDF::Node - return RdfResource.new(term, site, nil, covered) + return Jekyll::JekyllRdf::Helper::RdfHelper.resources(term) when RDF::Literal return RdfLiteral.new(term) else diff --git a/lib/jekyll/filters/rdf_get.rb b/lib/jekyll/filters/rdf_get.rb index f0c56b18..784188d1 100644 --- a/lib/jekyll/filters/rdf_get.rb +++ b/lib/jekyll/filters/rdf_get.rb @@ -36,14 +36,7 @@ def rdf_get(request_uri) request_uri = to_string_wrap(rdf_page_to_resource(request_uri)) return unless valid_resource?(request_uri) && (!request_uri[0..1].eql? "_:") request_uri = rdf_resolve_prefix(request_uri) - ask_exist = "ASK WHERE {{#{request_uri} ?p ?o}UNION{?s #{request_uri} ?o}UNION{?s ?p #{request_uri}}} " - exists = Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(ask_exist) - if(exists.instance_of? RDF::Literal::Boolean) - exists = exists.true? - else - exists = false || exists #take care of compatibility with virtuoso - end - Jekyll::JekyllRdf::Helper::RdfHelper.resources(request_uri[1..-2], exists) + Jekyll::JekyllRdf::Helper::RdfHelper.resources(request_uri[1..-2]) end end end diff --git a/lib/jekyll/filters/rdf_property.rb b/lib/jekyll/filters/rdf_property.rb index 65022f9a..b8319653 100644 --- a/lib/jekyll/filters/rdf_property.rb +++ b/lib/jekyll/filters/rdf_property.rb @@ -74,7 +74,7 @@ def filter_statements(n_triples, predicate, inverse = false, lang = nil) query = "SELECT ?s WHERE{ ?s #{predicate} #{n_triples} }" result = client.query(query).map do |solution| subject = RDF::URI(solution.s) - Jekyll::JekyllRdf::Helper::RdfHelper.resources(subject, true) + Jekyll::JekyllRdf::Helper::RdfHelper.resources(subject) end else query = "SELECT ?o ?dt ?lit ?lang WHERE{ #{n_triples} #{predicate} ?o BIND(datatype(?o) AS ?dt) BIND(isLiteral(?o) AS ?lit) BIND(lang(?o) AS ?lang) #{lang_query} }" @@ -95,7 +95,7 @@ def dist_literal_resource(solution) result = Jekyll::JekyllRdf::Drops::RdfLiteral.new(object) else object = RDF::URI(solution.o) - result = Jekyll::JekyllRdf::Helper::RdfHelper.resources(object, true) + result = Jekyll::JekyllRdf::Helper::RdfHelper.resources(object) end return result end diff --git a/lib/jekyll/helper/rdf_general_helper.rb b/lib/jekyll/helper/rdf_general_helper.rb index 7dbee570..77acb257 100644 --- a/lib/jekyll/helper/rdf_general_helper.rb +++ b/lib/jekyll/helper/rdf_general_helper.rb @@ -109,15 +109,23 @@ def self.pathiri @@baseiri end - def self.resources uri, exists = false + ## + # Constructs and returns a Jekyll::JekyllRdf::Drops::RdfResource. If the + # uri refers to an already created resource, this method wont create a + # new resource. + # + def self.resources uri resource = @@resources[uri.to_s] if resource.nil? - resource = Jekyll::JekyllRdf::Drops::RdfResource.new(RDF::URI(uri.to_s), @@site, @@page, exists) + resource = Jekyll::JekyllRdf::Drops::RdfResource.new(RDF::URI(uri.to_s), @@site, @@page) @@resources[uri.to_s] = resource end return resource end + ## + # resets RdfHelper to its initialization values + # def self.reinitialize @@prefixes.clear @@usePage = false diff --git a/lib/jekyll/helper/rdf_generator_helper.rb b/lib/jekyll/helper/rdf_generator_helper.rb index 6346862f..28e57214 100644 --- a/lib/jekyll/helper/rdf_generator_helper.rb +++ b/lib/jekyll/helper/rdf_generator_helper.rb @@ -20,7 +20,7 @@ def parse_resources (resources) @pageResources={}; @blanknodes=[] resources.each do |uri| - resource = Jekyll::JekyllRdf::Helper::RdfHelper.resources(uri, true) + resource = Jekyll::JekyllRdf::Helper::RdfHelper.resources(uri) if(uri.instance_of? RDF::URI) uriString = uri.to_s if((uriString.include? "#") && (uriString.index("#") < (uriString.length - 1))) #sorting in uris with a # diff --git a/test/cases/filter/test_rdf_filters.rb b/test/cases/filter/test_rdf_filters.rb index 21438616..16ce08b7 100644 --- a/test/cases/filter/test_rdf_filters.rb +++ b/test/cases/filter/test_rdf_filters.rb @@ -335,7 +335,7 @@ def config end should "return the input if the input is a resource" do - resource = Jekyll::JekyllRdf::Drops::RdfResource.new("http://example.org/instance/resource", nil, nil, true) + resource = Jekyll::JekyllRdf::Drops::RdfResource.new("http://example.org/instance/resource") assert_equal resource, rdf_get(resource) end diff --git a/test/cases/uniqueResources/test_unique_resources.rb b/test/cases/uniqueResources/test_unique_resources.rb index 2cd18ec2..ecc86fa3 100644 --- a/test/cases/uniqueResources/test_unique_resources.rb +++ b/test/cases/uniqueResources/test_unique_resources.rb @@ -17,7 +17,7 @@ class TestRenderedAttribute < Test::Unit::TestCase assert_equal "http://example.org/instance/resource", content[1] assert_equal "http://example.org/instance/resource", content[2] resources = Jekyll::JekyllRdf::Helper::RdfHelper.class_variable_get(:@@resources) - assert resources.length.eql? 1 + assert_equal 3, resources.length # 3 because the template mapping creates additional resources end end end \ No newline at end of file From 4d1ef8b3da90278d68ad156769beb90291c2736a Mon Sep 17 00:00:00 2001 From: Nime Date: Mon, 11 Mar 2019 20:19:12 +0100 Subject: [PATCH 47/85] separate data from graphs and construct queries --- lib/jekyll/filters/rdf_sparql_query.rb | 1 - test/cases/constructQueries/constructs.html | 6 ------ .../constructQueries/test_construct_queries.rb | 17 ++++------------- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/lib/jekyll/filters/rdf_sparql_query.rb b/lib/jekyll/filters/rdf_sparql_query.rb index 8bdccb44..75189f3d 100644 --- a/lib/jekyll/filters/rdf_sparql_query.rb +++ b/lib/jekyll/filters/rdf_sparql_query.rb @@ -43,7 +43,6 @@ def sparql_query(resource = nil, query) begin result = Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(query) if (result.class == RDF::Graph) - Jekyll::JekyllRdf::Helper::RdfHelper::sparql.insert_data(result) return Jekyll::JekyllRdf::Drops::RdfGraph.new(result) end result.map! do |solution| diff --git a/test/cases/constructQueries/constructs.html b/test/cases/constructQueries/constructs.html index 7753b4ba..f6df7290 100644 --- a/test/cases/constructQueries/constructs.html +++ b/test/cases/constructQueries/constructs.html @@ -10,13 +10,7 @@ {%- assign cquery = "CONSTRUCT {?x } where {?x }" -%} {%- assign test = cquery | sparql_query -%} - {%- assign query = "SELECT ?res {?res }" -%} - {%- assign results = query | sparql_query -%}
- {%- for result in results -%} - {{ result.res }} -
- {%- endfor -%} {{ test }}
{%- assign nquads = test.to_nquads -%} diff --git a/test/cases/constructQueries/test_construct_queries.rb b/test/cases/constructQueries/test_construct_queries.rb index e78fdaa9..dd21a607 100644 --- a/test/cases/constructQueries/test_construct_queries.rb +++ b/test/cases/constructQueries/test_construct_queries.rb @@ -13,25 +13,16 @@ class TestSciMath < Test::Unit::TestCase content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| entry.strip end - assert_equal 6, content.length - assert (content[0].eql?("http://example.org/instance/resource1") || content[0].eql?("http://example.org/instance/resource2") || content[0].eql?("http://example.org/instance/resource3")), "The
should contain http://example.org/instance/resource1, http://example.org/instance/resource2 and http://example.org/instance/resource3 at first position.\n It was: >#{content[0]}<." - assert (content[1].eql?("http://example.org/instance/resource1") || content[1].eql?("http://example.org/instance/resource2") || content[1].eql?("http://example.org/instance/resource3")), "The
should contain http://example.org/instance/resource1, http://example.org/instance/resource2 and http://example.org/instance/resource3 at second position.\n It was: >#{content[1]}<." - assert (content[2].eql?("http://example.org/instance/resource1") || content[2].eql?("http://example.org/instance/resource2") || content[2].eql?("http://example.org/instance/resource3")), "The
should contain http://example.org/instance/resource1, http://example.org/instance/resource2 and http://example.org/instance/resource3 at third position.\n It was: >#{content[2]}<." - assert content.include?("http://example.org/instance/resource1"), "The
should include http://example.org/instance/resource1." - assert content.include?("http://example.org/instance/resource2"), "The
should include http://example.org/instance/resource2." - assert content.include?("http://example.org/instance/resource3"), "The
should include http://example.org/instance/resource3." - assert !content.include?("http://example.org/instance/resource4"), "The
should not include http://example.org/instance/resource4." - assert !content.include?("http://example.org/instance/resource5"), "The
should not include http://example.org/instance/resource5." - assert !content.include?("http://example.org/instance/resource6"), "The
should not include http://example.org/instance/resource6." - nquads = content[3].split("\n") + assert_equal 3, content.length + nquads = content[0].split("\n") assert (nquads.include? " ."), "the return graph should contain >>> <<<" assert (nquads.include? " ."), "the return graph should contain >>> <<<" assert (nquads.include? " ."), "the return graph should contain >>> <<<" - nquads = content[4].split("\n") + nquads = content[1].split("\n") assert (nquads.include? " ."), "the return graph should contain >>> <<<" assert (nquads.include? " ."), "the return graph should contain >>> <<<" assert (nquads.include? " ."), "the return graph should contain >>> <<<" - ntriples = content[5].split("\n") + ntriples = content[2].split("\n") assert (ntriples.include? " ."), "the return graph should contain >>> <<<" assert (ntriples.include? " ."), "the return graph should contain >>> <<<" assert (ntriples.include? " ."), "the return graph should contain >>> <<<" From 366694369af3ce8aac1fe8f7d9190e69fe929798 Mon Sep 17 00:00:00 2001 From: Nime Date: Mon, 11 Mar 2019 23:42:55 +0100 Subject: [PATCH 48/85] move prefix loading into the pre_render hooks --- lib/jekyll/helper/rdf_hook_helper.rb | 23 +++++++++++++++++++++++ lib/jekyll/helper/rdf_page_helper.rb | 10 ---------- lib/jekyll/hooks/rdf_page_pointer.rb | 24 +++--------------------- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/lib/jekyll/helper/rdf_hook_helper.rb b/lib/jekyll/helper/rdf_hook_helper.rb index 89782030..9e3be5b1 100644 --- a/lib/jekyll/helper/rdf_hook_helper.rb +++ b/lib/jekyll/helper/rdf_hook_helper.rb @@ -26,6 +26,29 @@ module Jekyll module JekyllRdf module Helper module RdfHookHelper + def backload_prefixes page, payload + prefix_path = page.data["rdf_prefix_path"] + # posts frontmatter does not contain values from layout frontmatters + if(prefix_path.nil?) + unless(payload.layout.nil? || page.data["layout"].nil?) + prefix_path = payload.layout["rdf_prefix_path"] + base_path = search_prefix_definition page.site.layouts[page.data["layout"]], prefix_path + end + else + base_path = payload.site["source"]#page.path[0..-(page.relative_path.length + 1)] + end + + if(page.data["rdf_prefixes"].nil? && !(prefix_path.nil? || base_path.nil?)) + Jekyll::JekyllRdf::Helper::RdfHelper.load_prefixes( + File.join( + base_path, + prefix_path + ), + page.data + ) + end + end + def search_prefix_definition layout, rdf_prefix_path if(rdf_prefix_path.eql? layout.data["rdf_prefix_path"]) return layout.instance_variable_get(:@base_dir) diff --git a/lib/jekyll/helper/rdf_page_helper.rb b/lib/jekyll/helper/rdf_page_helper.rb index b9106601..b3962820 100644 --- a/lib/jekyll/helper/rdf_page_helper.rb +++ b/lib/jekyll/helper/rdf_page_helper.rb @@ -36,7 +36,6 @@ def re_init_as_rdf(resource, mapper) load_data(@site) self.data['permalink'] = File.join(@dir, @name) #overwrite permalinks to stop them from interfering with JekyllRdfs rendersystem return unless @complete - load_prefixes_yaml() resource.page = self resource.site = @site @site.data['resources'] << resource @@ -109,15 +108,6 @@ def setData self.data['rdf'] = @resource self.data['template'] = @template end - - ## - # loads the prefix data passed in the layout yaml-frontmatter into page.data["rdf_prefixes"] and page.data["rdf_prefix_map"] - def load_prefixes_yaml - unless self.data["rdf_prefix_path"].nil? - load_prefixes(File.join(@site.layouts[@template].instance_variable_get(:@base_dir), self.data["rdf_prefix_path"].strip), self.data) - end - end - end end diff --git a/lib/jekyll/hooks/rdf_page_pointer.rb b/lib/jekyll/hooks/rdf_page_pointer.rb index 526d51f4..e4efee55 100644 --- a/lib/jekyll/hooks/rdf_page_pointer.rb +++ b/lib/jekyll/hooks/rdf_page_pointer.rb @@ -27,9 +27,8 @@ unless(page.data['rdf'].nil?) payload["content"] = "" end - if(page.data["rdf_prefixes"].nil? && !page.data["rdf_prefix_path"].nil?) - Jekyll::JekyllRdf::Helper::RdfHelper.load_prefixes(File.join(page.instance_variable_get(:@base), page.data["rdf_prefix_path"]), page.data) - end + include Jekyll::JekyllRdf::Helper::RdfHookHelper + backload_prefixes page, payload Jekyll::JekyllRdf::Helper::RdfHelper::page = page end @@ -39,23 +38,6 @@ Jekyll::Hooks.register :posts, :pre_render do |page, payload| include Jekyll::JekyllRdf::Helper::RdfHookHelper - prefix_path = page.data["rdf_prefix_path"] - # posts frontmatter does not contain values from layout frontmatters - if(prefix_path.nil?) - prefix_path = payload.layout["rdf_prefix_path"] - base_path = search_prefix_definition page.site.layouts[page.data["layout"]], prefix_path - else - base_path = page.path[0..-(page.relative_path.length + 1)] - end - - if(page.data["rdf_prefixes"].nil? && !(prefix_path.nil? || base_path.nil?)) - Jekyll::JekyllRdf::Helper::RdfHelper.load_prefixes( - File.join( - base_path, - prefix_path - ), - page.data - ) - end + backload_prefixes page, payload Jekyll::JekyllRdf::Helper::RdfHelper::page = page end From 6a62eb7b728c212f155d125769899b7c262815f2 Mon Sep 17 00:00:00 2001 From: Nime Date: Tue, 12 Mar 2019 19:10:08 +0100 Subject: [PATCH 49/85] reworked prefix page assignment --- lib/jekyll/helper/rdf_hook_helper.rb | 38 ++++++++++++++++++++++------ lib/jekyll/helper/rdf_page_helper.rb | 11 ++++++++ lib/jekyll/hooks/rdf_page_pointer.rb | 26 ++++++++++++++++++- 3 files changed, 66 insertions(+), 9 deletions(-) diff --git a/lib/jekyll/helper/rdf_hook_helper.rb b/lib/jekyll/helper/rdf_hook_helper.rb index 9e3be5b1..de14aea6 100644 --- a/lib/jekyll/helper/rdf_hook_helper.rb +++ b/lib/jekyll/helper/rdf_hook_helper.rb @@ -28,14 +28,19 @@ module Helper module RdfHookHelper def backload_prefixes page, payload prefix_path = page.data["rdf_prefix_path"] - # posts frontmatter does not contain values from layout frontmatters - if(prefix_path.nil?) - unless(payload.layout.nil? || page.data["layout"].nil?) - prefix_path = payload.layout["rdf_prefix_path"] - base_path = search_prefix_definition page.site.layouts[page.data["layout"]], prefix_path - end - else - base_path = payload.site["source"]#page.path[0..-(page.relative_path.length + 1)] + if(!prefix_path.nil? && !page.data["rdf_prefix_set?"] && !page.data["layout"].nil?) + # rdf_prefix_path is set but not defined through the page + base_path = search_prefix_definition page.site.layouts[page.data["layout"]], prefix_path + elsif (prefix_path.nil? && !page.data["layout"].nil?) + # page might be a post (does not contain values from layout frontmatter) + # |->rdf_prefix_path can still be set in a layout + locations = check_prefix_definition page.site.layouts[page.data["layout"]] + base_path = locations[0] + prefix_path = locations[1] + elsif(!prefix_path.nil? && page.data["rdf_prefix_set?"]) + # rdf_prefix_path is set directly in the fronmatter of the page + base_path = page.instance_variable_get(:@base_dir) + base_path ||= payload.site["source"] end if(page.data["rdf_prefixes"].nil? && !(prefix_path.nil? || base_path.nil?)) @@ -55,6 +60,23 @@ def search_prefix_definition layout, rdf_prefix_path end return search_prefix_definition layout.site.layouts[layout.data["layout"]], rdf_prefix_path end + + def check_prefix_definition layout + unless(layout.data["rdf_prefix_path"].nil?) + return [layout.instance_variable_get(:@base_dir), layout.data["rdf_prefix_path"]] + end + return check_prefix_definition layout.site.layouts[layout.data["layout"]] unless layout.data["layout"].nil? + return [nil, nil] + end + + private + class EqualObject + def eql? object + true + end + end + + @@equal_object = EqualObject.new end end end diff --git a/lib/jekyll/helper/rdf_page_helper.rb b/lib/jekyll/helper/rdf_page_helper.rb index b3962820..211a6b42 100644 --- a/lib/jekyll/helper/rdf_page_helper.rb +++ b/lib/jekyll/helper/rdf_page_helper.rb @@ -36,6 +36,7 @@ def re_init_as_rdf(resource, mapper) load_data(@site) self.data['permalink'] = File.join(@dir, @name) #overwrite permalinks to stop them from interfering with JekyllRdfs rendersystem return unless @complete + load_prefixes_yaml() resource.page = self resource.site = @site @site.data['resources'] << resource @@ -108,6 +109,16 @@ def setData self.data['rdf'] = @resource self.data['template'] = @template end + + ## + # loads the prefix data passed in the layout yaml-frontmatter into page.data["rdf_prefixes"] and page.data["rdf_prefix_map"] + # only covers a specific case that can not be done by hooks (rdf_prefix_path is defined in a template that serves as page object) + def load_prefixes_yaml + unless self.data["rdf_prefix_path"].nil? + load_prefixes(File.join(@site.layouts[@template].instance_variable_get(:@base_dir), self.data["rdf_prefix_path"].strip), self.data) + end + end + end end diff --git a/lib/jekyll/hooks/rdf_page_pointer.rb b/lib/jekyll/hooks/rdf_page_pointer.rb index e4efee55..cb786567 100644 --- a/lib/jekyll/hooks/rdf_page_pointer.rb +++ b/lib/jekyll/hooks/rdf_page_pointer.rb @@ -22,13 +22,37 @@ # SOFTWARE. # +Jekyll::Hooks.register :documents, :post_init do |page| + if(page.data["rdf_prefix_path"].nil?) + page.data["rdf_prefix_set?"] = false + else + page.data["rdf_prefix_set?"] = true + end +end + +Jekyll::Hooks.register :pages, :post_init do |page| + if(page.data["rdf_prefix_path"].nil?) + page.data["rdf_prefix_set?"] = false + else + page.data["rdf_prefix_set?"] = true + end +end + +Jekyll::Hooks.register :posts, :post_init do |page| + if(page.data["rdf_prefix_path"].nil?) + page.data["rdf_prefix_set?"] = false + else + page.data["rdf_prefix_set?"] = true + end +end + Jekyll::Hooks.register :pages, :pre_render do |page, payload| unless(page.data['rdf'].nil?) payload["content"] = "" end include Jekyll::JekyllRdf::Helper::RdfHookHelper - backload_prefixes page, payload + backload_prefixes page, payload if page.data["rdf_prefixes"].nil? Jekyll::JekyllRdf::Helper::RdfHelper::page = page end From 72d942df612aee34521f9c1ecb91c242a23d602d Mon Sep 17 00:00:00 2001 From: Nime Date: Tue, 12 Mar 2019 21:44:54 +0100 Subject: [PATCH 50/85] added sanity check for search_prefix_definition --- lib/jekyll/helper/rdf_hook_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/helper/rdf_hook_helper.rb b/lib/jekyll/helper/rdf_hook_helper.rb index de14aea6..b32f45fb 100644 --- a/lib/jekyll/helper/rdf_hook_helper.rb +++ b/lib/jekyll/helper/rdf_hook_helper.rb @@ -58,7 +58,8 @@ def search_prefix_definition layout, rdf_prefix_path if(rdf_prefix_path.eql? layout.data["rdf_prefix_path"]) return layout.instance_variable_get(:@base_dir) end - return search_prefix_definition layout.site.layouts[layout.data["layout"]], rdf_prefix_path + return search_prefix_definition layout.site.layouts[layout.data["layout"]], rdf_prefix_path unless layout.data["layout"].nil? + return nil end def check_prefix_definition layout From e4f0988b771f7693cc68421af1af30412e7d4c79 Mon Sep 17 00:00:00 2001 From: Nime Date: Wed, 13 Mar 2019 00:07:16 +0100 Subject: [PATCH 51/85] missing template should not crash jekyll --- lib/jekyll/helper/rdf_hook_helper.rb | 36 +++++++++++++++++----------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/jekyll/helper/rdf_hook_helper.rb b/lib/jekyll/helper/rdf_hook_helper.rb index b32f45fb..e208bd69 100644 --- a/lib/jekyll/helper/rdf_hook_helper.rb +++ b/lib/jekyll/helper/rdf_hook_helper.rb @@ -28,21 +28,29 @@ module Helper module RdfHookHelper def backload_prefixes page, payload prefix_path = page.data["rdf_prefix_path"] - if(!prefix_path.nil? && !page.data["rdf_prefix_set?"] && !page.data["layout"].nil?) - # rdf_prefix_path is set but not defined through the page - base_path = search_prefix_definition page.site.layouts[page.data["layout"]], prefix_path - elsif (prefix_path.nil? && !page.data["layout"].nil?) - # page might be a post (does not contain values from layout frontmatter) - # |->rdf_prefix_path can still be set in a layout - locations = check_prefix_definition page.site.layouts[page.data["layout"]] - base_path = locations[0] - prefix_path = locations[1] - elsif(!prefix_path.nil? && page.data["rdf_prefix_set?"]) - # rdf_prefix_path is set directly in the fronmatter of the page - base_path = page.instance_variable_get(:@base_dir) - base_path ||= payload.site["source"] + begin + if(!prefix_path.nil? && !page.data["rdf_prefix_set?"] && !page.data["layout"].nil?) + # rdf_prefix_path is set but not defined through the page + base_path = search_prefix_definition page.site.layouts[page.data["layout"]], prefix_path + elsif (prefix_path.nil? && !page.data["layout"].nil?) + # page might be a post (does not contain values from layout frontmatter) + # |->rdf_prefix_path can still be set in a layout + locations = check_prefix_definition page.site.layouts[page.data["layout"]] + base_path = locations[0] + prefix_path = locations[1] + elsif(!prefix_path.nil? && page.data["rdf_prefix_set?"]) + # rdf_prefix_path is set directly in the fronmatter of the page + base_path = page.instance_variable_get(:@base_dir) + base_path ||= payload.site["source"] + end + rescue NoMethodError => ne + #just in case the error was caused by something different then a missing template + if(ne.message.eql? "undefined method `data' for nil:NilClass") + return + else + raise + end end - if(page.data["rdf_prefixes"].nil? && !(prefix_path.nil? || base_path.nil?)) Jekyll::JekyllRdf::Helper::RdfHelper.load_prefixes( File.join( From a64677dac6ff1689eb0e5e4d3bc6f5966f820a81 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Wed, 13 Mar 2019 10:16:17 +0100 Subject: [PATCH 52/85] Add prefixesInPostsWithGemTheme test --- .../cases/prefixesInPostsWithGemTheme/Gemfile | 5 +++++ .../prefixesInPostsWithGemTheme/_config.yml | 10 +++++++++ .../_data/knowledge-base.ttl | 5 +++++ .../_posts/2019-02-12-Blogpost.md | 5 +++++ .../prefixesInPostsWithGemTheme/blog.html | 5 +++++ .../test_prefixes.rb | 21 +++++++++++++++++++ 6 files changed, 51 insertions(+) create mode 100644 test/cases/prefixesInPostsWithGemTheme/Gemfile create mode 100644 test/cases/prefixesInPostsWithGemTheme/_config.yml create mode 100644 test/cases/prefixesInPostsWithGemTheme/_data/knowledge-base.ttl create mode 100644 test/cases/prefixesInPostsWithGemTheme/_posts/2019-02-12-Blogpost.md create mode 100644 test/cases/prefixesInPostsWithGemTheme/blog.html create mode 100644 test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb diff --git a/test/cases/prefixesInPostsWithGemTheme/Gemfile b/test/cases/prefixesInPostsWithGemTheme/Gemfile new file mode 100644 index 00000000..77abcf66 --- /dev/null +++ b/test/cases/prefixesInPostsWithGemTheme/Gemfile @@ -0,0 +1,5 @@ +source 'https://rubygems.org' +group :jekyll_plugins do + gem "jekyll-theme-jod", "= 0.1.9" + gem 'jekyll-rdf', :path => '../../../' +end diff --git a/test/cases/prefixesInPostsWithGemTheme/_config.yml b/test/cases/prefixesInPostsWithGemTheme/_config.yml new file mode 100644 index 00000000..9af24458 --- /dev/null +++ b/test/cases/prefixesInPostsWithGemTheme/_config.yml @@ -0,0 +1,10 @@ +baseurl: "" +url: "http://example.org/" + +theme: jekyll-theme-jod +plugins: +- jekyll-rdf +jekyll_rdf: + path: "_data/knowledge-base.ttl" + restriction: "SELECT ?resourceUri WHERE {?resourceUri ?p ?o}" + default_template: "ontology" diff --git a/test/cases/prefixesInPostsWithGemTheme/_data/knowledge-base.ttl b/test/cases/prefixesInPostsWithGemTheme/_data/knowledge-base.ttl new file mode 100644 index 00000000..08533bee --- /dev/null +++ b/test/cases/prefixesInPostsWithGemTheme/_data/knowledge-base.ttl @@ -0,0 +1,5 @@ +@prefix rdfs: . +@prefix owl: . + + a owl:Ontology ; + rdfs:label "My Jekyll RDF Blog" . diff --git a/test/cases/prefixesInPostsWithGemTheme/_posts/2019-02-12-Blogpost.md b/test/cases/prefixesInPostsWithGemTheme/_posts/2019-02-12-Blogpost.md new file mode 100644 index 00000000..84a7d539 --- /dev/null +++ b/test/cases/prefixesInPostsWithGemTheme/_posts/2019-02-12-Blogpost.md @@ -0,0 +1,5 @@ +--- +layout: ontology +--- + +This is a Blogpost diff --git a/test/cases/prefixesInPostsWithGemTheme/blog.html b/test/cases/prefixesInPostsWithGemTheme/blog.html new file mode 100644 index 00000000..ac960f63 --- /dev/null +++ b/test/cases/prefixesInPostsWithGemTheme/blog.html @@ -0,0 +1,5 @@ +--- +layout: ontology +--- + +A page diff --git a/test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb b/test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb new file mode 100644 index 00000000..50208a47 --- /dev/null +++ b/test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb @@ -0,0 +1,21 @@ +require 'test_helper' + +class TestPrefixes < Test::Unit::TestCase + context "load_prefixes form RdfPageHelper" do + include RdfTestUtility + should "map prefixes for posts also when using a gem theme" do + setup_jekyll File.dirname(__FILE__) + + content = [] + file = File.read(File.join(@source, "_site/2019/02/12/Blogpost.html")) + content = file[/\(.|\s)*\<\/body\>/][6..-6].strip.split("\n").map do |entry| + entry.strip + end + + #TODO This test case has to be completed once jekyll runs successfull + + assert_equal "

My Jekyll RDF Blog

", content[0] + assert_equal "

This is a Blogpost

", content[2] + end + end +end From 561e1363672a40f0017fdc3666de2a33306930dd Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Wed, 13 Mar 2019 10:27:45 +0100 Subject: [PATCH 53/85] Add test for undefined layouts --- test/cases/dontFailIfLayoutNoFound/Gemfile | 4 ++++ .../cases/dontFailIfLayoutNoFound/_config.yml | 9 +++++++++ .../_data/knowledge-base.ttl | 0 .../_posts/2019-02-12-Blogpost.md | 5 +++++ test/cases/dontFailIfLayoutNoFound/blog.html | 5 +++++ .../dontFailIfLayoutNoFound/test_prefixes.rb | 19 +++++++++++++++++++ 6 files changed, 42 insertions(+) create mode 100644 test/cases/dontFailIfLayoutNoFound/Gemfile create mode 100644 test/cases/dontFailIfLayoutNoFound/_config.yml create mode 100644 test/cases/dontFailIfLayoutNoFound/_data/knowledge-base.ttl create mode 100644 test/cases/dontFailIfLayoutNoFound/_posts/2019-02-12-Blogpost.md create mode 100644 test/cases/dontFailIfLayoutNoFound/blog.html create mode 100644 test/cases/dontFailIfLayoutNoFound/test_prefixes.rb diff --git a/test/cases/dontFailIfLayoutNoFound/Gemfile b/test/cases/dontFailIfLayoutNoFound/Gemfile new file mode 100644 index 00000000..4d519ca0 --- /dev/null +++ b/test/cases/dontFailIfLayoutNoFound/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +group :jekyll_plugins do + gem 'jekyll-rdf', :path => '../../../' +end diff --git a/test/cases/dontFailIfLayoutNoFound/_config.yml b/test/cases/dontFailIfLayoutNoFound/_config.yml new file mode 100644 index 00000000..ea0111a6 --- /dev/null +++ b/test/cases/dontFailIfLayoutNoFound/_config.yml @@ -0,0 +1,9 @@ +baseurl: "" +url: "http://example.org/" + +plugins: +- jekyll-rdf +jekyll_rdf: + path: "_data/knowledge-base.ttl" + restriction: "SELECT ?resourceUri WHERE {?resourceUri ?p ?o}" + default_template: "ontology" diff --git a/test/cases/dontFailIfLayoutNoFound/_data/knowledge-base.ttl b/test/cases/dontFailIfLayoutNoFound/_data/knowledge-base.ttl new file mode 100644 index 00000000..e69de29b diff --git a/test/cases/dontFailIfLayoutNoFound/_posts/2019-02-12-Blogpost.md b/test/cases/dontFailIfLayoutNoFound/_posts/2019-02-12-Blogpost.md new file mode 100644 index 00000000..84a7d539 --- /dev/null +++ b/test/cases/dontFailIfLayoutNoFound/_posts/2019-02-12-Blogpost.md @@ -0,0 +1,5 @@ +--- +layout: ontology +--- + +This is a Blogpost diff --git a/test/cases/dontFailIfLayoutNoFound/blog.html b/test/cases/dontFailIfLayoutNoFound/blog.html new file mode 100644 index 00000000..ec4f0f06 --- /dev/null +++ b/test/cases/dontFailIfLayoutNoFound/blog.html @@ -0,0 +1,5 @@ +--- +layout: special +--- + +A page diff --git a/test/cases/dontFailIfLayoutNoFound/test_prefixes.rb b/test/cases/dontFailIfLayoutNoFound/test_prefixes.rb new file mode 100644 index 00000000..f2335e5d --- /dev/null +++ b/test/cases/dontFailIfLayoutNoFound/test_prefixes.rb @@ -0,0 +1,19 @@ +require 'test_helper' + +class TestPrefixes < Test::Unit::TestCase + context "load_prefixes form RdfPageHelper" do + include RdfTestUtility + should "check that the prefix search doesnot fail of an undefined layout is specified" do + setup_jekyll File.dirname(__FILE__) + + content = [] + blogfile = File.read(File.join(@source, "_site/2019/02/12/Blogpost.html")) + page = File.read(File.join(@source, "_site/blog.html")) + + #TODO This test case has to be completed once jekyll runs successfull + + assert_equal "

This is a Blogpost

", blogfile.strip() + assert_equal "A page", page.strip() + end + end +end From b5dbd12ac78060758a211102c82f02fced51c6f7 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Wed, 13 Mar 2019 11:06:09 +0100 Subject: [PATCH 54/85] Require jekyll-rdf after starting coveralls --- test/test_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 6b21b6c9..96936e56 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -6,8 +6,9 @@ require 'coveralls' require 'ResourceHelper' require 'RdfTestUtility' -require_relative '../lib/jekyll-rdf' + Coveralls.wear! +require_relative '../lib/jekyll-rdf' Jekyll.logger.log_level = :error class TestHelper From 3924d7730b5332764b2f94a744da0fa180643f4e Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Wed, 13 Mar 2019 11:25:42 +0100 Subject: [PATCH 55/85] Configre filter to exclude vendor and test --- test/test_helper.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 96936e56..a79777ec 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -3,11 +3,18 @@ require 'shoulda-context' require 'rspec/expectations' require 'pry' +require 'simplecov' require 'coveralls' require 'ResourceHelper' require 'RdfTestUtility' -Coveralls.wear! +SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([ + SimpleCov::Formatter::HTMLFormatter, + Coveralls::SimpleCov::Formatter +]) +SimpleCov.start do + add_filter ["/.vendor", "/vendor", "/test"] +end require_relative '../lib/jekyll-rdf' Jekyll.logger.log_level = :error From 8fe18a4e68b8ca0624b87979cbb0e5072b5cce0a Mon Sep 17 00:00:00 2001 From: Nime Date: Mon, 25 Mar 2019 12:19:09 +0100 Subject: [PATCH 56/85] Proposed changes for test prefixesInPostsWithGemTheme --- .travis.yml | 3 +++ Gemfile | 3 +++ test/cases/prefixesInPostsWithGemTheme/Gemfile | 2 +- test/cases/prefixesInPostsWithGemTheme/_config.yml | 2 +- .../prefixesInPostsWithGemTheme/test_prefixes.rb | 2 +- test/theme-gem/Gemfile | 4 ++++ test/theme-gem/_layouts/ontology.html | 13 +++++++++++++ test/theme-gem/theme-gem.gemspec | 13 +++++++++++++ 8 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 test/theme-gem/Gemfile create mode 100644 test/theme-gem/_layouts/ontology.html create mode 100644 test/theme-gem/theme-gem.gemspec diff --git a/.travis.yml b/.travis.yml index 9aade6ed..973c29f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,9 @@ matrix: - rvm: ruby-head before_install: - docker run -p 3030:3030 -d stain/jena-fuseki:latest ./fuseki-server --mem /remote +- cd test/theme-gem +- bundle install +- cd ../.. script: - bundle exec rake test deploy: diff --git a/Gemfile b/Gemfile index fa75df15..40514ac8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,6 @@ source 'https://rubygems.org' + +gem "theme-gem", :path => 'test/theme-gem' gemspec + diff --git a/test/cases/prefixesInPostsWithGemTheme/Gemfile b/test/cases/prefixesInPostsWithGemTheme/Gemfile index 77abcf66..74fb4acd 100644 --- a/test/cases/prefixesInPostsWithGemTheme/Gemfile +++ b/test/cases/prefixesInPostsWithGemTheme/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' group :jekyll_plugins do - gem "jekyll-theme-jod", "= 0.1.9" + gem "theme-gem", :path => '../../theme-gem' gem 'jekyll-rdf', :path => '../../../' end diff --git a/test/cases/prefixesInPostsWithGemTheme/_config.yml b/test/cases/prefixesInPostsWithGemTheme/_config.yml index 9af24458..9503dfba 100644 --- a/test/cases/prefixesInPostsWithGemTheme/_config.yml +++ b/test/cases/prefixesInPostsWithGemTheme/_config.yml @@ -1,7 +1,7 @@ baseurl: "" url: "http://example.org/" -theme: jekyll-theme-jod +theme: theme-gem plugins: - jekyll-rdf jekyll_rdf: diff --git a/test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb b/test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb index 50208a47..ecd7b63e 100644 --- a/test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb +++ b/test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb @@ -15,7 +15,7 @@ class TestPrefixes < Test::Unit::TestCase #TODO This test case has to be completed once jekyll runs successfull assert_equal "

My Jekyll RDF Blog

", content[0] - assert_equal "

This is a Blogpost

", content[2] + assert_equal "

This is a Blogpost

", content[1] end end end diff --git a/test/theme-gem/Gemfile b/test/theme-gem/Gemfile new file mode 100644 index 00000000..9e9ddcc3 --- /dev/null +++ b/test/theme-gem/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +gemspec + diff --git a/test/theme-gem/_layouts/ontology.html b/test/theme-gem/_layouts/ontology.html new file mode 100644 index 00000000..25bbc507 --- /dev/null +++ b/test/theme-gem/_layouts/ontology.html @@ -0,0 +1,13 @@ +--- +--- + + + ontology layout + + + + +

My Jekyll RDF Blog

+ {{content}} + + diff --git a/test/theme-gem/theme-gem.gemspec b/test/theme-gem/theme-gem.gemspec new file mode 100644 index 00000000..b3a9d7dc --- /dev/null +++ b/test/theme-gem/theme-gem.gemspec @@ -0,0 +1,13 @@ +Gem::Specification.new do |s| + s.name = 'theme-gem' + s.version = '1.0.0' + s.summary = '' + s.description = '' + s.authors = [''] + s.email = '' + s.files = Dir['**/*'] + s.homepage = '' + s.license = '' + +end + From 414e42e97a5151fd4315f8f4fce67e2f48256460 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Tue, 26 Mar 2019 11:25:44 +0100 Subject: [PATCH 57/85] Add prefixes to test gem --- .../_data/knowledge-base.ttl | 3 +++ .../test_prefixes.rb | 18 +++++++++++++++--- test/theme-gem/_data/prefixes.sparql | 3 +++ test/theme-gem/_layouts/ontology.html | 7 +++++-- 4 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 test/theme-gem/_data/prefixes.sparql diff --git a/test/cases/prefixesInPostsWithGemTheme/_data/knowledge-base.ttl b/test/cases/prefixesInPostsWithGemTheme/_data/knowledge-base.ttl index 08533bee..39002fe1 100644 --- a/test/cases/prefixesInPostsWithGemTheme/_data/knowledge-base.ttl +++ b/test/cases/prefixesInPostsWithGemTheme/_data/knowledge-base.ttl @@ -3,3 +3,6 @@ a owl:Ontology ; rdfs:label "My Jekyll RDF Blog" . + + a owl:Ontology ; + rdfs:label "My Jekyll RDF Blogpost" . diff --git a/test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb b/test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb index ecd7b63e..c2daa658 100644 --- a/test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb +++ b/test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb @@ -8,14 +8,26 @@ class TestPrefixes < Test::Unit::TestCase content = [] file = File.read(File.join(@source, "_site/2019/02/12/Blogpost.html")) - content = file[/\(.|\s)*\<\/body\>/][6..-6].strip.split("\n").map do |entry| + content = file[/\(.|\s)*\<\/body\>/][6..-6].strip.split("
").map do |entry| entry.strip end - #TODO This test case has to be completed once jekyll runs successfull - assert_equal "

My Jekyll RDF Blog

", content[0] assert_equal "

This is a Blogpost

", content[1] + # this line has to be uncommented once page.rdf is set in posts + #assert_equal "My Jekyll RDF Blogpost", content[2] + assert_equal "My Jekyll RDF Blog", content[3] + + content = [] + file = File.read(File.join(@source, "_site/blog.html")) + content = file[/\(.|\s)*\<\/body\>/][6..-6].strip.split("
").map do |entry| + entry.strip + end + + assert_equal "

My Jekyll RDF Blog

", content[0] + assert_equal "A page", content[1] + assert_equal "My Jekyll RDF Blog", content[2] + assert_equal "My Jekyll RDF Blog", content[3] end end end diff --git a/test/theme-gem/_data/prefixes.sparql b/test/theme-gem/_data/prefixes.sparql new file mode 100644 index 00000000..a37afee6 --- /dev/null +++ b/test/theme-gem/_data/prefixes.sparql @@ -0,0 +1,3 @@ +PREFIX ex: +PREFIX jb: +PREFIX rdfs: diff --git a/test/theme-gem/_layouts/ontology.html b/test/theme-gem/_layouts/ontology.html index 25bbc507..4605887c 100644 --- a/test/theme-gem/_layouts/ontology.html +++ b/test/theme-gem/_layouts/ontology.html @@ -1,4 +1,5 @@ --- +rdf_prefix_path: "_data/prefixes.sparql" --- @@ -7,7 +8,9 @@ -

My Jekyll RDF Blog

- {{content}} +

My Jekyll RDF Blog


+ {{content}}
+ {{ page.rdf | rdf_property: "rdfs:label" }}
+ {{ "" | rdf_get | rdf_property: "rdfs:label" }}
From 4dd45128044bf14b8480afa7e5d8b1ece1a1a6b9 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Thu, 23 May 2019 17:51:04 +0200 Subject: [PATCH 58/85] Fix #271. Change page to page.rdf in README. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9628f7c3..a3fa1704 100644 --- a/README.md +++ b/README.md @@ -507,7 +507,7 @@ You can use `?resourceUri` inside the query to reference the resource which is g ``` {% assign query = 'SELECT ?sub ?pre WHERE { ?sub ?pre ?resourceUri }' %} -{% assign resultset = page | sparql_query: query %} +{% assign resultset = page.rdf | sparql_query: query %} {% for result in resultset %} From 8c16e10b3a3ccaad02af4f10af15da7b276754d4 Mon Sep 17 00:00:00 2001 From: SZ Date: Sat, 13 Apr 2019 13:05:01 +0200 Subject: [PATCH 59/85] jekyll-rdf still works on Jekyll reset --- lib/jekyll/hooks/rdf_page_pointer.rb | 4 ++++ test/cases/filter/test_rdf_filters.rb | 2 ++ 2 files changed, 6 insertions(+) diff --git a/lib/jekyll/hooks/rdf_page_pointer.rb b/lib/jekyll/hooks/rdf_page_pointer.rb index cb786567..93ff5b17 100644 --- a/lib/jekyll/hooks/rdf_page_pointer.rb +++ b/lib/jekyll/hooks/rdf_page_pointer.rb @@ -22,6 +22,10 @@ # SOFTWARE. # +Jekyll::Hooks.register :site, :after_reset do |site| + Jekyll::JekyllRdf::Helper::RdfHelper::reinitialize +end + Jekyll::Hooks.register :documents, :post_init do |page| if(page.data["rdf_prefix_path"].nil?) page.data["rdf_prefix_set?"] = false diff --git a/test/cases/filter/test_rdf_filters.rb b/test/cases/filter/test_rdf_filters.rb index 16ce08b7..c9fc91af 100644 --- a/test/cases/filter/test_rdf_filters.rb +++ b/test/cases/filter/test_rdf_filters.rb @@ -320,6 +320,8 @@ def config should "return the resource eg:resource" do Jekyll::JekyllRdf::Helper::RdfHelper::site = Jekyll::Site.new(Jekyll.configuration({})) + Jekyll::JekyllRdf::Helper::RdfHelper::page = PseudoPage.new() # setting site resets these values + Jekyll::JekyllRdf::Helper::RdfHelper::prefixes = prefix_path # setting site resets these values test_resource = rdf_get("eg:resource") assert_equal "http://example.org/instance/resource", test_resource.iri assert (test_resource.site.eql? Jekyll::JekyllRdf::Helper::RdfHelper::site), "The resource should contain the same site as Jekyll::JekyllRdf::Helper::RdfHelper" From c345a3b454bfd0e22b99f9e576c05adafb40f621 Mon Sep 17 00:00:00 2001 From: username Date: Mon, 17 Jun 2019 14:56:35 +0200 Subject: [PATCH 60/85] test jekyll-site reinitialize --- test/cases/resetSite/Gemfile | 4 ++ test/cases/resetSite/_config.yml | 11 ++++ test/cases/resetSite/_data/Prefixes.pref | 2 + test/cases/resetSite/_data/knowledge-base.ttl | 5 ++ .../resetSite/_layouts/default-resource.html | 6 ++ test/cases/resetSite/_layouts/default.html | 12 ++++ .../resetSite/_layouts/exampleInstance.html | 8 +++ test/cases/resetSite/_layouts/person.html | 15 +++++ test/cases/resetSite/reset-page.html | 6 ++ test/cases/resetSite/test_reset.rb | 58 +++++++++++++++++++ 10 files changed, 127 insertions(+) create mode 100644 test/cases/resetSite/Gemfile create mode 100644 test/cases/resetSite/_config.yml create mode 100644 test/cases/resetSite/_data/Prefixes.pref create mode 100644 test/cases/resetSite/_data/knowledge-base.ttl create mode 100644 test/cases/resetSite/_layouts/default-resource.html create mode 100644 test/cases/resetSite/_layouts/default.html create mode 100644 test/cases/resetSite/_layouts/exampleInstance.html create mode 100644 test/cases/resetSite/_layouts/person.html create mode 100644 test/cases/resetSite/reset-page.html create mode 100644 test/cases/resetSite/test_reset.rb diff --git a/test/cases/resetSite/Gemfile b/test/cases/resetSite/Gemfile new file mode 100644 index 00000000..4d519ca0 --- /dev/null +++ b/test/cases/resetSite/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +group :jekyll_plugins do + gem 'jekyll-rdf', :path => '../../../' +end diff --git a/test/cases/resetSite/_config.yml b/test/cases/resetSite/_config.yml new file mode 100644 index 00000000..d0ad8279 --- /dev/null +++ b/test/cases/resetSite/_config.yml @@ -0,0 +1,11 @@ +baseurl: "/instance" # the subpath of your site, e.g. /blog +url: "http://example.org/" # the base hostname & protocol for your site +# Build settings +markdown: kramdown +plugins: +- jekyll-rdf +jekyll_rdf: + path: "_data/knowledge-base.ttl" + restriction: "SELECT ?resourceUri WHERE {?resourceUri ?p ?o}" + default_template: "default-resource" + diff --git a/test/cases/resetSite/_data/Prefixes.pref b/test/cases/resetSite/_data/Prefixes.pref new file mode 100644 index 00000000..cd1928d9 --- /dev/null +++ b/test/cases/resetSite/_data/Prefixes.pref @@ -0,0 +1,2 @@ +PREFIX eg: + diff --git a/test/cases/resetSite/_data/knowledge-base.ttl b/test/cases/resetSite/_data/knowledge-base.ttl new file mode 100644 index 00000000..b1e49087 --- /dev/null +++ b/test/cases/resetSite/_data/knowledge-base.ttl @@ -0,0 +1,5 @@ +@prefix eg: . + +eg:resource1 eg:predicate eg:object . +eg:resource2 eg:predicate eg:object . + diff --git a/test/cases/resetSite/_layouts/default-resource.html b/test/cases/resetSite/_layouts/default-resource.html new file mode 100644 index 00000000..a6c58aec --- /dev/null +++ b/test/cases/resetSite/_layouts/default-resource.html @@ -0,0 +1,6 @@ +--- +layout: default +--- +
This is a resource

+ {{ page.rdf }} + diff --git a/test/cases/resetSite/_layouts/default.html b/test/cases/resetSite/_layouts/default.html new file mode 100644 index 00000000..fba5487b --- /dev/null +++ b/test/cases/resetSite/_layouts/default.html @@ -0,0 +1,12 @@ +--- +--- + + + + +
+

This is made with jekyll-rdf


+ {{content}} +
+ + diff --git a/test/cases/resetSite/_layouts/exampleInstance.html b/test/cases/resetSite/_layouts/exampleInstance.html new file mode 100644 index 00000000..655a2ea8 --- /dev/null +++ b/test/cases/resetSite/_layouts/exampleInstance.html @@ -0,0 +1,8 @@ +--- +layout: default +rdf_prefix_path: _data/Prefixes.pref +--- +
+
This page is mapped to:
+ {{page.rdf}} +
diff --git a/test/cases/resetSite/_layouts/person.html b/test/cases/resetSite/_layouts/person.html new file mode 100644 index 00000000..30e3bf3b --- /dev/null +++ b/test/cases/resetSite/_layouts/person.html @@ -0,0 +1,15 @@ +--- +layout: default +rdf_prefix_path: _data/Prefixes.pref +--- +
+
+ name: +
+ {{page.rdf | rdf_property: "foaf:name"}} +
+
+ age: +
+ {{page.rdf | rdf_property: "foaf:age"}} +
diff --git a/test/cases/resetSite/reset-page.html b/test/cases/resetSite/reset-page.html new file mode 100644 index 00000000..4b2d7f4d --- /dev/null +++ b/test/cases/resetSite/reset-page.html @@ -0,0 +1,6 @@ +--- +layout: default +--- + +
This is a page

+Test-Page diff --git a/test/cases/resetSite/test_reset.rb b/test/cases/resetSite/test_reset.rb new file mode 100644 index 00000000..29132622 --- /dev/null +++ b/test/cases/resetSite/test_reset.rb @@ -0,0 +1,58 @@ +require 'test_helper' + +class TestGeneral < Test::Unit::TestCase + include RSpec::Matchers + include RdfTestUtility + context "Jekyll-Rdf after reinitialization" do + setup do + setup_site_jekyll File.dirname(__FILE__) + end + + should "render content completly" do + file = File.read(File.join(@source, "_site/reset-page.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + assert_equal "

This is made with jekyll-rdf

", content[0] + assert_equal "
This is a page
", content[1] + assert_equal "Test-Page", content[2] + file = File.read(File.join(@source, "_site/resource1.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + assert_equal "

This is made with jekyll-rdf

", content[0] + assert_equal "
This is a resource
", content[1] + assert_equal "http://example.org/instance/resource1", content[2] + file = File.read(File.join(@source, "_site/resource2.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + assert_equal "

This is made with jekyll-rdf

", content[0] + assert_equal "
This is a resource
", content[1] + assert_equal "http://example.org/instance/resource2", content[2] + Jekyll::JekyllRdf::Helper::RdfHelper.reinitialize + @site.process + file = File.read(File.join(@source, "_site/reset-page.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + assert_equal "

This is made with jekyll-rdf

", content[0] + assert_equal "
This is a page
", content[1] + assert_equal "Test-Page", content[2] + file = File.read(File.join(@source, "_site/resource1.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + assert_equal "

This is made with jekyll-rdf

", content[0] + assert_equal "
This is a resource
", content[1] + assert_equal "http://example.org/instance/resource1", content[2] + file = File.read(File.join(@source, "_site/resource2.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + assert_equal "

This is made with jekyll-rdf

", content[0] + assert_equal "
This is a resource
", content[1] + assert_equal "http://example.org/instance/resource2", content[2] + end + end +end From 2b7bab750740f77114597589b853e405c5e24a81 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Tue, 18 Jun 2019 12:39:44 +0200 Subject: [PATCH 61/85] Add test for file existance --- test/cases/resetSite/test_reset.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/cases/resetSite/test_reset.rb b/test/cases/resetSite/test_reset.rb index 29132622..77f23d2b 100644 --- a/test/cases/resetSite/test_reset.rb +++ b/test/cases/resetSite/test_reset.rb @@ -30,12 +30,13 @@ class TestGeneral < Test::Unit::TestCase assert_equal "

This is made with jekyll-rdf

", content[0] assert_equal "
This is a resource
", content[1] assert_equal "http://example.org/instance/resource2", content[2] - Jekyll::JekyllRdf::Helper::RdfHelper.reinitialize + # Jekyll::JekyllRdf::Helper::RdfHelper.reinitialize @site.process file = File.read(File.join(@source, "_site/reset-page.html")) content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| entry.strip end + assert File.exist?(File.join(@source, "_site/resource1.html")), "resource1.html was in the render list but wasn't rendered after reset" assert_equal "

This is made with jekyll-rdf

", content[0] assert_equal "
This is a page
", content[1] assert_equal "Test-Page", content[2] From a3e3aa79556ca724e0e617af26dfae96927c0b8b Mon Sep 17 00:00:00 2001 From: username Date: Mon, 17 Jun 2019 16:26:56 +0200 Subject: [PATCH 62/85] test for the different restriction forms --- test/cases/restrictions/Gemfile | 4 ++ test/cases/restrictions/_config.yml | 11 +++ test/cases/restrictions/_data/Prefixes.pref | 5 ++ .../restrictions/_data/knowledge-base.ttl | 5 ++ .../restrictions/_data/restriction-file.rf | 2 + test/cases/restrictions/_layouts/default.html | 11 +++ test/cases/restrictions/test_restriction.rb | 72 +++++++++++++++++++ 7 files changed, 110 insertions(+) create mode 100644 test/cases/restrictions/Gemfile create mode 100644 test/cases/restrictions/_config.yml create mode 100644 test/cases/restrictions/_data/Prefixes.pref create mode 100644 test/cases/restrictions/_data/knowledge-base.ttl create mode 100644 test/cases/restrictions/_data/restriction-file.rf create mode 100644 test/cases/restrictions/_layouts/default.html create mode 100644 test/cases/restrictions/test_restriction.rb diff --git a/test/cases/restrictions/Gemfile b/test/cases/restrictions/Gemfile new file mode 100644 index 00000000..895226d4 --- /dev/null +++ b/test/cases/restrictions/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +group :jekyll_plugins do + gem 'jekyll-rdf', '>= 3.0.0.a' #, :path => '../../../' +end diff --git a/test/cases/restrictions/_config.yml b/test/cases/restrictions/_config.yml new file mode 100644 index 00000000..7e170334 --- /dev/null +++ b/test/cases/restrictions/_config.yml @@ -0,0 +1,11 @@ +baseurl: "/instance" # the subpath of your site, e.g. /blog +url: "http://example.org/" # the base hostname & protocol for your site +# Build settings +markdown: kramdown +plugins: +- jekyll-rdf +jekyll_rdf: + path: "_data/knowledge-base.ttl" + restriction: "SELECT ?resourceUri WHERE {?resourceUri ?p }" + default_template: "default" + diff --git a/test/cases/restrictions/_data/Prefixes.pref b/test/cases/restrictions/_data/Prefixes.pref new file mode 100644 index 00000000..f59c9317 --- /dev/null +++ b/test/cases/restrictions/_data/Prefixes.pref @@ -0,0 +1,5 @@ +PREFIX rdf: +PREFIX rdfs: +PREFIX xsd: +PREFIX foaf: +PREFIX eg: diff --git a/test/cases/restrictions/_data/knowledge-base.ttl b/test/cases/restrictions/_data/knowledge-base.ttl new file mode 100644 index 00000000..4c7f491d --- /dev/null +++ b/test/cases/restrictions/_data/knowledge-base.ttl @@ -0,0 +1,5 @@ +@prefix eg: . + +eg:resource1 eg:predicate eg:object1 . +eg:resource2 eg:predicate eg:object2 . + diff --git a/test/cases/restrictions/_data/restriction-file.rf b/test/cases/restrictions/_data/restriction-file.rf new file mode 100644 index 00000000..de9af412 --- /dev/null +++ b/test/cases/restrictions/_data/restriction-file.rf @@ -0,0 +1,2 @@ + + diff --git a/test/cases/restrictions/_layouts/default.html b/test/cases/restrictions/_layouts/default.html new file mode 100644 index 00000000..3ffc26ff --- /dev/null +++ b/test/cases/restrictions/_layouts/default.html @@ -0,0 +1,11 @@ +--- +--- + + + + +
+ {{ page.rdf }} +
+ + diff --git a/test/cases/restrictions/test_restriction.rb b/test/cases/restrictions/test_restriction.rb new file mode 100644 index 00000000..d130cfee --- /dev/null +++ b/test/cases/restrictions/test_restriction.rb @@ -0,0 +1,72 @@ +require 'test_helper' + +class TestRestriction < Test::Unit::TestCase + include RSpec::Matchers + include RdfTestUtility + context "Jekyll-Rdf restriction model" do + should "render all resources from the restriction query" do + @source = File.dirname(__FILE__) + config = Jekyll.configuration(YAML.load_file(File.join(@source, '_config.yml')).merge!({'source' => @source, 'destination' => File.join(@source, "_site")})) + site = Jekyll::Site.new(config) + Jekyll::JekyllRdf::Helper::RdfHelper.reinitialize + site.process + + file = File.read(File.join(@source, "_site/resource1.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + assert_equal "http://example.org/instance/resource1", content[0] + assert_equal 2, Dir[File.join(@source, '_site/**/*')].length + end + + should "render all resources from the restriction file" do + @source = File.dirname(__FILE__) + config = Jekyll.configuration(YAML.load_file(File.join(@source, '_config.yml')).merge!({'source' => @source, 'destination' => File.join(@source, "_site")})) + config["jekyll_rdf"].delete("restriction") + config["jekyll_rdf"]["restriction_file"] = "_data/restriction-file.rf" + site = Jekyll::Site.new(config) + Jekyll::JekyllRdf::Helper::RdfHelper.reinitialize + site.process + + file = File.read(File.join(@source, "_site/resource2.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + assert_equal "http://example.org/instance/resource2", content[0] + assert_equal 2, Dir[File.join(@source, '_site/**/*')].length + end + + should "render all resources if neither a restriction file nor a restriction query is given" do + @source = File.dirname(__FILE__) + config = Jekyll.configuration(YAML.load_file(File.join(@source, '_config.yml')).merge!({'source' => @source, 'destination' => File.join(@source, "_site")})) + config["jekyll_rdf"].delete("restriction") + site = Jekyll::Site.new(config) + Jekyll::JekyllRdf::Helper::RdfHelper.reinitialize + site.process + + file = File.read(File.join(@source, "_site/resource1.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + assert_equal "http://example.org/instance/resource1", content[0] + + file = File.read(File.join(@source, "_site/resource2.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + assert_equal "http://example.org/instance/resource2", content[0] + assert_equal 6, Dir[File.join(@source, '_site/**/*')].length + end + + should "render no resources if the restriction query returns no resources" do + @source = File.dirname(__FILE__) + config = Jekyll.configuration(YAML.load_file(File.join(@source, '_config.yml')).merge!({'source' => @source, 'destination' => File.join(@source, "_site")})) + config["jekyll_rdf"]["restriction"] = "SELECT ?resourceUri WHERE {?resourceUri ?p }" + site = Jekyll::Site.new(config) + Jekyll::JekyllRdf::Helper::RdfHelper.reinitialize + site.process + + assert_equal 1, Dir[File.join(@source, '_site/**/*')].length + end + end +end From c53d3ff65b4976976ddfa74051c64b234e7a01dd Mon Sep 17 00:00:00 2001 From: username Date: Sun, 23 Jun 2019 17:17:09 +0200 Subject: [PATCH 63/85] fixed: page_url wont constantly add .html after each refresh --- lib/jekyll/drops/rdf_resource.rb | 9 +++++---- test/cases/noElongatedPageNames/Gemfile | 4 ++++ test/cases/noElongatedPageNames/_config.yml | 10 ++++++++++ .../_data/knowledge-base.ttl | 4 ++++ test/cases/noElongatedPageNames/page.html | 16 +++++++++++++++ .../test_url_elongation.rb | 20 +++++++++++++++++++ 6 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 test/cases/noElongatedPageNames/Gemfile create mode 100644 test/cases/noElongatedPageNames/_config.yml create mode 100644 test/cases/noElongatedPageNames/_data/knowledge-base.ttl create mode 100644 test/cases/noElongatedPageNames/page.html create mode 100644 test/cases/noElongatedPageNames/test_url_elongation.rb diff --git a/lib/jekyll/drops/rdf_resource.rb b/lib/jekyll/drops/rdf_resource.rb index 9bdf69eb..8685ae64 100644 --- a/lib/jekyll/drops/rdf_resource.rb +++ b/lib/jekyll/drops/rdf_resource.rb @@ -154,18 +154,19 @@ def direct_classes # Return the URL of the page representing this RdfResource # def page_url - return @page_url unless @page_url.nil? + return @page_url.dup unless @page_url.nil? generate_file_name() - @page_url + #duplicate so outside sources do not edit this property + @page_url.dup end ## # Return the path to the page representing this RdfResource # def render_path - return @render_path unless @page_url.nil? + return @render_path.dup unless @page_url.nil? generate_file_name() - @render_path + @render_path.dup end def iri diff --git a/test/cases/noElongatedPageNames/Gemfile b/test/cases/noElongatedPageNames/Gemfile new file mode 100644 index 00000000..4d519ca0 --- /dev/null +++ b/test/cases/noElongatedPageNames/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +group :jekyll_plugins do + gem 'jekyll-rdf', :path => '../../../' +end diff --git a/test/cases/noElongatedPageNames/_config.yml b/test/cases/noElongatedPageNames/_config.yml new file mode 100644 index 00000000..4c50dbac --- /dev/null +++ b/test/cases/noElongatedPageNames/_config.yml @@ -0,0 +1,10 @@ +baseurl: "/instance" # the subpath of your site, e.g. /blog +url: "http://example.org/" # the base hostname & protocol for your site +# Build settings +markdown: kramdown +plugins: +- jekyll-rdf +jekyll_rdf: + path: "_data/knowledge-base.ttl" + restriction: "SELECT ?resourceUri WHERE {?resourceUri ?p }" + diff --git a/test/cases/noElongatedPageNames/_data/knowledge-base.ttl b/test/cases/noElongatedPageNames/_data/knowledge-base.ttl new file mode 100644 index 00000000..5c782582 --- /dev/null +++ b/test/cases/noElongatedPageNames/_data/knowledge-base.ttl @@ -0,0 +1,4 @@ +@prefix eg: . + +eg:resource eg:predicate eg:object . + diff --git a/test/cases/noElongatedPageNames/page.html b/test/cases/noElongatedPageNames/page.html new file mode 100644 index 00000000..8874ad7e --- /dev/null +++ b/test/cases/noElongatedPageNames/page.html @@ -0,0 +1,16 @@ +--- +--- + + + Page + + + + +
+ {% assign resource = "" | rdf_get %} + {% assign url = resource.page_url %} + {{ url }} +
+ + diff --git a/test/cases/noElongatedPageNames/test_url_elongation.rb b/test/cases/noElongatedPageNames/test_url_elongation.rb new file mode 100644 index 00000000..607e37ad --- /dev/null +++ b/test/cases/noElongatedPageNames/test_url_elongation.rb @@ -0,0 +1,20 @@ +require 'test_helper' + +class TestNoNameElongation < Test::Unit::TestCase + include RSpec::Matchers + include RdfTestUtility + context "Jekyll-Rdf" do + setup do + setup_jekyll File.dirname(__FILE__) + end + + should "support prefixes on non RdfPages too" do + file = File.read(File.join(@source, "_site/page.html")) + content = file[/\(.|\s)*\<\/div>/][5..-7].strip.split("
").map do |entry| + entry.strip + end + # there should be no .html attached to the url, since urls work without it + assert_equal "/resource", content[0] + end + end +end From 31c07544f36de698007dd099cee0dcdb0da13dac Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Tue, 9 Jul 2019 08:51:14 +0000 Subject: [PATCH 64/85] Test local jekyll rdf --- test/cases/restrictions/Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cases/restrictions/Gemfile b/test/cases/restrictions/Gemfile index 895226d4..4d519ca0 100644 --- a/test/cases/restrictions/Gemfile +++ b/test/cases/restrictions/Gemfile @@ -1,4 +1,4 @@ source 'https://rubygems.org' group :jekyll_plugins do - gem 'jekyll-rdf', '>= 3.0.0.a' #, :path => '../../../' + gem 'jekyll-rdf', :path => '../../../' end From d97506aaf2146d2412b1ac73ab751ea594c5e435 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Tue, 21 Jan 2020 15:25:25 +0100 Subject: [PATCH 65/85] Set gem dependency to jekyll to >=3.1 --- jekyll-rdf.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jekyll-rdf.gemspec b/jekyll-rdf.gemspec index d6ac3e51..eaf3ff8e 100644 --- a/jekyll-rdf.gemspec +++ b/jekyll-rdf.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'net-http-persistent', '~> 2.9' # https://github.com/AKSW/jekyll-rdf/issues/197 s.add_runtime_dependency 'linkeddata', '~> 2.0' s.add_runtime_dependency 'sparql-client', '~> 3.0', '>= 3.0.1' - s.add_runtime_dependency 'jekyll', '~> 3.1' + s.add_runtime_dependency 'jekyll', '>= 3.1' s.add_development_dependency 'rake', '~> 10.4' s.add_development_dependency 'rest-client', '~> 2.0', '>= 2.0.1' s.add_development_dependency 'coveralls', '~> 0.8' From e7ac546c49d267f00d73e267622adacbcf0ec54a Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Tue, 21 Jan 2020 15:47:29 +0100 Subject: [PATCH 66/85] Update travis ruby versions --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 973c29f2..ba8af76d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,9 @@ language: ruby services: - docker rvm: -- 2.2.4 -- 2.3.0 +- 2.3.8 - 2.5.3 +- 2.7.0 - ruby-head matrix: allow_failures: @@ -22,10 +22,12 @@ deploy: secure: D8rx4lfdlvWFjXPrHTOXudIrUpjBHu++4ebWzNcXNdk8ccNtRbkWCqK7vOp7BAXu8NXGQOT/XoHmcwuzOpaLMiPL6B+eNTPWnC2wqeQUlZcZak6btFXwMivKXRT5oyIP/UjciucLDN9jq+54fdr5M7+nJ+3D7upUA2P3ymb+69U0l0bXl9WA+c92LRi/wXXeyxdpImHym8PxBagS6GPiHswcHoeRRq5vNEmo/E9RYV5F0Kzyj8vOchO/83cDeqeQEPX969AtO0AKZczWfNx2qOBgcYcUmxfOdAooOnFYjw3A9QZgI3B/T7LC1137mCLQCcb/e0cFPiwQYxDXS8SEEd1t4t/4Tw/zUh+TFuSAbCPJz1tG91KYhcVBDzsvQh1dU0WY7TDXRrasvNU7HJ+TMGIq7nC+QvSRJ1SyKsI89aLKA8fAO06DwI/7LodG+G/0MAxFO5XLu1EBJ8k+mxdkbSqoZxSdtvvWkAUkdjWXtOtGNUhYtuVTJrzjrWUOM2YuhmnGAwJg8UgUKzDvjNCQ0Zm2q5TiYZT5nsv8FwE6zjSK7ETnp+ofW/RwxbZs7DNTDTShKAyoy2NEKrPfFvkFkoUSP3yR+e8hJpRo2hJFC/3GxgnTr4bdI814Y5UOBfGjVXUKsodMhtk0uhJCIQMm8Jri1o5600szSW+lG20KSkg= gem: jekyll-rdf on: + condition: $TRAVIS_RUBY_VERSION = 2.7.0 branch: master - provider: rubygems api_key: secure: D8rx4lfdlvWFjXPrHTOXudIrUpjBHu++4ebWzNcXNdk8ccNtRbkWCqK7vOp7BAXu8NXGQOT/XoHmcwuzOpaLMiPL6B+eNTPWnC2wqeQUlZcZak6btFXwMivKXRT5oyIP/UjciucLDN9jq+54fdr5M7+nJ+3D7upUA2P3ymb+69U0l0bXl9WA+c92LRi/wXXeyxdpImHym8PxBagS6GPiHswcHoeRRq5vNEmo/E9RYV5F0Kzyj8vOchO/83cDeqeQEPX969AtO0AKZczWfNx2qOBgcYcUmxfOdAooOnFYjw3A9QZgI3B/T7LC1137mCLQCcb/e0cFPiwQYxDXS8SEEd1t4t/4Tw/zUh+TFuSAbCPJz1tG91KYhcVBDzsvQh1dU0WY7TDXRrasvNU7HJ+TMGIq7nC+QvSRJ1SyKsI89aLKA8fAO06DwI/7LodG+G/0MAxFO5XLu1EBJ8k+mxdkbSqoZxSdtvvWkAUkdjWXtOtGNUhYtuVTJrzjrWUOM2YuhmnGAwJg8UgUKzDvjNCQ0Zm2q5TiYZT5nsv8FwE6zjSK7ETnp+ofW/RwxbZs7DNTDTShKAyoy2NEKrPfFvkFkoUSP3yR+e8hJpRo2hJFC/3GxgnTr4bdI814Y5UOBfGjVXUKsodMhtk0uhJCIQMm8Jri1o5600szSW+lG20KSkg= gem: jekyll-rdf on: + condition: $TRAVIS_RUBY_VERSION = 2.7.0 branch: develop From b31cb08a1252d71ad845a796674f08c9e0c45c7c Mon Sep 17 00:00:00 2001 From: Andy Fitzgerald Date: Tue, 30 Mar 2021 06:07:57 -0700 Subject: [PATCH 67/85] Update README default_branch parameter description Update remote > default_graph parameter description to communicate that default_graph replaces the endpoint default graph with a named graph. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a3fa1704..50191d6c 100644 --- a/README.md +++ b/README.md @@ -669,7 +669,7 @@ http://www.ifi.uio.no/INF3580/simpsons#Maggie |path|Relative path to the RDF-File|no default|Specifies the path to the RDF file from where you want to render the website|```path: "rdf-data/simpsons.ttl"```| |remote|Section to specify a remote data source|no default|Has to contain the `endpoint` key. The `remote` parameter overrides the `path` parameter.|| |remote > endpoint|SPARQL endpoint to get the data from|no default|Specifies the URL to the SPARQL endpoint from where you want to render the website|```remote: endpoint: "http://localhost:5000/sparql/"```| -|remote > default_graph|Select a default graph on the endpoint|no default|Specifies the IRI to the named graph to select from the SPARQL endpoint|```remote: endpoint: "http://localhost:5000/sparql/" default_graph: "http://example.org/"```| +|remote > default_graph|Select a named graph on the endpoint to use in place of the endpoint default graph|no default|Specifies the IRI to the named graph to select from the SPARQL endpoint|```remote: endpoint: "http://localhost:5000/sparql/" default_graph: "http://example.org/"```| |language|Language-Tag as String|no default|Specifies the preferred language when you select objects using our Liquid filters|```language: "en"```| |include_blank|Boolean-Expression|false|Specifies whether blank nodes should also be rendered or not|```include_blank: true```| |restriction|SPARQL-Query as String or subjects/objects/predicates|no default|Restricts the resource-selection with a given SPARQL-Query to the results bound to the special variable `?resourceUri` or the three keywords `subjects` (only subject URIs), `objects`, `predicates`|```restriction: "SELECT ?resourceUri WHERE { ?resourceUri }"```| From 7cf5e30b68caaee28e900e47d99b9fb590de333c Mon Sep 17 00:00:00 2001 From: Simon Bin Date: Tue, 7 Dec 2021 11:42:04 +0100 Subject: [PATCH 68/85] update dependencies --- jekyll-rdf.gemspec | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/jekyll-rdf.gemspec b/jekyll-rdf.gemspec index eaf3ff8e..72b2c3b9 100644 --- a/jekyll-rdf.gemspec +++ b/jekyll-rdf.gemspec @@ -1,4 +1,5 @@ -VERSION = '3.1.1' +# coding: utf-8 +VERSION = '3.1.2' RELEASE_VERSION = case when ENV['TRAVIS'] && ENV['TRAVIS_BRANCH'].match(/^master$/i) then "#{VERSION}" when ENV['TRAVIS'] && ENV['TRAVIS_BRANCH'].match(/^develop$/i) then "#{VERSION}-#{ENV['TRAVIS_BRANCH']}.#{ENV['TRAVIS_BUILD_NUMBER']}" @@ -15,11 +16,11 @@ Gem::Specification.new do |s| s.files = Dir['lib/**/*.rb'] s.homepage = 'https://github.com/AKSW/jekyll-rdf' s.license = 'MIT' - s.add_runtime_dependency 'net-http-persistent', '~> 2.9' # https://github.com/AKSW/jekyll-rdf/issues/197 - s.add_runtime_dependency 'linkeddata', '~> 2.0' - s.add_runtime_dependency 'sparql-client', '~> 3.0', '>= 3.0.1' - s.add_runtime_dependency 'jekyll', '>= 3.1' - s.add_development_dependency 'rake', '~> 10.4' + s.add_runtime_dependency 'net-http-persistent', '~> 4.0' # https://github.com/AKSW/jekyll-rdf/issues/197 + s.add_runtime_dependency 'linkeddata', '~> 3.1' + s.add_runtime_dependency 'sparql-client', '~> 3.1' + s.add_runtime_dependency 'jekyll', '>= 4.2' + s.add_development_dependency 'rake', '~> 13.0' s.add_development_dependency 'rest-client', '~> 2.0', '>= 2.0.1' s.add_development_dependency 'coveralls', '~> 0.8' s.add_development_dependency 'test-unit', '~> 3.0' From 071e6178b9067c2a2bf88fafb1b72c3cb68ca397 Mon Sep 17 00:00:00 2001 From: Simon Bin Date: Tue, 7 Dec 2021 15:07:01 +0100 Subject: [PATCH 69/85] fix Gemfile --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 50191d6c..b1fef8e6 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,7 @@ Probably you already using [Bundler](https://bundler.io/) and there is a [`Gemfi Add Jekyll-RDF to the plugins section: ``` -group :jekyll_plugins do - gem "jekyll-rdf", '~> 3.1.0' - … -end +gem "jekyll-rdf", "~> 3.1", git: "https://github.com/AKSW/jekyll-rdf", branch: "ruby3.0" ``` Replace the version string with the currently available stable release as listed on [rubygems.org](https://rubygems.org/gems/jekyll-rdf). From 31f4c2d83e35404ba5ed6e8cfb20d8885188e48d Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Sun, 27 Feb 2022 22:33:00 +0100 Subject: [PATCH 70/85] Add dependency for rdoc --- jekyll-rdf.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/jekyll-rdf.gemspec b/jekyll-rdf.gemspec index eaf3ff8e..4e6c9dfa 100644 --- a/jekyll-rdf.gemspec +++ b/jekyll-rdf.gemspec @@ -26,5 +26,6 @@ Gem::Specification.new do |s| s.add_development_dependency 'shoulda-context', '~> 1.1' s.add_development_dependency 'rspec', '~> 3.0' s.add_development_dependency 'pry-byebug', '~> 3.4' + s.add_development_dependency 'rdoc', '~> 6.2', '>= 6.2.1' s.add_development_dependency 'jekyll-theme-jod', '~> 0.1.5' end From bb0274af69f88e3bc262a58a0b84b022495492d6 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Sun, 27 Feb 2022 22:33:17 +0100 Subject: [PATCH 71/85] remove unused dependency for pry --- test/test_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index a79777ec..6adeb9ef 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,7 +2,6 @@ require 'test-unit' require 'shoulda-context' require 'rspec/expectations' -require 'pry' require 'simplecov' require 'coveralls' require 'ResourceHelper' From 85b4037d90574cd90d26eb684f5f5d41eb191586 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Sun, 27 Feb 2022 22:44:21 +0100 Subject: [PATCH 72/85] Forward linkeddata and sparql-client dependencies --- jekyll-rdf.gemspec | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/jekyll-rdf.gemspec b/jekyll-rdf.gemspec index 4e6c9dfa..adcbcdcb 100644 --- a/jekyll-rdf.gemspec +++ b/jekyll-rdf.gemspec @@ -15,9 +15,8 @@ Gem::Specification.new do |s| s.files = Dir['lib/**/*.rb'] s.homepage = 'https://github.com/AKSW/jekyll-rdf' s.license = 'MIT' - s.add_runtime_dependency 'net-http-persistent', '~> 2.9' # https://github.com/AKSW/jekyll-rdf/issues/197 - s.add_runtime_dependency 'linkeddata', '~> 2.0' - s.add_runtime_dependency 'sparql-client', '~> 3.0', '>= 3.0.1' + s.add_runtime_dependency 'linkeddata', '~> 3.2', '>= 3.2.0' + s.add_runtime_dependency 'sparql-client', '~> 3.2', '>= 3.2.0' s.add_runtime_dependency 'jekyll', '>= 3.1' s.add_development_dependency 'rake', '~> 10.4' s.add_development_dependency 'rest-client', '~> 2.0', '>= 2.0.1' From 1ff6999b76fa33098c25cc780f4b1d958fe55326 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 28 Feb 2022 11:47:52 +0100 Subject: [PATCH 73/85] Fix dependencies to correctly run the tests --- jekyll-rdf.gemspec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jekyll-rdf.gemspec b/jekyll-rdf.gemspec index adcbcdcb..1f70601d 100644 --- a/jekyll-rdf.gemspec +++ b/jekyll-rdf.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'linkeddata', '~> 3.2', '>= 3.2.0' s.add_runtime_dependency 'sparql-client', '~> 3.2', '>= 3.2.0' s.add_runtime_dependency 'jekyll', '>= 3.1' - s.add_development_dependency 'rake', '~> 10.4' + s.add_development_dependency 'rake', '~> 13.0' s.add_development_dependency 'rest-client', '~> 2.0', '>= 2.0.1' s.add_development_dependency 'coveralls', '~> 0.8' s.add_development_dependency 'test-unit', '~> 3.0' @@ -27,4 +27,5 @@ Gem::Specification.new do |s| s.add_development_dependency 'pry-byebug', '~> 3.4' s.add_development_dependency 'rdoc', '~> 6.2', '>= 6.2.1' s.add_development_dependency 'jekyll-theme-jod', '~> 0.1.5' + s.add_development_dependency 'kramdown-parser-gfm', '~> 1.1' end From 634c13df5ecaaaa45fbd0db9418fa65e49b548bc Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 28 Feb 2022 11:48:05 +0100 Subject: [PATCH 74/85] Since 3.1.0 the sparql-client interface has changed --- lib/jekyll/rdf_main_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/rdf_main_generator.rb b/lib/jekyll/rdf_main_generator.rb index ba5b5a2b..a8447866 100644 --- a/lib/jekyll/rdf_main_generator.rb +++ b/lib/jekyll/rdf_main_generator.rb @@ -58,7 +58,7 @@ def generate(site) if @config['remote']['default_graph'].nil? sparql = SPARQL::Client.new(graph) else - sparql = SPARQL::Client.new(graph, { :graph => @config['remote']['default_graph'] }) + sparql = SPARQL::Client.new(graph, graph: @config['remote']['default_graph']) end elsif(!@config['path'].nil?) sparql = SPARQL::Client.new(RDF::Graph.load( File.join( site.config['source'], @config['path']))) From 5ccc23f7bcc4d9541ff131e3344678df9394fcb6 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 28 Feb 2022 12:22:35 +0100 Subject: [PATCH 75/85] remove some unused variables --- lib/jekyll/helper/rdf_generator_helper.rb | 2 +- test/cases/dontFailIfLayoutNoFound/test_prefixes.rb | 1 - .../pagesFaultyPrefixAcess/test_pages_faulty_prefix_access.rb | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/helper/rdf_generator_helper.rb b/lib/jekyll/helper/rdf_generator_helper.rb index 28e57214..54c9069c 100644 --- a/lib/jekyll/helper/rdf_generator_helper.rb +++ b/lib/jekyll/helper/rdf_generator_helper.rb @@ -48,7 +48,7 @@ def parse_resources (resources) def load_config (site) begin @config = site.config.fetch('jekyll_rdf') - rescue KeyError => e + rescue KeyError Jekyll.logger.error("You've included Jekyll-RDF, but it is not configured. Aborting the jekyll-rdf plugin.") return false end diff --git a/test/cases/dontFailIfLayoutNoFound/test_prefixes.rb b/test/cases/dontFailIfLayoutNoFound/test_prefixes.rb index f2335e5d..dd31a9ee 100644 --- a/test/cases/dontFailIfLayoutNoFound/test_prefixes.rb +++ b/test/cases/dontFailIfLayoutNoFound/test_prefixes.rb @@ -6,7 +6,6 @@ class TestPrefixes < Test::Unit::TestCase should "check that the prefix search doesnot fail of an undefined layout is specified" do setup_jekyll File.dirname(__FILE__) - content = [] blogfile = File.read(File.join(@source, "_site/2019/02/12/Blogpost.html")) page = File.read(File.join(@source, "_site/blog.html")) diff --git a/test/cases/pagesFaultyPrefixAcess/test_pages_faulty_prefix_access.rb b/test/cases/pagesFaultyPrefixAcess/test_pages_faulty_prefix_access.rb index 790af43d..bb507d3b 100644 --- a/test/cases/pagesFaultyPrefixAcess/test_pages_faulty_prefix_access.rb +++ b/test/cases/pagesFaultyPrefixAcess/test_pages_faulty_prefix_access.rb @@ -8,7 +8,7 @@ class TestPagesFaultyPrefixAccess < Test::Unit::TestCase notFound = false begin setup_site_jekyll File.dirname(__FILE__) - rescue Errno::ENOENT => ex + rescue Errno::ENOENT notFound = true end assert notFound, "Faulty.pref should not have been found since it doesn't exist." From 66a5ac70bfdc93cf1412efa1c320dd0dd29a3a7e Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 28 Feb 2022 12:24:29 +0100 Subject: [PATCH 76/85] Use main jekyll-rdf release --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b1fef8e6..2a50a76e 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Probably you already using [Bundler](https://bundler.io/) and there is a [`Gemfi Add Jekyll-RDF to the plugins section: ``` -gem "jekyll-rdf", "~> 3.1", git: "https://github.com/AKSW/jekyll-rdf", branch: "ruby3.0" +gem "jekyll-rdf", "~> 3.1" ``` Replace the version string with the currently available stable release as listed on [rubygems.org](https://rubygems.org/gems/jekyll-rdf). From f3786002b57f91ed01e57a68641a416d470378e7 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 28 Feb 2022 12:35:19 +0100 Subject: [PATCH 77/85] clarify usage as binary operations --- lib/jekyll/drops/rdf_resource.rb | 2 +- lib/jekyll/drops/rdf_resource_class.rb | 2 +- test/ResourceHelper.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/drops/rdf_resource.rb b/lib/jekyll/drops/rdf_resource.rb index 8685ae64..e172fdb3 100644 --- a/lib/jekyll/drops/rdf_resource.rb +++ b/lib/jekyll/drops/rdf_resource.rb @@ -274,7 +274,7 @@ def identify_name_from_path(path) @filename = path else @filedir = path[0..last_slash] - @filename = path[(last_slash +1)..-1] + @filename = path[(last_slash + 1)..-1] end end diff --git a/lib/jekyll/drops/rdf_resource_class.rb b/lib/jekyll/drops/rdf_resource_class.rb index 2b85c0e2..6e09064b 100644 --- a/lib/jekyll/drops/rdf_resource_class.rb +++ b/lib/jekyll/drops/rdf_resource_class.rb @@ -67,7 +67,7 @@ def propagate_template(distance) return if @path.nil? return unless @path.template.nil? @path.template = @template - @path.propagate_template(distance +1) + @path.propagate_template(distance + 1) end ## diff --git a/test/ResourceHelper.rb b/test/ResourceHelper.rb index ad222cb6..573cc70e 100644 --- a/test/ResourceHelper.rb +++ b/test/ResourceHelper.rb @@ -266,7 +266,7 @@ def obj.read_yaml(path, template) end def obj_id - @obj_id = @obj_id*1 +1 + @obj_id = @obj_id * 1 + 1 return (@obj_id - 1) end end From a6f6a0249ad7575e8598ae8bb982443a05849c7a Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 28 Feb 2022 12:35:35 +0100 Subject: [PATCH 78/85] remove unused variables --- lib/jekyll/helper/rdf_general_helper.rb | 2 +- test/ResourceHelper.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/helper/rdf_general_helper.rb b/lib/jekyll/helper/rdf_general_helper.rb index 77acb257..afb92b32 100644 --- a/lib/jekyll/helper/rdf_general_helper.rb +++ b/lib/jekyll/helper/rdf_general_helper.rb @@ -79,7 +79,7 @@ def self.load_prefixes(path, prefHolder) next [nil, nil] if arr[1].nil? [arr[0][7..-1].strip, arr[1].strip[1..-2]] }.flatten.reject {|x| x.nil?})] - rescue Errno::ENOENT => ex + rescue Errno::ENOENT Jekyll.logger.error("Prefix file not found: #{path}") raise end diff --git a/test/ResourceHelper.rb b/test/ResourceHelper.rb index 573cc70e..e505eb7e 100644 --- a/test/ResourceHelper.rb +++ b/test/ResourceHelper.rb @@ -33,7 +33,7 @@ def basic_config(url, baseurl) end def primitve_site_bad_config - site = create_fake_site() + create_fake_site() end def resource_with_prefixes_config(uri, prefixHash) From 05d7b06091760d21db77d56df121ead8a5ef28e6 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 28 Feb 2022 12:36:54 +0100 Subject: [PATCH 79/85] Add jekyll-cache and vendor to ignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 379b4122..d63b0044 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ *.rbc *.swp .sass-cache/ +.jekyll-cache/ +.vendor/ /.config /coverage/ /InstalledFiles From 6feb0fff158093e67f31a48c5c50efd19e61419d Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 28 Feb 2022 12:37:56 +0100 Subject: [PATCH 80/85] Update changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5720c056..78b471af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [3.1.1] - ??? +## [3.1.2] - ??? ### changed - Repository moved from https://github.com/white-gecko/jekyll-rdf/ to https://github.com/AKSW/jekyll-rdf/ - Add possibility to specify the default graph on a SPARQL endpoint @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Minor code cleanup - New `resource.rendered` attribute to check if a page is rendered in the present site for this resource. - Update class-template selection to be straightforward +- Update dependencies +- Remove some warnings +- Works with ruby 3 ## [3.1.0] - 2018-11-27 ### Added From 2366c39b37bdb466fa72822dca7d6bf04fc777a1 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 28 Feb 2022 15:51:08 +0100 Subject: [PATCH 81/85] Removed unused variable --- lib/jekyll/helper/rdf_prefix_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/helper/rdf_prefix_helper.rb b/lib/jekyll/helper/rdf_prefix_helper.rb index 75aae946..4bbf97d8 100644 --- a/lib/jekyll/helper/rdf_prefix_helper.rb +++ b/lib/jekyll/helper/rdf_prefix_helper.rb @@ -33,7 +33,7 @@ module RdfPrefixHelper # loads the prefix data passed in the layout yaml-frontmatter or in _config.yml into page.data["rdf_prefixes"] and page.data["rdf_prefix_map"] def load_prefixes(path, prefHolder) Jekyll::JekyllRdf::Helper::RdfHelper.load_prefixes(path, prefHolder) - rescue Errno::ENOENT => ex + rescue Errno::ENOENT Jekyll.logger.error("--> context resource: #{@resource} template: #{@template}") unless self.data["rdf"].nil? raise if Jekyll.env.eql? "development" end From a017a3839e2cdde4244bc406ca75763bc1f4d2ff Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 28 Feb 2022 16:20:14 +0100 Subject: [PATCH 82/85] Remove space for method definition --- lib/jekyll/drops/rdf_term.rb | 2 +- lib/jekyll/helper/rdf_generator_helper.rb | 6 +++--- test/ResourceHelper.rb | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/jekyll/drops/rdf_term.rb b/lib/jekyll/drops/rdf_term.rb index 3c0e9c13..1281ea75 100644 --- a/lib/jekyll/drops/rdf_term.rb +++ b/lib/jekyll/drops/rdf_term.rb @@ -49,7 +49,7 @@ def initialize(term) ## # Function stub with no functionality. Its purpose is to keep RdfResource compatible. # - def add_necessities (site, page) + def add_necessities(site, page) return self end diff --git a/lib/jekyll/helper/rdf_generator_helper.rb b/lib/jekyll/helper/rdf_generator_helper.rb index 54c9069c..e1bd42e5 100644 --- a/lib/jekyll/helper/rdf_generator_helper.rb +++ b/lib/jekyll/helper/rdf_generator_helper.rb @@ -3,7 +3,7 @@ module JekyllRdf module Helper module RdfGeneratorHelper private - def prepare_pages (site, mapper) + def prepare_pages(site, mapper) Jekyll::Page.prepend Jekyll::JekyllRdf::Helper::RdfPageHelper @pageResources.each{|uri, entry| resource = entry.delete('./') @@ -16,7 +16,7 @@ def prepare_pages (site, mapper) } end - def parse_resources (resources) + def parse_resources(resources) @pageResources={}; @blanknodes=[] resources.each do |uri| @@ -45,7 +45,7 @@ def parse_resources (resources) } end - def load_config (site) + def load_config(site) begin @config = site.config.fetch('jekyll_rdf') rescue KeyError diff --git a/test/ResourceHelper.rb b/test/ResourceHelper.rb index e505eb7e..adfb9982 100644 --- a/test/ResourceHelper.rb +++ b/test/ResourceHelper.rb @@ -99,7 +99,7 @@ def site.config def attach_site(resource, site) if(!resource.respond_to?(:site)) - def resource.site= (obj) + def resource.site=(obj) @site = obj end def resource.site @@ -111,7 +111,7 @@ def resource.site def attach_page(resource, page) if(!resource.respond_to?(:page)) - def resource.page= (obj) + def resource.page=(obj) @page = obj end def resource.page @@ -142,7 +142,7 @@ def fake_page.data return @data end - def fake_page.id= (id) + def fake_page.id=(id) @type = :page @id = id end @@ -198,7 +198,7 @@ def fake_site.data return @data end - def fake_site.id= (id) + def fake_site.id=(id) @type = :site @id = id end @@ -222,7 +222,7 @@ def fake_site.inspect return fake_site end - def create_config_language (lang) + def create_config_language(lang) config = { 'jekyll_rdf' => { 'language' => 'en' From 062cc6eaae72d6d12054a889d3022e4346edf84a Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 28 Feb 2022 16:20:35 +0100 Subject: [PATCH 83/85] Remove redundant require for jekyll --- test/test_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 6adeb9ef..471ce2a9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,3 @@ -require 'jekyll' require 'test-unit' require 'shoulda-context' require 'rspec/expectations' From 1641b3582bb54f426449236c713c292ad8555be6 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 28 Feb 2022 16:20:50 +0100 Subject: [PATCH 84/85] Remove empty line --- Rakefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Rakefile b/Rakefile index eaf3ee0f..3fe2fe80 100644 --- a/Rakefile +++ b/Rakefile @@ -20,4 +20,3 @@ require 'rdoc/task' RDoc::Task.new do |rdoc| rdoc.rdoc_files.include("lib/**/*.rb") end - From 58005829d8500983a2f62adb3475c0ecf7262ba4 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 28 Feb 2022 16:28:32 +0100 Subject: [PATCH 85/85] Prepare 3.2.0 release --- CHANGELOG.md | 15 ++++++++------- README.md | 2 +- jekyll-rdf.gemspec | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78b471af..12a952fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,18 +4,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [3.1.2] - ??? -### changed +## [3.2.0] - 2022-02-28 +### Added +- Support for Ruby 3 +- New `resource.rendered` attribute to check if a page is rendered in the present site for this resource. + +### Changed - Repository moved from https://github.com/white-gecko/jekyll-rdf/ to https://github.com/AKSW/jekyll-rdf/ - Add possibility to specify the default graph on a SPARQL endpoint -- Some updates in the test/build system -- Update some dependencies -- Minor code cleanup -- New `resource.rendered` attribute to check if a page is rendered in the present site for this resource. - Update class-template selection to be straightforward - Update dependencies +- Minor code cleanup +- Some updates in the test/build system - Remove some warnings -- Works with ruby 3 ## [3.1.0] - 2018-11-27 ### Added diff --git a/README.md b/README.md index 2a50a76e..72ee21ad 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Probably you already using [Bundler](https://bundler.io/) and there is a [`Gemfi Add Jekyll-RDF to the plugins section: ``` -gem "jekyll-rdf", "~> 3.1" +gem "jekyll-rdf", "~> 3.2" ``` Replace the version string with the currently available stable release as listed on [rubygems.org](https://rubygems.org/gems/jekyll-rdf). diff --git a/jekyll-rdf.gemspec b/jekyll-rdf.gemspec index d8ddf49b..2653022c 100644 --- a/jekyll-rdf.gemspec +++ b/jekyll-rdf.gemspec @@ -1,5 +1,5 @@ # coding: utf-8 -VERSION = '3.1.2' +VERSION = '3.2.0' RELEASE_VERSION = case when ENV['TRAVIS'] && ENV['TRAVIS_BRANCH'].match(/^master$/i) then "#{VERSION}" when ENV['TRAVIS'] && ENV['TRAVIS_BRANCH'].match(/^develop$/i) then "#{VERSION}-#{ENV['TRAVIS_BRANCH']}.#{ENV['TRAVIS_BUILD_NUMBER']}"
{{ result.sub }}{{ result.pre }}