• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang storage.Graph类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/google/badwolf/storage.Graph的典型用法代码示例。如果您正苦于以下问题:Golang Graph类的具体用法?Golang Graph怎么用?Golang Graph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Graph类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: WriteGraph

// WriteGraph serializes the graph into the writer where each triple is
// marshaled into a separate line. If there is an error writing the
// serialization will stop. It returns the number of triples serialized
// regardless if it succeeded or failed partially.
func WriteGraph(ctx context.Context, w io.Writer, g storage.Graph) (int, error) {
	var (
		wg   sync.WaitGroup
		tErr error
		wErr error
	)
	cnt, ts := 0, make(chan *triple.Triple)
	wg.Add(1)
	go func() {
		defer wg.Done()
		tErr = g.Triples(ctx, ts)
	}()
	for t := range ts {
		if wErr != nil {
			continue
		}
		if _, err := io.WriteString(w, fmt.Sprintf("%s\n", t.String())); err != nil {
			wErr = err
			continue
		}
		cnt++
	}
	wg.Wait()
	if tErr != nil {
		return 0, tErr
	}
	if wErr != nil {
		return 0, wErr
	}
	return cnt, nil
}
开发者ID:google,项目名称:badwolf,代码行数:35,代码来源:io.go


示例2: BQLRandomGraphWalking

// BQLRandomGraphWalking creates the benchmark.
func BQLRandomGraphWalking(ctx context.Context, st storage.Store, chanSize int) ([]*runtime.BenchEntry, error) {
	rgSize := []int{1000, 10000}
	sizes := []int{10, 1000, 100000}
	var trplSets [][]*triple.Triple
	var ids []string
	var gids []string
	var gSizes []int
	gs, err := getGraphGenerators(rgSize)
	if err != nil {
		return nil, err
	}
	for idx, g := range gs {
		for _, s := range sizes {
			ts, err := g.Generate(s)
			if err != nil {
				return nil, err
			}
			trplSets = append(trplSets, ts)
			ids = append(ids, fmt.Sprintf("bql rg branch_factor=%04d, size=%07d", rgSize[idx], s))
			gids = append(gids, fmt.Sprintf("bql_b%d_s%d", rgSize[idx], s))
			gSizes = append(gSizes, s)
		}
	}
	var bes []*runtime.BenchEntry
	reps := []int{10}
	for bqlIdx, bqlQuery := range treeGraphWalkingBQL {
		bql := bqlQuery
		for i, max := 0, len(ids); i < max; i++ {
			for idxReps, r := range reps {
				var g storage.Graph
				gID := fmt.Sprintf("bql_rg_%d_%s_r%d_i%d", bqlIdx, gids[i], i, idxReps)
				data := trplSets[i]
				bes = append(bes, &runtime.BenchEntry{
					BatteryID: fmt.Sprintf("Run BQL random graph walking query %d", bqlIdx),
					ID:        fmt.Sprintf("%s, reps=%02d", ids[i], r),
					Triples:   gSizes[i],
					Reps:      r,
					Setup: func() error {
						var err error
						g, err = st.NewGraph(ctx, "?"+gID)
						if err != nil {
							return err
						}
						return g.AddTriples(ctx, data)
					},
					F: func() error {
						query := fmt.Sprintf(bql, gID)
						_, err := run.BQL(ctx, query, st, chanSize)
						return err
					},
					TearDown: func() error {
						return st.DeleteGraph(ctx, "?"+gID)
					},
				})
			}
		}
	}
	return bes, nil
}
开发者ID:google,项目名称:badwolf,代码行数:60,代码来源:bql.go


示例3: RemoveExistingTreeTriplesBenchmark

