本文整理汇总了Golang中github.com/google/badwolf/storage.Store.Graph方法的典型用法代码示例。如果您正苦于以下问题:Golang Store.Graph方法的具体用法?Golang Store.Graph怎么用?Golang Store.Graph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/google/badwolf/storage.Store
的用法示例。
在下文中一共展示了Store.Graph方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getGraphFromStore
// getGraphFromStore returns a Graph. Will create it if it does not exist.
func getGraphFromStore(ctx context.Context, st storage.Store, id string) (storage.Graph, error) {
g, err := st.Graph(ctx, id)
if err == nil {
return g, nil
}
return st.NewGraph(ctx, id)
}
示例2: newQueryPlan
// newQueryPlan returns a new query plan ready to be excecuted.
func newQueryPlan(store storage.Store, stm *semantic.Statement) (*queryPlan, error) {
bs := []string{}
for _, b := range stm.Bindings() {
bs = append(bs, b)
}
t, err := table.New([]string{})
if err != nil {
return nil, err
}
var gs []storage.Graph
for _, g := range stm.Graphs() {
ng, err := store.Graph(g)
if err != nil {
return nil, err
}
gs = append(gs, ng)
}
return &queryPlan{
stm: stm,
store: store,
bndgs: bs,
grfs: gs,
grfsNames: stm.Graphs(),
cls: stm.SortedGraphPatternClauses(),
tbl: t,
}, nil
}
示例3: update
func update(stm *semantic.Statement, store storage.Store, f updater) error {
var (
mu sync.Mutex
wg sync.WaitGroup
errs []string
)
appendError := func(err error) {
mu.Lock()
defer mu.Unlock()
errs = append(errs, err.Error())
}
for _, graphBinding := range stm.Graphs() {
wg.Add(1)
go func(graph string) {
defer wg.Done()
g, err := store.Graph(graph)
if err != nil {
appendError(err)
return
}
err = f(g, stm.Data())
if err != nil {
appendError(err)
}
}(graphBinding)
}
wg.Wait()
if len(errs) > 0 {
return errors.New(strings.Join(errs, "; "))
}
return nil
}
示例4: Eval
// Eval loads the triples in the file against as indicated by the command.
func Eval(ctx context.Context, usage string, args []string, store storage.Store, bulkSize int) int {
if len(args) <= 3 {
fmt.Fprintf(os.Stderr, "[ERROR] Missing required file path and/or graph names.\n\n%s", usage)
return 2
}
graphs, path := strings.Split(args[len(args)-2], ","), args[len(args)-1]
f, err := os.Create(path)
if err != nil {
fmt.Fprintf(os.Stderr, "[ERROR] Failed to open target file %q with error %v.\n\n", path, err)
return 2
}
defer f.Close()
var sgs []storage.Graph
for _, gr := range graphs {
g, err := store.Graph(ctx, gr)
if err != nil {
fmt.Fprintf(os.Stderr, "[ERROR] Failed to retrieve graph %q with error %v.\n\n", gr, err)
return 2
}
sgs = append(sgs, g)
}
cnt := 0
var errs []error
var mu sync.Mutex
chn := make(chan *triple.Triple, bulkSize)
for _, vg := range sgs {
go func(g storage.Graph) {
err := g.Triples(ctx, chn)
mu.Lock()
errs = append(errs, err)
mu.Unlock()
}(vg)
}
for t := range chn {
if _, err := f.WriteString(t.String() + "\n"); err != nil {
fmt.Fprintf(os.Stderr, "[ERROR] Failed to write triple %s to file %q, %v.\n\n", t.String(), path, err)
return 2
}
cnt++
}
for _, err := range errs {
if err != nil {
fmt.Fprintf(os.Stderr, "[ERROR] Failed to retrieve triples with error %v.\n\n", err)
return 2
}
}
fmt.Printf("Successfully written %d triples to file %q.\nTriples exported from graphs:\n\t- %s\n", cnt, path, strings.Join(graphs, "\n\t- "))
return 0
}
示例5: flush
func flush(ctx context.Context, graphs []string, store storage.Store) error {
defer func() {
workingTrpls = nil
}()
if len(workingTrpls) > 0 {
for _, graph := range graphs {
g, err := store.Graph(ctx, graph)
if err != nil {
return err
}
if err := g.AddTriples(ctx, workingTrpls); err != nil {
return err
}
}
}
return nil
}