• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang graph.Triple类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/google/cayley/graph.Triple的典型用法代码示例。如果您正苦于以下问题:Golang Triple类的具体用法?Golang Triple怎么用?Golang Triple使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Triple类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: RemoveTriple

func (ts *TripleStore) RemoveTriple(t *graph.Triple) {
	_, err := ts.db.Get(ts.createKeyFor(spo, t), ts.readopts)
	if err != nil && err != leveldb.ErrNotFound {
		glog.Errorf("Couldn't access DB to confirm deletion")
		return
	}
	if err == leveldb.ErrNotFound {
		// No such triple in the database, forget about it.
		return
	}
	batch := &leveldb.Batch{}
	batch.Delete(ts.createKeyFor(spo, t))
	batch.Delete(ts.createKeyFor(osp, t))
	batch.Delete(ts.createKeyFor(pos, t))
	ts.UpdateValueKeyBy(t.Get(graph.Subject), -1, batch)
	ts.UpdateValueKeyBy(t.Get(graph.Predicate), -1, batch)
	ts.UpdateValueKeyBy(t.Get(graph.Object), -1, batch)
	if t.Get(graph.Provenance) != "" {
		batch.Delete(ts.createProvKeyFor(pso, t))
		ts.UpdateValueKeyBy(t.Get(graph.Provenance), -1, batch)
	}
	err = ts.db.Write(batch, nil)
	if err != nil {
		glog.Errorf("Couldn't delete triple %s", t)
		return
	}
	ts.size--
}
开发者ID:ZSIT,项目名称:cayley,代码行数:28,代码来源:triplestore.go


示例2: RemoveTriple

func (ts *TripleStore) RemoveTriple(t *graph.Triple) {
	_, err := ts.db.Get(ts.createKeyFor("s", "p", "o", t), ts.readopts)
	if err != nil && err != leveldb.ErrNotFound {
		glog.Errorf("Couldn't access DB to confirm deletion")
		return
	}
	if err == leveldb.ErrNotFound {
		// No such triple in the database, forget about it.
		return
	}
	batch := &leveldb.Batch{}
	batch.Delete(ts.createKeyFor("s", "p", "o", t))
	batch.Delete(ts.createKeyFor("o", "s", "p", t))
	batch.Delete(ts.createKeyFor("p", "o", "s", t))
	ts.UpdateValueKeyBy(t.Get("s"), -1, batch)
	ts.UpdateValueKeyBy(t.Get("p"), -1, batch)
	ts.UpdateValueKeyBy(t.Get("o"), -1, batch)
	if t.Get("c") != "" {
		batch.Delete(ts.createProvKeyFor("p", "s", "o", t))
		ts.UpdateValueKeyBy(t.Get("c"), -1, batch)
	}
	err = ts.db.Write(batch, nil)
	if err != nil {
		glog.Errorf("Couldn't delete triple %s", t.ToString())
		return
	}
	ts.size--
}
开发者ID:nerodong,项目名称:cayley,代码行数:28,代码来源:triplestore.go


示例3: createKeyFor

func (ts *TripleStore) createKeyFor(dir1, dir2, dir3 string, triple *graph.Triple) []byte {
	key := make([]byte, 0, 2+(ts.hasher.Size()*3))
	key = append(key, []byte(dir1+dir2)...)
	key = append(key, ts.convertStringToByteHash(triple.Get(dir1))...)
	key = append(key, ts.convertStringToByteHash(triple.Get(dir2))...)
	key = append(key, ts.convertStringToByteHash(triple.Get(dir3))...)
	return key
}
开发者ID:nerodong,项目名称:cayley,代码行数:8,代码来源:triplestore.go


示例4: buildWrite

func (ts *TripleStore) buildWrite(batch *leveldb.Batch, t *graph.Triple) {
	ts.buildTripleWrite(batch, t)
	ts.UpdateValueKeyBy(t.Get(graph.Subject), 1, nil)
	ts.UpdateValueKeyBy(t.Get(graph.Predicate), 1, nil)
	ts.UpdateValueKeyBy(t.Get(graph.Object), 1, nil)
	if t.Get(graph.Provenance) != "" {
		ts.UpdateValueKeyBy(t.Get(graph.Provenance), 1, nil)
	}
}
开发者ID:ZSIT,项目名称:cayley,代码行数:9,代码来源:triplestore.go


示例5: createKeyFor

func (ts *TripleStore) createKeyFor(d [3]graph.Direction, triple *graph.Triple) []byte {
	key := make([]byte, 0, 2+(ts.hasher.Size()*3))
	// TODO(kortschak) Remove dependence on String() method.
	key = append(key, []byte{d[0].Prefix(), d[1].Prefix()}...)
	key = append(key, ts.convertStringToByteHash(triple.Get(d[0]))...)
	key = append(key, ts.convertStringToByteHash(triple.Get(d[1]))...)
	key = append(key, ts.convertStringToByteHash(triple.Get(d[2]))...)
	return key
}
开发者ID:ZSIT,项目名称:cayley,代码行数:9,代码来源:triplestore.go


示例6: AddTriple

func (ts *TripleStore) AddTriple(t *graph.Triple) {
	batch := &leveldb.Batch{}
	ts.buildWrite(batch, t)
	err := ts.db.Write(batch, ts.writeopts)
	if err != nil {
		glog.Errorf("Couldn't write to DB for triple %s", t.ToString())
		return
	}
	ts.size++
}
开发者ID:nerodong,项目名称:cayley,代码行数:10,代码来源:triplestore.go


示例7: buildTripleWrite

func (ts *TripleStore) buildTripleWrite(batch *leveldb.Batch, t *graph.Triple) {
	bytes, err := json.Marshal(*t)
	if err != nil {
		glog.Errorf("Couldn't write to buffer for triple %s\n  %s\n", t, err)
		return
	}
	batch.Put(ts.createKeyFor(spo, t), bytes)
	batch.Put(ts.createKeyFor(osp, t), bytes)
	batch.Put(ts.createKeyFor(pos, t), bytes)
	if t.Get(graph.Provenance) != "" {
		batch.Put(ts.createProvKeyFor(pso, t), bytes)
	}
}
开发者ID:ZSIT,项目名称:cayley,代码行数:13,代码来源:triplestore.go


示例8: buildTripleWrite

func (ts *TripleStore) buildTripleWrite(batch *leveldb.Batch, t *graph.Triple) {
	bytes, err := json.Marshal(*t)
	if err != nil {
		glog.Errorf("Couldn't write to buffer for triple %s\n  %s\n", t.ToString(), err)
		return
	}
	batch.Put(ts.createKeyFor("s", "p", "o", t), bytes)
	batch.Put(ts.createKeyFor("o", "s", "p", t), bytes)
	batch.Put(ts.createKeyFor("p", "o", "s", t), bytes)
	if t.Get("c") != "" {
		batch.Put(ts.createProvKeyFor("p", "s", "o", t), bytes)
	}
}
开发者ID:nerodong,项目名称:cayley,代码行数:13,代码来源:triplestore.go


示例9: buildWrite

func (ts *TripleStore) buildWrite(batch *leveldb.Batch, t *graph.Triple) {
	ts.buildTripleWrite(batch, t)
	ts.UpdateValueKeyBy(t.Get("s"), 1, nil)
	ts.UpdateValueKeyBy(t.Get("p"), 1, nil)
	ts.UpdateValueKeyBy(t.Get("o"), 1, nil)
	if t.Get("c") != "" {
		ts.UpdateValueKeyBy(t.Get("c"), 1, nil)
	}
}
开发者ID:nerodong,项目名称:cayley,代码行数:9,代码来源:triplestore.go


示例10: AddTriple

func (ts *TripleStore) AddTriple(t *graph.Triple) {
	if exists, _ := ts.tripleExists(t); exists {
		return
	}
	var tripleID int64
	ts.triples = append(ts.triples, *t)
	tripleID = ts.tripleIdCounter
	ts.size++
	ts.tripleIdCounter++

	for d := graph.Subject; d <= graph.Provenance; d++ {
		sid := t.Get(d)
		if d == graph.Provenance && sid == "" {
			continue
		}
		if _, ok := ts.idMap[sid]; !ok {
			ts.idMap[sid] = ts.idCounter
			ts.revIdMap[ts.idCounter] = sid
			ts.idCounter++
		}
	}

	for d := graph.Subject; d <= graph.Provenance; d++ {
		if d == graph.Provenance && t.Get(d) == "" {
			continue
		}
		id := ts.idMap[t.Get(d)]
		tree := ts.index.GetOrCreate(d, id)
		tree.ReplaceOrInsert(Int64(tripleID))
	}

	// TODO(barakmich): Add VIP indexing
}
开发者ID:ZSIT,项目名称:cayley,代码行数:33,代码来源:triplestore.go


