public void InstanceWithTrueInitialization() { var orOperator = new OrOperator(true); Assert.IsNotNull(orOperator); Assert.IsTrue(orOperator.Result); }
public void FalseTrueTest() { MockExpression leftExpression = new MockExpression(false); MockExpression rightExpression = new MockExpression(true); OrOperator expression = new OrOperator(leftExpression, rightExpression); Assert.IsTrue(expression.Evaluate(principal)); }
public void AndOrNotTestWithQuotedStrings() { Parser parser = new Parser(); BooleanExpression expression = parser.Parse( "(R:\"Human Resources\" OR R:\"General Managers\") AND NOT R:\"HR Specialist\""); Assert.AreEqual(typeof(AndOperator), expression.GetType()); AndOperator andOperator = (AndOperator)expression; Assert.AreEqual(typeof(OrOperator), andOperator.Left.GetType()); OrOperator orOperator = (OrOperator)andOperator.Left; Assert.AreEqual(typeof(RoleExpression), orOperator.Left.GetType()); RoleExpression hrRoleExpression = (RoleExpression)orOperator.Left; Assert.AreEqual("Human Resources", hrRoleExpression.Word.Value); Assert.AreEqual(typeof(RoleExpression), orOperator.Right.GetType()); RoleExpression gmRoleExpression = (RoleExpression)orOperator.Right; Assert.AreEqual("General Managers", gmRoleExpression.Word.Value); Assert.AreEqual(typeof(NotOperator), andOperator.Right.GetType()); NotOperator notOperator = (NotOperator)andOperator.Right; Assert.AreEqual(typeof(RoleExpression), notOperator.Expression.GetType()); RoleExpression specialistRoleExpression = (RoleExpression)notOperator.Expression; Assert.AreEqual("HR Specialist", specialistRoleExpression.Word.Value); }
public void InstanceWithFalseInitialization() { var orOperator = new OrOperator(false); Assert.IsNotNull(orOperator); Assert.IsFalse(orOperator.Result); }
public void Visit(OrOperator node) { builder.AppendLine($"Or"); builder.Indent(); node.Left.Accept(this); node.Right.Accept(this); builder.Outdent(); }
public override VariableValue Evaluate(IVariableStore variables) { var left = Left.Evaluate(variables); var right = Right.Evaluate(variables); var result = OrOperator.Or(ref left, ref right); return(Assign(variables, ref result)); }
public void FilterOrWithAndConditionTest() { string expected = @"<?xml version=""1.0"" encoding=""utf-8""?> <function controlid=""unittest""> <query> <select> <field>BATCHNO</field> <field>RECORDNO</field> <field>STATE</field> </select> <object>GLBATCH</object> <filter> <or> <equalto> <field>JOURNAL</field> <value>APJ</value> </equalto> <and> <greaterthanorequalto> <field>BATCHNO</field> <value>1</value> </greaterthanorequalto> <equalto> <field>STATE</field> <value>Posted</value> </equalto> </and> </or> </filter> <options /> </query> </function>"; SelectBuilder builder = new SelectBuilder(); ISelect[] fields = builder.Fields(new[] { "BATCHNO", "RECORDNO", "STATE" }).GetFields(); AndOperator batchnoAndState = new AndOperator(new List <IFilter>()); batchnoAndState.AddFilter((new Filter("BATCHNO")).SetGreaterThanOrEqualTo("1")); batchnoAndState.AddFilter((new Filter("STATE")).SetEqualTo("Posted")); IFilter journal = new Filter("JOURNAL").SetEqualTo("APJ"); IFilter filter = new OrOperator(new List <IFilter>() { journal, batchnoAndState }); IQueryFunction query = new QueryFunction("unittest") { FromObject = "GLBATCH", SelectFields = fields, Filter = filter }; this.CompareXml(expected, query); }
public void OrApplyConstants() { Constant c1 = Constant.Word32(1); Constant c2 = Constant.Word32(2); BinaryOperator op = new OrOperator(); Constant c3 = op.ApplyConstants(c1, c2); Assert.AreEqual(3, c3.ToInt32()); }
public void Visit(OrOperator node) { VisitBinary(node); ITerminalWrapper leftWrapper = ReferenceTables.GetValue(node.Left); ITerminalWrapper rightWrapper = ReferenceTables.GetValue(node.Right); ReferenceTables.SetValue(node, ((dynamic)leftWrapper) | ((dynamic)rightWrapper)); }
public void PerformLogicWithTrueInitializationAndTrue() { var orOperator = new OrOperator(true); Assert.IsNotNull(orOperator); var result = orOperator.PerformLogic(true); Assert.IsTrue(orOperator.Result); Assert.AreEqual(orOperator.Result, result); }
public void PerformLogicWithFalseInitializationAndFalse() { var orOperator = new OrOperator(false); Assert.IsNotNull(orOperator); var result = orOperator.PerformLogic(false); Assert.IsFalse(orOperator.Result); Assert.AreEqual(orOperator.Result, result); }
public void OrExpressionTest() { Parser parser = new Parser(); BooleanExpression expression = parser.Parse("(R:Role1 or R:Role2)"); OrOperator andOperator = (OrOperator)expression; Assert.IsNotNull(andOperator.Left); Assert.IsNotNull(andOperator.Right); Assert.AreEqual("Role1", ((RoleExpression)andOperator.Left).Word.Value); Assert.AreEqual("Role2", ((RoleExpression)andOperator.Right).Word.Value); }
public void FilterOrConditionTest() { string expected = @"<?xml version=""1.0"" encoding=""utf-8""?> <function controlid=""unittest""> <query> <select> <field>CUSTOMERID</field> <field>RECORDNO</field> </select> <object>ARINVOICE</object> <filter> <or> <lessthanorequalto> <field>RECORDNO</field> <value>10</value> </lessthanorequalto> <equalto> <field>RECORDNO</field> <value>100</value> </equalto> <equalto> <field>RECORDNO</field> <value>1000</value> </equalto> <equalto> <field>RECORDNO</field> <value>10000</value> </equalto> </or> </filter> <options /> </query> </function>"; SelectBuilder builder = new SelectBuilder(); ISelect[] fields = builder.Fields(new[] { "CUSTOMERID", "RECORDNO" }).GetFields(); OrOperator filter = new OrOperator(new List <IFilter>()); filter.AddFilter((new Filter("RECORDNO")).SetLessThanOrEqualTo("10")); filter.AddFilter((new Filter("RECORDNO")).SetEqualTo("100")); filter.AddFilter((new Filter("RECORDNO")).SetEqualTo("1000")); filter.AddFilter((new Filter("RECORDNO")).SetEqualTo("10000")); IQueryFunction query = new QueryFunction("unittest") { FromObject = "ARINVOICE", SelectFields = fields, Filter = filter }; this.CompareXml(expected, query); }
public void OrOperator_ShouldPrint() { var ast = new OrOperator ( position: 0, left: new Identifier(0, "x"), right: new Identifier(0, "y") ); Assert.That(PrettyPrinter.ToString(ast), Is.EqualTo( @"Or Identifier(x) Identifier(y) ")); }
public void CanPerformMultiOperationalExpression(int a, int b, int c, int d) { Dictionary <string, bool> expectedAnswersMap = new Dictionary <string, bool> { { "0000", false }, { "1000", false }, { "0100", false }, { "0010", false }, { "0001", true }, { "1100", false }, { "1010", true }, { "1001", true }, { "0110", true }, { "0101", true }, { "0011", true }, { "1110", true }, { "0111", true }, { "1101", true }, { "1011", true }, { "1111", true }, }; LeafNode <int> A = new LeafNode <int>(a, SimpleValueExpressionFunction); LeafNode <int> B = new LeafNode <int>(b, SimpleValueExpressionFunction); LeafNode <int> C = new LeafNode <int>(c, SimpleValueExpressionFunction); LeafNode <int> D = new LeafNode <int>(d, SimpleValueExpressionFunction); List <Node> firstOrChildren = new List <Node> { A, B }; List <Node> middleAndChildren = new List <Node>(); List <Node> lastOrChildren = new List <Node>(); Operator andOp = new AndOperator(); Operator orOp = new OrOperator(); OperatorNode firstOr = new OperatorNode(firstOrChildren, orOp); middleAndChildren.Add(firstOr); middleAndChildren.Add(C); OperatorNode middleAnd = new OperatorNode(middleAndChildren, andOp); lastOrChildren.Add(middleAnd); lastOrChildren.Add(D); OperatorNode lastOr = new OperatorNode(lastOrChildren, orOp); Assert.Equal(lastOr.Evaluate(), expectedAnswersMap[$"{a}{b}{c}{d}"]); }
public void DefaultParamsTest() { string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>" + "<or>" + "<lessthanorequalto>" + "<field>RECORDNO</field>" + "<value>1</value>" + "</lessthanorequalto>" + "<equalto>" + "<field>RECORDNO</field>" + "<value>100</value>" + "</equalto>" + "<equalto>" + "<field>RECORDNO</field>" + "<value>1000</value>" + "</equalto>" + "<equalto>" + "<field>RECORDNO</field>" + "<value>10000</value>" + "</equalto>" + "</or>"; Stream stream = new MemoryStream(); XmlWriterSettings xmlSettings = new XmlWriterSettings { Encoding = Encoding.GetEncoding("UTF-8") }; IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings); List <IFilter> filters = new List <IFilter>(); filters.Add((new Filter("RECORDNO")).SetLessThanOrEqualTo("1")); filters.Add((new Filter("RECORDNO")).SetEqualTo("100")); filters.Add((new Filter("RECORDNO")).SetEqualTo("1000")); filters.Add((new Filter("RECORDNO")).SetEqualTo("10000")); IFilter orFilter = new OrOperator(filters); orFilter.WriteXml(ref xml); xml.Flush(); stream.Position = 0; StreamReader reader = new StreamReader(stream); Assert.Equal(expected, reader.ReadToEnd()); }
public void NullFilterTest() { Stream stream = new MemoryStream(); XmlWriterSettings xmlSettings = new XmlWriterSettings { Encoding = Encoding.GetEncoding("UTF-8") }; IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings); IFilter orFilter = new OrOperator(null); var ex = Record.Exception(() => orFilter.WriteXml(ref xml)); Assert.IsType <IntacctException>(ex); Assert.Equal("Two or more IFilter objects required for or", ex.Message); }
/* Methods */ private void Tokenize() { tokens = new List<Token>(); Token prev = null; Token t = null; while (_inputReader.Peek() != -1) { char c = (char)_inputReader.Read(); switch (c) { case Token.AND: t = new AndOperator(); tokens.Add(t); break; case Token.OR: t = new OrOperator(); tokens.Add(t); break; case Token.LEFT_PAREN: // Insert implicit AND operators before ( if ((prev is RightParenthesis) || (prev is Literal) || (prev is NotOperator)) tokens.Add(new AndOperator()); t = new LeftParenthesis(); tokens.Add(t); break; case Token.RIGHT_PAREN: t = new RightParenthesis(); tokens.Add(t); break; case Token.NOT: t = new NotOperator(); tokens.Add(t); break; default: t = new Literal(c); // Insert implicit AND operators before Literals if ((prev is RightParenthesis) || (prev is Literal) || (prev is NotOperator)) tokens.Add(new AndOperator()); tokens.Add(t); break; } prev = t; } }
public void CreateExpressionTest1() { // Arrange var parameterExpression = Expression.Parameter(typeof(Employee), "sample"); var expressionProperty = Expression.Property(parameterExpression, nameof(Employee.FirstName)); var containsOperator = new ContainsOperator(); Expression leftExpression = containsOperator.CreateExpression(expressionProperty, Expression.Constant("xxx")); Expression rightExpression = containsOperator.CreateExpression(expressionProperty, Expression.Constant("yyy")); Expression expectedExpression = Expression.Or(leftExpression, rightExpression); var _operator = new OrOperator(); // Act Expression resultExpression = _operator.CreateExpression(leftExpression, rightExpression); // Assert Assert.AreEqual(expectedExpression.ToString(), resultExpression.ToString(), "Expression not correct"); }
public void SingleFilterTest() { Stream stream = new MemoryStream(); XmlWriterSettings xmlSettings = new XmlWriterSettings { Encoding = Encoding.GetEncoding("UTF-8") }; IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings); List <IFilter> filters = new List <IFilter>(); filters.Add((new Filter("RECORDNO")).SetGreaterThanOrEqualTo("1")); IFilter orFilter = new OrOperator(filters); var ex = Record.Exception(() => orFilter.WriteXml(ref xml)); Assert.IsType <IntacctException>(ex); Assert.Equal("Two or more IFilter objects required for or", ex.Message); }
public void Visit(OrOperator or) { var trueLabel = MakeNewLabel(); var endLabel = MakeNewLabel(); or.Left.Accept(this); var leftOperand = tacs.Last().Result; tacs.Add(Tac.IfTrue(leftOperand, trueLabel)); or.Right.Accept(this); var rightOperand = tacs.Last().Result; tacs.Add(Tac.IfTrue(rightOperand, trueLabel)); var resultVariable = MakeNewTemp(); tacs.Add(Tac.Assign("0", resultVariable)); tacs.Add(Tac.Goto(endLabel)); tacs.Add(Tac.Label(trueLabel, resultVariable)); tacs.Add(Tac.Assign("1", resultVariable)); tacs.Add(Tac.Label(endLabel, resultVariable)); }
public void BuildSupplyPoint() { MarketDB.Instance.InsertByForce(); datalayer = PolicyDL.Instance; UsernameEqualsLeaf2 = new UsernameEquals(PolicyType.Global, "bla", "bla_bla", 1); UsernameEqualsLeaf = new UsernameEquals(PolicyType.Global, "bla", "bla_bla", 2); QuantityLessThanLeaf = new QuantityLessThan(PolicyType.Global, "bla", "bla_bla", 3); QuantityGreaterThanLeaf = new QuantityGreaterThan(PolicyType.Global, "bla", "bla_bla", 4); PriceLessThanLeaf = new PriceLessThan(PolicyType.Global, "bla", "bla_bla", 5); PriceGreaterThanLeaf = new PriceGreaterThan(PolicyType.Global, "bla", "bla_bla", 6); AddressEqualsLeaf = new AddressEquals(PolicyType.Global, "bla", "bla_bla", 7); AndHas0opSun = new AndOperator(PolicyType.Global, "bla", PriceGreaterThanLeaf, PriceLessThanLeaf, 8); AndHas1opSun = new AndOperator(PolicyType.Global, "bla", AndHas0opSun, UsernameEqualsLeaf2, 9); OrHas0opSun = new OrOperator(PolicyType.Global, "bla", QuantityLessThanLeaf, QuantityGreaterThanLeaf, 10); OrHas1opSun = new OrOperator(PolicyType.Global, "bla", OrHas0opSun, UsernameEqualsLeaf, 11); NotHasCondSun = new NotOperator(PolicyType.Global, "bla", AddressEqualsLeaf, null, 12); NotHasopSun = new NotOperator(PolicyType.Global, "bla", NotHasCondSun, null, 13); OrHas2opSuns = new OrOperator(PolicyType.Global, "bla", AndHas1opSun, OrHas1opSun, 14); ROOT_AndHas2opSuns = new AndOperator(PolicyType.Global, "bla", OrHas2opSuns, NotHasopSun, 15); BadInputLeaf = new UsernameEquals(PolicyType.Global, "bla", "bla'bla", 1); }
public void CanPerformSimpleOrTree() { List <Node> children = new List <Node> { new LeafNode <int>(0, SimpleValueExpressionFunction), new LeafNode <int>(0, SimpleValueExpressionFunction) }; Operator op = new OrOperator(); OperatorNode opNode00 = new OperatorNode(children, op); children = new List <Node> { new LeafNode <int>(0, SimpleValueExpressionFunction), new LeafNode <int>(1, SimpleValueExpressionFunction) }; OperatorNode opNode01 = new OperatorNode(children, op); children = new List <Node> { new LeafNode <int>(1, SimpleValueExpressionFunction), new LeafNode <int>(0, SimpleValueExpressionFunction) }; OperatorNode opNode10 = new OperatorNode(children, op); children = new List <Node> { new LeafNode <int>(1, SimpleValueExpressionFunction), new LeafNode <int>(1, SimpleValueExpressionFunction) }; OperatorNode opNode11 = new OperatorNode(children, op); Assert.False(opNode00.Evaluate()); Assert.True(opNode01.Evaluate()); Assert.True(opNode10.Evaluate()); Assert.True(opNode11.Evaluate()); }
public void AndOrNotTest() { Parser parser = new Parser(); BooleanExpression expression = parser.Parse( "(R:HumanSR OR R:GeneralManagers) AND NOT R:HRSpecialist"); AndOperator andOperator = (AndOperator)expression; OrOperator orOperator = (OrOperator)andOperator.Left; RoleExpression hrRoleExpression = (RoleExpression)orOperator.Left; Assert.AreEqual("HumanSR", hrRoleExpression.Word.Value); RoleExpression gmRoleExpression = (RoleExpression)orOperator.Right; Assert.AreEqual("GeneralManagers", gmRoleExpression.Word.Value); NotOperator notOperator = (NotOperator)andOperator.Right; RoleExpression specialistRoleExpression = (RoleExpression)notOperator.Expression; Assert.AreEqual("HRSpecialist", specialistRoleExpression.Word.Value); }
/// <summary> /// Processes the or operator. /// </summary> /// <param name="op">The op.</param> /// <returns></returns> private static IConditionOperator <LanguageUnderstandingResult> ProcessOrOperator(OrOperator op) { var orOperator = new CognitiveServices.LanguageUnderstanding.Conditions.OrConditionOperator <LanguageUnderstandingResult>(); var operators = ProcessSuboperators(op); orOperator.Operators = operators.ToArray(); return(orOperator); }
public void Visit(OrOperator node) { }
public void Visit(OrOperator node) { VisitBinary(node); CheckOperandsAreOfSameType(node); }
public static void Run(ILogger logger) { OnlineClient client = Bootstrap.Client(logger); List <IFilter> filterList = new List <IFilter>(); filterList.Add((new Filter("CUSTOMERID")).SetLike("c%")); filterList.Add((new Filter("CUSTOMERID")).SetLike("1%")); OrOperator filter = new OrOperator(filterList); OrderBuilder orderBuilder = new OrderBuilder(); IOrder[] orders = orderBuilder.Descending("CUSTOMERID").GetOrders(); SelectBuilder selectBuilder = new SelectBuilder(); ISelect[] fields = selectBuilder. Fields(new[] { "CUSTOMERID", "CUSTOMERNAME" }). Sum("TOTALDUE"). GetFields(); QueryFunction query = new QueryFunction() { SelectFields = fields, FromObject = "ARINVOICE", Filter = filter, CaseInsensitive = true, PageSize = 100, OrderBy = orders }; logger.LogInformation("Executing query to Intacct API"); Task <OnlineResponse> task = client.Execute(query); task.Wait(); OnlineResponse response = task.Result; Result result = response.Results[0]; dynamic json = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(result.Data)); if (json != null && json.First != null) { Console.WriteLine("Success! Number of ARINVOICE objects found: " + result.TotalCount); Console.WriteLine("First ARINVOICE result found"); Console.WriteLine("CUSTOMERID: " + json.First["ARINVOICE"]["CUSTOMERID"].Value); Console.WriteLine("CUSTOMERNAME: " + json.First["ARINVOICE"]["CUSTOMERNAME"].Value); Console.WriteLine("SUM.TOTALDUE: " + json.First["ARINVOICE"]["SUM.TOTALDUE"].Value); Console.WriteLine("See the log file (logs/intacct.log) for the complete list of results."); } else { Console.WriteLine("The query executed, but no ARINVOICE objects met the query criteria."); Console.WriteLine("Either modify the filter or comment it out from the query."); Console.WriteLine("See the log file (logs/intacct.log) for the XML request."); } try { string jsonString = json.ToString(); logger.LogDebug( "Query successful [ Company ID={0}, User ID={1}, Request control ID={2}, Function control ID={3}, Total count={4}, Data={5} ]", response.Authentication.CompanyId, response.Authentication.UserId, response.Control.ControlId, result.ControlId, result.TotalCount, jsonString ); } catch (NullReferenceException e) { logger.LogDebug("No response in Data. {0}", e); } finally { LogManager.Flush(); } }
public void CanCreateOrOperator() { Operator orOperator = new OrOperator(); }
static Expression ToSAT(List <_3COL.Node> nodes) { curVariables = new List <Variable>(); AndOperator and = null; // Jeder Knoten muss mindestens eine Farbe haben foreach (var node in nodes) { OrOperator or = null; foreach (var color in colors) { if (or == null) { or = new OrOperator(Vari(node, color), null); } else if (or.Right == null) { or.Right = Vari(node, color); } else { or = new OrOperator(or, Vari(node, color)); } } if (and == null) { and = new AndOperator(or, null); } else if (and.Right == null) { and.Right = or; } else { and = new AndOperator(and, or); } } // Jeder Knoten darf maximal eine Farbe haben foreach (var node in nodes) { foreach (var c1 in colors) { foreach (var c2 in colors) { if (c1 == c2) { continue; } and = new AndOperator(and, new NotOperator( new AndOperator( Vari(node, c1), Vari(node, c2)))); } } } // Mein Nachbar darf nicht die selbe farbe haben foreach (var conn in connections) { foreach (var c in colors) { and = new AndOperator(and, new NotOperator( new AndOperator( Vari(conn.Item1, c), Vari(conn.Item2, c)))); } } string s = and.ToString(); return(and); }
// help with creating binary tree private void InsertTreeHelper(ref Node n, string c) { switch (c) { case "&": n = new AndOperator(c); n.LeftNode = this._myStack.Pop(); n.RightNode = this._myStack.Pop(); this._myStack.Push(n); break; case "|": n = new OrOperator(c); n.LeftNode = this._myStack.Pop(); n.RightNode = this._myStack.Pop(); this._myStack.Push(n); break; case ">": n = new Implication(c); n.LeftNode = this._myStack.Pop(); n.RightNode = this._myStack.Pop(); this._myStack.Push(n); break; case "~": n = new Negation(c); n.RightNode = this._myStack.Pop(); this._myStack.Push(n); break; case "=": n = new BiImplication(c); n.LeftNode = this._myStack.Pop(); n.RightNode = this._myStack.Pop(); this._myStack.Push(n); break; case "%": n = new NANDOperator(c); n.LeftNode = this._myStack.Pop(); n.RightNode = this._myStack.Pop(); this._myStack.Push(n); break; case "!": n = new Existential(c, new PredicateVariable(this._myStack.Pop().ToString())); n.RightNode = this._myStack.Pop(); this._myStack.Push(n); break; case "@": n = new Universal(c, new PredicateVariable(this._myStack.Pop().ToString())); n.RightNode = this._myStack.Pop(); this._myStack.Push(n); break; default: if (char.IsLower(char.Parse(c))) { n = new PredicateVariable(c); this._myStack.Push(n); } else { n = new Variable(c); int total = this._myStack.Count; for (int i = 0; i < total; i++) { if (_myStack.Peek() is PredicateVariable p) { n.AddVariable(p); _myStack.Pop(); } } this._myStack.Push(n); } break; } }
public static void Seed(ApplicationContext context) { #region Is entity equals operators var isShelf = context.IsEntityEquals.Add(new IsEntityEquals() { Name = "FurnitureType", Value = "shelf" }); var isArmchair = context.IsEntityEquals.Add(new IsEntityEquals() { Name = "FurnitureType", Value = "armchair" }); var isNumberTwo = context.IsEntityEquals.Add(new IsEntityEquals() { Name = "builtin.number", Value = "Two" }); var isNumber2 = context.IsEntityEquals.Add(new IsEntityEquals() { Name = "builtin.number", Value = "2" }); #endregion Is entity equals operators #region Or operators var isTwoOrOperator = new OrOperator() { IsEntityEquals = new List <IsEntityEquals>() }; isTwoOrOperator.IsEntityEquals.Add(isNumber2); isTwoOrOperator.IsEntityEquals.Add(isNumberTwo); #endregion Or operators #region Conditions var isShelfCondition = context.Conditions.Add(new Condition() { IsEntityEquals = isShelf }); var isArmchairCondition = context.Conditions.Add(new Condition() { IsEntityEquals = isArmchair }); var isTwoCondition = context.Conditions.Add(new Condition() { OrOperator = isTwoOrOperator }); #endregion Conditions #region Flow states List <LuisFlowState> flowStateWithError = new List <LuisFlowState>(); List <LuisFlowState> allFlowStates = new List <LuisFlowState>(); var initialFlowState = context.FlowStates.Add(new LuisFlowState() { IsInitialState = true, Name = "InitialState", StateBehaviorClass = "CognitiveServices.LanguageUnderstanding.Samples.Bot.ConversationSendBehavior, Bot Application" }); flowStateWithError.Add(initialFlowState); allFlowStates.Add(initialFlowState); var buildingShelfFlowState = context.FlowStates.Add(new LuisFlowState() { Name = "BuildingShelf", StateBehaviorClass = "CognitiveServices.LanguageUnderstanding.Samples.Bot.PostToUserBehavior, Bot Application" }); flowStateWithError.Add(buildingShelfFlowState); allFlowStates.Add(buildingShelfFlowState); var twoMetersFlowState = context.FlowStates.Add(new LuisFlowState() { Name = "TwoMeters", StateBehaviorClass = "CognitiveServices.LanguageUnderstanding.Samples.Bot.PostToUserBehavior, Bot Application" }); flowStateWithError.Add(twoMetersFlowState); allFlowStates.Add(twoMetersFlowState); var buildingArmchairFlowState = context.FlowStates.Add(new LuisFlowState() { Name = "BuildingArmchair", StateBehaviorClass = "CognitiveServices.LanguageUnderstanding.Samples.Bot.PostToUserBehavior, Bot Application" }); flowStateWithError.Add(buildingArmchairFlowState); allFlowStates.Add(buildingArmchairFlowState); var buildingSomethingElseFlowState = context.FlowStates.Add(new LuisFlowState() { Name = "BuildingSomethingElse", StateBehaviorClass = "CognitiveServices.LanguageUnderstanding.Samples.Bot.PostToUserBehavior, Bot Application" }); flowStateWithError.Add(buildingSomethingElseFlowState); allFlowStates.Add(buildingSomethingElseFlowState); var completedFlowState = context.FlowStates.Add(new LuisFlowState() { Name = "Completed", StateBehaviorClass = "CognitiveServices.LanguageUnderstanding.Samples.Bot.PostToUserBehavior, Bot Application" }); flowStateWithError.Add(completedFlowState); allFlowStates.Add(completedFlowState); var errorHandlingFlowState = context.FlowStates.Add(new LuisFlowState() { Name = "ErrorHandling", StateBehaviorClass = "CognitiveServices.LanguageUnderstanding.Samples.Bot.PostToUserBehavior, Bot Application" }); allFlowStates.Add(errorHandlingFlowState); #endregion Flow states #region Flow state transitions List <LuisFlowStateTransition> allTransitions = new List <LuisFlowStateTransition>(); var flowStateTransition1 = context.FlowStateTransitions.Add(new LuisFlowStateTransition() { CurrentState = initialFlowState, NextState = buildingShelfFlowState, Intent = "Build.Furniture", Condition = isShelfCondition }); allTransitions.Add(flowStateTransition1); var flowStateTransition2 = context.FlowStateTransitions.Add(new LuisFlowStateTransition() { CurrentState = initialFlowState, NextState = buildingArmchairFlowState, Intent = "Build.Furniture", Condition = isArmchairCondition }); allTransitions.Add(flowStateTransition2); var flowStateTransition3 = context.FlowStateTransitions.Add(new LuisFlowStateTransition() { CurrentState = initialFlowState, NextState = buildingSomethingElseFlowState, Intent = "Build.Furniture" }); allTransitions.Add(flowStateTransition3); var flowStateTransition4 = context.FlowStateTransitions.Add(new LuisFlowStateTransition() { CurrentState = buildingShelfFlowState, NextState = twoMetersFlowState, Intent = "Shelf.Size", Condition = isTwoCondition }); allTransitions.Add(flowStateTransition4); var flowStateTransition5 = context.FlowStateTransitions.Add(new LuisFlowStateTransition() { CurrentState = twoMetersFlowState, NextState = completedFlowState, Intent = "Acknowledgement" }); allTransitions.Add(flowStateTransition5); var flowStateTransition6 = context.FlowStateTransitions.Add(new LuisFlowStateTransition() { CurrentState = completedFlowState, NextState = buildingShelfFlowState, Intent = "Build.Furniture", Condition = isShelfCondition }); allTransitions.Add(flowStateTransition5); foreach (var state in flowStateWithError) { var transition = context.FlowStateTransitions.Add(new LuisFlowStateTransition() { CurrentState = state, NextState = errorHandlingFlowState, Intent = "None", }); allTransitions.Add(transition); } #endregion Flow state transitions #region Luis configuration var configuration = context.LuisConfigurations.Add(new LuisConfiguration() { Description = "LUIS Configuration", LuisFlowStates = new List <LuisFlowState>(), LuisFlowStateTransitions = new List <LuisFlowStateTransition>() }); allFlowStates.ForEach(x => configuration.LuisFlowStates.Add(x)); allTransitions.ForEach(x => configuration.LuisFlowStateTransitions.Add(x)); #endregion Luis configuration }
public void ThreeLevelFilterTest() { string expected = @"<?xml version=""1.0"" encoding=""utf-8""?> <function controlid=""unittest""> <query> <select> <field>BATCHNO</field> <field>RECORDNO</field> <field>STATE</field> </select> <object>GLBATCH</object> <filter> <or> <and> <equalto> <field>JOURNAL</field> <value>APJ</value> </equalto> <equalto> <field>STATE</field> <value>Posted</value> </equalto> </and> <and> <equalto> <field>JOURNAL</field> <value>RCPT</value> </equalto> <equalto> <field>STATE</field> <value>Posted</value> </equalto> <or> <equalto> <field>RECORDNO</field> <value>168</value> </equalto> <equalto> <field>RECORDNO</field> <value>132</value> </equalto> </or> </and> </or> </filter> <options /> </query> </function>"; SelectBuilder builder = new SelectBuilder(); ISelect[] fields = builder.Fields(new[] { "BATCHNO", "RECORDNO", "STATE" }).GetFields(); AndOperator apjAndState = new AndOperator(new List <IFilter>()); apjAndState.AddFilter((new Filter("JOURNAL")).SetEqualTo("APJ")); apjAndState.AddFilter((new Filter("STATE")).SetEqualTo("Posted")); OrOperator recordnoOr = new OrOperator(new List <IFilter>()); recordnoOr.AddFilter((new Filter("RECORDNO")).SetEqualTo("168")); recordnoOr.AddFilter((new Filter("RECORDNO")).SetEqualTo("132")); AndOperator rcptAndState = new AndOperator(new List <IFilter>()); rcptAndState.AddFilter((new Filter("JOURNAL")).SetEqualTo("RCPT")); rcptAndState.AddFilter((new Filter("STATE")).SetEqualTo("Posted")); rcptAndState.AddFilter(recordnoOr); IFilter filter = new OrOperator(new List <IFilter>() { apjAndState, rcptAndState }); IFunction query = new QueryFunction("unittest") { FromObject = "GLBATCH", SelectFields = fields, Filter = filter }; this.CompareXml(expected, query); }
private static ExpTreeNode GetAsExpressionTree(this ParseTreeNode parsedNode, ExpTreeNode parentExpNode) { //The current node is a variable / value token. Create a value node and return it back if (!parsedNode.ChildNodes.Any()) { switch (parsedNode.Term.Name) { case "variable": { var varName = parsedNode.FindTokenAndGetValue <string>(); return(new VariableValue(varName, parentExpNode)); } case "boolean": return(new LiteralValue(parsedNode.FindTokenAndGetValue <bool>(), parentExpNode)); case "integer": case "decimal": return(new LiteralValue(parsedNode.FindTokenAndGetValue <double>(), parentExpNode)); case "SingleQuoteString": case "DoubleQuoteString": return(new LiteralValue(parsedNode.FindTokenAndGetValue <string>(), parentExpNode)); default: throw parsedNode.GetException($"Invalid token type '{parsedNode.Term.Name}' in expression"); } } // Look on the next node down else if (parsedNode.ChildNodes.Count == 1) { return(GetAsExpressionTree(parsedNode.ChildNodes[0], parentExpNode)); } //Ignore parenthesis, the middle non-terminal is what we want // Look on the next node down else if (parsedNode.ChildNodes.Count == 3 && parsedNode.ChildNodes[0]?.Token?.Text == "(") { return(GetAsExpressionTree(parsedNode.ChildNodes[1], parentExpNode)); } //Binary operator else if (parsedNode.ChildNodes.Count == 3) { BinaryOperatorBase binaryOp; var opStr = parsedNode.ChildNodes[1].FindToken().ValueString; switch (opStr) { // Math case "+": binaryOp = new AdditionOperator(parentExpNode); break; case "-": binaryOp = new SubtractionOperator(parentExpNode); break; case "*": binaryOp = new MultiplacationOperator(parentExpNode); break; case "/": binaryOp = new DivisionOperator(parentExpNode); break; case "%": binaryOp = new ModulusOperator(parentExpNode); break; case "^": binaryOp = new PowerOperator(parentExpNode); break; // Bool case "~==": binaryOp = new LooseEqualsOperator(parentExpNode); break; case "~!=": binaryOp = new LooseNotEqualsOperator(parentExpNode); break; case "==": binaryOp = new EqualsOperator(parentExpNode); break; case "!=": binaryOp = new NotEqualsOperator(parentExpNode); break; case "like": binaryOp = new LikeOperator(parentExpNode); break; case "match": binaryOp = new MatchOperator(parentExpNode); break; case ">": binaryOp = new GreaterThanOperator(parentExpNode); break; case ">=": binaryOp = new GreaterThanOrEqualOperator(parentExpNode); break; case "<": binaryOp = new LessThanOperator(parentExpNode); break; case "<=": binaryOp = new LessThanOrEqualOperator(parentExpNode); break; case "&&": binaryOp = new AndOperator(parentExpNode); break; case "||": binaryOp = new OrOperator(parentExpNode); break; default: throw parsedNode.ChildNodes[1].GetException($"Unrecognized operator '{opStr}'"); } binaryOp.LeftOperand = GetAsExpressionTree(parsedNode.ChildNodes[0], binaryOp); binaryOp.RightOperand = GetAsExpressionTree(parsedNode.ChildNodes[2], binaryOp); //Optimize if (binaryOp.LeftOperand is LiteralValue && binaryOp.RightOperand is LiteralValue) { return(new LiteralValue(binaryOp.Eval(), parentExpNode)); } return(binaryOp); } // Unary operator else if (parsedNode.ChildNodes.Count == 2) { var opVal = parsedNode.ChildNodes[0].FindToken().Value; UnaryOperatorBase unaryOp; if (parsedNode.ChildNodes[0].FindToken().Value is TypeCode convertType) { unaryOp = new TypeConversionOperator(convertType, parentExpNode); } else { var opStr = opVal.ToString(); switch (opStr) { case "!": unaryOp = new NotOperator(parentExpNode); break; //Property Checking case "lengthof": unaryOp = new LengthOperator(parentExpNode); break; case "typeof": unaryOp = new TypeOperator(parentExpNode); break; default: unaryOp = new GenericUnaryMathFunctionOperator(opStr, parentExpNode); break; } } unaryOp.Operand = GetAsExpressionTree(parsedNode.ChildNodes[1], unaryOp); //Optimize if (unaryOp.Operand is LiteralValue) { return(new LiteralValue(unaryOp.Eval(), parentExpNode)); } return(unaryOp); } else { throw parsedNode.GetException($"Invalid number of tokens ({parsedNode.ChildNodes.Count})"); } }
static void Main(string[] args) { nodes = new List <Node>(); for (int i = 1; i <= 12; i++) { nodes.Add(i); } nodes.Add(1, 2); nodes.Add(1, 7); nodes.Add(1, 11); nodes.Add(2, 3); nodes.Add(2, 11); nodes.Add(3, 4); nodes.Add(3, 10); nodes.Add(4, 5); nodes.Add(4, 9); nodes.Add(5, 6); nodes.Add(5, 9); nodes.Add(6, 7); nodes.Add(6, 8); nodes.Add(7, 8); nodes.Add(8, 12); nodes.Add(9, 12); nodes.Add(10, 12); nodes.Add(10, 11); #region Random Graph //Random rand = new Random(); //for (int i = 0; i < 12; i++) //{ // nodes.Add(new Node((i + 1) + "")); //} //for (int i = 0; i < 20; i++) //{ // List<Node> forcon = nodes.Where(n => n.Neighbours.Count < 11).ToList(); // if (forcon.Count < 2) // break; // Node a = forcon[rand.Next(0, forcon.Count)]; // forcon = forcon.Where(n => n != a).ToList(); // Node b = forcon[rand.Next(0, forcon.Count)]; // a.AddNeighbour(b); //} #endregion CurVariables = new List <Variable>(); AndOperator and = null; foreach (var first in nodes) { foreach (var secound in first.NeighboursFromOneSide) { OrOperator or = new OrOperator(Vari(first), Vari(secound)); if (and == null) { and = new AndOperator(or, null); } else if (and.Right == null) { and.Right = or; } else { and = new AndOperator(and, or); } } } SATSolver.Program.OnFound += Program_OnFound; string str = and.ToString(); SATSolver.Program.Solve(and); Console.WriteLine(); foreach (var item in best) { Console.Write(item + ", "); nodes.FirstOrDefault(n => n.NodeName == item).NodeColor = Microsoft.Glee.Drawing.Color.Red; } GraphPlotter.GraphPlott.PlottToFile(nodes, "asd.jpg", 1000, true); Console.ReadLine(); }