formatted using gofmt
This commit is contained in:
parent
ce6e21d4aa
commit
f9ee0e77fc
1 changed files with 14 additions and 14 deletions
|
|
@ -1,19 +1,19 @@
|
||||||
package exporter
|
package exporter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Exporter struct {
|
type Exporter struct {
|
||||||
wr io.Writer
|
wr io.Writer
|
||||||
qstore graph.QuadStore
|
qstore graph.QuadStore
|
||||||
qi graph.Iterator
|
qi graph.Iterator
|
||||||
err error
|
err error
|
||||||
count int
|
count int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExporter(writer io.Writer, qstore graph.QuadStore) *Exporter {
|
func NewExporter(writer io.Writer, qstore graph.QuadStore) *Exporter {
|
||||||
|
|
@ -34,7 +34,7 @@ func (exp *Exporter) ExportQuad() {
|
||||||
for it := exp.qi; 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())
|
||||||
|
|
||||||
exp.WriteEscString(quad.Subject)
|
exp.WriteEscString(quad.Subject)
|
||||||
exp.Write(" ")
|
exp.Write(" ")
|
||||||
exp.WriteEscString(quad.Predicate)
|
exp.WriteEscString(quad.Predicate)
|
||||||
|
|
@ -45,11 +45,11 @@ func (exp *Exporter) ExportQuad() {
|
||||||
exp.WriteEscString(quad.Label)
|
exp.WriteEscString(quad.Label)
|
||||||
}
|
}
|
||||||
exp.Write(" .\n")
|
exp.Write(" .\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (exp *Exporter) ExportJson() {
|
func (exp *Exporter) ExportJson() {
|
||||||
var jstr []byte
|
var jstr []byte
|
||||||
exp.Write("[")
|
exp.Write("[")
|
||||||
exp.qi.Reset()
|
exp.qi.Reset()
|
||||||
for it := exp.qi; graph.Next(it); {
|
for it := exp.qi; graph.Next(it); {
|
||||||
|
|
@ -149,28 +149,28 @@ func (exp *Exporter) ExportGraphml() {
|
||||||
exp.Write(" <edge source=")
|
exp.Write(" <edge source=")
|
||||||
exp.WriteEscString(cur.Subject)
|
exp.WriteEscString(cur.Subject)
|
||||||
exp.Write(" target=")
|
exp.Write(" target=")
|
||||||
exp.WriteEscString(cur.Object)
|
exp.WriteEscString(cur.Object)
|
||||||
exp.Write(">\n")
|
exp.Write(">\n")
|
||||||
exp.Write(" <data key=\"predicate\">")
|
exp.Write(" <data key=\"predicate\">")
|
||||||
exp.Write(cur.Predicate)
|
exp.Write(cur.Predicate)
|
||||||
exp.Write("</data>\n </edge>\n")
|
exp.Write("</data>\n </edge>\n")
|
||||||
exp.count++
|
exp.count++
|
||||||
}
|
}
|
||||||
exp.Write(" </graph>\n</graphml>\n");
|
exp.Write(" </graph>\n</graphml>\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
//print out the string quoted, escaped
|
//print out the string quoted, escaped
|
||||||
func (exp *Exporter) WriteEscString(str string) {
|
func (exp *Exporter) WriteEscString(str string) {
|
||||||
var esc []byte
|
var esc []byte
|
||||||
|
|
||||||
if exp.err != nil {
|
if exp.err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
esc, exp.err = json.Marshal(str)
|
esc, exp.err = json.Marshal(str)
|
||||||
if exp.err != nil {
|
if exp.err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, exp.err = exp.wr.Write(esc)
|
_, exp.err = exp.wr.Write(esc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (exp *Exporter) Write(str string) {
|
func (exp *Exporter) Write(str string) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue