|
122 | 122 | it "should be able to parse a simple single-triple document" do |
123 | 123 | sampledoc = %q(<?xml version="1.0" ?> |
124 | 124 | <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
125 | | - xmlns:ex="http://www.example.org/" xml:lang="en" xml:base="http://www.example.org/foo"> |
| 125 | + xmlns:ex="http://www.example.org/" |
| 126 | + xml:lang="en" |
| 127 | + xml:base="http://www.example.org/foo"> |
126 | 128 | <ex:Thing rdf:about="http://example.org/joe" ex:name="bar"> |
127 | 129 | <ex:belongsTo rdf:resource="http://tommorris.org/" /> |
128 | 130 | <ex:sampleText rdf:datatype="http://www.w3.org/2001/XMLSchema#string">foo</ex:sampleText> |
|
435 | 437 | end |
436 | 438 | end |
437 | 439 |
|
| 440 | + context "Triple Terms" do |
| 441 | + { |
| 442 | + "ignored triple term": { |
| 443 | + input: %(<?xml version="1.0"?> |
| 444 | + <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
| 445 | + xmlns:ex="http://example.org/stuff/1.0/" |
| 446 | + xml:base="http://example.org/triples/"> |
| 447 | + <rdf:Description rdf:about="http://example.org/"> |
| 448 | + <ex:prop rdf:parseType="Triple"> |
| 449 | + <rdf:Description rdf:about="http://example.org/stuff/1.0/s"> |
| 450 | + <ex:p rdf:resource="http://example.org/stuff/1.0/o" /> |
| 451 | + </rdf:Description> |
| 452 | + </ex:prop> |
| 453 | + </rdf:Description> |
| 454 | + </rdf:RDF>), |
| 455 | + expected: %() |
| 456 | + }, |
| 457 | + "Triple term having IRI subject": { |
| 458 | + input: %(<?xml version="1.0"?> |
| 459 | + <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
| 460 | + xmlns:ex="http://example.org/stuff/1.0/" |
| 461 | + xml:base="http://example.org/triples/" |
| 462 | + rdf:version="1.2"> |
| 463 | + <rdf:Description rdf:about="http://example.org/"> |
| 464 | + <ex:prop rdf:parseType="Triple"> |
| 465 | + <rdf:Description rdf:about="http://example.org/stuff/1.0/s"> |
| 466 | + <ex:p rdf:resource="http://example.org/stuff/1.0/o" /> |
| 467 | + </rdf:Description> |
| 468 | + </ex:prop> |
| 469 | + </rdf:Description> |
| 470 | + </rdf:RDF>), |
| 471 | + expected: %( |
| 472 | + <http://example.org/> <http://example.org/stuff/1.0/prop> <<(<http://example.org/stuff/1.0/s> <http://example.org/stuff/1.0/p> <http://example.org/stuff/1.0/o>)>> . |
| 473 | + ) |
| 474 | + }, |
| 475 | + "Triple term having BNode subject": { |
| 476 | + input: %(<?xml version="1.0"?> |
| 477 | + <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
| 478 | + xmlns:ex="http://example.org/stuff/1.0/" |
| 479 | + xml:base="http://example.org/triples/" |
| 480 | + rdf:version="1.2"> |
| 481 | + <rdf:Description rdf:about="http://example.org/"> |
| 482 | + <ex:prop rdf:parseType="Triple"> |
| 483 | + <rdf:Description> |
| 484 | + <ex:p rdf:resource="http://example.org/stuff/1.0/o" /> |
| 485 | + </rdf:Description> |
| 486 | + </ex:prop> |
| 487 | + </rdf:Description> |
| 488 | + </rdf:RDF>), |
| 489 | + expected: %( |
| 490 | + <http://example.org/> <http://example.org/stuff/1.0/prop> <<(_:b1 <http://example.org/stuff/1.0/p> <http://example.org/stuff/1.0/o>)>> . |
| 491 | + ) |
| 492 | + }, |
| 493 | + "Triple term having a type": { |
| 494 | + input: %(<?xml version="1.0"?> |
| 495 | + <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
| 496 | + xmlns:ex="http://example.org/stuff/1.0/" |
| 497 | + xml:base="http://example.org/triples/" |
| 498 | + rdf:version="1.2"> |
| 499 | + <rdf:Description rdf:about="http://example.org/"> |
| 500 | + <ex:prop rdf:parseType="Triple"> |
| 501 | + <rdf:Description rdf:type="http://example.org/stuff/1.0/t" /> |
| 502 | + </ex:prop> |
| 503 | + </rdf:Description> |
| 504 | + </rdf:RDF>), |
| 505 | + expected: %( |
| 506 | + <http://example.org/> <http://example.org/stuff/1.0/prop> <<(_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/stuff/1.0/t>)>> . |
| 507 | + ) |
| 508 | + }, |
| 509 | + "Triple term having BNode object": { |
| 510 | + input: %(<?xml version="1.0"?> |
| 511 | + <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
| 512 | + xmlns:ex="http://example.org/stuff/1.0/" |
| 513 | + xml:base="http://example.org/triples/" |
| 514 | + rdf:version="1.2"> |
| 515 | + <rdf:Description rdf:about="http://example.org/"> |
| 516 | + <ex:prop rdf:parseType="Triple"> |
| 517 | + <rdf:Description rdf:about="http://example.org/stuff/1.0/s"> |
| 518 | + <ex:p rdf:nodeID="b1" /> |
| 519 | + </rdf:Description> |
| 520 | + </ex:prop> |
| 521 | + </rdf:Description> |
| 522 | + </rdf:RDF>), |
| 523 | + expected: %( |
| 524 | + <http://example.org/> <http://example.org/stuff/1.0/prop> <<(<http://example.org/stuff/1.0/s> <http://example.org/stuff/1.0/p> _:b1)>> . |
| 525 | + ) |
| 526 | + }, |
| 527 | + "Recursive triple term": { |
| 528 | + input: %(<?xml version="1.0"?> |
| 529 | + <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
| 530 | + xmlns:ex="http://example.org/stuff/1.0/" |
| 531 | + xml:base="http://example.org/triples/" |
| 532 | + rdf:version="1.2"> |
| 533 | + <rdf:Description rdf:about="http://example.org/"> |
| 534 | + <ex:prop rdf:parseType="Triple"> |
| 535 | + <rdf:Description rdf:about="http://example.org/stuff/1.0/s"> |
| 536 | + <ex:p rdf:parseType="Triple"> |
| 537 | + <rdf:Description rdf:about="http://example.org/stuff/1.0/s2"> |
| 538 | + <ex:p2 rdf:resource="http://example.org/stuff/1.0/o2" /> |
| 539 | + </rdf:Description> |
| 540 | + </ex:p> |
| 541 | + </rdf:Description> |
| 542 | + </ex:prop> |
| 543 | + </rdf:Description> |
| 544 | + </rdf:RDF>), |
| 545 | + expected: %( |
| 546 | + <http://example.org/> <http://example.org/stuff/1.0/prop> <<(<http://example.org/stuff/1.0/s> <http://example.org/stuff/1.0/p> <<(<http://example.org/stuff/1.0/s2> <http://example.org/stuff/1.0/p2> <http://example.org/stuff/1.0/o2>)>>)>> . |
| 547 | + ) |
| 548 | + }, |
| 549 | + "Invalid triple term having no predicate or object": { |
| 550 | + input: %(<?xml version="1.0"?> |
| 551 | + <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
| 552 | + xmlns:ex="http://example.org/stuff/1.0/" |
| 553 | + xml:base="http://example.org/triples/" |
| 554 | + rdf:version="1.2"> |
| 555 | + <rdf:Description rdf:about="http://example.org/"> |
| 556 | + <ex:prop rdf:parseType="Triple"> |
| 557 | + <rdf:Description rdf:about="http://example.org/stuff/1.0/s"> |
| 558 | + </rdf:Description> |
| 559 | + </ex:prop> |
| 560 | + </rdf:Description> |
| 561 | + </rdf:RDF>), |
| 562 | + exception: RDF::ReaderError |
| 563 | + }, |
| 564 | + "Invalid triple term having multiple triples": { |
| 565 | + input: %(<?xml version="1.0"?> |
| 566 | + <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
| 567 | + xmlns:ex="http://example.org/stuff/1.0/" |
| 568 | + xml:base="http://example.org/triples/" |
| 569 | + rdf:version="1.2"> |
| 570 | + <rdf:Description rdf:about="http://example.org/"> |
| 571 | + <ex:prop rdf:parseType="Triple"> |
| 572 | + <rdf:Description rdf:about="http://example.org/stuff/1.0/s"> |
| 573 | + <ex:p rdf:resource="http://example.org/stuff/1.0/o1" /> |
| 574 | + <ex:p rdf:resource="http://example.org/stuff/1.0/o2" /> |
| 575 | + </rdf:Description> |
| 576 | + </ex:prop> |
| 577 | + </rdf:Description> |
| 578 | + </rdf:RDF>), |
| 579 | + exception: RDF::ReaderError |
| 580 | + }, |
| 581 | + }.each do |title, properties| |
| 582 | + it title do |
| 583 | + if properties[:exception] |
| 584 | + expect do |
| 585 | + parse(properties[:input], validate: true) |
| 586 | + end.to raise_error(RDF::ReaderError) |
| 587 | + else |
| 588 | + graph = begin |
| 589 | + parse(properties[:input], validate: true) |
| 590 | + rescue RDF::ReaderError => e |
| 591 | + fail("Parse failed:#{logger.to_s}") |
| 592 | + end |
| 593 | + egraph = RDF::Graph.new {|g| g << RDF::NTriples::Reader.new(properties[:expected], rdfstar: true)} |
| 594 | + expect(graph).to be_equivalent_graph(egraph, logger: logger) |
| 595 | + end |
| 596 | + end |
| 597 | + end |
| 598 | + end |
| 599 | + |
438 | 600 | context :reification do |
439 | 601 | it "should be able to reify according to §2.17 of RDF/XML Syntax Specification" do |
440 | 602 | sampledoc = %q(<?xml version="1.0"?> |
|
0 commit comments