public void AttributeFilterSet(SetSymbol parameterSym1, PredicateNode predicateNode, SetSymbol returnSym) { Console.WriteLine("AttributeFilter'ing..."); var result = parameterSym1.Entites.Where(e => AttributeSetTestLocal(e, predicateNode)); returnSym.EntityDic = result.ToDictionary(e => e.Id); }
public void Visit(PredicateNode node) { var predicate = Expression.Lambda <Func <LogItem, bool> >(node.Predicate, QueryFactory.ItemVariable).Compile(); node.Inner[0].Accept(this); Items = Items.Where(predicate); }
public void SetupPredicate() { _predicate = new PredicateNode(new List <string> { "Col1" }, str => new List <object> { "Cell1" }); }
public override void Visit(PredicateNode node) { _symbolTable.SetCurrentNode(node); _symbolTable.OpenScope(node.Name); VisitChildren(node); _symbolTable.CloseScope(); }
public void MutateWalkerSetup() { _endPredicateNode = predicateBuilder("ReplacedMeNode", "ReplaceMeCell"); _position2Node = predicateBuilder("Position2Node", "Position2Cell"); _binaryNode = new BinaryNode(_endPredicateNode, _endPredicateNode, BinaryNodeType.AND); _baseNode = new BinaryNode(_position2Node, _binaryNode, BinaryNodeType.OR); _replacementNode = predicateBuilder("Replaced", "ReplacedColumn"); }
public void AddBranchBuilderSetup() { _replacePredicateNode = predicateBuilder("ReplacedMeNode", "ReplaceMeCell"); _keepPredicateNode = predicateBuilder("KeepMeNode", "KeepMeCell"); _replaceBinaryNode = new BinaryNode(_replacePredicateNode, _replacePredicateNode, BinaryNodeType.AND); _baseNode = new BinaryNode(_replaceBinaryNode, _keepPredicateNode, BinaryNodeType.OR); _replacementNode = predicateBuilder("Replaced", "ReplacedColumn"); }
public ExecutionPath Mount(Node startNode, PredicateNode predicate) { PathSourceNode = startNode; Nodes[0] = predicate; Predicate = predicate.PredicateEntry; ReferenceCount.AddReference(); return(this); }
private QueryContainer Visit(PredicateNode node) { if (node.Type == SymbolType.BooleanOperator) { return(VisitBooleanOperator(node)); } if (node.Type == SymbolType.Operator) { return(VisitOperator(node)); } throw new Exception("Unable to create from search query from tree"); }
public void InterpretWalkerSetup() { _node3 = new PredicateNode(new List <string> { "Column3" }, str => new List <object> { "Cell3" }, PredicateType.Equal); _node2 = new PredicateNode(new List <string> { "Column2" }, str => new List <object> { "Cell2" }, PredicateType.LessThanEqual); }
public override void Visit(PredicateNode node) { ProgramCode.Append($"PREDICATE {node.Name}("); int i = 0; foreach (ParameterNode parameter in node.Parameters) { InsertComma(ref i); ProgramCode.Append($"{parameter.Type} {parameter.Name}"); } ProgramCode.Append("): {"); VisitChildren(node); ProgramCode.Append("};\n"); }
private QueryContainer VisitBooleanOperator(PredicateNode node) { var value = (BooleanOperator)node.Value; var predicate1 = node.Children[0]; var predicate2 = node.Children[1]; if (value == BooleanOperator.And) { return(Visit(predicate1) && Visit(predicate2)); } return(Visit(predicate1) || Visit(predicate2)); }
protected override void Visit(PredicateNode visitedNode) { if (_first) { //We're going to add to the duplicateCounter and see if the correct results are generated here } //if the key exists, increase by 1 if (_duplicateCounter.ContainsKey(visitedNode)) { _duplicateCounter[visitedNode]++; } else { _duplicateCounter[visitedNode] = 1; } //otherwise, initialise the key at 1 }
public Func <T, bool> CreateEvaluator <T>() { PredicateNode predicate = FindChild <PredicateNode>(); if (predicate != null) { return(predicate.CreateFunction <T>()); } LiteralNode node = FindChild <LiteralNode>(); if (node != null) { return(node.CreateFunction <T>()); } Debug.Assert(false); return(null); }
public void Test02() { string _name = "xxx"; var p1 = new PredicateNode<PersonEntity, Operator>(x => x.Name, Operator.Equal, _name); var p2 = new PredicateNode<PersonEntity, Operator>(x => x.Name, Operator.NotEqual, _name); var pOr = new OrPredicateNode<PersonEntity, Operator>(p1, p2); var p3 = new PredicateNode<PersonEntity, Operator>(x => x.Name, Operator.Like, _name); var pAnd = new AndPredicateNode<PersonEntity, Operator>(pOr, p3); var parameters = pAnd.Parameters; SqlGenerator sqlGenerator = new SqlGenerator(); var sql = sqlGenerator.Generate(pAnd); }
public override void Visit(PredicateNode node) { SymbolTable.SetCurrentNode(node); string predicateName = node.Name; SymbolTable.EnterSymbol(predicateName, AllType.BOOL); SymbolTable.SetAssigned(predicateName); SymbolTable.AddPredicateToList(predicateName); SymbolTable.OpenScope(node.Name); foreach (ParameterNode parameter in node.Parameters) { SymbolTable.EnterPredicateParameter(node.Name, parameter.Type_enum); parameter.Accept(this); } if (_initialBuildDone) { VisitChildren(node); } SymbolTable.CloseScope(); }
public override AbstractNode VisitPredicate([NotNull] GiraphParser.PredicateContext context) { PredicateNode PNode = new PredicateNode(context.Start.Line, context.Start.Column); PNode.Name = context.variable().GetText(); // Check if there is any parameters if (context.predicateParams() != null && context.predicateParams().predicateParam() != null) { // If there are any parameters, loop though all of them foreach (var Param in context.predicateParams().predicateParam()) { string ParameterName = Param.variable().GetText(); string ParameterType = Param.allType().GetText(); // Add them to the paramter list PNode.AddParameter(ParameterType, ParameterName, context.Start.Line, context.Start.Column); } } // Adopt the boolcomparisons of the Predicate as children to the PNode PNode.AdoptChildren(Visit(context.simpleBoolCompOrExp())); return(PNode); }
public bool AttributeSetTestLocal(QLEntity entity, PredicateNode predicateNode) //todo all possible versions { var secondNode = predicateNode.SecondNode; var exAtt = (predicateNode.FirstNode as AttributeAccessNode).ExAttNode; //property present? var part = entity.GetPropertyValue(exAtt.Value); if (part == null) { return(false); } //todo check if un nesting is ok (supports IFC TYPES such as IFCBOOLEAN) if (part.QLClass != null) { part = part.QLClass.QLDirectList[0]; } if (secondNode is CStringNode && TestStringValue(part, secondNode)) { return(true); } if (secondNode is CNumberNode && TestIntValue(part, secondNode, predicateNode.Compare)) { return(true); } if (secondNode is CFloatNode && TestFloatValue(part, secondNode, predicateNode.Compare)) { return(true); } return(false); }
/// <summary> /// Creates a query tree for the given query elements /// </summary> /// <param name="match"><see cref="MatchNode"/> for matching log items</param> /// <param name="parser"><see cref="IParser"/> for parsing log items</param> /// <param name="filter">An <see cref="Expression"/> for filtering log items</param> /// <param name="grouping">An enumerable of tuples of group names and grouping <see cref="Expression"/>s for grouping the log items</param> /// <param name="selects">An enumerable of tuples of projection labels and <see cref="Expression"/>s for projecting log items</param> /// <param name="order">An enumerable of tuples indicating sorting fields and sort order</param> /// <param name="limit">The number of items to return</param> /// <returns>A query tree for executing the query</returns> private static Node CreateQueryTree( MatchNode match, IOption <Tuple <string, IParser> > parser, IOption <Expression> filter, IOption <IEnumerable <Tuple <string, Expression> > > grouping, IOption <IEnumerable <Tuple <string, IAggregate> > > selects, IOption <IEnumerable <Tuple <string, bool> > > order, IOption <int> limit) { Node query = match; if (!parser.IsEmpty) { query = new ParseNode(query, parser.Get().Item2, parser.Get().Item1); } if (!filter.IsEmpty) { query = new PredicateNode(query, filter.Get()); } if (!grouping.IsEmpty) { var keyNames = grouping.Get().Select(g => g.Item1).ToArray(); var keyExpressions = grouping.Get().Select(g => g.Item2).ToArray(); if (selects.IsEmpty) { query = new GroupByNode(query, keyNames, keyExpressions, new string[0], new IAggregate[0]); } else { var aggregateNames = selects.Get().Select(s => s.Item1).ToArray(); var aggregates = selects.Get().Select(s => s.Item2).ToArray(); query = new GroupByNode(query, keyNames, keyExpressions, aggregateNames, aggregates); } } else if (!selects.IsEmpty) { var aggregateNames = selects.Get().Select(s => s.Item1).ToArray(); var aggregates = selects.Get().Select(s => s.Item2).ToArray(); if (aggregates.All(a => a is ListAggregate)) { query = new ProjectNode(query, aggregateNames, aggregates.Cast <ListAggregate>().Select(a => a.Expression).ToArray()); } else { query = new AggregateNode(query, aggregateNames, aggregates); } } if (!order.IsEmpty) { query = new OrderByNode(query, order.Get().Select(a => a.Item1).ToArray(), order.Get().Select(a => a.Item2).ToArray()); } if (!limit.IsEmpty) { query = new LimitNode(query, limit.Get()); } return(query); }
public void Visit(PredicateNode node) => Format(node);
public void Visit(PredicateNode node) { node.Inner[0].Accept(this); Mode = Query.EvaluationMode.Evaluate; }
private QueryContainer VisitOperator(PredicateNode node) { var value = (Operator)node.Value; var op1 = (Operand)node.Children[0].Value; var op2 = (Operand)node.Children[1].Value; if (op1.OperandType != OperandType.Property) { throw new Exception("First operand must be a property"); } var prop1Name = (string)op1.Value; var prop1Details = _propertyDetailsProvider.GetPropertyDetails(prop1Name); if (prop1Details == null) { throw new Exception($"Property {prop1Name} does not exist"); } if (op2.OperandType == OperandType.Property) { throw new Exception("Secon operand cannot be a property"); } switch (value) { case Operator.Contains: if (op2.OperandType != OperandType.String) { throw new Exception("Second operand must be string"); } return(new QueryContainer(new MatchQuery { Query = (string)op2.Value, Field = prop1Details.SourceName })); case Operator.Equal: // can be a string or number return(new QueryContainer(new MatchQuery { Query = (string)op2.Value, Field = prop1Details.SourceName })); case Operator.NotEqual: return(!(new QueryContainer(new MatchQuery { Query = (string)op2.Value, Field = prop1Details.SourceName }))); case Operator.LessThan: case Operator.LessThanEqual: case Operator.GreaterThan: case Operator.GreaterThanEqual: if (op2.OperandType != OperandType.Number) { throw new Exception($"Second operator {op2.Value} must be a number"); } if (prop1Details.Type != ConcreteType.Number) { throw new Exception($"First operator {op1.Value} must be a property of type number"); } var rangeQuery = new NumericRangeQuery { Field = prop1Details.SourceName }; if (value == Operator.LessThan) { rangeQuery.LessThan = (double)(decimal)op2.Value; } if (value == Operator.LessThanEqual) { rangeQuery.LessThanOrEqualTo = (double)(decimal)op2.Value; } if (value == Operator.GreaterThan) { rangeQuery.GreaterThan = (double)(decimal)op2.Value; } if (value == Operator.GreaterThanEqual) { rangeQuery.GreaterThanOrEqualTo = (double)(decimal)op2.Value; } return(new QueryContainer(rangeQuery)); default: throw new Exception($"Unknown Operator {node.Value}"); } }
public QueryContainer BuildNestQuery(PredicateNode root) { return(Visit(root)); }
/// <summary> /// A method that is called to actually build a tree from a given input. Is called from ProcessStringInput() /// </summary> /// <param name="input">input string</param> /// <param name="root">Node used in recursion for creating a binary tree</param> /// <exception cref="Exception"></exception> private void BuildTree(string input, Node root) { if (input == string.Empty) { return; } char first_character = input[0]; if (first_character == '~') { NotNode node = new NotNode(input, root); root.Insert(node); BuildTree(node.Value, node); } else if (first_character == '>') { ImplicationNode node = new ImplicationNode(input, root); root.Insert(node); BuildTree(node.Value, node); } else if (first_character == '=') { BiImplicationNode node = new BiImplicationNode(input, root); root.Insert(node); BuildTree(node.Value, node); } else if (first_character == '&') { ConjunctionNode node = new ConjunctionNode(input, root); root.Insert(node); BuildTree(node.Value, node); } else if (first_character == '|') { DisjunctionNode node = new DisjunctionNode(input, root); root.Insert(node); BuildTree(node.Value, node); } else if (first_character == '%') { NandNode node = new NandNode(input, root); root.Insert(node); BuildTree(node.Value, node); } else if (Char.IsUpper(first_character) && input[1] == '(') { /* predicate case */ /* P(x), Q(x) */ int closingBracketIndex = GetIndexOfClosingBracket(input, 1); var vars = QuantifierInputHandler.StringStartEndIndex(input, 2, closingBracketIndex - 1).Split(','); PredicateNode predicate = new PredicateNode(first_character); List <PropositionNode> propositions = new List <PropositionNode>(); foreach (var variable in vars) { propositions.Add(new PropositionNode(variable)); } predicate.Formulas = propositions; root.Insert(predicate); predicate.parent = root; input = input.Substring(closingBracketIndex + 1); BuildTree(input, predicate); } else if (first_character == '@' || first_character == '!') { string quantifierInput = QuantifierInputHandler.ParseOutInputForQuantifiers(input); QuantifierInputHandler quantifierInputHandler = new QuantifierInputHandler(quantifierInput); var node = quantifierInputHandler.Create(); node.parent = root; root.Insert(node); var newInput = input.Substring(IndexTillWhichStringAreSame(quantifierInput, input) + 1); BuildTree(newInput, node); } else if (first_character == ',') { if (root.parent == null) { throw new Exception("Error in your input"); } root = root.parent; input = input.Substring(1); BuildTree(input, root); } else if (Char.IsLetter(first_character)) { PropositionNode node = new PropositionNode(first_character.ToString(), input, root); root.Insert(node); BuildTree(node.Value, node); } else if (first_character == ')') { int numberOflevels = CalculateNumberOfLevelsToGoUp(input); for (int i = 0; i < numberOflevels; i++) { if (root.parent != null) { root = root.parent; } else { throw new Exception("Error in string input. Source: class Processor, method BuildTree, else if (')')"); } } input = input.Substring(numberOflevels); BuildTree(input, root); } else if (first_character == '(') { input = input.Substring(1); BuildTree(input, root); } }
public abstract void Visit(PredicateNode node);
public void Visit(PredicateNode node) { node.Inner[0].Accept(this); }
/// <summary> /// Creates and returns a quantifier tree /// </summary> /// <returns>Tree with quantifiers</returns> /// <exception cref="Exception"></exception> /// <exception cref="InputException"></exception> public Node Create() { if (IsPredicate(input[0])) { /* case with predicates */ PredicateNode predicate = new PredicateNode(input[0]); input = StringBetweenParenthesis(input); var varsOfPredicate = GetVariables(input); List <PropositionNode> propositions = new List <PropositionNode>(varsOfPredicate.Length); foreach (var s in varsOfPredicate) { if (!IsVariable(s[0])) { throw new Exception("problems"); } if (!listOfAcceptableVars.Contains(s[0])) { MessageBox.Show( "You cannot create a predicate with variables that have not been introduced by a quantifier!"); throw new InputException(); } propositions.Add(new PropositionNode(s[0].ToString())); } predicate.Formulas = propositions; return(predicate); } if (IsBasicExpression(input[0])) { /* for instance: |(P(x),Q(x))), need to get: |(P(x),Q(x))*/ int indexOfClosingBracket = Functions.GetIndexOfClosingBracket(input, 1); string expression = StringStartEndIndex(input, 0, indexOfClosingBracket); Processor temp = new Processor(); temp.ProcessStringInput(expression); return(temp.Root); } /* case with quantifiers */ var quantifier = GenerateQuantifier(input[0]); quantifier.Variable = new PropositionNode(input[1].ToString()); AddAllowableVar(input[1]); input = input.Substring(3); // get the string starting (excluding) from '.' quantifier.Insert(Create()); return(quantifier); }
public void Visit(PredicateNode node) => VisitInternal(node);