Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

WIP: Coverage recovery #268

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/jekyll/drops/rdf_literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def literal
# rdf literals as well
# source: https://github.com/eccenca/jekyll-rdf/commit/704dd98c5e457a81e97fcd011562f1f39fc3f813
#
def to_liquid
def to_s
# Convert scientific notation

term_str = term.to_s
Expand All @@ -55,6 +55,17 @@ def to_liquid
return term.to_s
end

# allows filters like plus/subtract to work
def to_number
obj = to_s
#ripped from https://github.com/Shopify/liquid/blob/8dcc3191281478c4ba544d3c507fdb99aa512f75/lib/liquid/utils.rb
(obj.strip =~ /\A-?\d+\.\d+\z/) ? BigDecimal(obj) : obj.to_i
end

# allows filters like date to work
def strftime format
Time.parse(to_s).strftime(format)
end
end
end
end
Expand Down
15 changes: 8 additions & 7 deletions lib/jekyll/helper/rdf_class_extraction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ def request_class_template resource
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
if(!min_class.nil? &&( min_template_lock == lock || (min_template_lock == -1 && lock == 0))) #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
Expand Down Expand Up @@ -98,7 +97,8 @@ def request_class_template resource
#
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)
return (@template_cache[hash_str] = class_resource.get_path_root.template) unless(class_resource.get_path_root.template.nil?) #toDo: remove the unless-part + the default under it in another pr
return class_resource.template #toDo find_highlevel_inheritance: "@classResources[uri].path = resource" causes get_path_root to go to far or propagate_template does not work correctly?
end

##
Expand All @@ -107,17 +107,18 @@ def extract_template class_resource, hash_str
# +resource+ is the original input of request_class_template.
#
def find_highlevel_inheritance current_best, class_list, resource #check at the end of the search for direct inheritance on highest level
class_list.each{|resource|
all_solutions = class_list.dup.push(current_best)
all_solutions.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)
while(all_solutions.include?(current_best.path))
slice = all_solutions.index(current_best)
# parent alternatives are no real alternatives
class_list.slice!(slice) unless slice.nil?
all_solutions.slice!(slice) unless slice.nil?
current_best = current_best.path
end
return consistence_templates(current_best, class_list, resource) unless class_list.empty?
Expand Down
5 changes: 4 additions & 1 deletion test/cases/classHierarchy/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ plugins:
- jekyll-rdf
jekyll_rdf:
path: "_data/knowledge-base.ttl"
restriction: "SELECT ?resourceUri WHERE {?resourceUri <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?o}"
restriction: "SELECT ?resourceUri WHERE {?resourceUri <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://jekyll.com/jekyll-rdf/render>}"
class_template_mappings:
"http://animals.org/classification/landBorn": "landBorn"
"http://animals.org/classification/layingEggs": "layingEggs"
"http://animals.org/classification/foodFromWater": "foodFromWater"
"http://animals.org/classification/breathingAir": "breathingAir"
"http://animals.org/classification/PseudoClass31": "PseudoClass03"
"http://animals.org/classification/PseudoClass32": "PseudoClass30"
"http://animals.org/classification/TestClass" : "PseudoClass03"
30 changes: 30 additions & 0 deletions test/cases/classHierarchy/_data/knowledge-base.ttl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix an: <http://animals.org/classification/> .
@prefix ani: <http://animals.org/instance/> .
@prefix jrdf: <http://jekyll.com/jekyll-rdf/> .

an:landBorn rdfs:subClassOf an:animal .
an:birds rdfs:subClassOf an:animal .
Expand Down Expand Up @@ -30,3 +31,32 @@ ani:Fish a an:waterHunting .
ani:Fish a an:waterFiltering .
ani:Whale a an:breathingAir .
ani:Whale a an:foodFromWater .

ani:ape a jrdf:render .
ani:Lizard a jrdf:render .
ani:Penguins a jrdf:render .
ani:Fish a jrdf:render .
ani:Whale a jrdf:render .

an:PseudoClass11 rdfs:subClassOf an:PseudoClass21 .
an:PseudoClass21 rdfs:subClassOf an:PseudoClass31 .
an:PseudoClass12 rdfs:subClassOf an:PseudoClass22 .
an:PseudoClass22 rdfs:subClassOf an:PseudoClass32 .
an:PseudoMergeClass rdfs:subClassOf an:PseudoClass11 .
an:PseudoMergeClass rdfs:subClassOf an:PseudoClass12 .
an:PseudoClass32 rdfs:subClassOf an:PseudoClass31 .
an:PseudoDirectClass rdfs:subClassOf an:PseudoClass31 .
an:PseudoDirectClass rdfs:subClassOf an:PseudoClass32 .

ani:PseudoInstance1 a an:PseudoClass11 .
ani:PseudoInstance2 a an:PseudoClass12 .
ani:PseudoTestInstance a an:PseudoMergeClass .
ani:PseudoTestDirectInstance a an:PseudoDirectClass .

