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

Golang graph.Next函数代码示例

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

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



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

示例1: TestMultipleConstraintParse

func TestMultipleConstraintParse(t *testing.T) {
	ts, _ := graph.NewTripleStore("memstore", "", nil)
	for _, tv := range []*quad.Quad{
		{"i", "like", "food", ""},
		{"i", "like", "beer", ""},
		{"you", "like", "beer", ""},
	} {
		ts.AddTriple(tv)
	}
	query := `(
		$a
		(:like :beer)
		(:like "food")
	)`
	it := BuildIteratorTreeForQuery(ts, query)
	if it.Type() != graph.And {
		t.Error("Odd iterator tree. Got: %s", it.DebugString(0))
	}
	out, ok := graph.Next(it)
	if !ok {
		t.Error("Got no results")
	}
	if out != ts.ValueOf("i") {
		t.Errorf("Got %d, expected %d", out, ts.ValueOf("i"))
	}
	_, ok = graph.Next(it)
	if ok {
		t.Error("Too many results")
	}
}
开发者ID:neevor,项目名称:cayley,代码行数:30,代码来源:parser_test.go


示例2: TestMultipleConstraintParse

func TestMultipleConstraintParse(t *testing.T) {
	qs, _ := graph.NewQuadStore("memstore", "", nil)
	w, _ := graph.NewQuadWriter("single", qs, nil)
	for _, tv := range []quad.Quad{
		{"i", "like", "food", ""},
		{"i", "like", "beer", ""},
		{"you", "like", "beer", ""},
	} {
		w.AddQuad(tv)
	}
	query := `(
		$a
		(:like :beer)
		(:like "food")
	)`
	it := BuildIteratorTreeForQuery(qs, query)
	if it.Type() != graph.And {
		t.Errorf("Odd iterator tree. Got: %#v", it.Describe())
	}
	if !graph.Next(it) {
		t.Error("Got no results")
	}
	out := it.Result()
	if out != qs.ValueOf("i") {
		t.Errorf("Got %d, expected %d", out, qs.ValueOf("i"))
	}
	if graph.Next(it) {
		t.Error("Too many results")
	}
}
开发者ID:ericcapricorn,项目名称:cayley,代码行数:30,代码来源:parser_test.go


示例3: TestSQLLinkIteration

func TestSQLLinkIteration(t *testing.T) {
	if *postgres_path == "" {
		t.SkipNow()
	}
	db, err := newQuadStore(*postgres_path, nil)
	qs := db.(*QuadStore)
	if err != nil {
		t.Fatal(err)
	}
	it := NewSQLLinkIterator(qs, quad.Object, "Humphrey Bogart")
	for graph.Next(it) {
		fmt.Println(it.Result())
	}
	it = NewSQLLinkIterator(qs, quad.Subject, "/en/casablanca_1942")
	s, v := it.sql.buildSQL(true, nil)
	t.Log(s, v)
	c := 0
	for graph.Next(it) {
		fmt.Println(it.Result())
		c += 1
	}
	if c != 18 {
		t.Errorf("Not enough results, got %d expected 18", c)
	}
}
开发者ID:e4x,项目名称:cayley,代码行数:25,代码来源:sql_link_iterator_test.go


示例4: Next

// Next()ing a LinksTo operates as described above.
func (it *LinksTo) Next() bool {
	graph.NextLogIn(it)
	it.runstats.Next += 1
	if graph.Next(it.nextIt) {
		it.runstats.ContainsNext += 1
		it.result = it.nextIt.Result()
		return graph.NextLogOut(it, it.result, true)
	}

	// If there's an error in the 'next' iterator, we save it and we're done.
	it.err = it.nextIt.Err()
	if it.err != nil {
		return false
	}

	// Subiterator is empty, get another one
	if !graph.Next(it.primaryIt) {
		// Possibly save error
		it.err = it.primaryIt.Err()

		// We're out of nodes in our subiterator, so we're done as well.
		return graph.NextLogOut(it, nil, false)
	}
	it.nextIt.Close()
	it.nextIt = it.qs.QuadIterator(it.dir, it.primaryIt.Result())

	// Recurse -- return the first in the next set.
	return it.Next()
}
开发者ID:dennwc,项目名称:cayley,代码行数:30,代码来源:linksto_iterator.go