// RemoveExistingTreeTriplesBenchmark creates the benchmark.
func RemoveExistingTreeTriplesBenchmark(ctx context.Context, st storage.Store, chanSize int) ([]*runtime.BenchEntry, error) {
	bFactors := []int{2, 200}
	sizes := []int{10, 1000, 100000}
	var trplSets [][]*triple.Triple
	var ids []string
	var gids []string
	var gSizes []int
	gs, err := getTreeGenerators(bFactors)
	if err != nil {
		return nil, err
	}
	for idx, g := range gs {
		for _, s := range sizes {
			ts, err := g.Generate(s)
			if err != nil {
				return nil, err
			}
			trplSets = append(trplSets, ts)
			ids = append(ids, fmt.Sprintf("etg branch_factor=%04d, size=%07d", bFactors[idx], s))
			gids = append(gids, fmt.Sprintf("b%d_s%d", bFactors[idx], s))
			gSizes = append(gSizes, s)
		}
	}
	var bes []*runtime.BenchEntry
	reps := []int{10}
	for i, max := 0, len(ids); i < max; i++ {
		for idxReps, r := range reps {
			var g storage.Graph
			gID := fmt.Sprintf("remove_existing_tree_%s_r%d_i%d", gids[i], i, idxReps)
			data := trplSets[i]
			bes = append(bes, &runtime.BenchEntry{
				BatteryID: "Remove existing triples",
				ID:        fmt.Sprintf("%s, reps=%02d", ids[i], r),
				Triples:   gSizes[i],
				Reps:      r,
				Setup: func() error {
					var err error
					g, err = st.NewGraph(ctx, gID)
					if err != nil {
						return err
					}
					return g.AddTriples(ctx, data)
				},
				F: func() error {
					return g.RemoveTriples(ctx, data)
				},
				TearDown: func() error {
					return st.DeleteGraph(ctx, gID)
				},
			})
		}
	}
	return bes, nil
}
开发者ID:google,项目名称:badwolf,代码行数:55,代码来源:remove.go


示例4: WriteGraph

// WriteGraph serializes the graph into the writer where each triple is
// marshalled into a separate line. If there is an error writting the
// serializatino will stop. It returns the number of triples serialized
// regardless if it succeded of it failed partialy.
func WriteGraph(w io.Writer, g storage.Graph) (int, error) {
	cnt := 0
	for t := range g.Triples() {
		_, err := io.WriteString(w, fmt.Sprintf("%s\n", t.String()))
		if err != nil {
			return cnt, err
		}
		cnt++
	}
	return cnt, nil
}
开发者ID:ranjeet-floyd,项目名称:badwolf,代码行数:15,代码来源:io.go


示例5: WriteGraph

// WriteGraph serializes the graph into the writer where each triple is
// marshalled into a separate line. If there is an error writting the
// serialization will stop. It returns the number of triples serialized
// regardless if it succeded of it failed partialy.
func WriteGraph(ctx context.Context, w io.Writer, g storage.Graph) (int, error) {
	cnt := 0
	ts, err := g.Triples(ctx)
	if err != nil {
		return 0, err
	}
	for t := range ts {
		if _, err := io.WriteString(w, fmt.Sprintf("%s\n", t.String())); err != nil {
			return cnt, err
		}
		cnt++
	}
	return cnt, nil
}
开发者ID:msingle,项目名称:badwolf,代码行数:18,代码来源:io.go


示例6: ReadIntoGraph

// ReadIntoGraph reads a graph out of the provided reader. The data on the
// reader is interpret as text. Each line represents one triple using the
// standard serialized format. ReadIntoGraph will stop if fails to Parse
// a triple on the stream. The triples read till then would have also been
// added to the graph. The int value returns the number of triples added
func ReadIntoGraph(g storage.Graph, r io.Reader, b literal.Builder) (int, error) {
	cnt, scanner := 0, bufio.NewScanner(r)
	scanner.Split(bufio.ScanLines)
	for scanner.Scan() {
		text := strings.TrimSpace(scanner.Text())
		if text == "" {
			continue
		}
		t, err := triple.ParseTriple(text, b)
		if err != nil {
			return cnt, err
		}
		cnt++
		g.AddTriples([]*triple.Triple{t})
	}
	return cnt, nil
}
开发者ID:rtu,项目名称:badwolf,代码行数:22,代码来源:io.go



注:本文中的github.com/google/badwolf/storage.Graph类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang storage.Store类代码示例发布时间:2022-05-23
下一篇:
Golang table.New函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap