當前位置: 首頁>>代碼示例>>Golang>>正文


Golang graph.QuadStore類代碼示例

本文整理匯總了Golang中github.com/cayleygraph/cayley/graph.QuadStore的典型用法代碼示例。如果您正苦於以下問題:Golang QuadStore類的具體用法?Golang QuadStore怎麽用?Golang QuadStore使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了QuadStore類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: buildViaPath

func buildViaPath(qs graph.QuadStore, via ...interface{}) *Path {
	if len(via) == 0 {
		return PathFromIterator(qs, qs.NodesAllIterator())
	} else if len(via) == 1 {
		v := via[0]
		switch p := v.(type) {
		case nil:
			return PathFromIterator(qs, qs.NodesAllIterator())
		case *Path:
			if p.qs != qs {
				newp := &Path{
					qs:          qs,
					baseContext: p.baseContext,
					stack:       p.stack[:],
				}
				return newp
			}
			return p
		case string:
			return StartPath(qs, p)
		default:
			panic(fmt.Sprintln("Invalid type passed to buildViaPath.", reflect.TypeOf(v), p))
		}
	}
	var strings []string
	for _, s := range via {
		if str, ok := s.(string); ok {
			strings = append(strings, str)
		} else {
			panic("Non-string type passed to long Via path")
		}
	}
	return StartPath(qs, strings...)
}
開發者ID:RamboWANG,項目名稱:cayley,代碼行數:34,代碼來源:morphism_apply_functions.go

示例2: NewSingleReplication

func NewSingleReplication(qs graph.QuadStore, opts graph.Options) (graph.QuadWriter, error) {
	var (
		ignoreMissing   bool
		ignoreDuplicate bool
		err             error
	)

	if *graph.IgnoreMissing {
		ignoreMissing = true
	} else {
		ignoreMissing, _, err = opts.BoolKey("ignore_missing")
		if err != nil {
			return nil, err
		}
	}

	if *graph.IgnoreDup {
		ignoreDuplicate = true
	} else {
		ignoreDuplicate, _, err = opts.BoolKey("ignore_duplicate")
		if err != nil {
			return nil, err
		}
	}

	return &Single{
		currentID: qs.Horizon(),
		qs:        qs,
		ignoreOpts: graph.IgnoreOpts{
			IgnoreDup:     ignoreDuplicate,
			IgnoreMissing: ignoreMissing,
		},
	}, nil
}
開發者ID:kortschak,項目名稱:cayley,代碼行數:34,代碼來源:single.go

示例3: buildViaPath

func buildViaPath(qs graph.QuadStore, via ...interface{}) *Path {
	if len(via) == 0 {
		return PathFromIterator(qs, qs.NodesAllIterator())
	} else if len(via) == 1 {
		v := via[0]
		switch p := v.(type) {
		case nil:
			return PathFromIterator(qs, qs.NodesAllIterator())
		case *Path:
			if p.qs != qs {
				newp := &Path{
					qs:          qs,
					baseContext: p.baseContext,
					stack:       p.stack[:],
				}
				return newp
			}
			return p
		case quad.Value:
			return StartPath(qs, p)
		}
	}
	nodes := make([]quad.Value, 0, len(via))
	for _, v := range via {
		qv, ok := quad.AsValue(v)
		if !ok {
			panic(fmt.Errorf("Invalid type passed to buildViaPath: %v (%T)", v, v))
		}
		nodes = append(nodes, qv)
	}
	return StartPath(qs, nodes...)
}
開發者ID:coralproject,項目名稱:xenia,代碼行數:32,代碼來源:morphism_apply_functions.go

示例4: buildSave

func buildSave(
	qs graph.QuadStore, via interface{},
	tag string, from graph.Iterator, reverse bool, optional bool,
) graph.Iterator {

	allNodes := qs.NodesAllIterator()
	allNodes.Tagger().Add(tag)

	start, goal := quad.Subject, quad.Object
	if reverse {
		start, goal = goal, start
	}
	viaIter := buildViaPath(qs, via).
		BuildIterator()

	dest := iterator.NewLinksTo(qs, allNodes, goal)
	trail := iterator.NewLinksTo(qs, viaIter, quad.Predicate)

	route := join(qs, trail, dest)
	save := graph.Iterator(iterator.NewHasA(qs, route, start))

	if optional {
		save = iterator.NewOptional(save)
	}
	return join(qs, from, save)
}
開發者ID:RamboWANG,項目名稱:cayley,代碼行數:26,代碼來源:morphism_apply_functions.go

