/// <summary> /// Optimises an Algebra to a form that uses <see cref="LazyBgp">LazyBgp</see> where possible /// </summary> /// <param name="algebra">Algebra</param> /// <param name="depth">Depth</param> /// <returns></returns> /// <remarks> /// <para> /// By transforming a query to use <see cref="LazyBgp">LazyBgp</see> we can achieve much more efficient processing of some forms of queries /// </para> /// </remarks> protected override ISparqlAlgebra OptimiseInternal(ISparqlAlgebra algebra, int depth) { try { ISparqlAlgebra temp; //Note this first test is specifically for the default BGP implementation since other optimisers //may run before us and replace with other BGP implementations which we don't want to replace hence //why we don't check for IBgp here if (algebra is Bgp) { temp = new LazyBgp(((Bgp)algebra).TriplePatterns); } //else if (algebra is ILeftJoin) //{ // ILeftJoin join = (ILeftJoin)algebra; // temp = new LeftJoin(this.OptimiseInternal(join.Lhs, depth + 1), join.Rhs, ((LeftJoin)algebra).Filter); //} else if (algebra is IUnion) { IUnion join = (IUnion)algebra; temp = new LazyUnion(this.OptimiseInternal(join.Lhs, depth + 1), this.OptimiseInternal(join.Rhs, depth + 1)); } else if (algebra is IJoin) { IJoin join = (IJoin)algebra; if (join.Lhs.Variables.IsDisjoint(join.Rhs.Variables)) { //If the sides of the Join are disjoint then can fully transform the join since we only need to find the requisite number of //solutions on either side to guarantee a product which meets/exceeds the required results //temp = new Join(this.OptimiseInternal(join.Lhs, depth + 1), this.OptimiseInternal(join.Rhs, depth + 1)); temp = join.Transform(this); } else { //If the sides are not disjoint then the LHS must be fully evaluated but the RHS need only produce enough //solutions that match //temp = new Join(join.Lhs, this.OptimiseInternal(join.Rhs, depth + 1)); temp = join.TransformRhs(this); } } else if (algebra is Algebra.Graph) { //Algebra.Graph g = (Algebra.Graph)algebra; //temp = new Algebra.Graph(this.OptimiseInternal(g.InnerAlgebra, depth + 1), g.GraphSpecifier); IUnaryOperator op = (IUnaryOperator)algebra; temp = op.Transform(this); } else { temp = algebra; } return(temp); } catch { //If the Optimise fails return the current algebra return(algebra); } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private HappilOperand <T> CreateUnaryExpression <T>(IUnaryOperator <T> @operator, IHappilOperand <T> operand) { return(new HappilUnaryExpression <T, T>( ownerMethod: null, @operator: @operator, operand: operand)); }
public GraphTraversalSource WithSack(ISupplier initialValue, IUnaryOperator splitOperator, IBinaryOperator mergeOperator) { var source = new GraphTraversalSource(new List <ITraversalStrategy>(TraversalStrategies), new Bytecode(Bytecode)); source.Bytecode.AddSource("withSack", initialValue, splitOperator, mergeOperator); return(source); }
public void PerformUnaryOperation(IUnaryOperator <T> unary_operator) { Utils.ThrowException(unary_operator == null ? new ArgumentNullException("unary_operator") : null); foreach (SparseVector <T> row in m_rows) { row.PerformUnaryOperation(unary_operator); } }
/// <summary> /// Adds an unary operator. /// </summary> /// <param name="name">The name of the operator.</param> /// <param name="unaryOperator">The unary operator.</param> /// <returns>This <see cref="MathContextBuilder"/> instance.</returns> /// <exception cref="ArgumentException">If unary operator already exists.</exception> public MathContextBuilder AddUnaryOperator(string name, IUnaryOperator unaryOperator) { if (_unaryOperators.TryAdd(name, unaryOperator) is false) { throw new ArgumentException($"An unary operator named '{name}' already exists."); } return(this); }
/// <summary> /// Updates the active unary operator. /// </summary> /// <param name="op">The new operator.</param> internal void SetUnaryOperator(IUnaryOperator op) { if (UnaryOperator != null) { throw new QueryConstructionException("Cannot set operator - Another unary operator is already active"); } UnaryOperator = op; }
public void UnaryOperatorCLick(object sender, TextView textView, EventArgs e , IUnaryOperator unary_operator_passed, string operator_display) { History_list.Add (operator_display); History_list.Add (textView.Text); History_list.Add("\r\n"); string pendingUnaryOperator = sender.ToString(); UopClicked = true; UnaryResult = unary_operator_passed.perform(Convert.ToDouble(textView.Text)); textView.Text = Convert.ToString(UnaryResult); }
/// <summary> /// Initializes a new instance of the <see cref="Rule"/> class. /// </summary> /// /// <param name="fuzzyDatabase">A fuzzy <see cref="Database"/> containig the linguistic variables /// (see <see cref="LinguisticVariable"/>) that will be used in the Rule.</param> /// /// <param name="name">Name of this <see cref="Rule"/>.</param> /// /// <param name="rule">A string representing the <see cref="Rule"/>. It must be a "IF..THEN" statement. /// For a more detailed description see <see cref="Rule"/> class.</param> /// /// <param name="normOperator">A class that implements a <see cref="INorm"/> interface to /// evaluate the AND operations of the Rule. </param> /// /// <param name="coNormOperator">A class that implements a <see cref="ICoNorm"/> interface /// to evaluate the OR operations of the Rule. </param> /// public Rule(Database fuzzyDatabase, string name, string rule, INorm normOperator, ICoNorm coNormOperator) { // the list with the RPN expression rpnTokenList = new List <object>( ); // setting attributes this.name = name; this.rule = rule; this.database = fuzzyDatabase; this.normOperator = normOperator; this.conormOperator = coNormOperator; this.notOperator = new NotOperator( ); // parsing the rule to obtain RPN of the expression ParseRule( ); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public HappilUnaryExpression( HappilMethod ownerMethod, IUnaryOperator <TOperand> @operator, IHappilOperand <TOperand> operand, UnaryOperatorPosition position = UnaryOperatorPosition.Prefix) : base(ownerMethod) { m_Operand = operand; m_Operator = @operator; m_Position = position; var scope = StatementScope.Current; scope.Consume(operand as IHappilExpression); scope.RegisterExpressionStatement(this); }
public void PerformUnaryOperation(IUnaryOperator <T> unary_operator) { Utils.ThrowException(unary_operator == null ? new ArgumentNullException("unary_operator") : null); for (int i = m_dat.Count - 1; i >= 0; i--) { T value = unary_operator.PerformOperation(m_dat[i]); if (value == null) { RemoveDirect(i); } else { SetDirect(i, value); } } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public UnaryExpressionOperand( IUnaryOperator <TOperand> @operator, IOperand <TOperand> operand, UnaryOperatorPosition position = UnaryOperatorPosition.Prefix) { m_Operand = operand; m_Operator = @operator; m_Position = position; if (StatementScope.Exists) { var scope = StatementScope.Current; scope.Consume(operand as IExpressionOperand); scope.RegisterExpressionStatement(this); } }
/// <summary> /// Applies the specified property condition to this query. /// </summary> /// <param name="condition">The condition to apply.</param> internal void ApplyCondition(Condition condition) { // Apply the active unary condition. condition = ApplyUnaryOperator(condition); // If the current active condition is null, not need to apply the binary operator. // If it isn't null, apply the binary operator. if (Query.Conditions == null) { Query.Conditions = condition; } else { Query.Conditions = JoinWithBinaryOperator(Query.Conditions, condition); } // Reset the operators for the next condition. UnaryOperator = null; BinaryOperator = null; }
public Token(IUnaryOperator unaryOperator) { value = unaryOperator; Type = TokenType.UnaryOperator; }
/// <summary> /// Initializes a new instance of the <see cref="Rule"/> class. /// </summary> /// /// <param name="fuzzyDatabase">A fuzzy <see cref="Database"/> containig the linguistic variables /// (see <see cref="LinguisticVariable"/>) that will be used in the Rule.</param> /// /// <param name="name">Name of this <see cref="Rule"/>.</param> /// /// <param name="rule">A string representing the <see cref="Rule"/>. It must be a "IF..THEN" statement. /// For a more detailed description see <see cref="Rule"/> class.</param> /// /// <param name="normOperator">A class that implements a <see cref="INorm"/> interface to /// evaluate the AND operations of the Rule. </param> /// /// <param name="coNormOperator">A class that implements a <see cref="ICoNorm"/> interface /// to evaluate the OR operations of the Rule. </param> /// public Rule( Database fuzzyDatabase, string name, string rule, INorm normOperator, ICoNorm coNormOperator ) { // the list with the RPN expression rpnTokenList = new List<object>( ); // setting attributes this.name = name; this.rule = rule; this.database = fuzzyDatabase; this.normOperator = normOperator; this.conormOperator = coNormOperator; this.notOperator = new NotOperator( ); // parsing the rule to obtain RPN of the expression ParseRule( ); }
public UnaryOperatorRule(IUnaryOperator unaryOperator) { this.unaryOperator = unaryOperator; }
/// <summary> /// Initializes a new instance of the <see cref="UnaryOperatorTerm"/> class. /// </summary> /// <param name="op"></param> public UnaryOperatorTerm(IUnaryOperator op) { Operator = op; }
/// <summary> /// Optimises an Algebra to a form that uses <see cref="AskBgp">AskBgp</see> where possible /// </summary> /// <param name="algebra">Algebra</param> /// <param name="depth">Depth</param> /// <returns></returns> /// <remarks> /// <para> /// By transforming a query to use <see cref="AskBgp">AskBgp</see> we can achieve much more efficient processing of some forms of queries /// </para> /// </remarks> protected override ISparqlAlgebra OptimiseInternal(ISparqlAlgebra algebra, int depth) { try { ISparqlAlgebra temp; if (algebra is Bgp) { //Bgp is transformed into AskBgp //This tries to find 1 possible solution temp = new AskBgp(((Bgp)algebra).TriplePatterns); } else if (algebra is ILeftJoin) { //LeftJoin is transformed to just be the LHS as the RHS is irrelevant for ASK queries //UNLESS the LeftJoin occurs inside a Filter/Minus BUT we should never get called to transform a //LeftJoin() for those branches of the algebra as the Optimiseer does not transform //Filter()/Minus() operators temp = this.OptimiseInternal(((ILeftJoin)algebra).Lhs, depth + 1); } else if (algebra is IUnion) { IUnion join = (IUnion)algebra; temp = new AskUnion(this.OptimiseInternal(join.Lhs, depth + 1), this.OptimiseInternal(join.Rhs, depth + 1)); } else if (algebra is IJoin) { IJoin join = (IJoin)algebra; if (join.Lhs.Variables.IsDisjoint(join.Rhs.Variables)) { //If the sides of the Join are disjoint then can fully transform the join since we only need to find at least //one solution on either side in order for the query to match //temp = new Join(this.OptimiseInternal(join.Lhs, depth + 1), this.OptimiseInternal(join.Rhs, depth + 1)); temp = join.Transform(this); } else { //If the sides are not disjoint then the LHS must be fully evaluated but the RHS need only produce at least //one solution based on the full input from the LHS for the query to match //temp = new Join(join.Lhs, this.OptimiseInternal(join.Rhs, depth + 1)); temp = join.TransformRhs(this); } } else if (algebra is Algebra.Graph) { //Algebra.Graph g = (Algebra.Graph)algebra; //temp = new Algebra.Graph(this.OptimiseInternal(g.InnerAlgebra, depth + 1), g.GraphSpecifier); IUnaryOperator op = (IUnaryOperator)algebra; temp = op.Transform(this); } else { temp = algebra; } return(temp); } catch { //If the Optimise fails return the current algebra return(algebra); } }
/// <summary> /// Updates the active unary operator. /// </summary> /// <param name="op">The new operator.</param> internal void SetUnaryOperator(IUnaryOperator op) { if (UnaryOperator != null) throw new QueryConstructionException("Cannot set operator - Another unary operator is already active"); UnaryOperator = op; }
/// <summary> /// Applies the specified property condition to this query. /// </summary> /// <param name="condition">The condition to apply.</param> internal void ApplyCondition(Condition condition) { // Apply the active unary condition. condition = ApplyUnaryOperator(condition); // If the current active condition is null, not need to apply the binary operator. // If it isn't null, apply the binary operator. if (Query.Conditions == null) Query.Conditions = condition; else Query.Conditions = JoinWithBinaryOperator(Query.Conditions, condition); // Reset the operators for the next condition. UnaryOperator = null; BinaryOperator = null; }
public static IRightValue Parse(ISyntaxNode parent, ref string Input) { string temp = Input; System.Text.RegularExpressions.Regex endRegEx = new System.Text.RegularExpressions.Regex("^\\s*$"); System.Text.RegularExpressions.Regex bracketsRegEx = new System.Text.RegularExpressions.Regex("^\\s*\\)\\s*"); System.Text.RegularExpressions.Regex commaRegEx = new System.Text.RegularExpressions.Regex("^\\s*,\\s*"); IRightValue highestNode = null; while ((!endRegEx.IsMatch(Input)) && (!bracketsRegEx.IsMatch(Input)) && (!commaRegEx.IsMatch(Input))) { IntegerConstant iconst = TryParse <IntegerConstant>(parent, ref Input); if (iconst != null) { if (highestNode != null) // Function calls can only be the first one. { throw new SyntaxException("Syntax error: Invalid rvalue before integer constant."); } highestNode = iconst; continue; } FloatingConstant fconst = TryParse <FloatingConstant>(parent, ref Input); if (fconst != null) { if (highestNode != null) // Function calls can only be the first one. { throw new SyntaxException("Syntax error: Invalid rvalue before floating constant."); } highestNode = fconst; continue; } FunctionCall fcall = TryParse <FunctionCall>(parent, ref Input); if (fcall != null) { if (highestNode != null) // Function calls can only be the first one. { throw new SyntaxException("Syntax error: Invalid rvalue before function call."); } highestNode = fcall; continue; } //string tmp = Input; IBinaryOperator binop = IBinaryOperator.Parse(parent, ref Input, highestNode); if (binop != null) { // Input = tmp; if (highestNode == null) // Function calls can only be the first one. { throw new SyntaxException("Syntax error: Missing first operand for binary operator."); } highestNode = binop; continue; } IUnaryOperator unop = IUnaryOperator.Parse(parent, ref Input, highestNode); if (unop != null) { if ((unop.Position == OperatorPosition.Postfix) && (highestNode == null)) // Function calls can only be the first one. { throw new SyntaxException("Syntax error: Missing first operand for unary operator."); } highestNode = unop; continue; } Brackets backets = TryParse <Brackets>(parent, ref Input); if (backets != null) { if (highestNode != null) // Function calls can only be the first one. { throw new SyntaxException("Syntax error: Invalid rvalue before brackets."); } highestNode = backets; continue; } // InfixOperator iopp = TryParse<InfixOperator>(ref Input, delegate(ref string i) { return new InfixOperator(parent, ref i, highestNode); }); // if (iopp != null) // highestNode = fcall; // Well, if nothing got parsed, then it's a invalid expression throw new SyntaxException("Syntax error: Invalid token \"" + Input + "\""); } if ((highestNode is IOperator) && ((highestNode as IOperator).SecondaryOperand is IOperator) && (highestNode.Priority < (highestNode as IOperator).SecondaryOperand.Priority)) { IOperator higher = (highestNode as IOperator); IOperator lower = (IOperator)higher.SecondaryOperand; higher.SecondaryOperand = lower.PrimaryOperand; lower.PrimaryOperand = higher; higher = lower; highestNode = higher; } return(highestNode); }
public UnaryOperation(IUnaryOperator @operator, IAst value) { Operator = @operator; Value = value; }
public void PerformEdgeOperation(IUnaryOperator <EdgeT> unary_op) { m_mtx.PerformUnaryOperation(unary_op); // throws ArgumentNullException }
private void AddUnaryOperator(OperatorType Type, IUnaryOperator Operator) { unaryOperators.Add(Type, Operator); }
internal Token(IUnaryOperator expr) { Type = TokenType.UnaryOperator; _expr = expr; }