本文整理汇总了Golang中github.com/google/badwolf/triple.Triple.O方法的典型用法代码示例。如果您正苦于以下问题:Golang Triple.O方法的具体用法?Golang Triple.O怎么用?Golang Triple.O使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/google/badwolf/triple.Triple
的用法示例。
在下文中一共展示了Triple.O方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: tripleToRow
// tripleToRow converts a triple into a row using the binndings specidfied
// on the graph clause.
func tripleToRow(t *triple.Triple, cls *semantic.GraphClause) (table.Row, error) {
r, s, p, o := make(table.Row), t.S(), t.P(), t.O()
// Subject related bindings.
if cls.SBinding != "" {
r[cls.SBinding] = &table.Cell{N: s}
}
if cls.SAlias != "" {
r[cls.SAlias] = &table.Cell{N: s}
}
if cls.STypeAlias != "" {
r[cls.STypeAlias] = &table.Cell{S: s.Type().String()}
}
if cls.SIDAlias != "" {
r[cls.SIDAlias] = &table.Cell{S: s.ID().String()}
}
// Predicate related bindings.
if cls.PBinding != "" {
r[cls.PBinding] = &table.Cell{P: p}
}
if cls.PAlias != "" {
r[cls.PAlias] = &table.Cell{P: p}
}
if cls.PIDAlias != "" {
r[cls.PIDAlias] = &table.Cell{S: string(p.ID())}
}
if cls.PAnchorBinding != "" {
if p.Type() != predicate.Temporal {
return nil, fmt.Errorf("cannot retrieve the time anchor value for non temporal predicate %q in binding %q", p, cls.PAnchorBinding)
}
t, err := p.TimeAnchor()
if err != nil {
return nil, fmt.Errorf("failed to retrieve the time anchor value for predicate %q in binding %q with error %v", p, cls.PAnchorBinding, err)
}
r[cls.PAnchorBinding] = &table.Cell{T: t}
}
if cls.PAnchorAlias != "" {
if p.Type() != predicate.Temporal {
return nil, fmt.Errorf("cannot retrieve the time anchor value for non temporal predicate %q in binding %q", p, cls.PAnchorAlias)
}
t, err := p.TimeAnchor()
if err != nil {
return nil, fmt.Errorf("failed to retrieve the time anchor value for predicate %q in binding %q with error %v", p, cls.PAnchorAlias, err)
}
r[cls.PAnchorAlias] = &table.Cell{T: t}
}
// Object related bindings.
if cls.OBinding != "" {
// Extract the object type.
c, err := objectToCell(o)
if err != nil {
return nil, err
}
r[cls.OBinding] = c
}
if cls.OAlias != "" {
// Extract the object type.
c, err := objectToCell(o)
if err != nil {
return nil, err
}
r[cls.OAlias] = c
}
if cls.OTypeAlias != "" {
n, err := o.Node()
if err != nil {
return nil, err
}
r[cls.OTypeAlias] = &table.Cell{S: n.Type().String()}
}
if cls.OIDAlias != "" {
n, err := o.Node()
if err == nil {
r[cls.OIDAlias] = &table.Cell{S: n.ID().String()}
} else {
p, err := o.Predicate()
if err != nil {
return nil, err
}
r[cls.OIDAlias] = &table.Cell{S: string(p.ID())}
}
}
if cls.OAnchorBinding != "" {
p, err := o.Predicate()
if err != nil {
return nil, err
}
ts, err := p.TimeAnchor()
if err != nil {
return nil, err
}
r[cls.OAnchorBinding] = &table.Cell{T: ts}
}
if cls.OAnchorAlias != "" {
p, err := o.Predicate()
//.........这里部分代码省略.........
示例2: tripleToRow
// tripleToRow converts a triple into a row using the binndings specidfied
// on the graph clause.
func tripleToRow(t *triple.Triple, cls *semantic.GraphClause) (table.Row, error) {
r, s, p, o := make(table.Row), t.S(), t.P(), t.O()
// Enforce binding validity inside te clause.
bnd := make(map[string]*table.Cell)
validBinding := func(k string, v *table.Cell) bool {
c, ok := bnd[k]
bnd[k] = v
if !ok {
return true
}
if reflect.DeepEqual(c, v) {
return true
}
return false
}
// Subject related bindings.
if cls.SBinding != "" {
c := &table.Cell{N: s}
r[cls.SBinding] = c
if !validBinding(cls.SBinding, c) {
return nil, nil
}
}
if cls.SAlias != "" {
c := &table.Cell{N: s}
r[cls.SAlias] = c
if !validBinding(cls.SAlias, c) {
return nil, nil
}
}
if cls.STypeAlias != "" {
c := &table.Cell{S: s.Type().String()}
r[cls.STypeAlias] = c
if !validBinding(cls.STypeAlias, c) {
return nil, nil
}
}
if cls.SIDAlias != "" {
c := &table.Cell{S: s.ID().String()}
r[cls.SIDAlias] = c
if !validBinding(cls.SIDAlias, c) {
return nil, nil
}
}
// Predicate related bindings.
if cls.PBinding != "" {
c := &table.Cell{P: p}
r[cls.PBinding] = c
if !validBinding(cls.PBinding, c) {
return nil, nil
}
}
if cls.PAlias != "" {
c := &table.Cell{P: p}
r[cls.PAlias] = c
if !validBinding(cls.PAlias, c) {
return nil, nil
}
}
if cls.PIDAlias != "" {
c := &table.Cell{S: string(p.ID())}
r[cls.PIDAlias] = c
if !validBinding(cls.PIDAlias, c) {
return nil, nil
}
}
if cls.PAnchorBinding != "" {
if p.Type() != predicate.Temporal {
return nil, fmt.Errorf("cannot retrieve the time anchor value for non temporal predicate %q in binding %q", p, cls.PAnchorBinding)
}
t, err := p.TimeAnchor()
if err != nil {
return nil, fmt.Errorf("failed to retrieve the time anchor value for predicate %q in binding %q with error %v", p, cls.PAnchorBinding, err)
}
c := &table.Cell{T: t}
r[cls.PAnchorBinding] = c
if !validBinding(cls.PAnchorBinding, c) {
return nil, nil
}
}
if cls.PAnchorAlias != "" {
if p.Type() != predicate.Temporal {
return nil, fmt.Errorf("cannot retrieve the time anchor value for non temporal predicate %q in binding %q", p, cls.PAnchorAlias)
}
t, err := p.TimeAnchor()
if err != nil {
return nil, fmt.Errorf("failed to retrieve the time anchor value for predicate %q in binding %q with error %v", p, cls.PAnchorAlias, err)
}
c := &table.Cell{T: t}
r[cls.PAnchorAlias] = c
if !validBinding(cls.PAnchorAlias, c) {
return nil, nil
}
}
//.........这里部分代码省略.........