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...)
}
示例#2
0
// DecorateWith decorates the given graph node with a predicate with the given Go value.
func (gn ModifiableGraphNode) DecorateWith(predicate Predicate, value interface{}) {
	quadValue, ok := quad.AsValue(value)
	if !ok {
		panic("Unsupported golang type")
	}

	gn.DecorateWithValue(predicate, GraphValue{quadValue})
}
示例#3
0
文件: quad.go 项目: Serulian/compiler
// toQuadValues converts a slice of arbitrary values into their Cayley values.
func toQuadValues(values []interface{}, gl *GraphLayer) []quad.Value {
	quadValues := make([]quad.Value, len(values))
	for index, v := range values {
		switch v := v.(type) {
		case GraphNodeId:
			quadValues[index] = nodeIdToValue(v)

		case TaggedValue:
			quadValues[index] = gl.getTaggedKey(v)

		default:
			vle, ok := quad.AsValue(v)
			if !ok {
				panic(fmt.Sprintf("Unknown value %v", v))
			}

			quadValues[index] = vle
		}

	}

	return quadValues
}