#| -*-Scheme-*-
-$Id: rdf-nt.scm,v 1.1 2006/02/18 04:31:47 cph Exp $
+$Id: rdf-nt.scm,v 1.2 2006/02/24 17:47:25 cph Exp $
Copyright 2006 Massachusetts Institute of Technology
\f
;;;; Decoder
+(define (read-rdf/nt-file pathname)
+ (fluid-let ((*bnodes* (make-bnode-table)))
+ (call-with-input-file pathname
+ (lambda (port)
+ (let loop ((triples '()))
+ (let ((triple (%read-rdf/nt port)))
+ (if (eof-object? triple)
+ triples
+ (loop (cons triple triples)))))))))
+
+(define (rdf/nt-file->source pathname)
+ (fluid-let ((*bnodes* (make-bnode-table)))
+ (let ((port (open-input-file pathname)))
+ (lambda ()
+ (let ((triple (%read-rdf/nt port)))
+ (if (eof-object? triple)
+ #f
+ triple))))))
+
(define (read-rdf/nt port)
+ (fluid-let ((*bnodes* (bnode-table port)))
+ (let ((triple (%read-rdf/nt port)))
+ (if (eof-object? triple)
+ (drop-bnode-table port))
+ triple)))
+
+(define (%read-rdf/nt port)
(let loop ()
(let ((line (read-line port)))
(if (eof-object? line)
(if (fix:= (vector-length v) 0)
(loop)
(vector-ref v 0)))))))
-
+\f
(define parse-one-line
(*parser
(complete
(define parse-node-id
(*parser
- (encapsulate (lambda (v) (make-rdf-bnode (vector-ref v 0)))
+ (encapsulate (lambda (v) (make-bnode (vector-ref v 0)))
(seq "_:"
(match match-bnode-name)))))
(port/set-coding port 'UTF-8)
(loop)))
\f
+(define *bnodes*)
+
+(define (make-bnode-table)
+ (make-string-hash-table))
+
+(define (bnode-table port)
+ (or (port/get-property port 'BNODE-TABLE #f)
+ (let ((table (make-string-hash-table)))
+ (port/set-property! port 'BNODE-TABLE table)
+ table)))
+
+(define (drop-bnode-table port)
+ (port/remove-property! port 'BNODE-TABLE))
+
+(define (make-bnode name)
+ (hash-table/intern! *bnodes* name
+ (lambda ()
+ (make-rdf-bnode name))))
+
(define match-language
(*matcher
(seq (+ (char-set char-set:language-head))
#| -*-Scheme-*-
-$Id: xml.pkg,v 1.64 2006/02/18 04:31:55 cph Exp $
+$Id: xml.pkg,v 1.65 2006/02/24 17:47:26 cph Exp $
Copyright 2001,2002,2003,2004,2005,2006 Massachusetts Institute of Technology
(parent (runtime rdf))
(export ()
read-rdf/nt
+ read-rdf/nt-file
+ rdf/nt-file->source
write-rdf/nt))
\ No newline at end of file