本文整理汇总了Golang中github.com/cayleygraph/cayley/quad.Raw函数的典型用法代码示例。如果您正苦于以下问题:Golang Raw函数的具体用法?Golang Raw怎么用?Golang Raw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Raw函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ToNative
// ToNative converts protobuf Quad to quad.Quad.
func (m *Quad) ToNative() (q quad.Quad) {
if m == nil {
return
}
if m.SubjectValue != nil {
q.Subject = m.SubjectValue.ToNative()
} else if m.Subject != "" {
q.Subject = quad.Raw(m.Subject)
}
if m.PredicateValue != nil {
q.Predicate = m.PredicateValue.ToNative()
} else if m.Predicate != "" {
q.Predicate = quad.Raw(m.Predicate)
}
if m.ObjectValue != nil {
q.Object = m.ObjectValue.ToNative()
} else if m.Object != "" {
q.Object = quad.Raw(m.Object)
}
if m.LabelValue != nil {
q.Label = m.LabelValue.ToNative()
} else if m.Label != "" {
q.Label = quad.Raw(m.Label)
}
return
}
示例2: TestRemoveQuad
func TestRemoveQuad(t *testing.T) {
qs, w, _ := makeTestStore(simpleGraph)
err := w.RemoveQuad(quad.MakeRaw(
"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 newIt.Next() {
t.Error("E should not have any followers.")
}
}
示例3: TestMultipleConstraintParse
func TestMultipleConstraintParse(t *testing.T) {
qs, _ := graph.NewQuadStore("memstore", "", nil)
w, _ := graph.NewQuadWriter("single", qs, nil)
for _, tv := range []quad.Quad{
quad.MakeRaw("i", "like", "food", ""),
quad.MakeRaw("i", "like", "beer", ""),
quad.MakeRaw("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 !it.Next() {
t.Error("Got no results")
}
out := it.Result()
if out != qs.ValueOf(quad.Raw("i")) {
t.Errorf("Got %d, expected %d", out, qs.ValueOf(quad.Raw("i")))
}
if it.Next() {
t.Error("Too many results")
}
}
示例4: 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, quad.Raw("Humphrey Bogart"))
for it.Next() {
fmt.Println(it.Result())
}
it = NewSQLLinkIterator(qs, quad.Subject, quad.Raw("/en/casablanca_1942"))
s, v := it.sql.buildSQL(true, nil)
t.Log(s, v)
c := 0
for it.Next() {
fmt.Println(it.Result())
c += 1
}
if c != 18 {
t.Errorf("Not enough results, got %d expected 18", c)
}
}
示例5: TestIterators
func TestIterators(t *testing.T) {
qs, opts, closer := makeGAE(t)
defer closer()
graphtest.MakeWriter(t, qs, opts, graphtest.MakeQuadSet()...)
require.Equal(t, int64(11), qs.Size(), "Incorrect number of quads")
var expected = []quad.Quad{
quad.MakeRaw("C", "follows", "B", ""),
quad.MakeRaw("C", "follows", "D", ""),
}
it := qs.QuadIterator(quad.Subject, qs.ValueOf(quad.Raw("C")))
graphtest.ExpectIteratedQuads(t, qs, it, expected)
// Test contains
it = qs.QuadIterator(quad.Label, qs.ValueOf(quad.Raw("status_graph")))
gqs := qs.(*QuadStore)
key := gqs.createKeyForQuad(quad.MakeRaw("G", "status", "cool", "status_graph"))
token := &Token{quadKind, key.StringID()}
require.True(t, it.Contains(token), "Contains failed")
// Test cloning an iterator
var it2 graph.Iterator
it2 = it.Clone()
x := it2.Describe()
y := it.Describe()
require.Equal(t, y.Name, x.Name, "Iterator Clone was not successful")
}
示例6: TestInterestingQuery
func TestInterestingQuery(t *testing.T) {
if *postgres_path == "" {
t.SkipNow()
}
db, err := newQuadStore(*postgres_path, nil)
if err != nil {
t.Fatal(err)
}
qs := db.(*QuadStore)
a := NewSQLLinkIterator(qs, quad.Object, quad.Raw("Humphrey Bogart"))
b := NewSQLLinkIterator(qs, quad.Predicate, quad.Raw("name"))
it1, err := intersect(a.sql, b.sql, qs)
if err != nil {
t.Error(err)
}
it2, err := hasa(it1.sql, quad.Subject, qs)
if err != nil {
t.Error(err)
}
it2.Tagger().Add("hb")
it3, err := linksto(it2.sql, quad.Object, qs)
if err != nil {
t.Error(err)
}
b = NewSQLLinkIterator(db.(*QuadStore), quad.Predicate, quad.Raw("/film/performance/actor"))
it4, err := intersect(it3.sql, b.sql, qs)
if err != nil {
t.Error(err)
}
it5, err := hasa(it4.sql, quad.Subject, qs)
if err != nil {
t.Error(err)
}
it6, err := linksto(it5.sql, quad.Object, qs)
if err != nil {
t.Error(err)
}
b = NewSQLLinkIterator(db.(*QuadStore), quad.Predicate, quad.Raw("/film/film/starring"))
it7, err := intersect(it6.sql, b.sql, qs)
if err != nil {
t.Error(err)
}
it8, err := hasa(it7.sql, quad.Subject, qs)
if err != nil {
t.Error(err)
}
s, v := it8.sql.buildSQL(true, nil)
it8.Tagger().Add("id")
t.Log(s, v)
for it8.Next() {
t.Log(it8.Result())
out := make(map[string]graph.Value)
it8.TagResults(out)
for k, v := range out {
t.Log("%s: %v\n", k, v)
}
}
}
示例7: TestBuildIntersect
func TestBuildIntersect(t *testing.T) {
a := NewSQLLinkIterator(nil, quad.Subject, quad.Raw("Foo"))
b := NewSQLLinkIterator(nil, quad.Predicate, quad.Raw("is_equivalent_to"))
it, err := intersect(a.sql, b.sql, nil)
if err != nil {
t.Error(err)
}
s, v := it.sql.buildSQL(true, nil)
t.Log(s, v)
}
示例8: 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)
}
示例9: TestBuildHasa
func TestBuildHasa(t *testing.T) {
a := NewSQLLinkIterator(nil, quad.Subject, quad.Raw("Foo"))
a.Tagger().Add("foo")
b := NewSQLLinkIterator(nil, quad.Predicate, quad.Raw("is_equivalent_to"))
it1, err := intersect(a.sql, b.sql, nil)
if err != nil {
t.Error(err)
}
it2, err := hasa(it1.sql, quad.Object, nil)
if err != nil {
t.Error(err)
}
s, v := it2.sql.buildSQL(true, nil)
t.Log(s, v)
}
示例10: TestIteratorsAndNextResultOrderA
func TestIteratorsAndNextResultOrderA(t *testing.T) {
qs, _, _ := makeTestStore(simpleGraph)
fixed := qs.FixedIterator()
fixed.Add(qs.ValueOf(quad.Raw("C")))
fixed2 := qs.FixedIterator()
fixed2.Add(qs.ValueOf(quad.Raw("follows")))
all := qs.NodesAllIterator()
innerAnd := iterator.NewAnd(qs)
innerAnd.AddSubIterator(iterator.NewLinksTo(qs, fixed2, quad.Predicate))
innerAnd.AddSubIterator(iterator.NewLinksTo(qs, all, quad.Object))
hasa := iterator.NewHasA(qs, innerAnd, quad.Subject)
outerAnd := iterator.NewAnd(qs)
outerAnd.AddSubIterator(fixed)
outerAnd.AddSubIterator(hasa)
if !outerAnd.Next() {
t.Error("Expected one matching subtree")
}
val := outerAnd.Result()
if qs.NameOf(val) != quad.Raw("C") {
t.Errorf("Matching subtree should be %s, got %s", "barak", qs.NameOf(val))
}
var (
got []string
expect = []string{"B", "D"}
)
for {
got = append(got, qs.NameOf(all.Result()).String())
if !outerAnd.NextPath() {
break
}
}
sort.Strings(got)
if !reflect.DeepEqual(got, expect) {
t.Errorf("Unexpected result, got:%q expect:%q", got, expect)
}
if outerAnd.Next() {
t.Error("More than one possible top level output?")
}
}
示例11: TestLinksToOptimization
func TestLinksToOptimization(t *testing.T) {
qs, _, _ := makeTestStore(simpleGraph)
fixed := qs.FixedIterator()
fixed.Add(qs.ValueOf(quad.Raw("cool")))
lto := iterator.NewLinksTo(qs, fixed, quad.Object)
lto.Tagger().Add("foo")
newIt, changed := lto.Optimize()
if !changed {
t.Error("Iterator didn't change")
}
if newIt.Type() != Type() {
t.Fatal("Didn't swap out to LLRB")
}
v := newIt.(*Iterator)
vClone := v.Clone()
origDesc := v.Describe()
cloneDesc := vClone.Describe()
origDesc.UID, cloneDesc.UID = 0, 0 // We are more strict now, so fake UID equality.
if !reflect.DeepEqual(cloneDesc, origDesc) {
t.Fatalf("Unexpected iterator description.\ngot: %#v\nexpect: %#v", cloneDesc, origDesc)
}
vt := vClone.Tagger()
if len(vt.Tags()) < 1 || vt.Tags()[0] != "foo" {
t.Fatal("Tag on LinksTo did not persist")
}
}
示例12: 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, quad.Raw("/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 it.Next() {
t.Log(it.Result())
c += 1
}
if c != 56 {
t.Errorf("Not enough results, got %d expected 56", c)
}
}
示例13: TestIteratorsAndNextResultOrderA
func TestIteratorsAndNextResultOrderA(t testing.TB, gen DatabaseFunc) {
qs, opts, closer := gen(t)
defer closer()
MakeWriter(t, qs, opts, MakeQuadSet()...)
require.Equal(t, int64(11), qs.Size(), "Incorrect number of quads")
fixed := qs.FixedIterator()
fixed.Add(qs.ValueOf(quad.Raw("C")))
fixed2 := qs.FixedIterator()
fixed2.Add(qs.ValueOf(quad.Raw("follows")))
all := qs.NodesAllIterator()
innerAnd := iterator.NewAnd(qs)
innerAnd.AddSubIterator(iterator.NewLinksTo(qs, fixed2, quad.Predicate))
innerAnd.AddSubIterator(iterator.NewLinksTo(qs, all, quad.Object))
hasa := iterator.NewHasA(qs, innerAnd, quad.Subject)
outerAnd := iterator.NewAnd(qs)
outerAnd.AddSubIterator(fixed)
outerAnd.AddSubIterator(hasa)
require.True(t, outerAnd.Next(), "Expected one matching subtree")
val := outerAnd.Result()
require.Equal(t, quad.Raw("C"), qs.NameOf(val))
var (
got []string
expect = []string{"B", "D"}
)
for {
got = append(got, qs.NameOf(all.Result()).String())
if !outerAnd.NextPath() {
break
}
}
sort.Strings(got)
require.Equal(t, expect, got)
require.True(t, !outerAnd.Next(), "More than one possible top level output?")
}
示例14: Upgrade
func (m *Quad) Upgrade() {
if m.SubjectValue == nil {
m.SubjectValue = MakeValue(quad.Raw(m.Subject))
m.Subject = ""
}
if m.PredicateValue == nil {
m.PredicateValue = MakeValue(quad.Raw(m.Predicate))
m.Predicate = ""
}
if m.ObjectValue == nil {
m.ObjectValue = MakeValue(quad.Raw(m.Object))
m.Object = ""
}
if m.LabelValue == nil && m.Label != "" {
m.LabelValue = MakeValue(quad.Raw(m.Label))
m.Label = ""
}
}
示例15: valueAt
func (qs *store) valueAt(i int) quad.Value {
if !qs.parse {
return quad.Raw(qs.data[i])
}
iv, err := strconv.Atoi(qs.data[i])
if err == nil {
return quad.Int(iv)
}
return quad.String(qs.data[i])
}