an:priorSplit rdfs:subClassOf an:Split1 .
an:priorSplit rdfs:subClassOf an:Split2 .
an:Split1 rdfs:subClassOf an:afterSplit .
an:Split2 rdfs:subClassOf an:afterSplit .
an:afterSplit rdfs:subClassOf an:TestClass .

ani:PseudoInstance3 a an:priorSplit .
14 changes: 14 additions & 0 deletions test/cases/classHierarchy/_layouts/PseudoClass03.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
---
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="mapping">{{page.rdf}}<br/>
PseudoClass03
</div>
</body>
</html>
14 changes: 14 additions & 0 deletions test/cases/classHierarchy/_layouts/PseudoClass30.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
---
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="mapping">{{page.rdf}}<br/>
PseudoClass30
</div>
</body>
</html>
10 changes: 10 additions & 0 deletions test/cases/classHierarchy/test_class_hierarchy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ class TestClassHierarchy < Test::Unit::TestCase

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: ***<<<"

config = Jekyll.configuration(YAML.load_file(File.join(@source, '_config.yml')).merge!({'source' => @source, 'destination' => File.join(@source, "_site")}))
mapper = Jekyll::RdfTemplateMapper.new(config["jekyll_rdf"]['instance_template_mappings'], config["jekyll_rdf"]['class_template_mappings'], config["jekyll_rdf"]['default_template'])

assert_equal "PseudoClass30", mapper.map(Jekyll::JekyllRdf::Drops::RdfResource.new(RDF::URI("http://animals.org/instance/PseudoTestDirectInstance")))
mapper.map(Jekyll::JekyllRdf::Drops::RdfResource.new(RDF::URI("http://animals.org/instance/PseudoInstance1")))
mapper.map(Jekyll::JekyllRdf::Drops::RdfResource.new(RDF::URI("http://animals.org/instance/PseudoInstance2")))
test = mapper.map(Jekyll::JekyllRdf::Drops::RdfResource.new(RDF::URI("http://animals.org/instance/PseudoTestInstance")))
assert (("PseudoClass30".eql? test) || ("PseudoClass03".eql? test)), "The mapper should have returned PseudoClass03 or PseudoClass30, but returned: #{test}"
assert_equal "PseudoClass03", mapper.map(Jekyll::JekyllRdf::Drops::RdfResource.new(RDF::URI("http://animals.org/instance/PseudoInstance3")))
end
end
end
4 changes: 4 additions & 0 deletions test/cases/debugTools/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'
group :jekyll_plugins do
gem 'jekyll-rdf', '>= 3.0.0.a' #, :path => '../../../'
end
14 changes: 14 additions & 0 deletions test/cases/debugTools/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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"
class_template_mappings:
"http://xmlns.com/foaf/0.1/Person": "person"
instance_template_mappings:
"http://example.org/instance/resource": "exampleInstance"
5 changes: 5 additions & 0 deletions test/cases/debugTools/_data/Prefixes.pref
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX eg: <http://example.org/instance/>
10 changes: 10 additions & 0 deletions test/cases/debugTools/_data/knowledge-base.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix eg: <http://example.org/instance/> .

eg:resource eg:predicate eg:object .
eg:person a foaf:Person .
eg:person foaf:age "28"^^xsd:int .
eg:person foaf:name "Jeanne Doe" .
12 changes: 12 additions & 0 deletions test/cases/debugTools/_layouts/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
---
<!DOCTYPE html>
<html>
<head></head>
<body>
<div>
<h4>This is made with jekyll-rdf</h4>
{{content}}
</div>
</body>
</html>
8 changes: 8 additions & 0 deletions test/cases/debugTools/_layouts/exampleInstance.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
layout: default
rdf_prefix_path: _data/Prefixes.pref
---
<div class="instance">
<h6> This page is mapped to: </h6>
{{page.rdf}}
</div>
15 changes: 15 additions & 0 deletions test/cases/debugTools/_layouts/person.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
layout: default
rdf_prefix_path: _data/Prefixes.pref
---
<div class="person">
<h6>
name:
</h6>
{{page.rdf | rdf_property: "foaf:name"}}
<br/>
<h6>
age:
</h6>
{{page.rdf | rdf_property: "foaf:age"}}
</div>
18 changes: 18 additions & 0 deletions test/cases/debugTools/debug.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
---
<html>
<head>
<title>Debug Messages</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>
{%- assign message = "Info message" | rdf_debug_message: "info" -%}
{%- assign message = "Warn message" | rdf_debug_message: "warn" -%}
{%- assign message = "Error message" | rdf_debug_message: "error" -%}
{%- assign message = "Debug message" | rdf_debug_message: "debug" -%}
{%- assign message = "message" | rdf_debug_message: "none" -%}
</div>
</body>
</html>
25 changes: 25 additions & 0 deletions test/cases/debugTools/test_debug.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class TestPages < Test::Unit::TestCase
include RdfTestUtility
context "Jekyll logger" do
setup do
Jekyll.logger.log_level = :debug
old_err_out = $stderr
old_std_out = $stdout
dummy_out = StringIO.new
$stderr = dummy_out
$stdout = dummy_out
setup_jekyll File.dirname(__FILE__)
$stderr = old_err_out
$stdout = old_std_out
Jekyll.logger.log_level = :error
end

