rdf-xml/tests/convert-manifest.rb
author Ivan Herman <ivan@ivan-herman.net>
Sat, 29 Nov 2014 09:59:49 +0100
changeset 2035 1fda78347d91
parent 1688 ee80328964cc
permissions -rwxr-xr-x
rdfs:approval has been changed to rift:approval
1688
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
     1
#!/usr/bin/env ruby
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
     2
# Convert 2004 manifest to 2013 format and vocabulary
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
     3
require 'linkeddata'
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
     4
require 'fileutils'
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
     5
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
     6
TEST = RDF::Vocabulary.new("http://www.w3.org/2000/10/rdf-tests/rdfcore/testSchema#")
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
     7
QUERY = SPARQL.parse(%(
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
     8
  PREFIX test: <http://www.w3.org/2000/10/rdf-tests/rdfcore/testSchema#>
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
     9
  SELECT ?subject ?type ?description ?action ?result
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    10
  WHERE {
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    11
    ?subject a ?type;
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    12
      test:status "APPROVED";
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    13
      test:inputDocument ?action;
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    14
      OPTIONAL {
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    15
        ?subject test:description ?description
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    16
      }
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    17
      OPTIONAL {
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    18
        ?subject test:outputDocument ?result
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    19
      }
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    20
    FILTER(?type = test:PositiveParserTest || ?type = test:NegativeParserTest)
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    21
  }
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    22
))
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    23
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    24
g = RDF::Repository.load("2004-test-suite/Manifest.rdf")
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    25
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    26
tests = {}
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    27
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    28
File.open("manifest.ttl", "w") do |f|
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    29
  f.write(%(
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    30
    # RDF/XML Syntax tests
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    31
    ## Distributed under both the W3C Test Suite License[1] and the W3C 3-
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    32
    ## clause BSD License[2]. To contribute to a W3C Test Suite, see the
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    33
    ## policies and contribution forms [3]
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    34
    ##
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    35
    ## 1. http://www.w3.org/Consortium/Legal/2008/04-testsuite-license
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    36
    ## 2. http://www.w3.org/Consortium/Legal/2008/03-bsd-license
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    37
    ## 3. http://www.w3.org/2004/10/27-testcases
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    38
    
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    39
    @prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    40
    @prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    41
    @prefix mf: <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#> .
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    42
    @prefix rdft:   <http://www.w3.org/ns/rdftest#> .
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    43
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    44
    <> rdf:type mf:Manifest ;
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    45
      rdfs:comment "RDF/XML Syntax tests" ;
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    46
      mf:entries \()[1..-1].gsub(/^    /, ''))
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    47
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    48
  QUERY.execute(g).each do |soln|
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    49
    #puts soln.inspect
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    50
    dir = soln.subject.path.split('/')[-2]
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    51
    frag = "##{dir}-#{soln.subject.fragment}"
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    52
    puts "test #{dir}/'#{frag}' already defined" if tests.has_key?(frag)
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    53
    f.write("\n    <#{frag}>")
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    54
    tests[frag] = soln
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    55
  end
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    56
  f.puts("\n  ) .\n\n")
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    57
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    58
  tests.each_pair do |frag, test|
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    59
    raise "test #{frag} missing description" unless test[:description]
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    60
    # Wrap description to 40 characters and indent
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    61
    desc = test.description.
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    62
      to_s.
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    63
      strip.
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    64
      gsub(/\s+/m, ' ').
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    65
      scan(/\S.{0,60}\S(?=\s|$)|\S+/).
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    66
      join("\n    ")
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    67
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    68
    type = test.type.fragment == "PositiveParserTest" ? "TestXMLEval" : "TestXMLNegativeSyntax"
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    69
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    70
    test_desc = %(
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    71
    <#{frag}> a rdft:#{type};
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    72
      mf:name "#{frag[1..-1]}";
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    73
      rdfs:comment """
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    74
        #{desc}
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    75
      """;
2035
1fda78347d91 rdfs:approval has been changed to rift:approval
Ivan Herman <ivan@ivan-herman.net>
parents: 1688
diff changeset
    76
      rdft:approval rdft:Approved
1688
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    77
    ).gsub(/^    /, '')[1..-2]
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    78
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    79
    [:action, :result].each do |t|
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    80
      next unless test[t]
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    81
      path = test[t].path.split('/')[-2..-1].join('/')
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    82
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    83
      # Copy the test into place, if it does not exist.
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    84
      parts = path.split('/')
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    85
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    86
      FileUtils.mkdir(parts.first) unless Dir.exist?(parts.first)
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    87
      puts "Copy 2004-test-suite/#{path} to #{path}"
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    88
      FileUtils.cp "2004-test-suite/#{path}", path
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    89
      test_desc += ";\n  mf:#{t} <#{path}>"
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    90
    end
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    91
    test_desc += " .\n\n"
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    92
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    93
    f.puts test_desc
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    94
  end
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    95
end
ee80328964cc Moved over 2004 RDF/XML tests into current manifest structure and location.
Gregg Kellogg <gregg@kellogg-assoc.com>
parents:
diff changeset
    96