本文整理汇总了Golang中kythe/io/kythe/go/util/schema.MirrorEdge函数的典型用法代码示例。如果您正苦于以下问题:Golang MirrorEdge函数的具体用法?Golang MirrorEdge怎么用?Golang MirrorEdge使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MirrorEdge函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: EnsureReverseEdges
// EnsureReverseEdges checks if gs contains reverse edges. If it doesn't, it
// will scan gs for all forward edges, adding a reverse for each back into the
// GraphStore. This is necessary for a GraphStoreService to work properly.
func EnsureReverseEdges(ctx context.Context, gs graphstore.Service) error {
var edge *spb.Entry
if err := gs.Scan(ctx, &spb.ScanRequest{}, func(e *spb.Entry) error {
if graphstore.IsEdge(e) {
edge = e
return io.EOF
}
return nil
}); err != nil {
return err
}
if edge == nil {
log.Println("No edges found in GraphStore")
return nil
} else if schema.EdgeDirection(edge.EdgeKind) == schema.Reverse {
return nil
}
var foundReverse bool
if err := gs.Read(ctx, &spb.ReadRequest{
Source: edge.Target,
EdgeKind: schema.MirrorEdge(edge.EdgeKind),
}, func(entry *spb.Entry) error {
foundReverse = true
return nil
}); err != nil {
return fmt.Errorf("error checking for reverse edge: %v", err)
}
if foundReverse {
return nil
}
return addReverseEdges(ctx, gs)
}
示例2: addReverseEdges
func addReverseEdges(ctx context.Context, gs graphstore.Service) error {
log.Println("Adding reverse edges")
var (
totalEntries int
addedEdges int
)
startTime := time.Now()
err := gs.Scan(ctx, new(spb.ScanRequest), func(entry *spb.Entry) error {
kind := entry.EdgeKind
if kind != "" && schema.EdgeDirection(kind) == schema.Forward {
if err := gs.Write(ctx, &spb.WriteRequest{
Source: entry.Target,
Update: []*spb.WriteRequest_Update{{
Target: entry.Source,
EdgeKind: schema.MirrorEdge(kind),
FactName: entry.FactName,
FactValue: entry.FactValue,
}},
}); err != nil {
return fmt.Errorf("Failed to write reverse edge: %v", err)
}
addedEdges++
}
totalEntries++
return nil
})
log.Printf("Wrote %d reverse edges to GraphStore (%d total entries): %v", addedEdges, totalEntries, time.Since(startTime))
return err
}
示例3: CrossReference
// CrossReference returns a (Referent, TargetAnchor) *ipb.CrossReference
// equivalent to the given decoration. The decoration's anchor is expanded
// given its parent file and associated Normalizer.
func CrossReference(file *srvpb.File, norm *xrefs.Normalizer, d *srvpb.FileDecorations_Decoration, tgt *srvpb.Node) (*ipb.CrossReference, error) {
if file == nil || norm == nil {
return nil, errors.New("missing decoration's parent file")
}
ea, err := ExpandAnchor(d.Anchor, file, norm, schema.MirrorEdge(d.Kind))
if err != nil {
return nil, fmt.Errorf("error expanding anchor {%+v}: %v", d.Anchor, err)
}
// Throw away most of the referent's facts. They are not needed.
var facts []*cpb.Fact
if tgt != nil {
for _, fact := range tgt.Fact {
if fact.Name == schema.CompleteFact {
facts = append(facts, fact)
}
}
}
return &ipb.CrossReference{
Referent: &srvpb.Node{
Ticket: d.Target,
Fact: facts,
},
TargetAnchor: ea,
}, nil
}
示例4: ReverseSinglePath
// ReverseSinglePath returns the reverse p, assuming it is a single-edge Path.
func ReverseSinglePath(p *ipb.Path) *ipb.Path {
return &ipb.Path{
Pivot: p.Edges[0].Target,
Edges: []*ipb.Path_Edge{{
Kind: schema.MirrorEdge(p.Edges[0].Kind),
Ordinal: p.Edges[0].Ordinal,
Target: p.Pivot,
}},
}
}
示例5: ToString
// ToString returns a human-readable string representation of p.
func ToString(p *ipb.Path) string {
s := "**" + p.Pivot.NodeKind + "**"
for _, e := range p.Edges {
if schema.EdgeDirection(e.Kind) == schema.Forward {
s += fmt.Sprintf(" -[%s]> %s", e.Kind, e.Target.NodeKind)
} else {
s += fmt.Sprintf(" <[%s]- %s", schema.MirrorEdge(e.Kind), e.Target.NodeKind)
}
}
return s
}
示例6: expandEdgeKind
// expandEdgeKind prefixes unrooted (not starting with "/") edge kinds with the
// standard Kythe edge prefix ("/kythe/edge/").
func expandEdgeKind(kind string) string {
ck := schema.Canonicalize(kind)
if strings.HasPrefix(ck, "/") {
return kind
}
expansion := schema.EdgePrefix + ck
if schema.EdgeDirection(kind) == schema.Reverse {
return schema.MirrorEdge(expansion)
}
return expansion
}
示例7: CrossReference
// CrossReference returns a (Referent, TargetAnchor) *srvpb.CrossReference
// equivalent to the given decoration. The decoration's anchor is expanded
// given its parent file and associated Normalizer.
func CrossReference(file *srvpb.File, norm *xrefs.Normalizer, d *srvpb.FileDecorations_Decoration) (*srvpb.CrossReference, error) {
if file == nil || norm == nil {
return nil, errors.New("missing decoration's parent file")
}
ea, err := expandAnchor(d.Anchor, file, norm, schema.MirrorEdge(d.Kind))
if err != nil {
return nil, fmt.Errorf("error expanding anchor {%+v}: %v", d.Anchor, err)
}
return &srvpb.CrossReference{
// Throw away the referent's facts. They are not needed.
Referent: &srvpb.Node{Ticket: d.Target.Ticket},
TargetAnchor: ea,
}, nil
}
示例8: writeCompletedEdges
func writeCompletedEdges(ctx context.Context, edges disksort.Interface, e *srvpb.Edge) error {
if err := edges.Add(&srvpb.Edge{
Source: &srvpb.Node{Ticket: e.Source.Ticket},
Kind: e.Kind,
Target: e.Target,
}); err != nil {
return fmt.Errorf("error writing complete edge: %v", err)
}
if err := edges.Add(&srvpb.Edge{
Source: &srvpb.Node{Ticket: e.Target.Ticket},
Kind: schema.MirrorEdge(e.Kind),
Target: assemble.FilterTextFacts(e.Source),
}); err != nil {
return fmt.Errorf("error writing complete edge mirror: %v", err)
}
return nil
}
示例9: writeWithReverses
func writeWithReverses(ctx context.Context, tbl *table.KVProto, src, kind string, targets []string) error {
if err := tbl.Put(ctx, []byte(src+tempTableKeySep+kind+tempTableKeySep), &srvpb.EdgeSet_Group{
Kind: kind,
TargetTicket: targets,
}); err != nil {
return fmt.Errorf("error writing edges group: %v", err)
}
revGroup := &srvpb.EdgeSet_Group{
Kind: schema.MirrorEdge(kind),
TargetTicket: []string{src},
}
for _, tgt := range targets {
if err := tbl.Put(ctx, []byte(tgt+tempTableKeySep+revGroup.Kind+tempTableKeySep+src), revGroup); err != nil {
return fmt.Errorf("error writing rev edges group: %v", err)
}
}
return nil
}
示例10: writeWithReverses
func writeWithReverses(ctx context.Context, gs graphstore.Service, req *spb.WriteRequest) error {
if err := gs.Write(ctx, req); err != nil {
return fmt.Errorf("error writing edges: %v", err)
}
for _, u := range req.Update {
if err := gs.Write(ctx, &spb.WriteRequest{
Source: u.Target,
Update: []*spb.WriteRequest_Update{{
Target: req.Source,
EdgeKind: schema.MirrorEdge(u.EdgeKind),
FactName: u.FactName,
FactValue: u.FactValue,
}},
}); err != nil {
return fmt.Errorf("error writing rev edge: %v", err)
}
}
return nil
}
示例11: PartialReverseEdges
// PartialReverseEdges returns the set of partial reverse edges from the given source. Each
// reversed Edge has its Target fully populated and its Source will have no facts. To ensure every
// node has at least 1 Edge, the first Edge will be a self-edge without a Kind or Target. To reduce
// the size of edge sets, each Target will have any text facts filtered (see FilterTextFacts).
func PartialReverseEdges(src *Source) []*srvpb.Edge {
node := src.Node()
edges := []*srvpb.Edge{{
Source: node, // self-edge to ensure every node has at least 1 edge
}}
targetNode := FilterTextFacts(node)
for kind, targets := range src.Edges {
rev := schema.MirrorEdge(kind)
for _, target := range targets {
edges = append(edges, &srvpb.Edge{
Source: &srvpb.Node{Ticket: target},
Kind: rev,
Target: targetNode,
})
}
}
return edges
}
示例12: FromSource
// FromSource creates a set of *ipb.Paths for each of its edges as well as a
// single *ipb.Path with only its pivot set to be the source node.
func FromSource(src *ipb.Source) []*ipb.Path {
var paths []*ipb.Path
n := specialize(assemble.Node(src))
paths = append(paths, &ipb.Path{Pivot: n})
for kind, group := range src.EdgeGroups {
if schema.EdgeDirection(kind) != schema.Forward {
continue
}
for _, tgt := range group.Edges {
paths = append(paths, &ipb.Path{
Pivot: &ipb.Path_Node{
Ticket: tgt.Ticket,
},
Edges: []*ipb.Path_Edge{{
Kind: schema.MirrorEdge(kind),
Ordinal: int32(tgt.Ordinal),
Target: n,
}},
})
}
}
return paths
}
示例13: main
} `json:"span"`
Kind string `json:"kind"`
Node struct {
Ticket string `json:"ticket"`
Names []string `json:"names,omitempty"`
Kind string `json:"kind,omitempty"`
Subkind string `json:"subkind,omitempty"`
Typed string `json:"typed,omitempty"`
Definitions []*definition `json:"definitions,omitempty"`
} `json:"node"`
}
var (
definedAtEdge = schema.MirrorEdge(schema.DefinesEdge)
definedBindingAtEdge = schema.MirrorEdge(schema.DefinesBindingEdge)
)
func main() {
flag.Parse()
if flag.NArg() > 0 {
flagutil.UsageErrorf("unknown non-flag argument(s): %v", flag.Args())
} else if *offset < 0 && (*lineNumber < 0 || *columnOffset < 0) {
flagutil.UsageError("non-negative --offset (or --line and --column) required")
} else if *signature == "" && *path == "" {
flagutil.UsageError("must provide at least --path or --signature")
}
defer (*apiFlag).Close()
xs, idx = *apiFlag, *apiFlag
示例14: writeDecorations
if err := gs.Write(ctx, &spb.WriteRequest{
Source: u.Target,
Update: []*spb.WriteRequest_Update{{
Target: req.Source,
EdgeKind: schema.MirrorEdge(u.EdgeKind),
FactName: u.FactName,
FactValue: u.FactValue,
}},
}); err != nil {
return fmt.Errorf("error writing rev edge: %v", err)
}
}
return nil
}
var revChildOfEdgeKind = schema.MirrorEdge(schema.ChildOfEdge)
func writeDecorations(ctx context.Context, t table.Proto, es xrefs.NodesEdgesService, files []string) error {
log.Println("Writing Decorations")
edges := make(chan *xpb.EdgesReply)
var eErr error
go func() {
eErr = readEdges(ctx, es, files, edges,
decorationFilters, []string{revChildOfEdgeKind})
close(edges)
}()
for e := range edges {
decor := &srvpb.FileDecorations{}
if len(e.EdgeSet) == 0 {
示例15:
testAnchorVName = sig("testAnchor")
testAnchorTargetVName = sig("someSemanticNode")
testNodes = []*node{
{sig("orphanedNode"), facts(schema.NodeKindFact, "orphan"), nil},
{testFileVName, facts(
schema.NodeKindFact, schema.FileKind,
schema.TextFact, testFileContent,
schema.TextEncodingFact, testFileEncoding), map[string][]*spb.VName{
revChildOfEdgeKind: {testAnchorVName},
}},
{sig("sig2"), facts(schema.NodeKindFact, "test"), map[string][]*spb.VName{
"someEdgeKind": {sig("signature")},
}},
{sig("signature"), facts(schema.NodeKindFact, "test"), map[string][]*spb.VName{
schema.MirrorEdge("someEdgeKind"): {sig("sig2")},
}},
{testAnchorVName, facts(
schema.AnchorEndFact, "4",
schema.AnchorStartFact, "1",
schema.NodeKindFact, schema.AnchorKind,
), map[string][]*spb.VName{
schema.ChildOfEdge: {testFileVName},
schema.RefEdge: {testAnchorTargetVName},
}},
{testAnchorTargetVName, facts(schema.NodeKindFact, "record"), map[string][]*spb.VName{
schema.MirrorEdge(schema.RefEdge): {testAnchorVName},
}},
}
testEntries = nodesToEntries(testNodes)
)