def ntString(self, base=None, flags="bravestpun"): "Dump the formula to an absolute string in N3" buffer = StringIO.StringIO() _outSink = notation3.ToN3(buffer.write, quiet=1, base=base, flags=flags) self.store.dumpBySubject(self, _outSink) return buffer.getvalue().decode('utf_8')
if args: file = args[0] else: file = 'test.xml' if file == '-': f = sys.stdin else: try: f = open(file, 'r') except IOError, msg: print file, ":", msg sys.exit(1) x = klass(notation3.ToN3(sys.stdout.write), "file:/test.rdf") # test only! p = xml.sax.make_parser() from xml.sax.handler import feature_namespaces p.setFeature(feature_namespaces, 1) p.setContentHandler(x) p.setErrorHandler(xml.sax.ErrorHandler()) s = xml.sax.InputSource() t0 = time() try: if do_time: #print "parsing:", f s.setByteStream(f) p.parse(s) else: data = f.read() #print "data:", data
return null, predict except ImportError: p = get_productions(uri) f = find_nulls(p) predict = find_null_connected(p, f) out = file('earley_tables.py', 'w') make_table(out, f, predict) return f, predict if __name__ == '__main__': f, predict = cache_get(sys.argv[1]) ## for m in sorted(predict.items()): ## print '\t%s: %s\n' % m ## sys.exit(0) print 'ready to lex' results, t1, k2 = parse(sys.argv[3], sys.argv[2], predict, f) t2 = time.time() - k2 #print '\n\n\t'.join([`a` for a in results]) import sparql2cwm, myStore, notation3 _outSink = notation3.ToN3(sys.stdout.write, quiet=1, flags='') for a in results: sink = sparql2cwm.FromSparql(myStore._checkStore(), ve=1) f = AST((sys.argv[2], ) + a[3], sink).run().close() myStore._checkStore().dumpNested(f, _outSink) print t1, t2, t1 + t2
def test(text): gen = notation3.ToN3(sys.stdout.write) p = Parser(gen, 'http://example.org/2001/stuff/doc23') gen.startDoc() p.feed(text) gen.endDoc()