Use error returns and interface type for parsing
Fixes issue #72 This change simplifies interactions with parsing N-Quads and makes reading datasets more robust. Changes made while here also improve performance: benchmark old ns/op new ns/op delta BenchmarkParser 1058 667 -36.96% We still use string concatenation which I'm not wildly happy about, but I think this can be left for a later change. Initial changes towards idiomatic error handling have been made. More significant changes are needed, but these have subtle design implication and need to be thought about more. 30kmoviesdata.nt.gz has been altered to properly escape double quotes. This was done mechanically and with manual curation to pick up straglers.
This commit is contained in:
parent
abdd649c82
commit
0e0e382d2b
11 changed files with 260 additions and 226 deletions
|
|
@ -25,17 +25,26 @@ var testNTriples = []struct {
|
|||
message string
|
||||
input string
|
||||
expect *graph.Triple
|
||||
err error
|
||||
}{
|
||||
// NTriple tests.
|
||||
{
|
||||
message: "not parse invalid triples",
|
||||
input: "invalid",
|
||||
expect: nil,
|
||||
err: ErrAbsentPredicate,
|
||||
},
|
||||
{
|
||||
message: "invalid internal quote",
|
||||
input: `":103032" "/film/performance/character" "Walter "Teacher" Cole" .`,
|
||||
expect: nil,
|
||||
err: ErrUnterminated,
|
||||
},
|
||||
{
|
||||
message: "not parse comments",
|
||||
input: "# nominally valid triple .",
|
||||
expect: nil,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
message: "parse simple triples",
|
||||
|
|
@ -110,7 +119,10 @@ var testNTriples = []struct {
|
|||
|
||||
func TestParse(t *testing.T) {
|
||||
for _, test := range testNTriples {
|
||||
got := Parse(test.input)
|
||||
got, err := Parse(test.input)
|
||||
if err != test.err {
|
||||
t.Errorf("Unexpected error when %s: got:%v expect:%v", test.message, err, test.err)
|
||||
}
|
||||
if !reflect.DeepEqual(got, test.expect) {
|
||||
t.Errorf("Failed to %s, %q, got:%q expect:%q", test.message, test.input, got, test.expect)
|
||||
}
|
||||
|
|
@ -121,6 +133,6 @@ var result *graph.Triple
|
|||
|
||||
func BenchmarkParser(b *testing.B) {
|
||||
for n := 0; n < b.N; n++ {
|
||||
result = Parse("<http://example/s> <http://example/p> \"object of some real\\tlength\"@en . # comment")
|
||||
result, _ = Parse("<http://example/s> <http://example/p> \"object of some real\\tlength\"@en . # comment")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue