Skip to content
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
6 changes: 5 additions & 1 deletion lib/ldpath/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def initialize(type)
def evaluate(program, uri, _context)
return unless uri.literal?

uri if uri.has_datatype? && uri.datatype == type
uri if (uri.has_datatype? && uri.datatype == type) || (uri.plain? && string_type?(type))
end

def string_type? type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a private method?

[RDF.langString, RDF::URI("http://www.w3.org/2001/XMLSchema#string")].include?(type)
end
end

Expand Down
9 changes: 7 additions & 2 deletions spec/ldpath_program_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
conditional_false = dcterms:isPartOf[dcterms:description] ;
int_value = <info:intProperty>[^^xsd:integer] :: xsd:integer ;
numeric_value = <info:numericProperty> :: xsd:integer ;
string_title = dcterms:title[^^xsd:string] :: xsd:string ;
escaped_string = "\\"" :: xsd:string;
and_test = .[dcterms:title & dcterms:gone] ;
or_test = .[dcterms:title | dcterms:gone] ;
Expand All @@ -38,7 +39,10 @@
end

it "should work" do
b1 = RDF::Node.new('b1')
graph << [object, RDF::Vocab::DC.title, "Hello, world!"]
graph << [object, RDF::Vocab::DC.title, b1]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding in a blank node to the title because there needs to be something other than string for test differentiation.

graph << [b1, RDF::Vocab::SKOS.prefLabel, "Title through blank node"]
graph << [object, RDF::Vocab::DC.isPartOf, parent]
graph << [object, RDF::Vocab::DC.description, RDF::Literal.new("English!", language: "en")]
graph << [object, RDF::Vocab::DC.description, RDF::Literal.new("French!", language: "fr")]
Expand All @@ -53,20 +57,21 @@
graph << [parent, RDF::Vocab::DC.isPartOf, grandparent]

result = subject.evaluate object, context: graph
expect(result["title"]).to match_array "Hello, world!"
expect(result["title"]).to match_array ["Hello, world!", "_:b1"]
expect(result["parent_title"]).to match_array ["Parent title", "Parent English!", "Parent French!"]
expect(result["parent_title_en"]).to match_array "Parent English!"
expect(result["self"]).to match_array(object)
expect(result["wildcard"]).to include "Hello, world!", parent
expect(result["child_title"]).to match_array "Child title"
expect(result["titles"]).to match_array ["Hello, world!", "Parent title", "Child title", "Parent English!", "Parent French!"]
expect(result["titles"]).to match_array ["Hello, world!", "Parent title", "Child title", "Parent English!", "Parent French!", "_:b1"]
expect(result["no_titles"]).to be_empty
expect(result["recursive"]).to match_array [parent, grandparent]
expect(result["en_description"].first.to_s).to eq "English!"
expect(result["conditional"]).to match_array parent
expect(result["conditional_false"]).to be_empty
expect(result["int_value"]).to match_array 1
expect(result["numeric_value"]).to match_array 1
expect(result["string_title"]).to match_array ["Hello, world!"]
expect(result["escaped_string"]).to match_array '\"'
expect(result["and_test"]).to be_empty
expect(result["or_test"]).to match_array(object)
Expand Down