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 diff --git a/.travis.yml b/.travis.yml index dac99bb8..ba8af76d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,19 @@ -sudo: required 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: - 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 +- cd test/theme-gem +- bundle install +- cd ../.. script: - bundle exec rake test deploy: @@ -21,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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 60075f90..12a952fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,20 @@ 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.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 +- Update class-template selection to be straightforward +- Update dependencies +- Minor code cleanup +- Some updates in the test/build system +- Remove some warnings + ## [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/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 - 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/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 diff --git a/README.md b/README.md index e7c03c76..72ee21ad 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# jekyll-rdf +# Jekyll RDF 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/). @@ -27,15 +27,12 @@ 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: ``` -group :jekyll_plugins do - gem "jekyll-rdf", '~> 3.0.0.pre.a' - … -end +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). @@ -66,7 +63,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 +82,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 @@ -110,7 +121,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 @@ -127,7 +138,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`: @@ -146,7 +157,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` (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: @@ -271,8 +282,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 %} @@ -342,8 +353,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 knowledge base. + +### 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. @@ -379,7 +394,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):** ``` @@ -436,7 +451,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):** ``` @@ -489,7 +504,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 %} @@ -649,8 +664,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 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 }"```| @@ -664,7 +680,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: ``` @@ -679,7 +695,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 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 - diff --git a/jekyll-rdf.gemspec b/jekyll-rdf.gemspec index 352481ae..2653022c 100644 --- a/jekyll-rdf.gemspec +++ b/jekyll-rdf.gemspec @@ -1,4 +1,5 @@ -VERSION = '3.1.0' +# coding: utf-8 +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']}" @@ -13,18 +14,19 @@ 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 'linkeddata', '~> 2.0' - s.add_runtime_dependency 'sparql', '~> 2.2', '>= 2.2.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_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', '~> 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' 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' + s.add_development_dependency 'kramdown-parser-gfm', '~> 1.1' end diff --git a/lib/jekyll-rdf.rb b/lib/jekyll-rdf.rb index 8624c59c..c488f0c6 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' @@ -51,15 +52,15 @@ 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/helper/rdf_hook_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_resolve_prefix.rb b/lib/jekyll/drops/rdf_graph.rb similarity index 50% rename from lib/jekyll/filters/rdf_resolve_prefix.rb rename to lib/jekyll/drops/rdf_graph.rb index 7f3300a1..a6fcafe0 100644 --- a/lib/jekyll/filters/rdf_resolve_prefix.rb +++ b/lib/jekyll/drops/rdf_graph.rb @@ -23,38 +23,34 @@ # SOFTWARE. # -module Jekyll - module JekyllRdf - module ResolvePrefixes - private - def rdf_resolve_prefix(predicate) - if(predicate[0] == "<" && predicate[-1] == ">") - # iri - return predicate +module Jekyll #:nodoc: + module JekyllRdf #:nodoc: + module Drops #:nodoc: + class RdfGraph < Liquid::Drop + attr_reader :graph + + def initialize(graph) + @graph = graph 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 + + def to_s + to_nquads 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 + + def to_nquads + result = @graph.statements.map{|state| + state.to_nquads + }.join("") + return result end - end - end - end -end -module Jekyll - module JekyllRdf - module Filter - include Jekyll::JekyllRdf::ResolvePrefixes + def to_ntriples + result = @graph.statements.map{|state| + state.to_ntriples + }.join("") + return result + end + end end end end diff --git a/lib/jekyll/drops/rdf_resource.rb b/lib/jekyll/drops/rdf_resource.rb index 7fdce008..e172fdb3 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 # @@ -146,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 @@ -216,6 +225,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) @@ -254,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 19138ec7..6e09064b 100644 --- a/lib/jekyll/drops/rdf_resource_class.rb +++ b/lib/jekyll/drops/rdf_resource_class.rb @@ -31,58 +31,68 @@ 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_reader :distance #distance to next class with template attr_accessor :template - attr_accessor :alternativeTemplates - attr_accessor :subClasses - attr_accessor :subClassHierarchyValue - attr_reader :sparql + attr_accessor :path + attr_accessor :base # important for template mapping + # true if _config.yml assigned this class a template - def initialize(term, sparql) + def initialize(term, base = false) super(term) - @subClasses = [] + @base = base @lock = -1 - @subClassHierarchyValue = 0 - @alternativeTemplates = [] - @sparql = sparql + @lockNumber = 0 + @distance = 0 end - def multiple_templates? - !@alternativeTemplates.empty? - end - - def find_direct_subclasses - query = "SELECT ?s WHERE{ ?s #{@term.to_ntriples}}" - selection = @sparql.query(query).map{ |solution| solution.s.to_s} + ## + # 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 }" + selection = Jekyll::JekyllRdf::Helper::RdfHelper::sparql. + query(query).map{ |solution| solution.s.to_s} + @superclasses = selection return selection end - def add_subclass(resource) - @subClasses << resource + ## + # Propagate the current template to the parent of the breadth-first search + # in RdfClassExtraction.request_class_template. + # + def propagate_template(distance) + @distance = distance + return if @path.nil? + return unless @path.template.nil? + @path.template = @template + @path.propagate_template(distance + 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 + ## + # 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 - def traverse_hierarchy_value(predecessorHierarchyValue) - if(@subClassHierarchyValue + 1 >= predecessorHierarchyValue) #avoid loops - @subClassHierarchyValue += 1 - subClasses.each{|sub| sub.traverse_hierarchy_value(@subClassHierarchyValue)} + ## + # 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 + # used to recognize different searchpasses of request_class_template + @lock_number = lock_number + @lock = -1 + true + else + false end end - end + end #RdfResourceClass end end end diff --git a/lib/jekyll/drops/rdf_term.rb b/lib/jekyll/drops/rdf_term.rb index 42346ad3..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 @@ -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 b191296a..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::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]) end end end 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_property.rb b/lib/jekyll/filters/rdf_property.rb index 29d5c015..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::Drops::RdfResource.new(subject, Jekyll::JekyllRdf::Helper::RdfHelper::site, Jekyll::JekyllRdf::Helper::RdfHelper::page, 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::Drops::RdfResource.new(object, Jekyll::JekyllRdf::Helper::RdfHelper::site, Jekyll::JekyllRdf::Helper::RdfHelper::page, true) + result = Jekyll::JekyllRdf::Helper::RdfHelper.resources(object) end return result end diff --git a/lib/jekyll/filters/rdf_sparql_query.rb b/lib/jekyll/filters/rdf_sparql_query.rb index f7d105a7..75189f3d 100644 --- a/lib/jekyll/filters/rdf_sparql_query.rb +++ b/lib/jekyll/filters/rdf_sparql_query.rb @@ -38,27 +38,14 @@ 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| + result = Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(query) + if (result.class == RDF::Graph) + return Jekyll::JekyllRdf::Drops::RdfGraph.new(result) + 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/lib/jekyll/helper/rdf_class_extraction.rb b/lib/jekyll/helper/rdf_class_extraction.rb index b1470f5d..bb95c52e 100644 --- a/lib/jekyll/helper/rdf_class_extraction.rb +++ b/lib/jekyll/helper/rdf_class_extraction.rb @@ -2,47 +2,165 @@ 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 + + ## + # 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| + @classResources[uri] = Jekyll::JekyllRdf::Drops:: + RdfResourceClass.new(RDF::URI(uri), true) + @classResources[uri].template = template + } end - return class_search_results end - def create_resource_class(class_search_results, sparql) - class_search_results.each do |uri| - @classResources[uri.to_s]=Jekyll::JekyllRdf::Drops::RdfResourceClass.new(uri, sparql) - end + ## + # 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 + #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 + next_increase = -1 + lock_number = rand + min_template_lock = @stop_object #ruby does not have MAX_VALUE + 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] + } + alternatives = [] + class_list.each{|class_resource| + if(next_increase <= count) # the next level of the breadth-first search + 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() + lock += 1 + next_increase = class_list.length + end - @classResources.each{|key, value| - value.find_direct_subclasses.each{|s| - value.add_subclass(@classResources[s]) + 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)) + 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] unless min_class.eql? @classResources[uri] + else + min_template_lock = lock + min_class = @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 + # 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] 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 + class_list.push(@classResources[uri]) + @classResources[uri].lock = lock + end } + count += 1 } + + unless min_class.nil? + return extract_template(find_highlevel_inheritance(min_class, alternatives, resource), hash_str) + end + return nil 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].traverse_hierarchy_value(0); - } - @classResources.default = nil + ## + # 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 + + ## + # Check at the end of the search for direct inheritance on highest level. + # Returns the most specific class resource from +class_list+ based on + # +current_best+. + # + # +class_list+ is the list of clases that the +resource+ is assigned to. + # +resource+ is the original input of request_class_template resp. the + # resource on which to decide. + # + 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)) + @classResources[uri].path = resource + } if resource.base + } + # this is valnuable to cyclic inheritance + while(class_list.include?(current_best.path)) + slice = class_list.index(current_best) + # 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? + return current_best + end + + ## + # 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). + map {|x| + x.template + }. + sort!.join(", ") + begin + @consistence[hash_str] = [] + @consistence[hash_str].push(classRes) + @consistence[hash_str].push([]) + end if @consistence[hash_str].nil? + # 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 - class StopObject #unfortunately next does not work in this setup, it avoids to have "if" in every iteration - def propagate_template(template, lock) - return + ## + # used to escape loops without an if-statement + # + class StopObject + def > object + true end - def traverse_hierarchy_value(predecessorHierarchyValue) - return + def <= object + false 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..abcb31f8 --- /dev/null +++ b/lib/jekyll/helper/rdf_filter_helper.rb @@ -0,0 +1,117 @@ +## +# 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 + + 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 + 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/helper/rdf_general_helper.rb b/lib/jekyll/helper/rdf_general_helper.rb index f71c4e5a..afb92b32 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 @@ -76,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 @@ -105,8 +108,32 @@ def self.pathiri= path def self.pathiri @@baseiri end - end - end - end -end + ## + # 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) + @@resources[uri.to_s] = resource + end + return resource + end + + ## + # resets RdfHelper to its initialization values + # + def self.reinitialize + @@prefixes.clear + @@usePage = false + @@resources.clear + @@site = nil + @@page = nil + end + end #RdfHelper + end #Helper + end #JekyllRdf +end #Jekyll diff --git a/lib/jekyll/helper/rdf_generator_helper.rb b/lib/jekyll/helper/rdf_generator_helper.rb index e3443372..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,11 +16,11 @@ def prepare_pages (site, mapper) } end - def parse_resources (resources) + 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) if(uri.instance_of? RDF::URI) uriString = uri.to_s if((uriString.include? "#") && (uriString.index("#") < (uriString.length - 1))) #sorting in uris with a # @@ -41,14 +41,14 @@ 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 - def load_config (site) + 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/lib/jekyll/helper/rdf_hook_helper.rb b/lib/jekyll/helper/rdf_hook_helper.rb new file mode 100644 index 00000000..e208bd69 --- /dev/null +++ b/lib/jekyll/helper/rdf_hook_helper.rb @@ -0,0 +1,92 @@ +## +# 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 backload_prefixes page, payload + prefix_path = page.data["rdf_prefix_path"] + 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( + 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) + end + 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 + 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 +end diff --git a/lib/jekyll/helper/rdf_page_helper.rb b/lib/jekyll/helper/rdf_page_helper.rb index b9106601..211a6b42 100644 --- a/lib/jekyll/helper/rdf_page_helper.rb +++ b/lib/jekyll/helper/rdf_page_helper.rb @@ -112,6 +112,7 @@ def setData ## # 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) 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 diff --git a/lib/jekyll/hooks/rdf_page_pointer.rb b/lib/jekyll/hooks/rdf_page_pointer.rb index 60940f7f..93ff5b17 100644 --- a/lib/jekyll/hooks/rdf_page_pointer.rb +++ b/lib/jekyll/hooks/rdf_page_pointer.rb @@ -22,14 +22,41 @@ # 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 + 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 - 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 if page.data["rdf_prefixes"].nil? Jekyll::JekyllRdf::Helper::RdfHelper::page = page end @@ -38,5 +65,7 @@ end Jekyll::Hooks.register :posts, :pre_render do |page, payload| + include Jekyll::JekyllRdf::Helper::RdfHookHelper + backload_prefixes page, payload Jekyll::JekyllRdf::Helper::RdfHelper::page = page -end \ No newline at end of file +end diff --git a/lib/jekyll/rdf_main_generator.rb b/lib/jekyll/rdf_main_generator.rb index 77af4c0f..a8447866 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 @@ -55,13 +55,17 @@ def generate(site) else graph = @config['remote']['endpoint'].strip end + 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 @@ -71,14 +75,14 @@ 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'] = [] 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..b5951f3f 100644 --- a/lib/jekyll/rdf_template_mapper.rb +++ b/lib/jekyll/rdf_template_mapper.rb @@ -37,14 +37,15 @@ 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) - assign_class_templates(classes_to_templates) + @consistence = {} #ensures that the same template is chosen for each combination of templates + @template_cache = {} + @stop_object = StopObject.new + + create_resource_class(classes_to_templates) end ## @@ -53,45 +54,17 @@ def initialize(resources_to_templates, classes_to_templates, default_template, s # 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 - 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") + tmpl = request_class_template(resource) 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 + # outputs all warnings prepared by RdfClassExtraction.consistence_templates # - 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 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/ResourceHelper.rb b/test/ResourceHelper.rb index ad222cb6..adfb9982 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) @@ -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' @@ -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 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..2693f802 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:waterFiltering . +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/Advanced.html b/test/cases/classHierarchy/_layouts/foodFromWater.html similarity index 92% rename from test/cases/classHierarchy/_layouts/Advanced.html rename to test/cases/classHierarchy/_layouts/foodFromWater.html index 05f4abff..d8c6e9d1 100644 --- a/test/cases/classHierarchy/_layouts/Advanced.html +++ b/test/cases/classHierarchy/_layouts/foodFromWater.html @@ -8,7 +8,7 @@
{{page.rdf}}
- Advanced + foodFromWater
diff --git a/test/cases/classHierarchy/_layouts/Master.html b/test/cases/classHierarchy/_layouts/landBorn.html similarity index 93% rename from test/cases/classHierarchy/_layouts/Master.html rename to test/cases/classHierarchy/_layouts/landBorn.html index 42d58ea8..d73db2ef 100644 --- a/test/cases/classHierarchy/_layouts/Master.html +++ b/test/cases/classHierarchy/_layouts/landBorn.html @@ -8,7 +8,7 @@
{{page.rdf}}
- Master + landBorn
diff --git a/test/cases/classHierarchy/_layouts/Supreme.html b/test/cases/classHierarchy/_layouts/layingEggs.html similarity index 93% rename from test/cases/classHierarchy/_layouts/Supreme.html rename to test/cases/classHierarchy/_layouts/layingEggs.html index ac7555bb..4474bfd3 100644 --- a/test/cases/classHierarchy/_layouts/Supreme.html +++ b/test/cases/classHierarchy/_layouts/layingEggs.html @@ -8,7 +8,7 @@
{{page.rdf}}
- Supreme + layingEggs
diff --git a/test/cases/classHierarchy/test_class_hierarchy.rb b/test/cases/classHierarchy/test_class_hierarchy.rb index 320cd49f..c08840b6 100644 --- a/test/cases/classHierarchy/test_class_hierarchy.rb +++ b/test/cases/classHierarchy/test_class_hierarchy.rb @@ -4,40 +4,55 @@ 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/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 "Master", 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] + + 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 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/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/constructs.html b/test/cases/constructQueries/constructs.html new file mode 100644 index 00000000..f6df7290 --- /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 | sparql_query -%} +
+ {{ 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 new file mode 100644 index 00000000..dd21a607 --- /dev/null +++ b/test/cases/constructQueries/test_construct_queries.rb @@ -0,0 +1,31 @@ +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 + 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[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[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 >>> <<<" + end + end +end 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..dd31a9ee --- /dev/null +++ b/test/cases/dontFailIfLayoutNoFound/test_prefixes.rb @@ -0,0 +1,18 @@ +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__) + + 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 diff --git a/test/cases/filter/test_rdf_filters.rb b/test/cases/filter/test_rdf_filters.rb index 21438616..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" @@ -335,7 +337,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/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 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." 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..c965ee0b --- /dev/null +++ b/test/cases/prefixesInPosts/_config.yml @@ -0,0 +1,11 @@ +baseurl: "/instance" +url: "http://example.org/" + +plugins: +- jekyll-rdf +jekyll_rdf: + path: "_data/knowledge-base.ttl" + restriction: "SELECT ?resourceUri WHERE {?resourceUri ?p ?o}" + instance_template_mappings: + "http://example.org/blog" : "post" + 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..405c543b --- /dev/null +++ b/test/cases/prefixesInPosts/_layouts/post.html @@ -0,0 +1,12 @@ +--- +rdf_prefix_path: _data/Prefixes.pref +--- + + + {% 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 diff --git a/test/cases/prefixesInPostsWithGemTheme/Gemfile b/test/cases/prefixesInPostsWithGemTheme/Gemfile new file mode 100644 index 00000000..74fb4acd --- /dev/null +++ b/test/cases/prefixesInPostsWithGemTheme/Gemfile @@ -0,0 +1,5 @@ +source 'https://rubygems.org' +group :jekyll_plugins do + 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 new file mode 100644 index 00000000..9503dfba --- /dev/null +++ b/test/cases/prefixesInPostsWithGemTheme/_config.yml @@ -0,0 +1,10 @@ +baseurl: "" +url: "http://example.org/" + +theme: theme-gem +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..39002fe1 --- /dev/null +++ b/test/cases/prefixesInPostsWithGemTheme/_data/knowledge-base.ttl @@ -0,0 +1,8 @@ +@prefix rdfs: . +@prefix owl: . + + a owl:Ontology ; + rdfs:label "My Jekyll RDF Blog" . + + a owl:Ontology ; + rdfs:label "My Jekyll RDF Blogpost" . 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..c2daa658 --- /dev/null +++ b/test/cases/prefixesInPostsWithGemTheme/test_prefixes.rb @@ -0,0 +1,33 @@ +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("
").map do |entry| + entry.strip + end + + 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/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 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 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..77f23d2b --- /dev/null +++ b/test/cases/resetSite/test_reset.rb @@ -0,0 +1,59 @@ +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 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] + 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 diff --git a/test/cases/restrictions/Gemfile b/test/cases/restrictions/Gemfile new file mode 100644 index 00000000..4d519ca0 --- /dev/null +++ b/test/cases/restrictions/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +group :jekyll_plugins do + gem 'jekyll-rdf', :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 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 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..ecc86fa3 --- /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_equal 3, resources.length # 3 because the template mapping creates additional resources + 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}} +
+ + diff --git a/test/test_helper.rb b/test/test_helper.rb index 6b21b6c9..471ce2a9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,13 +1,19 @@ -require 'jekyll' require 'test-unit' require 'shoulda-context' require 'rspec/expectations' -require 'pry' +require 'simplecov' require 'coveralls' require 'ResourceHelper' require 'RdfTestUtility' + +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' -Coveralls.wear! Jekyll.logger.log_level = :error class TestHelper 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/_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 new file mode 100644 index 00000000..4605887c --- /dev/null +++ b/test/theme-gem/_layouts/ontology.html @@ -0,0 +1,16 @@ +--- +rdf_prefix_path: "_data/prefixes.sparql" +--- + + + ontology layout + + + + +

My Jekyll RDF Blog


+ {{content}}
+ {{ page.rdf | rdf_property: "rdfs:label" }}
+ {{ "" | rdf_get | rdf_property: "rdfs:label" }}
+ + 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 +
{{ result.sub }}{{ result.pre }}