本文整理汇总了Golang中github.com/cayleygraph/cayley/quad.Quad类的典型用法代码示例。如果您正苦于以下问题:Golang Quad类的具体用法?Golang Quad怎么用?Golang Quad使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Quad类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ParseJSONToQuadList
func ParseJSONToQuadList(jsonBody []byte) (out []quad.Quad, _ error) {
var quads []struct {
Subject string `json:"subject"`
Predicate string `json:"predicate"`
Object string `json:"object"`
Label string `json:"label"`
}
err := json.Unmarshal(jsonBody, &quads)
if err != nil {
return nil, err
}
out = make([]quad.Quad, 0, len(quads))
for i, jq := range quads {
q := quad.Quad{
Subject: quad.StringToValue(jq.Subject),
Predicate: quad.StringToValue(jq.Predicate),
Object: quad.StringToValue(jq.Object),
Label: quad.StringToValue(jq.Label),
}
if !q.IsValid() {
return nil, fmt.Errorf("invalid quad at index %d. %s", i, q)
}
out = append(out, q)
}
return out, nil
}
开发者ID:rlugojr,项目名称:cayley,代码行数:26,代码来源:write.go
示例2: indexOf
func (qs *QuadStore) indexOf(t quad.Quad) (int64, bool) {
min := maxInt
var tree *b.Tree
for d := quad.Subject; d <= quad.Label; d++ {
sid := t.Get(d)
if d == quad.Label && sid == "" {
continue
}
id, ok := qs.idMap[sid]
// If we've never heard about a node, it must not exist
if !ok {
return 0, false
}
index, ok := qs.index.Get(d, id)
if !ok {
// If it's never been indexed in this direction, it can't exist.
return 0, false
}
if l := index.Len(); l < min {
min, tree = l, index
}
}
it := NewIterator(tree, qs, 0, 0)
for it.Next() {
val := it.Result()
if t == qs.log[val.(int64)].Quad {
return val.(int64), true
}
}
return 0, false
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:32,代码来源:quadstore.go
示例3: createKeyFor
func (qs *QuadStore) createKeyFor(d [4]quad.Direction, q quad.Quad) []byte {
key := make([]byte, 0, (hashSize * 4))
key = append(key, hashOf(q.Get(d[0]))...)
key = append(key, hashOf(q.Get(d[1]))...)
key = append(key, hashOf(q.Get(d[2]))...)
key = append(key, hashOf(q.Get(d[3]))...)
return key
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:8,代码来源:quadstore.go
示例4: createKeyFor
func (qs *QuadStore) createKeyFor(d [4]quad.Direction, q quad.Quad) []byte {
key := make([]byte, quad.HashSize*4)
quad.HashTo(q.Get(d[0]), key[quad.HashSize*0:quad.HashSize*1])
quad.HashTo(q.Get(d[1]), key[quad.HashSize*1:quad.HashSize*2])
quad.HashTo(q.Get(d[2]), key[quad.HashSize*2:quad.HashSize*3])
quad.HashTo(q.Get(d[3]), key[quad.HashSize*3:quad.HashSize*4])
return key
}
开发者ID:rlugojr,项目名称:cayley,代码行数:8,代码来源:quadstore.go
示例5: buildResult
func (l *SQLLinkIterator) buildResult(result []string, cols []string) map[string]string {
var q quad.Quad
q.Subject = result[0]
q.Predicate = result[1]
q.Object = result[2]
q.Label = result[3]
l.resultQuad = q
m := make(map[string]string)
for i, c := range cols[4:] {
m[c] = result[i+4]
}
return m
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:13,代码来源:sql_link_iterator.go
示例6: buildQuadWrite
func (qs *QuadStore) buildQuadWrite(tx *bolt.Tx, q quad.Quad, id int64, isAdd bool) error {
var entry proto.HistoryEntry
b := tx.Bucket(spoBucket)
b.FillPercent = localFillPercent
data := b.Get(qs.createKeyFor(spo, q))
if data != nil {
// We got something.
err := entry.Unmarshal(data)
if err != nil {
return err
}
}
if isAdd && len(entry.History)%2 == 1 {
clog.Errorf("attempt to add existing quad %v: %#v", entry, q)
return graph.ErrQuadExists
}
if !isAdd && len(entry.History)%2 == 0 {
clog.Errorf("attempt to delete non-existent quad %v: %#v", entry, q)
return graph.ErrQuadNotExist
}
entry.History = append(entry.History, uint64(id))
bytes, err := entry.Marshal()
if err != nil {
clog.Errorf("Couldn't write to buffer for entry %#v: %s", entry, err)
return err
}
for _, index := range [][4]quad.Direction{spo, osp, pos, cps} {
if index == cps && q.Get(quad.Label) == "" {
continue
}
b := tx.Bucket(bucketFor(index))
b.FillPercent = localFillPercent
err = b.Put(qs.createKeyFor(index, q), bytes)
if err != nil {
return err
}
}
return nil
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:42,代码来源:quadstore.go
注:本文中的github.com/cayleygraph/cayley/quad.Quad类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论