parseNTriple

Decode line into an RDF N-Triple.

@safe pure nothrow @nogc
parseNTriple
(
scope return inout(char)[] line
)

Examples

const x = `<http://dbpedia.org/resource/180%C2%B0_(Gerardo_album)> <http://dbpedia.org/ontology/artist> <http://dbpedia.org/resource/Gerardo_Mej%C3%ADa> .`;
auto nt = x.parseNTriple;
static assert(is(typeof(nt.subject) == immutable(string))); // TODO should be `string` or `const(char)[]`
static assert(is(typeof(nt.predicate) == immutable(string))); // TODO should be `string` or `const(char)[]`
static assert(is(typeof(nt.object) == immutable(string))); // TODO should be `string` or `const(char)[]`
assert(nt.subject == `http://dbpedia.org/resource/180%C2%B0_(Gerardo_album)`);
assert(nt.subjectFormat == SubjectFormat.IRI);
assert(nt.predicate == `http://dbpedia.org/ontology/artist`);
assert(nt.object == `http://dbpedia.org/resource/Gerardo_Mej%C3%ADa`);
assert(nt.objectLanguageCode is null);
assert(nt.objectDataTypeIRI is null);
assert(nt.objectFormat == ObjectFormat.IRI);
const x = `<http://dbpedia.org/resource/1950_Chatham_Cup> <http://xmlns.com/foaf/0.1/name> "Chatham Cup"@en .`;
const nt = x.parseNTriple;
assert(nt.subject == `http://dbpedia.org/resource/1950_Chatham_Cup`);
assert(nt.subjectFormat == SubjectFormat.IRI);
assert(nt.predicate == `http://xmlns.com/foaf/0.1/name`);
assert(nt.object == `Chatham Cup`);
assert(nt.objectLanguageCode == `en`);
assert(nt.objectDataTypeIRI is null);
assert(nt.objectFormat == ObjectFormat.literal);
const x = `<http://dbpedia.org/resource/1950_Chatham_Cup> <http://xmlns.com/foaf/0.1/name> "Chatham Cup" .`;
const nt = x.parseNTriple;
assert(nt.subject == `http://dbpedia.org/resource/1950_Chatham_Cup`);
assert(nt.subjectFormat == SubjectFormat.IRI);
assert(nt.predicate == `http://xmlns.com/foaf/0.1/name`);
assert(nt.object == `Chatham Cup`);
assert(nt.objectLanguageCode is null);
assert(nt.objectDataTypeIRI is null);
assert(nt.objectFormat == ObjectFormat.literal);
const x = `<http://dbpedia.org/resource/007:_Quantum_of_Solace> <http://dbpedia.org/ontology/releaseDate> "2008-10-31"^^<http://www.w3.org/2001/XMLSchema#date> .`;
const nt = x.parseNTriple;
assert(nt.subject == `http://dbpedia.org/resource/007:_Quantum_of_Solace`);
assert(nt.subjectFormat == SubjectFormat.IRI);
assert(nt.predicate == `http://dbpedia.org/ontology/releaseDate`);
assert(nt.object == `2008-10-31`);
assert(nt.objectLanguageCode is null);
assert(nt.objectDataTypeIRI == `http://www.w3.org/2001/XMLSchema#date`);
assert(nt.objectFormat == ObjectFormat.literal);
const x = `<http://dbpedia.org/resource/Ceremony_(song)> <http://dbpedia.org/ontology/bSide> "\"In a Lonely Place\"".`;
const nt = x.parseNTriple;
assert(nt.subject == `http://dbpedia.org/resource/Ceremony_(song)`);
assert(nt.subjectFormat == SubjectFormat.IRI);
assert(nt.predicate == `http://dbpedia.org/ontology/bSide`);
assert(nt.object == `\"In a Lonely Place\"`); // to be unescaped
assert(nt.objectLanguageCode is null);
assert(nt.objectDataTypeIRI is null);
assert(nt.objectFormat == ObjectFormat.literal);
const x = `<http://dbpedia.org/resource/16_@_War> <http://xmlns.com/foaf/0.1/name> "16 @ War"@en .`;
auto nt = x.parseNTriple;
assert(nt.subject == `http://dbpedia.org/resource/16_@_War`);
assert(nt.subjectFormat == SubjectFormat.IRI);
assert(nt.predicate == `http://xmlns.com/foaf/0.1/name`);
assert(nt.object == `16 @ War`);
assert(nt.objectLanguageCode == `en`);
assert(nt.objectDataTypeIRI is null);
assert(nt.objectFormat == ObjectFormat.literal);
const x = `<http://dbpedia.org/resource/CT_Rei_Pel%C3%A9> <http://xmlns.com/foaf/0.1/homepage> <http://www.santosfc.com.br/clube/default.asp?c=Sedes&st=CT%20Rei%20Pel%E9> .`;
auto nt = x.parseNTriple;
assert(nt.subjectFormat == SubjectFormat.IRI);
assert(nt.subject == `http://dbpedia.org/resource/CT_Rei_Pel%C3%A9`);
assert(nt.predicate == `http://xmlns.com/foaf/0.1/homepage`);
assert(nt.object == `http://www.santosfc.com.br/clube/default.asp?c=Sedes&st=CT%20Rei%20Pel%E9`);
assert(nt.objectFormat == ObjectFormat.IRI);

See Also

Meta