Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/rdflib/plugins/parsers/nt.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
| author | guerler |
|---|---|
| date | Fri, 31 Jul 2020 00:32:28 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:d30785e31577 | 1:56ad4e20f292 |
|---|---|
| 1 from rdflib.parser import Parser | |
| 2 from rdflib.plugins.parsers.ntriples import NTriplesParser | |
| 3 | |
| 4 __all__ = ['NTSink', 'NTParser'] | |
| 5 | |
| 6 | |
| 7 class NTSink(object): | |
| 8 def __init__(self, graph): | |
| 9 self.graph = graph | |
| 10 | |
| 11 def triple(self, s, p, o): | |
| 12 self.graph.add((s, p, o)) | |
| 13 | |
| 14 | |
| 15 class NTParser(Parser): | |
| 16 """parser for the ntriples format, often stored with the .nt extension | |
| 17 | |
| 18 See http://www.w3.org/TR/rdf-testcases/#ntriples""" | |
| 19 | |
| 20 def __init__(self): | |
| 21 super(NTParser, self).__init__() | |
| 22 | |
| 23 def parse(self, source, sink, baseURI=None): | |
| 24 f = source.getByteStream() # TODO getCharacterStream? | |
| 25 parser = NTriplesParser(NTSink(sink)) | |
| 26 parser.parse(f) | |
| 27 f.close() |
