Exemplo n.º 1
0
        public object Evaluate(PropertyVertexModel vertex)
        {
            var left  = _left.Evaluate(vertex);
            var right = _right.Evaluate(vertex);

            if (left == null)
            {
                return(ToArray(right));
            }
            if (right == null)
            {
                return(ToArray(left));
            }

            // convert to arrays is props are not arrays
            object[] leftArr  = ToArray(left);
            object[] rightArr = ToArray(right);

            // compute union of two
            Dictionary <string, object> result = leftArr.ToDictionary(e => e.ToString(), e => e);

            foreach (var e in rightArr)
            {
                var key = e.ToString();
                if (result.ContainsKey(key))
                {
                    continue;
                }
                result.Add(key, e);
            }

            return(result.Values.ToArray());
        }
Exemplo n.º 2
0
        public bool Evaluate(PropertyVertexModel vertex, PropertyEdgeModel edge)
        {
            switch (Scope)
            {
            case EdgeTraversalScope.All:
                return(vertex.Edges.Any(edgeIterator => Expression.Evaluate(null, edgeIterator)));

            case EdgeTraversalScope.In:
                return(vertex.Edges.Any(edgeIterator => edgeIterator.TargetVertex.Id == vertex.Id && Expression.Evaluate(null, edgeIterator)));

            case EdgeTraversalScope.Out:
                return(vertex.Edges.Any(edgeIterator => edgeIterator.SourceVertex.Id == vertex.Id && Expression.Evaluate(null, edgeIterator)));

            case EdgeTraversalScope.Mutual:
                return(vertex.Edges.Any(edgeIterator =>
                                        Expression.Evaluate(null, edgeIterator) &&
                                        vertex.Edges.Any(mutual =>
                                                         mutual.SourceVertex.Id == edgeIterator.TargetVertex.Id &&
                                                         mutual.TargetVertex.Id == edgeIterator.SourceVertex.Id &&
                                                         Expression.Evaluate(null, mutual)
                                                         )));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 3
0
        private SigmaNodeModel TransformVertex(PropertyVertexModel vertex, int idx)
        {
            object label = null;
            object size  = (double)1.0;
            Dictionary <string, object> props = null;

            if (vertex.Props != null)
            {
                props = new Dictionary <string, object>(vertex.Props, StringComparer.OrdinalIgnoreCase);
                if (vertex.Props.TryGetValue("label", out label))
                {
                    props.Remove("label");
                }

                if (vertex.Props.TryGetValue("size", out size))
                {
                    props.Remove("size");
                }

                if (props.Count == 0)
                {
                    props = null;
                }
            }
            return(new SigmaNodeModel()
            {
                Id = "n" + idx,
                Label = label?.ToString(),
                Entity = vertex.Id,
                Props = props,
                Size = Convert.ToDouble(size)
            });
        }
Exemplo n.º 4
0
        public object Evaluate(PropertyVertexModel vertex)
        {
            object value;

            if (vertex.Props != null && vertex.Props.TryGetValue(Name, out value))
            {
                return(value);
            }
            return(null);
        }
Exemplo n.º 5
0
        public bool Evaluate(PropertyVertexModel vertex, PropertyEdgeModel edge)
        {
            switch (BinaryOperator)
            {
            case BinaryOperator.And:
                return(Left.Evaluate(vertex, edge) && Right.Evaluate(vertex, edge));

            case BinaryOperator.Or:
                return(Left.Evaluate(vertex, edge) || Right.Evaluate(vertex, edge));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 6
0
        public bool Evaluate(PropertyVertexModel vertex, PropertyEdgeModel edge)
        {
            var leftValue  = Left.Evaluate(vertex, edge);
            var rightValue = Right.Evaluate(vertex, edge);

            if (leftValue is Array)
            {
                return(ArrayEval(leftValue as Array, rightValue));
            }
            if (rightValue is Array)
            {
                return(ArrayEval(rightValue as Array, leftValue));
            }
            return(SingleEval(leftValue, rightValue));
        }
Exemplo n.º 7
0
        public object Evaluate(PropertyVertexModel vertex, PropertyEdgeModel edge)
        {
            if (edge == null)
            {
                return(null);
            }

            switch (_direction)
            {
            case EdgeDirection.Source:
                return(_propIdentifier.Evaluate(edge.SourceVertex));

            case EdgeDirection.Target:
                return(_propIdentifier.Evaluate(edge.TargetVertex));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 8
0
        public object Evaluate(PropertyVertexModel vertex)
        {
            var left  = _left.Evaluate(vertex);
            var right = _right.Evaluate(vertex);

            if (left == null)
            {
                return(null);
            }
            if (right == null)
            {
                return(null);
            }

            // convert to arrays is props are not arrays
            object[] leftArr = ToArray(left);
            string   filter  = right.ToString().Trim(new char[] { '\'' });

            return(leftArr.Where(e => e.ToString().Like(filter)));
        }
Exemplo n.º 9
0
        public virtual object Evaluate(PropertyVertexModel vertex, PropertyEdgeModel edge = null)
        {
            if (PropName.ToLower() == "null")
            {
                return(null);
            }

            if (edge != null)
            {
                if (PropName.ToLower() == "name")
                {
                    return(edge.Name);
                }
                if (edge.Props == null)
                {
                    return(null);
                }
                object result = null;
                edge.Props.TryGetValue(PropName, out result);
                return(result);
            }
            if (vertex != null)
            {
                if (PropName.ToLower() == "id")
                {
                    return(vertex.Id.ToString());
                }
                if (vertex.Props == null)
                {
                    return(null);
                }
                object result = null;
                vertex.Props.TryGetValue(PropName, out result);
                return(result);
            }
            return(null);
        }
Exemplo n.º 10
0
        private object[] GroupKeyArray(PropertyVertexModel vertex)
        {
            if (vertex?.Props != null && vertex.Props.ContainsKey(GroupingProp))

            {
                var key = vertex.Props[GroupingProp];
                if (key is JArray)
                {
                    return((key as JArray).Select(v => (object)v).ToArray());
                }
                else if (key is Array)
                {
                    return(key as object[]);
                }
                else
                {
                    return new object[] { key }
                };
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 11
0
 public bool Evaluate(PropertyVertexModel vertex, PropertyEdgeModel edge)
 {
     return(Value);
 }
Exemplo n.º 12
0
 public object Evaluate(PropertyVertexModel vertex = null, PropertyEdgeModel edge = null)
 {
     return(Val);
 }
Exemplo n.º 13
0
 public object Evaluate(PropertyVertexModel vertex)
 {
     return(Value);
 }
Exemplo n.º 14
0
 public object Evaluate(PropertyVertexModel vertex)
 {
     return(vertex.Props);
 }