本文整理汇总了Golang中github.com/google/cayley/quad.Raw函数的典型用法代码示例。如果您正苦于以下问题:Golang Raw函数的具体用法?Golang Raw怎么用?Golang Raw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Raw函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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 graph.Next(it) {
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 graph.Next(it) {
fmt.Println(it.Result())
c += 1
}
if c != 18 {
t.Errorf("Not enough results, got %d expected 18", c)
}
}
开发者ID:dennwc,项目名称:cayley,代码行数:25,代码来源:sql_link_iterator_test.go
示例2: 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
示例3: 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.Make("C", "follows", "B", ""),
quad.Make("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.Make("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")
}
开发者ID:dennwc,项目名称:cayley,代码行数:32,代码来源:quadstore_test.go
示例4: TestMultipleConstraintParse
func TestMultipleConstraintParse(t *testing.T) {
qs, _ := graph.NewQuadStore("memstore", "", nil)
w, _ := graph.NewQuadWriter("single", qs, nil)
for _, tv := range []quad.Quad{
quad.Make("i", "like", "food", ""),
quad.Make("i", "like", "beer", ""),
quad.Make("you", "like", "beer", ""),
} {
w.WriteQuad(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(quad.Raw("i")) {
t.Errorf("Got %d, expected %d", out, qs.ValueOf(quad.Raw("i")))
}
if graph.Next(it) {
t.Error("Too many results")
}
}
开发者ID:dennwc,项目名称:cayley,代码行数:30,代码来源:parser_test.go
示例5: 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
}
开发者ID:dennwc,项目名称:cayley,代码行数:27,代码来源:quad.go
示例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 graph.Next(it8) {
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)
}
}
}
开发者ID:dennwc,项目名称:cayley,代码行数:58,代码来源:optimizers_test.go
示例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)
}
开发者ID:dennwc,项目名称:cayley,代码行数:10,代码来源:optimizers_test.go
示例8: unEscape
func unEscape(r []rune, isEscaped bool) quad.Value {
if !isEscaped {
return quad.Raw(string(r))
}
buf := bytes.NewBuffer(make([]byte, 0, len(r)))
for i := 0; i < len(r); {
switch r[i] {
case '\\':
i++
var c byte
switch r[i] {
case 't':
c = '\t'
case 'b':
c = '\b'
case 'n':
c = '\n'
case 'r':
c = '\r'
case 'f':
c = '\f'
case '"':
c = '"'
case '\'':
c = '\''
case '\\':
c = '\\'
case 'u':
rc, err := strconv.ParseInt(string(r[i+1:i+5]), 16, 32)
if err != nil {
panic(fmt.Errorf("internal parser error: %v", err))
}
buf.WriteRune(rune(rc))
i += 5
continue
case 'U':
rc, err := strconv.ParseInt(string(r[i+1:i+9]), 16, 32)
if err != nil {
panic(fmt.Errorf("internal parser error: %v", err))
}
buf.WriteRune(rune(rc))
i += 9
continue
}
buf.WriteByte(c)
default:
buf.WriteRune(r[i])
}
i++
}
return quad.Raw(buf.String())
}
开发者ID:dennwc,项目名称:cayley,代码行数:55,代码来源:nquads.go
示例9: 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:dennwc,项目名称:cayley,代码行数:14,代码来源:query_shape_test.go
示例10: 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)
}
开发者ID:dennwc,项目名称:cayley,代码行数:15,代码来源:optimizers_test.go
示例11: 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", "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)
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?")
}
}
开发者ID:dennwc,项目名称:cayley,代码行数:48,代码来源:quadstore_test.go
示例12: ReadQuad
func (r *Reader) ReadQuad() (quad.Quad, error) {
if r.err != nil {
return quad.Quad{}, r.err
}
next:
if len(r.graphs) == 0 {
return quad.Quad{}, io.EOF
}
if r.name == "" {
for gname, _ := range r.graphs {
r.name = gname
break
}
}
if r.n >= len(r.graphs[r.name]) {
r.n = 0
delete(r.graphs, r.name)
r.name = ""
goto next
}
cur := r.graphs[r.name][r.n]
r.n++
var graph quad.Value
if r.name != "" && r.name != "@default" {
graph = quad.Raw(r.name)
}
return quad.Quad{
Subject: toQuadValue(cur.Subject),
Predicate: toQuadValue(cur.Predicate),
Object: toQuadValue(cur.Object),
Label: graph,
}, nil
}
开发者ID:dennwc,项目名称:cayley,代码行数:33,代码来源:jsonld.go
示例13: toQuadValue
func toQuadValue(o interface{}) (quad.Value, bool) {
var qv quad.Value
switch v := o.(type) {
case quadValue:
qv = v.v
case quad.Value:
qv = v
case string:
qv = quad.Raw(v)
case bool:
qv = quad.Bool(v)
case int:
qv = quad.Int(v)
case int64:
qv = quad.Int(v)
case float64:
if float64(int(v)) == v {
qv = quad.Int(int64(v))
} else {
qv = quad.Float(v)
}
case time.Time:
qv = quad.Time(v)
default:
return nil, false
}
return qv, true
}
开发者ID:dennwc,项目名称:cayley,代码行数:28,代码来源:environ.go
示例14: 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")
}
}
开发者ID:dennwc,项目名称:cayley,代码行数:30,代码来源:quadstore_test.go
示例15: 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 graph.Next(it) {
t.Log(it.Result())
c += 1
}
if c != 56 {
t.Errorf("Not enough results, got %d expected 56", c)
}
}
开发者ID:dennwc,项目名称:cayley,代码行数:32,代码来源:sql_link_iterator_test.go
示例16: 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?")
}
开发者ID:dennwc,项目名称:cayley,代码行数:46,代码来源:graphtest.go
示例17: 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 = ""
}
}
开发者ID:dennwc,项目名称:cayley,代码行数:18,代码来源:quad.go
示例18: 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])
}
开发者ID:dennwc,项目名称:cayley,代码行数:10,代码来源:mock_ts_test.go
示例19: GetNativeValue
// GetNativeValue returns the value stored in Node.
func (m *NodeData) GetNativeValue() quad.Value {
if m == nil {
return nil
} else if m.Value == nil {
if m.Name == "" {
return nil
}
return quad.Raw(m.Name)
}
return m.Value.ToNative()
}
开发者ID:dennwc,项目名称:cayley,代码行数:12,代码来源:quad.go
示例20: TestTreeConstraintParse
func TestTreeConstraintParse(t *testing.T) {
qs, _ := graph.NewQuadStore("memstore", "", nil)
w, _ := graph.NewQuadWriter("single", qs, nil)
w.WriteQuad(quad.Make("i", "like", "food", ""))
w.WriteQuad(quad.Make("food", "is", "good", ""))
query := "(\"i\"\n" +
"(:like\n" +
"($a (:is :good))))"
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(quad.Raw("i")) {
t.Errorf("Got %d, expected %d", out, qs.ValueOf(quad.Raw("i")))
}
}
开发者ID:dennwc,项目名称:cayley,代码行数:20,代码来源:parser_test.go
注:本文中的github.com/google/cayley/quad.Raw函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论