export nquads
This commit is contained in:
parent
1e9c6990bb
commit
76e4a5d15e
2 changed files with 32 additions and 1 deletions
|
|
@ -23,6 +23,25 @@ func (exp *Exporter) Count() int32 {
|
|||
return exp.count
|
||||
}
|
||||
|
||||
func (exp *Exporter) ExportNquad() {
|
||||
it := exp.qstore.QuadsAllIterator()
|
||||
for graph.Next(it) {
|
||||
exp.count++
|
||||
quad := exp.qstore.Quad(it.Result())
|
||||
|
||||
exp.WriteEscString(quad.Subject)
|
||||
exp.Write(" ")
|
||||
exp.WriteEscString(quad.Predicate)
|
||||
exp.Write(" ")
|
||||
exp.WriteEscString(quad.Object)
|
||||
if quad.Label != "" {
|
||||
exp.Write(" ")
|
||||
exp.WriteEscString(quad.Label)
|
||||
}
|
||||
exp.Write(" .\n")
|
||||
}
|
||||
}
|
||||
|
||||
func (exp *Exporter) ExportJson() {
|
||||
var jstr []byte
|
||||
exp.Write("[")
|
||||
|
|
|
|||
|
|
@ -28,7 +28,19 @@ func Dump(qs graph.QuadStore, outFile, typ string) error {
|
|||
if export.Err() != nil {
|
||||
return export.Err()
|
||||
}
|
||||
|
||||
switch typ {
|
||||
case "nquad":
|
||||
export.ExportNquad()
|
||||
case "json":
|
||||
export.ExportJson()
|
||||
default:
|
||||
return fmt.Errorf("unknown format %q", typ)
|
||||
}
|
||||
|
||||
if export.Err() != nil {
|
||||
return export.Err()
|
||||
}
|
||||
|
||||
if outFile != "-" {
|
||||
fmt.Printf("%d entries were written\n", export.Count())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue