diff --git a/quad/cquads/cquads.go b/quad/cquads/cquads.go index 4c548fb..c3355ed 100644 --- a/quad/cquads/cquads.go +++ b/quad/cquads/cquads.go @@ -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) } diff --git a/quad/cquads/cquads_test.go b/quad/cquads/cquads_test.go index 276c1b8..c6cc344 100644 --- a/quad/cquads/cquads_test.go +++ b/quad/cquads/cquads_test.go @@ -125,9 +125,9 @@ var testNTriples = []struct { message: "handle simple case with comments", input: " . # comment", expect: &quad.Quad{ - Subject: "", - Predicate: "", - Object: "", + 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: " _:o . # comment", expect: &quad.Quad{ - Subject: "", - Predicate: "", + 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: " \"o\" . # comment", expect: &quad.Quad{ - Subject: "", - Predicate: "", + 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: " \"o\"^^ . # comment", expect: &quad.Quad{ - Subject: "", - Predicate: "", + Subject: "http://example/s", + Predicate: "http://example/p", Object: `"o"^^`, Provenance: "", }, @@ -165,8 +165,8 @@ var testNTriples = []struct { message: "handle simple case with comments", input: " \"o\"@en . # comment", expect: &quad.Quad{ - Subject: "", - Predicate: "", + Subject: "http://example/s", + Predicate: "http://example/p", Object: `"o"@en`, Provenance: ""}, }, @@ -179,8 +179,8 @@ var testNTriples = []struct { input: `_:100000 . # example from 30movies`, expect: &quad.Quad{ Subject: "_:100000", - Predicate: "", - Object: "", + Predicate: "/film/performance/actor", + Object: "/en/larry_fine_1902", Provenance: "", }, err: nil, @@ -191,7 +191,7 @@ var testNTriples = []struct { input: `_:10011 "Tomás de Torquemada" . # example from 30movies with unicode`, expect: &quad.Quad{ Subject: "_:10011", - Predicate: "", + Predicate: "/film/performance/character", Object: "Tomás de Torquemada", Provenance: "", }, @@ -203,9 +203,9 @@ var testNTriples = []struct { message: "parse triple with commment", input: ` . # comments here`, expect: &quad.Quad{ - Subject: "", - Predicate: "", - Object: "", + 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 "object1" .`, expect: &quad.Quad{ Subject: "_:subject1", - Predicate: "", + Predicate: "http://an.example/predicate1", Object: "object1", Provenance: "", }, @@ -226,7 +226,7 @@ var testNTriples = []struct { input: `_:subject2 "object2" .`, expect: &quad.Quad{ Subject: "_:subject2", - Predicate: "", + Predicate: "http://an.example/predicate2", Object: "object2", Provenance: "", }, @@ -238,9 +238,9 @@ var testNTriples = []struct { message: "parse triple with three IRIREFs", input: ` .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", - Object: "", + 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 _:bob .`, expect: &quad.Quad{ Subject: "_:alice", - Predicate: "", + Predicate: "http://xmlns.com/foaf/0.1/knows", Object: "_:bob", Provenance: "", }, @@ -263,7 +263,7 @@ var testNTriples = []struct { input: `_:bob _:alice .`, expect: &quad.Quad{ Subject: "_:bob", - Predicate: "", + Predicate: "http://xmlns.com/foaf/0.1/knows", Object: "_:alice", Provenance: "", }, @@ -275,10 +275,10 @@ var testNTriples = []struct { message: "parse quad with commment", input: ` . # comments here`, expect: &quad.Quad{ - Subject: "", - Predicate: "", - Object: "", - Provenance: "", + 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 "object1" .`, expect: &quad.Quad{ Subject: "_:subject1", - Predicate: "", + Predicate: "http://an.example/predicate1", Object: "object1", - Provenance: "", + Provenance: "http://example.org/graph1", }, err: nil, }, @@ -298,9 +298,9 @@ var testNTriples = []struct { input: `_:subject2 "object2" .`, expect: &quad.Quad{ Subject: "_:subject2", - Predicate: "", + Predicate: "http://an.example/predicate2", Object: "object2", - Provenance: "", + Provenance: "http://example.org/graph5", }, err: nil, }, @@ -310,10 +310,10 @@ var testNTriples = []struct { message: "parse quad with all IRIREF parts", input: ` .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", - Object: "", - Provenance: "", + 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 _:bob .`, expect: &quad.Quad{ Subject: "_:alice", - Predicate: "", + Predicate: "http://xmlns.com/foaf/0.1/knows", Object: "_:bob", - Provenance: "", + Provenance: "http://example.org/graphs/john", }, err: nil, }, @@ -335,9 +335,9 @@ var testNTriples = []struct { input: `_:bob _:alice .`, expect: &quad.Quad{ Subject: "_:bob", - Predicate: "", + Predicate: "http://xmlns.com/foaf/0.1/knows", Object: "_:alice", - Provenance: "", + Provenance: "http://example.org/graphs/james", }, err: nil, }, @@ -347,9 +347,9 @@ var testNTriples = []struct { message: "parse triple with all IRIREF parts", input: ` .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", - Object: "", + 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: ` .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", - Object: "", + 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: ` "1990-07-04"^^ .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", + Subject: "http://example.org/bob#me", + Predicate: "http://schema.org/birthDate", Object: `"1990-07-04"^^`, Provenance: "", }, @@ -380,9 +380,9 @@ var testNTriples = []struct { message: "parse commented IRIREF in triple", input: ` .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", - Object: "", + 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: ` "Mona Lisa" .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", + 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: ` .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", - Object: "", + 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: ` .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", - Object: "", + 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: ` .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", - Object: "", - Provenance: "", + 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: ` .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", - Object: "", - Provenance: "", + 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: ` "1990-07-04"^^ .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", + Subject: "http://example.org/bob#me", + Predicate: "http://schema.org/birthDate", Object: `"1990-07-04"^^`, - Provenance: "", + Provenance: "http://example.org/bob", }, err: nil, }, @@ -459,10 +459,10 @@ var testNTriples = []struct { message: "parse commented IRIREF in quad (2)", input: ` .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", - Object: "", - Provenance: "", + 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: ` "Mona Lisa" .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", + Subject: "http://www.wikidata.org/entity/Q12418", + Predicate: "http://purl.org/dc/terms/title", Object: "Mona Lisa", - Provenance: "", + 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: ` .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", - Object: "", - Provenance: "", + 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: ` .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", - Object: "", - Provenance: "", + 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: ` .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", - Object: "", + 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: ` .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", - Object: "", + 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: ` .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", + 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: ` .`, expect: &quad.Quad{ - Subject: "", - Predicate: "", + Subject: "http://example.org/bob#me", + Predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", Object: "", Provenance: "", },