|
36 | 36 | schema: "http://schema.org/",
|
37 | 37 | xsd: "http://www.w3.org/2001/XMLSchema#"
|
38 | 38 | }
|
39 |
| -example_dir = yaml_dir = verbose = number = nil |
| 39 | +example_dir = yaml_dir = verbose = number = line = nil |
40 | 40 |
|
41 | 41 | opts = GetoptLong.new(
|
42 | 42 | ["--example-dir", GetoptLong::REQUIRED_ARGUMENT],
|
43 | 43 | ["--yaml-dir", GetoptLong::REQUIRED_ARGUMENT],
|
44 | 44 | ["--verbose", '-v', GetoptLong::NO_ARGUMENT],
|
45 | 45 | ["--number", '-n', GetoptLong::REQUIRED_ARGUMENT],
|
| 46 | + ["--line", '-l', GetoptLong::REQUIRED_ARGUMENT], |
46 | 47 | )
|
47 | 48 | opts.each do |opt, arg|
|
48 | 49 | case opt
|
49 | 50 | when '--example-dir' then example_dir = arg && FileUtils::mkdir_p(arg)
|
50 | 51 | when '--yaml-dir' then yaml_dir = arg && FileUtils::mkdir_p(arg)
|
51 | 52 | when '--verbose' then verbose = true
|
52 | 53 | when '--number' then number = arg.to_i
|
| 54 | + when '--line' then line = arg.to_i |
53 | 55 | end
|
54 | 56 | end
|
55 | 57 |
|
@@ -106,17 +108,15 @@ def table_to_dataset(table)
|
106 | 108 | when /IRI/, '-', /^\s*$/, " "
|
107 | 109 | else
|
108 | 110 | # We might think something was an IRI, but determine that it's not
|
109 |
| - object = RDF::Literal(object.to_s) unless object.literal? |
110 |
| - object.datatype = RDF::Vocabulary.expand_pname(cell.sub("dcterms:", "dc:")) |
| 111 | + dt = RDF::Vocabulary.expand_pname(cell.sub("dcterms:", "dc:")) |
| 112 | + object = RDF::Literal(object.to_s, datatype: dt) |
111 | 113 | end
|
112 | 114 | when 'Language'
|
113 | 115 | case cell
|
114 | 116 | when '-', /^\s*$/
|
115 | 117 | else
|
116 | 118 | # We might think something was an IRI, but determine that it's not
|
117 |
| - object = RDF::Literal(object.to_s) unless object.literal? |
118 |
| - object.datatype = RDF.langString |
119 |
| - object.language = cell.to_sym |
| 119 | + object = RDF::Literal(object.to_s, language: cell.to_sym) |
120 | 120 | end
|
121 | 121 | end
|
122 | 122 | end
|
@@ -187,6 +187,9 @@ def dataset_to_table(repo)
|
187 | 187 | end.join("\n ") + "\n </tbody>\n</table>"
|
188 | 188 | end
|
189 | 189 |
|
| 190 | +# Allow linting examples |
| 191 | +RDF::Reasoner.apply(:rdfs, :schema) |
| 192 | + |
190 | 193 | ARGV.each do |input|
|
191 | 194 | $stderr.puts "\ninput: #{input}"
|
192 | 195 | example_number = 1 # Account for imported Example 1 in typographical conventions
|
@@ -244,6 +247,7 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:)
|
244 | 247 | fromRdf: element.attr('data-from-rdf'),
|
245 | 248 | toRdf: element.attr('data-to-rdf'),
|
246 | 249 | frame_for: element.attr('data-frame-for'),
|
| 250 | + no_lint: element.attr('data-no-lint'), |
247 | 251 | frame: element.attr('data-frame'),
|
248 | 252 | result_for: element.attr('data-result-for'),
|
249 | 253 | options: element.attr('data-options'),
|
@@ -282,6 +286,7 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:)
|
282 | 286 | # Process API functions for
|
283 | 287 | examples.values.sort_by {|ex| ex[:number]}.each do |ex|
|
284 | 288 | next if number && number != ex[:number]
|
| 289 | + next if line && line != ex[:line] |
285 | 290 |
|
286 | 291 | xpath = '//script[@type="application/ld+json"]'
|
287 | 292 | xpath += %([@id="#{ex[:target][1..-1]}"]) if ex[:target]
|
@@ -588,14 +593,27 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:)
|
588 | 593 | if expected.is_a?(RDF::Dataset)
|
589 | 594 | expected_norm = RDF::Normalize.new(expected).map(&:to_nquads)
|
590 | 595 | result_norm = RDF::Normalize.new(result).map(&:to_nquads)
|
591 |
| - unless expected_norm.sort == result_norm.sort |
| 596 | + if expected_norm.sort != result_norm.sort |
592 | 597 | if verbose
|
593 | 598 | $stderr.puts "expected_norm:\n" + expected_norm.sort.join("")
|
594 | 599 | $stderr.puts "result_norm:\n" + result_norm.sort.join("")
|
595 | 600 | end
|
596 | 601 | errors << "Example #{ex[:number]} at line #{ex[:line]} not isomorphic with #{examples[ex[:result_for]][:number]}"
|
597 | 602 | $stdout.write "F".colorize(:red)
|
598 | 603 | next
|
| 604 | + elsif !ex[:no_lint] && !(messages = expected.lint).empty? |
| 605 | + # Lint problems in resulting graph. |
| 606 | + if verbose |
| 607 | + messages.each do |kind, term_messages| |
| 608 | + term_messages.each do |term, messages| |
| 609 | + $stderr.puts "lint #{kind} #{term}" |
| 610 | + messages.each {|m| $stderr.puts " #{m}"} |
| 611 | + end |
| 612 | + end |
| 613 | + end |
| 614 | + errors << "Example #{ex[:number]} at line #{ex[:line]} has lint errors" |
| 615 | + $stdout.write "F".colorize(:red) |
| 616 | + next |
599 | 617 | end
|
600 | 618 | else
|
601 | 619 | unless result == expected
|
|
0 commit comments