should "contain messages" do
assert (Jekyll.logger.messages.any? {|message| !!(message =~/.*Info message.*/)}), "Jekyll.logger should contain message: >>>Info message<<<"
assert (Jekyll.logger.messages.any? {|message| !!(message =~/.*Warn message.*/)}), "Jekyll.logger should contain message: >>>Warn message<<<"
assert (Jekyll.logger.messages.any? {|message| !!(message =~/.*Error message.*/)}), "Jekyll.logger should contain message: >>>Error message<<<"
assert (Jekyll.logger.messages.any? {|message| !!(message =~/.*Debug message.*/)}), "Jekyll.logger should contain message: >>>Debug message<<<"
assert (Jekyll.logger.messages.any? {|message| !!(message =~/.*NoLevel: message.*/)}), "Jekyll.logger should contain message: >>>NoLevel: message<<<"
end
end
end
2 changes: 2 additions & 0 deletions test/cases/generalTest/_data/knowledge-base.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

eg:resource eg:predicate eg:object .
eg:subject eg:resource "label"@en .
eg:subject eg:predicate eg:resource .
eg:person a foaf:Person .
eg:person foaf:age "28"^^xsd:int .
eg:person foaf:name "Jeanne Doe" .
Expand Down
23 changes: 18 additions & 5 deletions test/cases/generalTest/_layouts/exampleInstance.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
---
layout: default
rdf_prefix_path: _data/Prefixes.pref
---
<div class="instance">
<h6> This page is mapped to: </h6>
{{page.rdf}}
</div>
<!DOCTYPE html>
<html>
<head></head>
<body>
<div>
<h6> This page is mapped to: </h6> <br/>
{{ page.rdf }} <br/>
<h6> Statements </h6> <br/>
{%- for statement in page.rdf.statements -%}
{{ statement.subject }}--{{ statement.predicate }}--{{ statement.object }} <br/>
{%- endfor -%}
{%- assign lit = "eg:subject" | rdf_property: "eg:resource" -%}
{{ lit }}<br/>
{%- assign liter = lit.literal -%}
{{ liter }}<br/>
</div>
</body>
</html>
10 changes: 10 additions & 0 deletions test/cases/generalTest/test_general.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,15 @@ class TestGeneral < Test::Unit::TestCase
assert "<h6>Prefix rdfs:Container</h6>".eql?(content[4]), "Headline should be <h6>Prefix rdf:type</h6>\nIt was: #{content[4]}"
assert "http://www.w3.org/2000/01/rdf-schema#Container".eql?(content[5]), "This line should be >>>http://www.w3.org/2000/01/rdf-schema#Container<<< \nIt was :#{content[5]}"
end

should "render statements" do
file = File.read(File.join(@source, "_site/resource.html"))
content = file[/\<div\>(.|\s)*\<\/div>/][5..-7].strip.split("<br/>").map do |entry|
entry.strip
end
assert (content.include? "http://example.org/instance/resource--http://example.org/instance/predicate--http://example.org/instance/object"), "statement http://example.org/instance/resource--http://example.org/instance/predicate--http://example.org/instance/object was not rendered"
assert (content.include? "http://example.org/instance/subject--http://example.org/instance/resource--label"), "statement http://example.org/instance/subject--http://example.org/instance/resource--label was not rendered"
assert (content.include? "http://example.org/instance/subject--http://example.org/instance/predicate--http://example.org/instance/resource"), "statement http://example.org/instance/subject--http://example.org/instance/predicate--http://example.org/instance/resource was not rendered"
end
end
end
5 changes: 5 additions & 0 deletions test/cases/includeAll/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'https://rubygems.org'
group :jekyll_plugins do
gem 'jekyll-rdf', :path => '../../../'
end

10 changes: 10 additions & 0 deletions test/cases/includeAll/_config.yml
Original file line number Diff line number Diff line change
@@ -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
plugins:
- jekyll-rdf
jekyll_rdf:
baseiri: "http://example.org/instance"
path: "_data/knowledge-base.ttl"
include_blank: true
default_template: "default"
2 changes: 2 additions & 0 deletions test/cases/includeAll/_data/Prefixes.pref
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PREFIX eg: <http://example.org/instance/>

3 changes: 3 additions & 0 deletions test/cases/includeAll/_data/knowledge-base.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@prefix eg: <http://example.org/instance/> .

_:resource eg:predicate eg:object .
12 changes: 12 additions & 0 deletions test/cases/includeAll/_layouts/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
---
<!DOCTYPE html>
<html>
<head></head>
<body>
<div>
<h4>This is made with jekyll-rdf</h4>
{{content}}
</div>
</body>
</html>
8 changes: 8 additions & 0 deletions test/cases/includeAll/_layouts/exampleInstance.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
layout: default
rdf_prefix_path: _data/Prefixes.pref
---
<div class="instance">
<h6> This page is mapped to: </h6>
{{page.rdf}}
</div>
Loading