Strip quoting angle in lone IRIRef terms

This commit is contained in:
kortschak 2014-07-29 08:33:35 +09:30
parent 7ce3a10d57
commit 410202f3e0
2 changed files with 98 additions and 95 deletions

View file

@ -85,6 +85,9 @@ func unEscape(r []rune, isQuoted, isEscaped bool) string {
if isQuoted {
r = r[1 : len(r)-1]
}
if len(r) >= 2 && r[0] == '<' && r[len(r)-1] == '>' {
return string(r[1 : len(r)-1])
}
if !isEscaped {
return string(r)
}

View file

@ -125,9 +125,9 @@ var testNTriples = []struct {
message: "handle simple case with comments",
input: "<http://example/s> <http://example/p> <http://example/o> . # comment",
expect: &quad.Quad{
Subject: "<http://example/s>",
Predicate: "<http://example/p>",
Object: "<http://example/o>",
Subject: "http://example/s",
Predicate: "http://example/p",
Object: "http://example/o",
Provenance: "",
},
},
@ -135,8 +135,8 @@ var testNTriples = []struct {
message: "handle simple case with comments",
input: "<http://example/s> <http://example/p> _:o . # comment",
expect: &quad.Quad{
Subject: "<http://example/s>",
Predicate: "<http://example/p>",
Subject: "http://example/s",
Predicate: "http://example/p",
Object: "_:o",
Provenance: "",
},
@ -145,8 +145,8 @@ var testNTriples = []struct {
message: "handle simple case with comments",
input: "<http://example/s> <http://example/p> \"o\" . # comment",
expect: &quad.Quad{
Subject: "<http://example/s>",
Predicate: "<http://example/p>",
Subject: "http://example/s",
Predicate: "http://example/p",
Object: "o",
Provenance: "",
},
@ -155,8 +155,8 @@ var testNTriples = []struct {
message: "handle simple case with comments",
input: "<http://example/s> <http://example/p> \"o\"^^<http://example/dt> . # comment",
expect: &quad.Quad{
Subject: "<http://example/s>",
Predicate: "<http://example/p>",
Subject: "http://example/s",
Predicate: "http://example/p",
Object: `"o"^^<http://example/dt>`,
Provenance: "",
},
@ -165,8 +165,8 @@ var testNTriples = []struct {
message: "handle simple case with comments",
input: "<http://example/s> <http://example/p> \"o\"@en . # comment",
expect: &quad.Quad{
Subject: "<http://example/s>",
Predicate: "<http://example/p>",
Subject: "http://example/s",
Predicate: "http://example/p",
Object: `"o"@en`,
Provenance: ""},
},
@ -179,8 +179,8 @@ var testNTriples = []struct {
input: `_:100000 </film/performance/actor> </en/larry_fine_1902> . # example from 30movies`,
expect: &quad.Quad{
Subject: "_:100000",
Predicate: "</film/performance/actor>",
Object: "</en/larry_fine_1902>",
Predicate: "/film/performance/actor",
Object: "/en/larry_fine_1902",
Provenance: "",
},
err: nil,
@ -191,7 +191,7 @@ var testNTriples = []struct {
input: `_:10011 </film/performance/character> "Tomás de Torquemada" . # example from 30movies with unicode`,
expect: &quad.Quad{
Subject: "_:10011",
Predicate: "</film/performance/character>",
Predicate: "/film/performance/character",
Object: "Tomás de Torquemada",
Provenance: "",
},
@ -203,9 +203,9 @@ var testNTriples = []struct {
message: "parse triple with commment",
input: `<http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> . # comments here`,
expect: &quad.Quad{
Subject: "<http://one.example/subject1>",
Predicate: "<http://one.example/predicate1>",
Object: "<http://one.example/object1>",
Subject: "http://one.example/subject1",
Predicate: "http://one.example/predicate1",
Object: "http://one.example/object1",
Provenance: "",
},
err: nil,
@ -215,7 +215,7 @@ var testNTriples = []struct {
input: `_:subject1 <http://an.example/predicate1> "object1" .`,
expect: &quad.Quad{
Subject: "_:subject1",
Predicate: "<http://an.example/predicate1>",
Predicate: "http://an.example/predicate1",
Object: "object1",
Provenance: "",
},
@ -226,7 +226,7 @@ var testNTriples = []struct {
input: `_:subject2 <http://an.example/predicate2> "object2" .`,
expect: &quad.Quad{
Subject: "_:subject2",
Predicate: "<http://an.example/predicate2>",
Predicate: "http://an.example/predicate2",
Object: "object2",
Provenance: "",
},
@ -238,9 +238,9 @@ var testNTriples = []struct {
message: "parse triple with three IRIREFs",
input: `<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green-goblin> .`,
expect: &quad.Quad{
Subject: "<http://example.org/#spiderman>",
Predicate: "<http://www.perceive.net/schemas/relationship/enemyOf>",
Object: "<http://example.org/#green-goblin>",
Subject: "http://example.org/#spiderman",
Predicate: "http://www.perceive.net/schemas/relationship/enemyOf",
Object: "http://example.org/#green-goblin",
Provenance: "",
},
err: nil,
@ -252,7 +252,7 @@ var testNTriples = []struct {
input: `_:alice <http://xmlns.com/foaf/0.1/knows> _:bob .`,
expect: &quad.Quad{
Subject: "_:alice",
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
Predicate: "http://xmlns.com/foaf/0.1/knows",
Object: "_:bob",
Provenance: "",
},
@ -263,7 +263,7 @@ var testNTriples = []struct {
input: `_:bob <http://xmlns.com/foaf/0.1/knows> _:alice .`,
expect: &quad.Quad{
Subject: "_:bob",
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
Predicate: "http://xmlns.com/foaf/0.1/knows",
Object: "_:alice",
Provenance: "",
},
@ -275,10 +275,10 @@ var testNTriples = []struct {
message: "parse quad with commment",
input: `<http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> <http://example.org/graph3> . # comments here`,
expect: &quad.Quad{
Subject: "<http://one.example/subject1>",
Predicate: "<http://one.example/predicate1>",
Object: "<http://one.example/object1>",
Provenance: "<http://example.org/graph3>",
Subject: "http://one.example/subject1",
Predicate: "http://one.example/predicate1",
Object: "http://one.example/object1",
Provenance: "http://example.org/graph3",
},
err: nil,
},
@ -287,9 +287,9 @@ var testNTriples = []struct {
input: `_:subject1 <http://an.example/predicate1> "object1" <http://example.org/graph1> .`,
expect: &quad.Quad{
Subject: "_:subject1",
Predicate: "<http://an.example/predicate1>",
Predicate: "http://an.example/predicate1",
Object: "object1",
Provenance: "<http://example.org/graph1>",
Provenance: "http://example.org/graph1",
},
err: nil,
},
@ -298,9 +298,9 @@ var testNTriples = []struct {
input: `_:subject2 <http://an.example/predicate2> "object2" <http://example.org/graph5> .`,
expect: &quad.Quad{
Subject: "_:subject2",
Predicate: "<http://an.example/predicate2>",
Predicate: "http://an.example/predicate2",
Object: "object2",
Provenance: "<http://example.org/graph5>",
Provenance: "http://example.org/graph5",
},
err: nil,
},
@ -310,10 +310,10 @@ var testNTriples = []struct {
message: "parse quad with all IRIREF parts",
input: `<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green-goblin> <http://example.org/graphs/spiderman> .`,
expect: &quad.Quad{
Subject: "<http://example.org/#spiderman>",
Predicate: "<http://www.perceive.net/schemas/relationship/enemyOf>",
Object: "<http://example.org/#green-goblin>",
Provenance: "<http://example.org/graphs/spiderman>",
Subject: "http://example.org/#spiderman",
Predicate: "http://www.perceive.net/schemas/relationship/enemyOf",
Object: "http://example.org/#green-goblin",
Provenance: "http://example.org/graphs/spiderman",
},
err: nil,
},
@ -324,9 +324,9 @@ var testNTriples = []struct {
input: `_:alice <http://xmlns.com/foaf/0.1/knows> _:bob <http://example.org/graphs/john> .`,
expect: &quad.Quad{
Subject: "_:alice",
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
Predicate: "http://xmlns.com/foaf/0.1/knows",
Object: "_:bob",
Provenance: "<http://example.org/graphs/john>",
Provenance: "http://example.org/graphs/john",
},
err: nil,
},
@ -335,9 +335,9 @@ var testNTriples = []struct {
input: `_:bob <http://xmlns.com/foaf/0.1/knows> _:alice <http://example.org/graphs/james> .`,
expect: &quad.Quad{
Subject: "_:bob",
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
Predicate: "http://xmlns.com/foaf/0.1/knows",
Object: "_:alice",
Provenance: "<http://example.org/graphs/james>",
Provenance: "http://example.org/graphs/james",
},
err: nil,
},
@ -347,9 +347,9 @@ var testNTriples = []struct {
message: "parse triple with all IRIREF parts",
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .`,
expect: &quad.Quad{
Subject: "<http://example.org/bob#me>",
Predicate: "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>",
Object: "<http://xmlns.com/foaf/0.1/Person>",
Subject: "http://example.org/bob#me",
Predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
Object: "http://xmlns.com/foaf/0.1/Person",
Provenance: "",
},
err: nil,
@ -358,9 +358,9 @@ var testNTriples = []struct {
message: "parse triple with all IRIREF parts",
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/knows> <http://example.org/alice#me> .`,
expect: &quad.Quad{
Subject: "<http://example.org/bob#me>",
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
Object: "<http://example.org/alice#me>",
Subject: "http://example.org/bob#me",
Predicate: "http://xmlns.com/foaf/0.1/knows",
Object: "http://example.org/alice#me",
Provenance: "",
},
err: nil,
@ -369,8 +369,8 @@ var testNTriples = []struct {
message: "parse triple with IRIREF schema on literal object",
input: `<http://example.org/bob#me> <http://schema.org/birthDate> "1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date> .`,
expect: &quad.Quad{
Subject: "<http://example.org/bob#me>",
Predicate: "<http://schema.org/birthDate>",
Subject: "http://example.org/bob#me",
Predicate: "http://schema.org/birthDate",
Object: `"1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date>`,
Provenance: "",
},
@ -380,9 +380,9 @@ var testNTriples = []struct {
message: "parse commented IRIREF in triple",
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/topic_interest> <http://www.wikidata.org/entity/Q12418> .`,
expect: &quad.Quad{
Subject: "<http://example.org/bob#me>",
Predicate: "<http://xmlns.com/foaf/0.1/topic_interest>",
Object: "<http://www.wikidata.org/entity/Q12418>",
Subject: "http://example.org/bob#me",
Predicate: "http://xmlns.com/foaf/0.1/topic_interest",
Object: "http://www.wikidata.org/entity/Q12418",
Provenance: "",
},
err: nil,
@ -391,8 +391,8 @@ var testNTriples = []struct {
message: "parse triple with literal subject",
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/title> "Mona Lisa" .`,
expect: &quad.Quad{
Subject: "<http://www.wikidata.org/entity/Q12418>",
Predicate: "<http://purl.org/dc/terms/title>",
Subject: "http://www.wikidata.org/entity/Q12418",
Predicate: "http://purl.org/dc/terms/title",
Object: "Mona Lisa",
Provenance: "",
},
@ -402,9 +402,9 @@ var testNTriples = []struct {
message: "parse triple with all IRIREF parts (1)",
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/creator> <http://dbpedia.org/resource/Leonardo_da_Vinci> .`,
expect: &quad.Quad{
Subject: "<http://www.wikidata.org/entity/Q12418>",
Predicate: "<http://purl.org/dc/terms/creator>",
Object: "<http://dbpedia.org/resource/Leonardo_da_Vinci>",
Subject: "http://www.wikidata.org/entity/Q12418",
Predicate: "http://purl.org/dc/terms/creator",
Object: "http://dbpedia.org/resource/Leonardo_da_Vinci",
Provenance: "",
},
err: nil,
@ -413,9 +413,9 @@ var testNTriples = []struct {
message: "parse triple with all IRIREF parts (2)",
input: `<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619> <http://purl.org/dc/terms/subject> <http://www.wikidata.org/entity/Q12418> .`,
expect: &quad.Quad{
Subject: "<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619>",
Predicate: "<http://purl.org/dc/terms/subject>",
Object: "<http://www.wikidata.org/entity/Q12418>",
Subject: "http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619",
Predicate: "http://purl.org/dc/terms/subject",
Object: "http://www.wikidata.org/entity/Q12418",
Provenance: "",
},
err: nil,
@ -426,10 +426,10 @@ var testNTriples = []struct {
message: "parse commented IRIREF in quad (1)",
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://example.org/bob> .`,
expect: &quad.Quad{
Subject: "<http://example.org/bob#me>",
Predicate: "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>",
Object: "<http://xmlns.com/foaf/0.1/Person>",
Provenance: "<http://example.org/bob>",
Subject: "http://example.org/bob#me",
Predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
Object: "http://xmlns.com/foaf/0.1/Person",
Provenance: "http://example.org/bob",
},
err: nil,
},
@ -437,10 +437,10 @@ var testNTriples = []struct {
message: "parse quad with all IRIREF parts",
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/knows> <http://example.org/alice#me> <http://example.org/bob> .`,
expect: &quad.Quad{
Subject: "<http://example.org/bob#me>",
Predicate: "<http://xmlns.com/foaf/0.1/knows>",
Object: "<http://example.org/alice#me>",
Provenance: "<http://example.org/bob>",
Subject: "http://example.org/bob#me",
Predicate: "http://xmlns.com/foaf/0.1/knows",
Object: "http://example.org/alice#me",
Provenance: "http://example.org/bob",
},
err: nil,
},
@ -448,10 +448,10 @@ var testNTriples = []struct {
message: "parse quad with IRIREF schema on literal object",
input: `<http://example.org/bob#me> <http://schema.org/birthDate> "1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date> <http://example.org/bob> .`,
expect: &quad.Quad{
Subject: "<http://example.org/bob#me>",
Predicate: "<http://schema.org/birthDate>",
Subject: "http://example.org/bob#me",
Predicate: "http://schema.org/birthDate",
Object: `"1990-07-04"^^<http://www.w3.org/2001/XMLSchema#date>`,
Provenance: "<http://example.org/bob>",
Provenance: "http://example.org/bob",
},
err: nil,
},
@ -459,10 +459,10 @@ var testNTriples = []struct {
message: "parse commented IRIREF in quad (2)",
input: `<http://example.org/bob#me> <http://xmlns.com/foaf/0.1/topic_interest> <http://www.wikidata.org/entity/Q12418> <http://example.org/bob> .`,
expect: &quad.Quad{
Subject: "<http://example.org/bob#me>",
Predicate: "<http://xmlns.com/foaf/0.1/topic_interest>",
Object: "<http://www.wikidata.org/entity/Q12418>",
Provenance: "<http://example.org/bob>",
Subject: "http://example.org/bob#me",
Predicate: "http://xmlns.com/foaf/0.1/topic_interest",
Object: "http://www.wikidata.org/entity/Q12418",
Provenance: "http://example.org/bob",
},
err: nil,
},
@ -470,10 +470,10 @@ var testNTriples = []struct {
message: "parse literal object and colon qualified label in quad",
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/title> "Mona Lisa" <https://www.wikidata.org/wiki/Special:EntityData/Q12418> .`,
expect: &quad.Quad{
Subject: "<http://www.wikidata.org/entity/Q12418>",
Predicate: "<http://purl.org/dc/terms/title>",
Subject: "http://www.wikidata.org/entity/Q12418",
Predicate: "http://purl.org/dc/terms/title",
Object: "Mona Lisa",
Provenance: "<https://www.wikidata.org/wiki/Special:EntityData/Q12418>",
Provenance: "https://www.wikidata.org/wiki/Special:EntityData/Q12418",
},
err: nil,
},
@ -481,10 +481,10 @@ var testNTriples = []struct {
message: "parse all IRIREF parts with colon qualified label in quad (1)",
input: `<http://www.wikidata.org/entity/Q12418> <http://purl.org/dc/terms/creator> <http://dbpedia.org/resource/Leonardo_da_Vinci> <https://www.wikidata.org/wiki/Special:EntityData/Q12418> .`,
expect: &quad.Quad{
Subject: "<http://www.wikidata.org/entity/Q12418>",
Predicate: "<http://purl.org/dc/terms/creator>",
Object: "<http://dbpedia.org/resource/Leonardo_da_Vinci>",
Provenance: "<https://www.wikidata.org/wiki/Special:EntityData/Q12418>",
Subject: "http://www.wikidata.org/entity/Q12418",
Predicate: "http://purl.org/dc/terms/creator",
Object: "http://dbpedia.org/resource/Leonardo_da_Vinci",
Provenance: "https://www.wikidata.org/wiki/Special:EntityData/Q12418",
},
err: nil,
},
@ -492,10 +492,10 @@ var testNTriples = []struct {
message: "parse all IRIREF parts with colon qualified label in quad (2)",
input: `<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619> <http://purl.org/dc/terms/subject> <http://www.wikidata.org/entity/Q12418> <https://www.wikidata.org/wiki/Special:EntityData/Q12418> .`,
expect: &quad.Quad{
Subject: "<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619>",
Predicate: "<http://purl.org/dc/terms/subject>",
Object: "<http://www.wikidata.org/entity/Q12418>",
Provenance: "<https://www.wikidata.org/wiki/Special:EntityData/Q12418>",
Subject: "http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619",
Predicate: "http://purl.org/dc/terms/subject",
Object: "http://www.wikidata.org/entity/Q12418",
Provenance: "https://www.wikidata.org/wiki/Special:EntityData/Q12418",
},
err: nil,
},
@ -503,9 +503,9 @@ var testNTriples = []struct {
message: "parse all IRIREF parts (quad section - 1)",
input: `<http://example.org/bob> <http://purl.org/dc/terms/publisher> <http://example.org> .`,
expect: &quad.Quad{
Subject: "<http://example.org/bob>",
Predicate: "<http://purl.org/dc/terms/publisher>",
Object: "<http://example.org>",
Subject: "http://example.org/bob",
Predicate: "http://purl.org/dc/terms/publisher",
Object: "http://example.org",
Provenance: "",
},
err: nil,
@ -514,9 +514,9 @@ var testNTriples = []struct {
message: "parse all IRIREF parts (quad section - 2)",
input: `<http://example.org/bob> <http://purl.org/dc/terms/rights> <http://creativecommons.org/licenses/by/3.0/> .`,
expect: &quad.Quad{
Subject: "<http://example.org/bob>",
Predicate: "<http://purl.org/dc/terms/rights>",
Object: "<http://creativecommons.org/licenses/by/3.0/>",
Subject: "http://example.org/bob",
Predicate: "http://purl.org/dc/terms/rights",
Object: "http://creativecommons.org/licenses/by/3.0/",
Provenance: "",
},
err: nil,
@ -551,8 +551,8 @@ var testNTriples = []struct {
message: "parse incomplete quad (1)",
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> .`,
expect: &quad.Quad{
Subject: "<http://example.org/bob#me>",
Predicate: "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>",
Subject: "http://example.org/bob#me",
Predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
Object: "",
Provenance: "",
},
@ -562,8 +562,8 @@ var testNTriples = []struct {
message: "parse incomplete quad (2)",
input: `<http://example.org/bob#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> .`,
expect: &quad.Quad{
Subject: "<http://example.org/bob#me>",
Predicate: "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>",
Subject: "http://example.org/bob#me",
Predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
Object: "",
Provenance: "",
},