switched out QuadsAllIterator to allow any iterator
This commit is contained in:
parent
f1566ba182
commit
b5f0d3688b
2 changed files with 20 additions and 15 deletions
|
|
@ -11,12 +11,17 @@ import (
|
||||||
type Exporter struct {
|
type Exporter struct {
|
||||||
wr io.Writer
|
wr io.Writer
|
||||||
qstore graph.QuadStore
|
qstore graph.QuadStore
|
||||||
|
qi graph.Iterator
|
||||||
err error
|
err error
|
||||||
count int32
|
count int32
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExporter(writer io.Writer, qstore graph.QuadStore) *Exporter {
|
func NewExporter(writer io.Writer, qstore graph.QuadStore) *Exporter {
|
||||||
return &Exporter{wr: writer, qstore: qstore}
|
return NewExporterForIterator(writer, qstore, qstore.QuadsAllIterator())
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewExporterForIterator(writer io.Writer, qstore graph.QuadStore, qi graph.Iterator) *Exporter {
|
||||||
|
return &Exporter{wr: writer, qstore: qstore, qi: qi}
|
||||||
}
|
}
|
||||||
|
|
||||||
// number of records
|
// number of records
|
||||||
|
|
@ -24,9 +29,9 @@ func (exp *Exporter) Count() int32 {
|
||||||
return exp.count
|
return exp.count
|
||||||
}
|
}
|
||||||
|
|
||||||
func (exp *Exporter) ExportNquad() {
|
func (exp *Exporter) ExportQuad() {
|
||||||
it := exp.qstore.QuadsAllIterator()
|
exp.qi.Reset()
|
||||||
for graph.Next(it) {
|
for it := exp.qi; graph.Next(it); {
|
||||||
exp.count++
|
exp.count++
|
||||||
quad := exp.qstore.Quad(it.Result())
|
quad := exp.qstore.Quad(it.Result())
|
||||||
|
|
||||||
|
|
@ -46,8 +51,8 @@ func (exp *Exporter) ExportNquad() {
|
||||||
func (exp *Exporter) ExportJson() {
|
func (exp *Exporter) ExportJson() {
|
||||||
var jstr []byte
|
var jstr []byte
|
||||||
exp.Write("[")
|
exp.Write("[")
|
||||||
it := exp.qstore.QuadsAllIterator()
|
exp.qi.Reset()
|
||||||
for graph.Next(it) {
|
for it := exp.qi; graph.Next(it); {
|
||||||
exp.count++
|
exp.count++
|
||||||
if exp.count > 1 {
|
if exp.count > 1 {
|
||||||
exp.Write(",")
|
exp.Write(",")
|
||||||
|
|
@ -70,8 +75,8 @@ func (exp *Exporter) ExportGml() {
|
||||||
exp.Write("Creator Cayley\ngraph\n[\n")
|
exp.Write("Creator Cayley\ngraph\n[\n")
|
||||||
|
|
||||||
seen = make(map[string]int32)
|
seen = make(map[string]int32)
|
||||||
it := exp.qstore.QuadsAllIterator()
|
exp.qi.Reset()
|
||||||
for graph.Next(it) {
|
for it := exp.qi; graph.Next(it); {
|
||||||
cur := exp.qstore.Quad(it.Result())
|
cur := exp.qstore.Quad(it.Result())
|
||||||
if _, ok := seen[cur.Subject]; !ok {
|
if _, ok := seen[cur.Subject]; !ok {
|
||||||
exp.Write(" node\n [\n id ")
|
exp.Write(" node\n [\n id ")
|
||||||
|
|
@ -94,8 +99,8 @@ func (exp *Exporter) ExportGml() {
|
||||||
exp.count++
|
exp.count++
|
||||||
}
|
}
|
||||||
|
|
||||||
it.Reset()
|
exp.qi.Reset()
|
||||||
for graph.Next(it) {
|
for it := exp.qi; graph.Next(it); {
|
||||||
cur := exp.qstore.Quad(it.Result())
|
cur := exp.qstore.Quad(it.Result())
|
||||||
exp.Write(" edge\n [\n source ")
|
exp.Write(" edge\n [\n source ")
|
||||||
exp.Write(strconv.FormatInt(int64(seen[cur.Subject]), 10))
|
exp.Write(strconv.FormatInt(int64(seen[cur.Subject]), 10))
|
||||||
|
|
@ -120,8 +125,8 @@ func (exp *Exporter) ExportGraphml() {
|
||||||
exp.Write(" <graph id=\"Caylay\" edgedefault=\"directed\">\n")
|
exp.Write(" <graph id=\"Caylay\" edgedefault=\"directed\">\n")
|
||||||
|
|
||||||
seen = make(map[string]bool)
|
seen = make(map[string]bool)
|
||||||
it := exp.qstore.QuadsAllIterator()
|
exp.qi.Reset()
|
||||||
for graph.Next(it) {
|
for it := exp.qi; graph.Next(it); {
|
||||||
cur := exp.qstore.Quad(it.Result())
|
cur := exp.qstore.Quad(it.Result())
|
||||||
if found := seen[cur.Subject]; !found {
|
if found := seen[cur.Subject]; !found {
|
||||||
seen[cur.Subject] = true
|
seen[cur.Subject] = true
|
||||||
|
|
@ -138,8 +143,8 @@ func (exp *Exporter) ExportGraphml() {
|
||||||
exp.count++
|
exp.count++
|
||||||
}
|
}
|
||||||
|
|
||||||
it.Reset()
|
exp.qi.Reset()
|
||||||
for graph.Next(it) {
|
for it := exp.qi; graph.Next(it); {
|
||||||
cur := exp.qstore.Quad(it.Result())
|
cur := exp.qstore.Quad(it.Result())
|
||||||
exp.Write(" <edge source=")
|
exp.Write(" <edge source=")
|
||||||
exp.WriteEscString(cur.Subject)
|
exp.WriteEscString(cur.Subject)
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ func Dump(qs graph.QuadStore, outFile, typ string) error {
|
||||||
//TODO: add possible support for exporting specific queries only
|
//TODO: add possible support for exporting specific queries only
|
||||||
switch typ {
|
switch typ {
|
||||||
case "quad":
|
case "quad":
|
||||||
export.ExportNquad()
|
export.ExportQuad()
|
||||||
case "json":
|
case "json":
|
||||||
export.ExportJson()
|
export.ExportJson()
|
||||||
// gml/graphml experimental
|
// gml/graphml experimental
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue