Last active
March 25, 2019 02:05
-
-
Save elrayle/581e0ca23a0a5a8176fcbab26b02b5d1 to your computer and use it in GitHub Desktop.
Spec to demonstrate context + network call to get results for ldpath.rb issue #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
require 'byebug' | |
describe 'ldpath_program' do | |
let(:program) { ldpath_program(ldpath) } | |
let(:prefixes) do | |
{ | |
"madsrdf" => "http://www.loc.gov/mads/rdf/v1#", | |
"schema" => "http://www.w3.org/2000/01/rdf-schema#" | |
} | |
end | |
let(:subject_uri) { RDF::URI('http://id.loc.gov/authorities/names/n79021164') } | |
let(:graph) do | |
graph = RDF::Graph.new | |
graph << [subject_uri, RDF::Vocab::MADS.authoritativeLabel, 'Mark Twain'] | |
graph | |
end | |
let(:ldpath) { "madsrdf:authoritativeLabel :: xsd:string" } | |
let(:expected_values) { ['Mark Twain'] } | |
it 'returns values from context only' do | |
# Test fails with actual_values: ["Mark Twain", "Twain, Mark, 1835-1910"] | |
# The second value is retrieved by making a network request to the subject_uri. | |
# IN LOG: Loading "http://id.loc.gov/authorities/names/n79021164" | |
# Is there a way to force ldpath to use the provided context only? | |
expect(ldpath_evaluate(program, graph, subject_uri)).to eq expected_values | |
end | |
end | |
def ldpath_program(ldpath) | |
program_code = "" | |
prefixes.each { |key, url| program_code << "@prefix #{key} : <#{url}> \;\n" } | |
program_code << "property = #{ldpath} \;" | |
Ldpath::Program.parse program_code | |
end | |
def ldpath_evaluate(program, graph, subject_uri) | |
output = program.evaluate subject_uri, context: graph | |
output.nil? ? nil : output['property'].uniq | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment