home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / python-support / python-rdflib / rdflib / syntax / parsers / NTParser.py < prev    next >
Encoding:
Python Source  |  2007-04-04  |  556 b   |  27 lines

  1. from rdflib.syntax.parsers import Parser
  2. from rdflib.syntax.parsers.ntriples import NTriplesParser
  3.  
  4.  
  5. class NTSink(object):
  6.     def __init__(self, graph):
  7.         self.graph = graph
  8.  
  9.     def triple(self, s, p, o):
  10.         self.graph.add((s, p, o))
  11.  
  12.  
  13. import codecs
  14.  
  15. class NTParser(Parser):
  16.  
  17.     def __init__(self):
  18.         super(NTParser, self).__init__()
  19.  
  20.     def parse(self, source, sink, baseURI=None):
  21.         f = source.getByteStream() # TODO getCharacterStream?
  22.         parser = NTriplesParser(NTSink(sink))
  23.         parser.parse(f)
  24.         f.close()
  25.  
  26.  
  27.