示例5: Next

// Next advances the Or graph.iterator. Because the Or is the union of its
// subiterators, it must produce from all subiterators -- unless it it
// shortcircuiting, in which case, it is the first one that returns anything.
func (it *Or) Next() bool {
	graph.NextLogIn(it)
	var first bool
	for {
		if it.currentIterator == -1 {
			it.currentIterator = 0
			first = true
		}
		curIt := it.internalIterators[it.currentIterator]

		if graph.Next(curIt) {
			it.result = curIt.Result()
			return graph.NextLogOut(it, it.result, true)
		}

		if it.isShortCircuiting && !first {
			break
		}
		it.currentIterator++
		if it.currentIterator == it.itCount {
			break
		}
	}

	return graph.NextLogOut(it, nil, false)
}
开发者ID:ericcapricorn,项目名称:cayley,代码行数:29,代码来源:or_iterator.go


示例6: runIteratorWithCallback

func runIteratorWithCallback(it graph.Iterator, ses *Session, callback otto.Value, this otto.FunctionCall, limit int) {
	count := 0
	it, _ = it.Optimize()
	for {
		if ses.doHalt {
			return
		}
		_, ok := graph.Next(it)
		if !ok {
			break
		}
		tags := make(map[string]graph.Value)
		it.TagResults(tags)
		val, _ := this.Otto.ToValue(tagsToValueMap(tags, ses))
		val, _ = callback.Call(this.This, val)
		count++
		if limit >= 0 && count >= limit {
			break
		}
		for it.NextResult() == true {
			if ses.doHalt {
				return
			}
			tags := make(map[string]graph.Value)
			it.TagResults(tags)
			val, _ := this.Otto.ToValue(tagsToValueMap(tags, ses))
			val, _ = callback.Call(this.This, val)
			count++
			if limit >= 0 && count >= limit {
				break
			}
		}
	}
	it.Close()
}
开发者ID:neevor,项目名称:cayley,代码行数:35,代码来源:finals.go


示例7: runIteratorToArray

func runIteratorToArray(it graph.Iterator, ses *Session, limit int) []map[string]string {
	output := make([]map[string]string, 0)
	count := 0
	it, _ = it.Optimize()
	for {
		if ses.doHalt {
			return nil
		}
		_, ok := graph.Next(it)
		if !ok {
			break
		}
		tags := make(map[string]graph.Value)
		it.TagResults(tags)
		output = append(output, tagsToValueMap(tags, ses))
		count++
		if limit >= 0 && count >= limit {
			break
		}
		for it.NextResult() == true {
			if ses.doHalt {
				return nil
			}
			tags := make(map[string]graph.Value)
			it.TagResults(tags)
			output = append(output, tagsToValueMap(tags, ses))
			count++
			if limit >= 0 && count >= limit {
				break
			}
		}
	}
	it.Close()
	return output
}
开发者ID:neevor,项目名称:cayley,代码行数:35,代码来源:finals.go


示例8: main

func main() {

	store, err := cayley.NewGraph("bolt", dbPath, nil)
	if err != nil {
		fmt.Println("error in creating database", err)
	}

	path := cayley.StartPath(store, "Article").
		In().
		Tag("link").
		Save("has_image", "image").
		Save("has_title", "title").
		Save("has_description", "description")

	it := path.BuildIterator()
	it, _ = it.Optimize()

	for graph.Next(it) {
		tags := make(map[string]graph.Value)
		it.TagResults(tags)
		fmt.Println(store.NameOf(tags["image"]))
		fmt.Println(store.NameOf(tags["title"]))
		fmt.Println(store.NameOf(tags["description"]))
		fmt.Println(store.NameOf(tags["link"]))
	}

}
开发者ID:paritosh-gupta,项目名称:ArticleFinder,代码行数:27,代码来源:cayleyQueryApiTest.go


示例9: TestQuadStoreQuadsAllIterator

// TestQuadStoreQuadsAllIterator iterates the nodes in a fixture and asserts
// the result.
func TestQuadStoreQuadsAllIterator(t *testing.T, ctx context.Context) {
	qs := ContextQuadStore(ctx)

	_, err := WriteFixtureQuadStore(qs, "simple")
	if err != nil {
		t.Errorf("Unexpected error writing fixures: %v", err)
	}

	it := qs.QuadsAllIterator()
	defer it.Reset()
	graph.Next(it)
	t.Logf("%#v\n", it.Result())
	q := qs.Quad(it.Result())
	t.Log(q)
	set := Fixtures.QuadSet("simple").Quads
	var ok bool
	for _, e := range set {
		if e.String() == q.String() {
			ok = true
			break
		}
	}
	if !ok {
		t.Errorf("Failed to find %q during iteration, got:%q", q, set)
	}
}
开发者ID:bmatsuo,项目名称:cayley,代码行数:28,代码来源:tests.go


示例10: optimizeLinksTo

func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bool) {
	subs := it.SubIterators()
	if len(subs) != 1 {
		return it, false
	}
	primary := subs[0]
	if primary.Type() == graph.Fixed {
		size, _ := primary.Size()
		if size == 1 {
			val, ok := graph.Next(primary)
			if !ok {
				panic("Sizes lie")
			}
			newIt := ts.TripleIterator(it.Direction(), val)
			nt := newIt.Tagger()
			nt.CopyFrom(it)
			for _, tag := range primary.Tagger().Tags() {
				nt.AddFixed(tag, val)
			}
			return newIt, true
		}
	}
	it.Close()
	return it, false
}
开发者ID:neevor,项目名称:cayley,代码行数:25,代码来源:triplestore_iterator_optimize.go


示例11: Next

// Returns the Next value from the Or graph.iterator. Because the Or is the
// union of its subiterators, it must produce from all subiterators -- unless
// it's shortcircuiting, in which case, it's the first one that returns anything.
func (it *Or) Next() (graph.Value, bool) {
	graph.NextLogIn(it)
	var curr graph.Value
	var exists bool
	firstTime := false
	for {
		if it.currentIterator == -1 {
			it.currentIterator = 0
			firstTime = true
		}
		curIt := it.internalIterators[it.currentIterator]
		curr, exists = graph.Next(curIt)
		if !exists {
			if it.isShortCircuiting && !firstTime {
				return graph.NextLogOut(it, nil, false)
			}
			it.currentIterator++
			if it.currentIterator == it.itCount {
				return graph.NextLogOut(it, nil, false)
			}
		} else {
			it.result = curr
			return graph.NextLogOut(it, curr, true)
		}
	}
	panic("unreachable")
}
开发者ID:neevor,项目名称:cayley,代码行数:30,代码来源:or_iterator.go


示例12: materializeSet

func (it *Materialize) materializeSet() {
	i := 0
	for graph.Next(it.subIt) {
		i++
		if i > abortMaterializeAt {
			it.aborted = true
			break
		}
		id := it.subIt.Result()
		val := id
		if h, ok := id.(Keyer); ok {
			val = h.Key()
		}
		if _, ok := it.containsMap[val]; !ok {
			it.containsMap[val] = len(it.values)
			it.values = append(it.values, nil)
		}
		index := it.containsMap[val]
		tags := make(map[string]graph.Value)
		it.subIt.TagResults(tags)
		it.values[index] = append(it.values[index], result{id: id, tags: tags})
		for it.subIt.NextPath() {
			tags := make(map[string]graph.Value)
			it.subIt.TagResults(tags)
			it.values[index] = append(it.values[index], result{id: id, tags: tags})
		}
	}
	if it.aborted {
		it.values = nil
		it.containsMap = nil
		it.subIt.Reset()
	}
	glog.Infof("Materialization List %d: %#v", it.values)
	it.hasRun = true
}
开发者ID:jacqui,项目名称:cayley,代码行数:35,代码来源:materialize_iterator.go


示例13: iterated

func iterated(it graph.Iterator) []int {
	var res []int
	for graph.Next(it) {
		res = append(res, it.Result().(int))
	}
	return res
}
开发者ID:ericcapricorn,项目名称:cayley,代码行数:7,代码来源:or_iterator_test.go


示例14: optimizeLinksTo

func (ts *QuadStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bool) {
	subs := it.SubIterators()
	if len(subs) != 1 {
		return it, false
	}
	primary := subs[0]
	if primary.Type() == graph.Fixed {
		size, _ := primary.Size()
		if size == 1 {
			if !graph.Next(primary) {
				panic("unexpected size during optimize")
			}
			val := primary.Result()
			newIt := ts.TripleIterator(it.Direction(), val)
			nt := newIt.Tagger()
			nt.CopyFrom(it)
			for _, tag := range primary.Tagger().Tags() {
				nt.AddFixed(tag, val)
			}
			it.Close()
			return newIt, true
		}
	}
	return it, false
}
开发者ID:Joeento,项目名称:cayley,代码行数:25,代码来源:quadstore_iterator_optimize.go


示例15: ExecInput

func (s *Session) ExecInput(input string, c chan interface{}, _ int) {
	defer close(c)
	var mqlQuery interface{}
	err := json.Unmarshal([]byte(input), &mqlQuery)
	if err != nil {
		return
	}
	s.currentQuery = NewQuery(s)
	s.currentQuery.BuildIteratorTree(mqlQuery)
	if s.currentQuery.isError() {
		return
	}
	it, _ := s.currentQuery.it.Optimize()
	if glog.V(2) {
		b, err := json.MarshalIndent(it.Describe(), "", "  ")
		if err != nil {
			glog.Infof("failed to format description: %v", err)
		} else {
			glog.Infof("%s", b)
		}
	}
	for graph.Next(it) {
		tags := make(map[string]graph.Value)
		it.TagResults(tags)
		c <- tags
		for it.NextPath() == true {
			tags := make(map[string]graph.Value)
			it.TagResults(tags)
			c <- tags
		}
	}
}
开发者ID:ericcapricorn,项目名称:cayley,代码行数:32,代码来源:session.go


示例16: ExecInput

func (s *Session) ExecInput(input string, out chan interface{}, limit int) {
	it := BuildIteratorTreeForQuery(s.qs, input)
	newIt, changed := it.Optimize()
	if changed {
		it = newIt
	}

	if s.debug {
		fmt.Println(it.DebugString(0))
	}
	nResults := 0
	for graph.Next(it) {
		tags := make(map[string]graph.Value)
		it.TagResults(tags)
		out <- &tags
		nResults++
		if nResults > limit && limit != -1 {
			break
		}
		for it.NextPath() == true {
			tags := make(map[string]graph.Value)
			it.TagResults(tags)
			out <- &tags
			nResults++
			if nResults > limit && limit != -1 {
				break
			}
		}
	}
	close(out)
}
开发者ID:EntilZha,项目名称:cayley,代码行数:31,代码来源:session.go


示例17: TestRemoveQuad

func TestRemoveQuad(t *testing.T) {
	qs, w, _ := makeTestStore(simpleGraph)

	w.RemoveQuad(quad.Quad{
		Subject:   "E",
		Predicate: "follows",
		Object:    "F",
		Label:     "",
	})

	fixed := qs.FixedIterator()
	fixed.Add(qs.ValueOf("E"))

	fixed2 := qs.FixedIterator()
	fixed2.Add(qs.ValueOf("follows"))

	innerAnd := iterator.NewAnd()
	innerAnd.AddSubIterator(iterator.NewLinksTo(qs, fixed, quad.Subject))
	innerAnd.AddSubIterator(iterator.NewLinksTo(qs, fixed2, quad.Predicate))

	hasa := iterator.NewHasA(qs, innerAnd, quad.Object)

	newIt, _ := hasa.Optimize()
	if graph.Next(newIt) {
		t.Error("E should not have any followers.")
	}
}
开发者ID:ericcapricorn,项目名称:cayley,代码行数:27,代码来源:quadstore_test.go


示例18: TestRemoveQuad

func TestRemoveQuad(t *testing.T) {
	qs, w, _ := makeTestStore(simpleGraph)

	err := w.RemoveQuad(quad.Make(
		"E",
		"follows",
		"F",
		"",
	))

	if err != nil {
		t.Error("Couldn't remove quad", err)
	}

	fixed := qs.FixedIterator()
	fixed.Add(qs.ValueOf(quad.Raw("E")))

	fixed2 := qs.FixedIterator()
	fixed2.Add(qs.ValueOf(quad.Raw("follows")))

	innerAnd := iterator.NewAnd(qs)
	innerAnd.AddSubIterator(iterator.NewLinksTo(qs, fixed, quad.Subject))
	innerAnd.AddSubIterator(iterator.NewLinksTo(qs, fixed2, quad.Predicate))

	hasa := iterator.NewHasA(qs, innerAnd, quad.Object)

	newIt, _ := hasa.Optimize()
	if graph.Next(newIt) {
		t.Error("E should not have any followers.")
	}
}
开发者ID:dennwc,项目名称:cayley,代码行数:31,代码来源:quadstore_test.go


示例19: ExecInput

func (s *Session) ExecInput(input string, c chan interface{}, limit int) {
	defer close(c)
	var mqlQuery interface{}
	err := json.Unmarshal([]byte(input), &mqlQuery)
	if err != nil {
		return
	}
	s.currentQuery = NewQuery(s)
	s.currentQuery.BuildIteratorTree(mqlQuery)
	if s.currentQuery.isError() {
		return
	}
	it, _ := s.currentQuery.it.Optimize()
	if glog.V(2) {
		glog.V(2).Infoln(it.DebugString(0))
	}
	for {
		_, ok := graph.Next(it)
		if !ok {
			break
		}
		tags := make(map[string]graph.Value)
		it.TagResults(tags)
		c <- tags
		for it.NextResult() == true {
			tags := make(map[string]graph.Value)
			it.TagResults(tags)
			c <- tags
		}
	}
}
开发者ID:neevor,项目名称:cayley,代码行数:31,代码来源:session.go


示例20: TestSQLNodeIteration

func TestSQLNodeIteration(t *testing.T) {
	if *postgres_path == "" {
		t.SkipNow()
	}
	db, err := newQuadStore(*postgres_path, nil)
	if err != nil {
		t.Fatal(err)
	}
	link := NewSQLLinkIterator(db.(*QuadStore), quad.Object, "/en/humphrey_bogart")
	it := &SQLIterator{
		uid: iterator.NextUID(),
		qs:  db.(*QuadStore),
		sql: &SQLNodeIterator{
			tableName: newTableName(),
			linkIt: sqlItDir{
				it:  link.sql,
				dir: quad.Subject,
			},
		},
	}
	s, v := it.sql.buildSQL(true, nil)
	t.Log(s, v)
	c := 0
	for graph.Next(it) {
		t.Log(it.Result())
		c += 1
	}
	if c != 56 {
		t.Errorf("Not enough results, got %d expected 56", c)
	}

}
开发者ID:e4x,项目名称:cayley,代码行数:32,代码来源:sql_link_iterator_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang graph.NextLogIn函数代码示例发布时间:2022-05-23
下一篇:
Golang graph.NewSequentialKey函数代码示例发布时间: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