示例5: iteratedNames

func iteratedNames(qs graph.QuadStore, it graph.Iterator) []string {
	var res []string
	for graph.Next(it) {
		res = append(res, qs.NameOf(it.Result()))
	}
	sort.Strings(res)
	return res
}
開發者ID:RamboWANG,項目名稱:cayley,代碼行數:8,代碼來源:leveldb_test.go

示例6: iteratedQuads

func iteratedQuads(qs graph.QuadStore, it graph.Iterator) []quad.Quad {
	var res ordered
	for graph.Next(it) {
		res = append(res, qs.Quad(it.Result()))
	}
	sort.Sort(res)
	return res
}
開發者ID:RamboWANG,項目名稱:cayley,代碼行數:8,代碼來源:leveldb_test.go

示例7: IteratedQuads

func IteratedQuads(t testing.TB, qs graph.QuadStore, it graph.Iterator) []quad.Quad {
	var res quad.ByQuadString
	for it.Next() {
		res = append(res, qs.Quad(it.Result()))
	}
	require.Nil(t, it.Err())
	sort.Sort(res)
	return res
}
開發者ID:rlugojr,項目名稱:cayley,代碼行數:9,代碼來源:graphtest.go

示例8: IteratedValues

func IteratedValues(t testing.TB, qs graph.QuadStore, it graph.Iterator) []quad.Value {
	var res []quad.Value
	for it.Next() {
		res = append(res, qs.NameOf(it.Result()))
	}
	require.Nil(t, it.Err())
	sort.Sort(quad.ByValueString(res))
	return res
}
開發者ID:rlugojr,項目名稱:cayley,代碼行數:9,代碼來源:graphtest.go

示例9: IteratedRawStrings

func IteratedRawStrings(t testing.TB, qs graph.QuadStore, it graph.Iterator) []string {
	var res []string
	for it.Next() {
		res = append(res, qs.NameOf(it.Result()).String())
	}
	require.Nil(t, it.Err())
	sort.Strings(res)
	return res
}
開發者ID:rlugojr,項目名稱:cayley,代碼行數:9,代碼來源:graphtest.go

示例10: iterateResults

func iterateResults(qs graph.QuadStore, it graph.Iterator) []string {
	var res []string
	for graph.Next(it) {
		v := it.Result()
		if t, ok := v.(*Token); ok && t.Kind == nodeKind {
			res = append(res, qs.NameOf(it.Result()))
		} else {
			res = append(res, qs.Quad(it.Result()).String())
		}
	}
	sort.Strings(res)
	it.Reset()
	return res
}
開發者ID:RamboWANG,項目名稱:cayley,代碼行數:14,代碼來源:quadstore_test.go

示例11: hasaWithTag

func hasaWithTag(qs graph.QuadStore, tag string, target string) *HasA {
	and := NewAnd(qs)

	obj := qs.FixedIterator()
	obj.Add(qs.ValueOf(quad.Raw(target)))
	obj.Tagger().Add(tag)
	and.AddSubIterator(NewLinksTo(qs, obj, quad.Object))

	pred := qs.FixedIterator()
	pred.Add(qs.ValueOf(quad.Raw("status")))
	and.AddSubIterator(NewLinksTo(qs, pred, quad.Predicate))

	return NewHasA(qs, and, quad.Subject)
}
開發者ID:rlugojr,項目名稱:cayley,代碼行數:14,代碼來源:query_shape_test.go

示例12: buildHas

func buildHas(qs graph.QuadStore, via interface{}, in graph.Iterator, reverse bool, nodes []string) graph.Iterator {
	viaIter := buildViaPath(qs, via).
		BuildIterator()
	ends := func() graph.Iterator {
		if len(nodes) == 0 {
			return qs.NodesAllIterator()
		}

		fixed := qs.FixedIterator()
		for _, n := range nodes {
			fixed.Add(qs.ValueOf(n))
		}
		return fixed
	}()

	start, goal := quad.Subject, quad.Object
	if reverse {
		start, goal = goal, start
	}

	trail := iterator.NewLinksTo(qs, viaIter, quad.Predicate)
	dest := iterator.NewLinksTo(qs, ends, goal)

	// If we were given nodes, intersecting with them first will
	// be extremely cheap-- otherwise, it will be the most expensive
	// (requiring iteration over all nodes). We have enough info to
	// make this optimization now since intersections are commutative
	if len(nodes) == 0 { // Where dest involves an All iterator.
		route := join(qs, trail, dest)
		has := iterator.NewHasA(qs, route, start)
		return join(qs, in, has)
	}

	// This looks backwards. That's OK-- see the note above.
	route := join(qs, dest, trail)
	has := iterator.NewHasA(qs, route, start)
	return join(qs, has, in)
}
開發者ID:RamboWANG,項目名稱:cayley,代碼行數:38,代碼來源:morphism_apply_functions.go

示例13: BuildIteratorOn

// BuildIteratorOn will return an iterator for this path on the given QuadStore.
func (p *Path) BuildIteratorOn(qs graph.QuadStore) graph.Iterator {
	return p.Morphism()(qs, qs.NodesAllIterator())
}
開發者ID:kortschak,項目名稱:cayley,代碼行數:4,代碼來源:path.go

示例14: NewExporter

func NewExporter(writer io.Writer, qstore graph.QuadStore) *Exporter {
	return NewExporterForIterator(writer, qstore, qstore.QuadsAllIterator())
}
開發者ID:RamboWANG,項目名稱:cayley,代碼行數:3,代碼來源:exporter.go

示例15: buildIteratorTree

func buildIteratorTree(tree *peg.ExpressionTree, qs graph.QuadStore) graph.Iterator {
	switch tree.Name {
	case "Start":
		return buildIteratorTree(tree.Children[0], qs)
	case "NodeIdentifier":
		var out graph.Iterator
		nodeID := getIdentString(tree)
		if tree.Children[0].Name == "Variable" {
			allIt := qs.NodesAllIterator()
			allIt.Tagger().Add(nodeID)
			out = allIt
		} else {
			n := nodeID
			if tree.Children[0].Children[0].Name == "ColonIdentifier" {
				n = nodeID[1:]
			}
			fixed := qs.FixedIterator()
			fixed.Add(qs.ValueOf(n))
			out = fixed
		}
		return out
	case "PredIdentifier":
		i := 0
		if tree.Children[0].Name == "Reverse" {
			//Taken care of below
			i++
		}
		it := buildIteratorTree(tree.Children[i], qs)
		lto := iterator.NewLinksTo(qs, it, quad.Predicate)
		return lto
	case "RootConstraint":
		constraintCount := 0
		and := iterator.NewAnd(qs)
		for _, c := range tree.Children {
			switch c.Name {
			case "NodeIdentifier":
				fallthrough
			case "Constraint":
				it := buildIteratorTree(c, qs)
				and.AddSubIterator(it)
				constraintCount++
				continue
			default:
				continue
			}
		}
		return and
	case "Constraint":
		var hasa *iterator.HasA
		topLevelDir := quad.Subject
		subItDir := quad.Object
		subAnd := iterator.NewAnd(qs)
		isOptional := false
		for _, c := range tree.Children {
			switch c.Name {
			case "PredIdentifier":
				if c.Children[0].Name == "Reverse" {
					topLevelDir = quad.Object
					subItDir = quad.Subject
				}
				it := buildIteratorTree(c, qs)
				subAnd.AddSubIterator(it)
				continue
			case "PredicateKeyword":
				switch c.Children[0].Name {
				case "OptionalKeyword":
					isOptional = true
				}
			case "NodeIdentifier":
				fallthrough
			case "RootConstraint":
				it := buildIteratorTree(c, qs)
				l := iterator.NewLinksTo(qs, it, subItDir)
				subAnd.AddSubIterator(l)
				continue
			default:
				continue
			}
		}
		hasa = iterator.NewHasA(qs, subAnd, topLevelDir)
		if isOptional {
			optional := iterator.NewOptional(hasa)
			return optional
		}
		return hasa
	default:
		return &iterator.Null{}
	}
}
開發者ID:RamboWANG,項目名稱:cayley,代碼行數:89,代碼來源:parser.go


注:本文中的github.com/cayleygraph/cayley/graph.QuadStore類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。