/// <summary> /// Obtains a collection of nodes that is reachable from the provided node. /// </summary> /// <param name="start">The node to start the search at.</param> /// <param name="traversal">The type of traversal to use to discover the reachable nodes.</param> /// <returns>The nodes that were found reachable.</returns> public static ICollection <Node> GetReachableNodes(this Node start, ITraversal traversal) { var recorder = new TraversalRecorder(traversal); traversal.Run(start); return(recorder.TraversedNodes); }
/// <summary> /// Adds the "addV()" step to the traversal, creating a new vertex in the graph. /// </summary> /// <typeparam name="TEdge">The type of the edge.</typeparam> /// <param name="traversal">The graph traversal.</param> /// <param name="edge">The edge to add.</param> /// <returns>Returns the resulting traversal</returns> public static ISchemaBoundTraversal <object, TEdge> AddE <TEdge>(this ITraversal traversal, TEdge edge) where TEdge : IEdge { return(AddE(traversal, edge, new JsonSerializerSettings { ContractResolver = new ElementContractResolver() })); }
public VertexProgramStrategy(string graphComputer = null, int?workers = null, string persist = null, string result = null, ITraversal vertices = null, ITraversal edges = null, Dictionary <string, dynamic> configuration = null) { if (graphComputer != null) { Configuration["graphComputer"] = graphComputer; } if (workers != null) { Configuration["workers"] = workers; } if (persist != null) { Configuration["persist"] = persist; } if (result != null) { Configuration["result"] = result; } if (vertices != null) { Configuration["vertices"] = vertices; } if (edges != null) { Configuration["edges"] = edges; } configuration?.ToList().ForEach(x => Configuration[x.Key] = x.Value); }
/// <summary> /// Spawns a <see cref="GraphTraversal{SType, EType}" /> off this graph traversal source and adds the addV step to that /// traversal. /// </summary> public GraphTraversal <Vertex, Vertex> AddV(ITraversal vertexLabelTraversal) { var traversal = new GraphTraversal <Vertex, Vertex>(TraversalStrategies, new Bytecode(Bytecode)); traversal.Bytecode.AddStep("addV", vertexLabelTraversal); return(traversal); }
/// <summary> /// Spawns a <see cref="GraphTraversal{SType, EType}" /> off this graph traversal source and adds the addE step to that /// traversal. /// </summary> public GraphTraversal <Edge, Edge> AddE(ITraversal edgeLabelTraversal) { var traversal = new GraphTraversal <Edge, Edge>(TraversalStrategies, new Bytecode(Bytecode)); traversal.Bytecode.AddStep("addE", edgeLabelTraversal); return(traversal); }
public Dictionary <string, dynamic> Dictify(dynamic objectData, GraphSONWriter writer) { ITraversal traversal = objectData; var bytecode = traversal.Bytecode; return(writer.ToDict(bytecode)); }
public void Traversal(ITraversal pTraversal) { if (pTraversal == null) { return; } if (m_pTopLeft != null) { m_pTopLeft.Traversal(pTraversal); } if (m_pTopRight != null) { m_pTopRight.Traversal(pTraversal); } if (m_pBottomLeft != null) { m_pBottomLeft.Traversal(pTraversal); } if (m_pBottomRight != null) { m_pBottomRight.Traversal(pTraversal); } foreach (IElement element in m_lstElement) { pTraversal.Visit(element); } }
/// <summary> /// Adds the "addV()" step to the traversal, creating a new vertex in the graph. /// </summary> /// <typeparam name="TVertex">The type of the vertex.</typeparam> /// <param name="traversal">The traversal.</param> /// <returns>Returns the resulting traversal</returns> public static ISchemaBoundTraversal <object, TVertex> AddV <TVertex>(this ITraversal traversal) where TVertex : IVertex { var label = LabelNameResolver.GetLabelName(typeof(TVertex)); return(traversal.AsGraphTraversal().AddV(label).AsSchemaBound <object, TVertex>()); }
/// <summary> /// Adds the "addE()" step to the traversal, creating a new edge in the graph. /// </summary> /// <typeparam name="TEdge">The type of the edge.</typeparam> /// <param name="traversal">The traversal.</param> /// <returns>Returns the resulting traversal</returns> public static ISchemaBoundTraversal <object, TEdge> AddE <TEdge>(this ITraversal traversal) where TEdge : IEdge { var label = LabelNameResolver.GetLabelName(typeof(TEdge)); return(traversal.AsGraphTraversal().AddE(label).AsSchemaBound <object, TEdge>()); }
/// <summary> /// Adds the "addV()" step to the traversal, creating a new vertex in the graph. /// </summary> /// <typeparam name="TVertex">The type of the vertex.</typeparam> /// <param name="traversal">The graph traversal.</param> /// <param name="vertex">The vertex to add.</param> /// <returns>Returns the resulting traversal</returns> public static ISchemaBoundTraversal <object, TVertex> AddV <TVertex>(this ITraversal traversal, TVertex vertex) where TVertex : IVertex { return(AddV(traversal, vertex, new JsonSerializerSettings { ContractResolver = new ElementContractResolver() })); }
/// <summary> /// Creates a new traversal order recorder and hooks into the provided traversal object. /// </summary> /// <param name="traversal">The traversal object to hook into.</param> public TraversalOrderRecorder(ITraversal traversal) { if (traversal == null) { throw new ArgumentNullException(nameof(traversal)); } traversal.NodeDiscovered += TraversalOnNodeDiscovered; }
public void TranslateTraversal(string traversalText) { if (_g == null) { throw new InvalidOperationException("g should be a traversal source"); } _traversal = TraversalParser.GetTraversal(traversalText, _g, _parameters); }
/// <summary> /// Serializes the specified traversal. /// </summary> /// <param name="traversal">The traversal.</param> /// <param name="startAnonTraversal">true indicates that we're starting an anonymous traversal</param> /// <exception cref="ArgumentNullException">traversal</exception> private void Serialize(ITraversal traversal, bool startAnonTraversal) { if (traversal == null) { throw new ArgumentNullException(nameof(traversal)); } Serialize(traversal.Bytecode, startAnonTraversal); }
/// <summary> /// Creates an initialized <see cref="IGraphStatement"/> from a <c>GraphTraversal</c> to use directly with a /// <see cref="ISession"/>. /// <para> /// Note that the <c>IGraphStatement</c> will use the default <c>GraphOptions</c> at cluster level and not the /// ones defined on the <c>GraphTraversalSource</c>. /// </para> /// </summary> public static IGraphStatement StatementFromTraversal(ITraversal traversal) { if (traversal == null) { throw new ArgumentNullException(nameof(traversal)); } return(DseRemoteConnection.CreateStatement(traversal.Bytecode, null, false)); }
/// <summary> /// Serializes the specified traversal. /// </summary> /// <param name="traversal">The traversal.</param> /// <exception cref="ArgumentNullException">traversal</exception> public void Serialize(ITraversal traversal) { if (traversal == null) { throw new ArgumentNullException(nameof(traversal)); } Serialize(traversal.Bytecode); }
public TraversalRecorder(ITraversal traversal) { _traversal = traversal ?? throw new ArgumentNullException(nameof(traversal)); _traversal.NodeDiscovered += (sender, args) => { TraversedNodes.Add(args.NewNode); _nodes.Add(args.NewNode); }; }
public Graph(Vertex[] array, ITraversal strategy) { _vertices = new Vertex[array.Length]; _strategy = strategy; for (int i = 0; i < array.Length; i++) { _vertices[i] = array[i]; } }
/// <inheritdoc /> public async Task ApplyAsync <S, E>(ITraversal <S, E> traversal) { if (traversal.Traversers != null) { return; } var remoteTraversal = await _remoteConnection.SubmitAsync <S, E>(traversal.Bytecode).ConfigureAwait(false); traversal.Traversers = remoteTraversal.Traversers; }
/// <summary> /// Adds the "addV()" step to the traversal, creating a new vertex in the graph. /// </summary> /// <typeparam name="TEdge">The type of the edge.</typeparam> /// <param name="traversal">The graph traversal.</param> /// <param name="edge">The edge to add.</param> /// <param name="serializationSettings">The serialization settings.</param> /// <returns>Returns the resulting traversal</returns> public static ISchemaBoundTraversal <object, TEdge> AddE <TEdge>(this ITraversal traversal, TEdge edge, JsonSerializerSettings serializationSettings) where TEdge : IEdge { var label = LabelNameResolver.GetLabelName(typeof(TEdge)); var t = traversal.AsGraphTraversal().AddE(label); t = TraversalHelper.AddObjectProperties(t, edge, serializationSettings); return(t.AsSchemaBound <object, TEdge>()); }
/// <summary> /// Adds the "addV()" step to the traversal, creating a new vertex in the graph. /// </summary> /// <typeparam name="TVertex">The type of the vertex.</typeparam> /// <param name="traversal">The graph traversal.</param> /// <param name="vertex">The vertex to add.</param> /// <param name="serializationSettings">The serialization settings.</param> /// <returns>Returns the resulting traversal</returns> public static ISchemaBoundTraversal <object, TVertex> AddV <TVertex>(this ITraversal traversal, TVertex vertex, JsonSerializerSettings serializationSettings) where TVertex : IVertex { var label = LabelNameResolver.GetLabelName(typeof(TVertex)); var t = traversal.AsGraphTraversal().AddV(label); t = TraversalHelper.AddObjectProperties(t, vertex, serializationSettings); return(t.AsSchemaBound <object, TVertex>()); }
public void TranslateTraversal(string traversalText) { if (_g == null) { throw new InvalidOperationException("g should be a traversal source"); } _traversal = Gremlin.UseTraversal(ScenarioData.CurrentScenario.Name, _g, _parameters); }
/// <summary> /// Returns the string-equivalent of the given traversal /// </summary> /// <param name="traversal">The traversal.</param> /// <returns>Returns the string query</returns> public static string ToGremlinQuery(this ITraversal traversal) { var sb = new StringBuilder(); using (var serializer = new GremlinQuerySerializer(new StringWriter(sb))) { serializer.Serialize(traversal); } return(sb.ToString()); }
public ParentRecorder(ITraversal traversal) { _traversal = traversal ?? throw new ArgumentNullException(nameof(traversal)); traversal.NodeDiscovered += (sender, args) => { if (!_parents.ContainsKey(args.NewNode)) { _parents[args.NewNode] = args.Origin; } }; }
public void IterateToList() { if (_traversal == null) { throw new InvalidOperationException("Traversal should be set before iterating"); } ITraversal t = _traversal; var list = new List <object>(); while (t.MoveNext()) { list.Add(t.Current); } _result = list.ToArray(); }
/// <summary> /// Serializes the specified traversal. /// </summary> /// <param name="traversal">The traversal.</param> /// <exception cref="ArgumentNullException">traversal</exception> public void Serialize(ITraversal traversal) { if (traversal == null) { throw new ArgumentNullException(nameof(traversal)); } _writer.Write("g"); foreach (var instr in traversal.Bytecode.StepInstructions) { _writer.Write('.'); Serialize(instr); } }
public void Traverse <T>(TreeIterationType iterationType, TreeTraversalType traversalType, TreeNode input) { ITraversal traversal = null; if (iterationType == TreeIterationType.Iterative) { traversal = new IterativeLinkedListTreeTraversal(); traversal.Traverse <T>(traversalType, input); } else { traversal = new RecursiveLinkedListTreeTraversal(); traversal.Traverse <T>(traversalType, input); } }
public void TranslateTraversal(string traversalText) { if (_g == null) { throw new InvalidOperationException("g should be a traversal source"); } if (ScenarioData.CurrentFeature.Tags.Select(t => t.Name).ToList().Contains("@GraphComputerOnly")) { _g = _g.WithComputer(); } _traversal = Gremlin.UseTraversal(ScenarioData.CurrentScenario.Name, _g, _parameters); }
/// <summary> /// Performs a search on a node in a graph using the provided traversal method. /// </summary> /// <param name="start">The node to start the search on.</param> /// <param name="traversal">The type of traversal to perform.</param> /// <param name="predicate">The predicate the to-be-searched node needs to satisfy.</param> /// <returns>The first node matching the provided predicate, or <c>null</c> if none was found.</returns> public static Node Search(this Node start, ITraversal traversal, Predicate <Node> predicate) { Node result = null; traversal.NodeDiscovered += (sender, args) => { if (predicate(args.NewNode)) { args.ContinueExploring = false; args.Abort = true; result = args.NewNode; } }; traversal.Run(start); return(result); }
/// <summary> /// Initializes a new instance of the <see cref="SubgraphStrategy" /> class. /// </summary> /// <param name="vertexCriterion">Constrains vertices for the <see cref="ITraversal" />.</param> /// <param name="edgeCriterion">Constrains edges for the <see cref="ITraversal" />.</param> /// <param name="vertexPropertyCriterion">Constrains vertex properties for the <see cref="ITraversal" />.</param> public SubgraphStrategy(ITraversal vertexCriterion = null, ITraversal edgeCriterion = null, ITraversal vertexPropertyCriterion = null) { if (vertexCriterion != null) { Configuration["vertices"] = vertexCriterion; } if (edgeCriterion != null) { Configuration["edges"] = edgeCriterion; } if (vertexPropertyCriterion != null) { Configuration["vertexProperties"] = vertexPropertyCriterion; } }
/// <summary> /// Expects an incoming <code>Vertex</code> converts it to a <code>IDictionary</code> and folds additional data into it /// based on the specified <code>Enrichment</code> values passed to it. /// </summary> public static GraphTraversal <Vertex, IDictionary <object, object> > enrich(this GraphTraversal <Vertex, Vertex> t, params Enrichment[] enrichments) { var enrichmentTraversals = new ITraversal[enrichments.Length + 1]; enrichmentTraversals[0] = __.ValueMap <object>(true); if (enrichments.Length > 0) { enrichments.Select(e => EnrichmentLookup.Traversals[e]).ToArray().CopyTo(enrichmentTraversals, 1); } return(t.Union <IDictionary <object, object> >(enrichmentTraversals). Unfold <object>(). Group <object, object>(). By(Keys). By(__.Select <object>(Values).Unfold <object>())); }