示例11: AddTriple

func (ts *MemTripleStore) AddTriple(t *graph.Triple) {
	if exists, _ := ts.tripleExists(t); exists {
		return
	}
	var tripleID int64
	ts.triples = append(ts.triples, *t)
	tripleID = ts.tripleIdCounter
	ts.size++
	ts.tripleIdCounter++

	for _, dir := range graph.TripleDirections {
		sid := t.Get(dir)
		if dir == "c" && sid == "" {
			continue
		}
		if _, ok := ts.idMap[sid]; !ok {
			ts.idMap[sid] = ts.idCounter
			ts.revIdMap[ts.idCounter] = sid
			ts.idCounter++
		}
	}

	for _, dir := range graph.TripleDirections {
		if dir == "c" && t.Get(dir) == "" {
			continue
		}
		id := ts.idMap[t.Get(dir)]
		tree := ts.index.GetOrCreate(dir, id)
		tree.ReplaceOrInsert(Int64(tripleID))
	}

	// TODO(barakmich): Add VIP indexing
}
开发者ID:java10000,项目名称:cayley,代码行数:33,代码来源:memtriplestore.go


示例12: tripleExists

func (ts *TripleStore) tripleExists(t *graph.Triple) (bool, int64) {
	smallest := -1
	var smallest_tree *llrb.LLRB
	for d := graph.Subject; d <= graph.Provenance; d++ {
		sid := t.Get(d)
		if d == graph.Provenance && sid == "" {
			continue
		}
		id, ok := ts.idMap[sid]
		// If we've never heard about a node, it most not exist
		if !ok {
			return false, 0
		}
		index, exists := ts.index.Get(d, id)
		if !exists {
			// If it's never been indexed in this direction, it can't exist.
			return false, 0
		}
		if smallest == -1 || index.Len() < smallest {
			smallest = index.Len()
			smallest_tree = index
		}
	}
	it := NewLlrbIterator(smallest_tree, "")

	for {
		val, ok := it.Next()
		if !ok {
			break
		}
		if t.Equals(&ts.triples[val.(int64)]) {
			return true, val.(int64)
		}
	}
	return false, 0
}
开发者ID:ZSIT,项目名称:cayley,代码行数:36,代码来源:triplestore.go


示例13: RemoveTriple

func (ts *MemTripleStore) RemoveTriple(t *graph.Triple) {
	var tripleID int64
	var exists bool
	tripleID = 0
	if exists, tripleID = ts.tripleExists(t); !exists {
		return
	}

	ts.triples[tripleID] = graph.Triple{}
	ts.size--

	for _, dir := range graph.TripleDirections {
		if dir == "c" && t.Get(dir) == "" {
			continue
		}
		id := ts.idMap[t.Get(dir)]
		tree := ts.index.GetOrCreate(dir, id)
		tree.Delete(Int64(tripleID))
	}

	for _, dir := range graph.TripleDirections {
		if dir == "c" && t.Get(dir) == "" {
			continue
		}
		id, ok := ts.idMap[t.Get(dir)]
		if !ok {
			continue
		}
		stillExists := false
		for _, dir := range graph.TripleDirections {
			if dir == "c" && t.Get(dir) == "" {
				continue
			}
			nodeTree := ts.index.GetOrCreate(dir, id)
			if nodeTree.Len() != 0 {
				stillExists = true
				break
			}
		}
		if !stillExists {
			delete(ts.idMap, t.Get(dir))
			delete(ts.revIdMap, id)
		}
	}
}
开发者ID:java10000,项目名称:cayley,代码行数:45,代码来源:memtriplestore.go



注:本文中的github.com/google/cayley/graph.Triple类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang graph.TripleStore类代码示例发布时间:2022-05-23
下一篇:
Golang graph.QuadWriter类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap