/// <summary> /// Tries to create a SPARQL Function expression if the function Uri correseponds to a supported SPARQL Function /// </summary> /// <param name="u">Function Uri</param> /// <param name="args">Function Arguments</param> /// <param name="scalarArguments">Scalar Arguments</param> /// <param name="expr">Generated Expression</param> /// <returns>Whether an expression was successfully generated</returns> public bool TryCreateExpression(Uri u, List<ISparqlExpression> args, Dictionary<string, ISparqlExpression> scalarArguments, out ISparqlExpression expr) { String func = u.ToString(); if (func.StartsWith(SparqlFunctionsNamespace)) { func = func.Substring(SparqlBuiltInFunctionFactory.SparqlFunctionsNamespace.Length); func = func.ToUpper(); //If any Scalar Arguments are present then can't be a SPARQL Function UNLESS it is //a GROUP_CONCAT function and it has the SEPARATOR argument if (scalarArguments.Count > 0) { if (func.Equals(SparqlSpecsHelper.SparqlKeywordGroupConcat) && scalarArguments.Count == 1 && scalarArguments.ContainsKey(SparqlSpecsHelper.SparqlKeywordSeparator)) { //OK } else { expr = null; return false; } } //Q: Will there be special URIs for the DISTINCT modified forms of aggregates? ISparqlExpression sparqlFunc = null; switch (func) { case SparqlSpecsHelper.SparqlKeywordAbs: if (args.Count == 1) { sparqlFunc = new AbsFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ABS() function"); } break; case SparqlSpecsHelper.SparqlKeywordAvg: if (args.Count == 1) { sparqlFunc = new AggregateExpressionTerm(new AverageAggregate(args.First())); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL AVG() aggregate"); } break; case SparqlSpecsHelper.SparqlKeywordBound: if (args.Count == 1) { if (args[0] is VariableExpressionTerm) { sparqlFunc = new BoundFunction((VariableExpressionTerm)args[0]); } else { throw new RdfParseException("The SPARQL BOUND() function only operates over Variables"); } } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL BOUND() function"); } break; case SparqlSpecsHelper.SparqlKeywordCeil: if (args.Count == 1) { sparqlFunc = new CeilFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL CEIL() function"); } break; case SparqlSpecsHelper.SparqlKeywordCoalesce: if (args.Count >= 1) { sparqlFunc = new CoalesceFunction(args); } else { throw new RdfParseException("The SPARQL COALESCE() function requires at least 1 argument"); } break; case SparqlSpecsHelper.SparqlKeywordConcat: if (args.Count >= 1) { sparqlFunc = new ConcatFunction(args); } else { throw new RdfParseException("The SPARQL CONCAT() function requires at least 1 argument"); } break; case SparqlSpecsHelper.SparqlKeywordContains: if (args.Count == 2) { sparqlFunc = new ContainsFunction(args[0], args[1]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL CONTAINS() function"); } break; case SparqlSpecsHelper.SparqlKeywordCount: //Q: What will the URIs be for the special forms of COUNT? if (args.Count == 1) { sparqlFunc = new AggregateExpressionTerm(new CountAggregate(args.First())); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL COUNT() aggregate"); } break; case SparqlSpecsHelper.SparqlKeywordDataType: if (args.Count == 1) { sparqlFunc = new DataTypeFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL DATATYPE() function"); } break; case SparqlSpecsHelper.SparqlKeywordDay: if (args.Count == 1) { sparqlFunc = new DayFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL DAY() function"); } break; case SparqlSpecsHelper.SparqlKeywordEncodeForUri: if (args.Count == 1) { sparqlFunc = new EncodeForUriFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ENCODE_FOR_URI() function"); } break; case SparqlSpecsHelper.SparqlKeywordFloor: if (args.Count == 1) { sparqlFunc = new FloorFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL FLOOR() function"); } break; case SparqlSpecsHelper.SparqlKeywordGroupConcat: if (args.Count == 1) { if (scalarArguments.ContainsKey(SparqlSpecsHelper.SparqlKeywordSeparator)) { sparqlFunc = new NonNumericAggregateExpressionTerm(new GroupConcatAggregate(args.First(), scalarArguments[SparqlSpecsHelper.SparqlKeywordSeparator])); } else { sparqlFunc = new NonNumericAggregateExpressionTerm(new GroupConcatAggregate(args.First())); } } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL GROUP_CONCAT() aggregate"); } break; case SparqlSpecsHelper.SparqlKeywordHours: if (args.Count == 1) { sparqlFunc = new HoursFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL HOURS() function"); } break; case SparqlSpecsHelper.SparqlKeywordIf: if (args.Count == 3) { sparqlFunc = new IfElseFunction(args[0], args[1], args[2]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL IF() function"); } break; case SparqlSpecsHelper.SparqlKeywordIri: if (args.Count == 1) { sparqlFunc = new IriFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL IRI() function"); } break; case SparqlSpecsHelper.SparqlKeywordIsBlank: if (args.Count == 1) { sparqlFunc = new IsBlankFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ISBLANK() function"); } break; case SparqlSpecsHelper.SparqlKeywordIsIri: if (args.Count == 1) { sparqlFunc = new IsIriFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ISIRI() function"); } break; case SparqlSpecsHelper.SparqlKeywordIsLiteral: if (args.Count == 1) { sparqlFunc = new IsLiteralFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ISLITERAL() function"); } break; case SparqlSpecsHelper.SparqlKeywordIsNumeric: if (args.Count == 1) { sparqlFunc = new IsNumericFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ISNUMERIC() function"); } break; case SparqlSpecsHelper.SparqlKeywordIsUri: if (args.Count == 1) { sparqlFunc = new IsUriFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ISURI() function"); } break; case SparqlSpecsHelper.SparqlKeywordLang: if (args.Count == 1) { sparqlFunc = new LangFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL LANG() function"); } break; case SparqlSpecsHelper.SparqlKeywordLangMatches: if (args.Count == 2) { sparqlFunc = new LangMatchesFunction(args[0], args[1]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL LANGMATCHES() function"); } break; case SparqlSpecsHelper.SparqlKeywordLCase: if (args.Count == 1) { sparqlFunc = new LCaseFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL LCASE() function"); } break; case SparqlSpecsHelper.SparqlKeywordMax: if (args.Count == 1) { sparqlFunc = new NonNumericAggregateExpressionTerm(new MaxAggregate(args.First())); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL MAX() aggregate"); } break; case SparqlSpecsHelper.SparqlKeywordMD5: if (args.Count == 1) { sparqlFunc = new MD5HashFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL CONTAINS() function"); } break; case SparqlSpecsHelper.SparqlKeywordMin: if (args.Count == 1) { sparqlFunc = new NonNumericAggregateExpressionTerm(new MinAggregate(args.First())); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL MIN() aggregate"); } break; case SparqlSpecsHelper.SparqlKeywordMinutes: if (args.Count == 1) { sparqlFunc = new MinutesFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL MINUTES() function"); } break; case SparqlSpecsHelper.SparqlKeywordMonth: if (args.Count == 1) { sparqlFunc = new MonthFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL MONTH() function"); } break; case SparqlSpecsHelper.SparqlKeywordNow: if (args.Count == 0) { sparqlFunc = new NowFunction(); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ABS() function"); } break; case SparqlSpecsHelper.SparqlKeywordRegex: if (args.Count == 2) { sparqlFunc = new RegexFunction(args[0], args[1]); } else if (args.Count == 3) { sparqlFunc = new RegexFunction(args[0], args[1], args[2]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL REGEX() function"); } break; case SparqlSpecsHelper.SparqlKeywordRound: if (args.Count == 1) { sparqlFunc = new RoundFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ROUND() function"); } break; case SparqlSpecsHelper.SparqlKeywordSameTerm: if (args.Count == 2) { sparqlFunc = new SameTermFunction(args[0], args[1]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SAMETERM() function"); } break; case SparqlSpecsHelper.SparqlKeywordSample: if (args.Count == 1) { sparqlFunc = new NonNumericAggregateExpressionTerm(new SampleAggregate(args.First())); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL AVG() aggregate"); } break; case SparqlSpecsHelper.SparqlKeywordSeconds: if (args.Count == 1) { sparqlFunc = new SecondsFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SECONDS() function"); } break; case SparqlSpecsHelper.SparqlKeywordSha1: if (args.Count == 1) { sparqlFunc = new Sha1HashFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SHA1() function"); } break; case SparqlSpecsHelper.SparqlKeywordSha224: if (args.Count == 1) { sparqlFunc = new Sha224HashFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SHA224() function"); } break; case SparqlSpecsHelper.SparqlKeywordSha256: if (args.Count == 1) { sparqlFunc = new Sha256HashFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SHA256() function"); } break; case SparqlSpecsHelper.SparqlKeywordSha384: if (args.Count == 1) { sparqlFunc = new Sha384HashFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SHA384() function"); } break; case SparqlSpecsHelper.SparqlKeywordSha512: if (args.Count == 1) { sparqlFunc = new Sha512HashFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SHA512() function"); } break; case SparqlSpecsHelper.SparqlKeywordStr: if (args.Count == 1) { sparqlFunc = new StrFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL STR() function"); } break; case SparqlSpecsHelper.SparqlKeywordStrDt: if (args.Count == 2) { sparqlFunc = new StrDtFunction(args[0], args[1]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL STRDT() function"); } break; case SparqlSpecsHelper.SparqlKeywordStrEnds: if (args.Count == 2) { sparqlFunc = new StrEndsFunction(args[0], args[1]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL STRENDS() function"); } break; case SparqlSpecsHelper.SparqlKeywordStrLang: if (args.Count == 2) { sparqlFunc = new StrLangFunction(args[0], args[1]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL STRLANG() function"); } break; case SparqlSpecsHelper.SparqlKeywordStrLen: if (args.Count == 1) { sparqlFunc = new StrLenFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL STRKEN() function"); } break; case SparqlSpecsHelper.SparqlKeywordStrStarts: if (args.Count == 2) { sparqlFunc = new StrStartsFunction(args[0], args[1]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL STRSTARTS() function"); } break; case SparqlSpecsHelper.SparqlKeywordSubStr: if (args.Count == 2) { sparqlFunc = new SubStrFunction(args[0], args[1]); } else if (args.Count == 3) { sparqlFunc = new SubStrFunction(args[0], args[1], args[2]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SUBSTR() function"); } break; case SparqlSpecsHelper.SparqlKeywordSum: if (args.Count == 1) { sparqlFunc = new AggregateExpressionTerm(new SumAggregate(args.First())); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SUM() aggregate"); } break; case SparqlSpecsHelper.SparqlKeywordTimezone: if (args.Count == 1) { sparqlFunc = new TimezoneFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL TIMEZONE() function"); } break; case SparqlSpecsHelper.SparqlKeywordTz: if (args.Count == 1) { sparqlFunc = new TZFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL TZ() function"); } break; case SparqlSpecsHelper.SparqlKeywordUCase: if (args.Count == 1) { sparqlFunc = new UCaseFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL UCASE() function"); } break; case SparqlSpecsHelper.SparqlKeywordUri: if (args.Count == 1) { sparqlFunc = new IriFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL URI() function"); } break; case SparqlSpecsHelper.SparqlKeywordYear: if (args.Count == 1) { sparqlFunc = new YearFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL YEAR() function"); } break; } if (sparqlFunc != null) { expr = sparqlFunc; return true; } } expr = null; return false; }
/// <summary> /// Tries to create an Leviathan Function expression if the function Uri correseponds to a supported Leviathan Function /// </summary> /// <param name="u">Function Uri</param> /// <param name="args">Function Arguments</param> /// <param name="scalarArgs">Scalar Arguments</param> /// <param name="expr">Generated Expression</param> /// <returns>Whether an expression was successfully generated</returns> public bool TryCreateExpression(Uri u, List <ISparqlExpression> args, Dictionary <String, ISparqlExpression> scalarArgs, out ISparqlExpression expr) { //If any Scalar Arguments are present then can't possibly be a Leviathan Function if (scalarArgs.Count > 0) { expr = null; return(false); } String func = u.ToString(); if (func.StartsWith(LeviathanFunctionFactory.LeviathanFunctionsNamespace)) { func = func.Substring(LeviathanFunctionFactory.LeviathanFunctionsNamespace.Length); ISparqlExpression lvnFunc = null; switch (func) { case LeviathanFunctionFactory.All: if (args.Count == 1) { lvnFunc = new NonNumericAggregateExpressionTerm(new AllAggregate(args.First())); } else if (args.Count == 2 && args.First() is DistinctModifierExpression) { lvnFunc = new NonNumericAggregateExpressionTerm(new AllAggregate(args.Last(), true)); } else { throw new RdfParseException("Incorrect number of arguments for Leviathan all() aggregate"); } break; case LeviathanFunctionFactory.Any: if (args.Count == 1) { lvnFunc = new NonNumericAggregateExpressionTerm(new AnyAggregate(args.First())); } else if (args.Count == 2 && args.First() is DistinctModifierExpression) { lvnFunc = new NonNumericAggregateExpressionTerm(new AnyAggregate(args.Last(), true)); } else { throw new RdfParseException("Incorrect number of arguments for Leviathan any() aggregate"); } break; case LeviathanFunctionFactory.Cartesian: if (args.Count == 4) { lvnFunc = new LeviathanCartesianFunction(args[0], args[1], args[2], args[3]); } else if (args.Count == 6) { lvnFunc = new LeviathanCartesianFunction(args[0], args[1], args[2], args[3], args[4], args[5]); } else { throw new RdfParseException("Incorrect number of arguments for Leviathan cartesian() function"); } break; case LeviathanFunctionFactory.Cube: if (args.Count == 1) { lvnFunc = new LeviathanCubeFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan cube() function"); } break; case LeviathanFunctionFactory.DegreesToRadians: if (args.Count == 1) { lvnFunc = new LeviathanDegreesToRadiansFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan degrees-to-radians() function"); } break; case LeviathanFunctionFactory.E: if (args.Count == 1) { lvnFunc = new LeviathanEFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan e() function"); } break; case LeviathanFunctionFactory.Factorial: if (args.Count == 1) { lvnFunc = new LeviathanFactorialFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan factorial() function"); } break; case LeviathanFunctionFactory.Ln: if (args.Count == 1) { lvnFunc = new LeviathanNaturalLogFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan ln() function"); } break; case LeviathanFunctionFactory.Log: if (args.Count == 1) { lvnFunc = new LeviathanLogFunction(args.First()); } else if (args.Count == 2) { lvnFunc = new LeviathanLogFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan log() function"); } break; case LeviathanFunctionFactory.MD5Hash: if (args.Count == 1) { lvnFunc = new LeviathanMD5HashFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan md5hash() function"); } break; case LeviathanFunctionFactory.Median: if (args.Count == 1) { lvnFunc = new NonNumericAggregateExpressionTerm(new MedianAggregate(args.First())); } else if (args.Count == 2 && args.First() is DistinctModifierExpression) { lvnFunc = new NonNumericAggregateExpressionTerm(new MedianAggregate(args.Last(), true)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan median() aggregate"); } break; case LeviathanFunctionFactory.Mode: if (args.Count == 1) { lvnFunc = new NonNumericAggregateExpressionTerm(new ModeAggregate(args.First())); } else if (args.Count == 2 && args.First() is DistinctModifierExpression) { lvnFunc = new NonNumericAggregateExpressionTerm(new ModeAggregate(args.Last(), true)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan mode() aggregate"); } break; case LeviathanFunctionFactory.None: if (args.Count == 1) { lvnFunc = new NonNumericAggregateExpressionTerm(new NoneAggregate(args.First())); } else if (args.Count == 2 && args.First() is DistinctModifierExpression) { lvnFunc = new NonNumericAggregateExpressionTerm(new NoneAggregate(args.Last(), true)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan none() aggregate"); } break; case LeviathanFunctionFactory.NumericMax: if (args.Count == 1) { lvnFunc = new AggregateExpressionTerm(new NumericMaxAggregate(args.First())); } else if (args.Count == 2 && args.First() is DistinctModifierExpression) { lvnFunc = new NonNumericAggregateExpressionTerm(new NumericMaxAggregate(args.Last(), true)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan nmax() aggregate"); } break; case LeviathanFunctionFactory.NumericMin: if (args.Count == 1) { lvnFunc = new AggregateExpressionTerm(new NumericMinAggregate(args.First())); } else if (args.Count == 2 && args.First() is DistinctModifierExpression) { lvnFunc = new NonNumericAggregateExpressionTerm(new NumericMinAggregate(args.Last(), true)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan nmin() aggregate"); } break; case LeviathanFunctionFactory.Power: if (args.Count == 1) { lvnFunc = new LeviathanSquareFunction(args.First()); } else if (args.Count == 2) { lvnFunc = new LeviathanPowerFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan pow() function"); } break; case LeviathanFunctionFactory.Pythagoras: if (args.Count == 2) { lvnFunc = new LeviathanPyathagoreanDistanceFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan pythagoras() function"); } break; case LeviathanFunctionFactory.RadiansToDegrees: if (args.Count == 1) { lvnFunc = new LeviathanRadiansToDegreesFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan radians-to-degrees() function"); } break; case LeviathanFunctionFactory.Random: if (args.Count == 0) { lvnFunc = new LeviathanRandomFunction(); } else if (args.Count == 1) { lvnFunc = new LeviathanRandomFunction(args.First()); } else if (args.Count == 2) { lvnFunc = new LeviathanRandomFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan rnd() function"); } break; case LeviathanFunctionFactory.Reciprocal: if (args.Count == 1) { lvnFunc = new LeviathanReciprocalFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan reciprocal() function"); } break; case LeviathanFunctionFactory.Root: if (args.Count == 1) { lvnFunc = new LeviathanSquareRootFunction(args.First()); } else if (args.Count == 2) { lvnFunc = new LeviathanRootFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan root() function"); } break; case LeviathanFunctionFactory.Sha256Hash: if (args.Count == 1) { lvnFunc = new LeviathanSha256HashFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan sha256hash() function"); } break; case LeviathanFunctionFactory.Square: if (args.Count == 1) { lvnFunc = new LeviathanSquareFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan sq() function"); } break; case LeviathanFunctionFactory.SquareRoot: if (args.Count == 1) { lvnFunc = new LeviathanSquareRootFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan sqrt() function"); } break; case LeviathanFunctionFactory.Ten: if (args.Count == 1) { lvnFunc = new LeviathanTenFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan ten() function"); } break; case LeviathanFunctionFactory.TrigCos: case LeviathanFunctionFactory.TrigCosInv: if (args.Count == 1) { lvnFunc = new LeviathanCosineFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigCosInv)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function"); } break; case LeviathanFunctionFactory.TrigCosec: case LeviathanFunctionFactory.TrigCosecInv: if (args.Count == 1) { lvnFunc = new LeviathanCosecantFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigCosecInv)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function"); } break; case LeviathanFunctionFactory.TrigCotan: case LeviathanFunctionFactory.TrigCotanInv: if (args.Count == 1) { lvnFunc = new LeviathanCotangentFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigCotanInv)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function"); } break; case LeviathanFunctionFactory.TrigSec: case LeviathanFunctionFactory.TrigSecInv: if (args.Count == 1) { lvnFunc = new LeviathanSecantFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigSecInv)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function"); } break; case LeviathanFunctionFactory.TrigSin: case LeviathanFunctionFactory.TrigSinInv: if (args.Count == 1) { lvnFunc = new LeviathanSineFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigSinInv)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function"); } break; case LeviathanFunctionFactory.TrigTan: case LeviathanFunctionFactory.TrigTanInv: if (args.Count == 1) { lvnFunc = new LeviathanTangentFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigTanInv)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function"); } break; } if (lvnFunc != null) { expr = lvnFunc; return(true); } } expr = null; return(false); }
/// <summary> /// Tries to create a SPARQL Function expression if the function Uri correseponds to a supported SPARQL Function /// </summary> /// <param name="u">Function Uri</param> /// <param name="args">Function Arguments</param> /// <param name="scalarArguments">Scalar Arguments</param> /// <param name="expr">Generated Expression</param> /// <returns>Whether an expression was successfully generated</returns> public bool TryCreateExpression(Uri u, List <ISparqlExpression> args, Dictionary <string, ISparqlExpression> scalarArguments, out ISparqlExpression expr) { String func = u.ToString(); if (func.StartsWith(SparqlFunctionsNamespace)) { func = func.Substring(SparqlBuiltInFunctionFactory.SparqlFunctionsNamespace.Length); func = func.ToUpper(); //If any Scalar Arguments are present then can't be a SPARQL Function UNLESS it is //a GROUP_CONCAT function and it has the SEPARATOR argument if (scalarArguments.Count > 0) { if (func.Equals(SparqlSpecsHelper.SparqlKeywordGroupConcat) && scalarArguments.Count == 1 && scalarArguments.ContainsKey(SparqlSpecsHelper.SparqlKeywordSeparator)) { //OK } else { expr = null; return(false); } } //Q: Will there be special URIs for the DISTINCT modified forms of aggregates? ISparqlExpression sparqlFunc = null; switch (func) { case SparqlSpecsHelper.SparqlKeywordAbs: if (args.Count == 1) { sparqlFunc = new AbsFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ABS() function"); } break; case SparqlSpecsHelper.SparqlKeywordAvg: if (args.Count == 1) { sparqlFunc = new AggregateExpressionTerm(new AverageAggregate(args.First())); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL AVG() aggregate"); } break; case SparqlSpecsHelper.SparqlKeywordBound: if (args.Count == 1) { if (args[0] is VariableExpressionTerm) { sparqlFunc = new BoundFunction((VariableExpressionTerm)args[0]); } else { throw new RdfParseException("The SPARQL BOUND() function only operates over Variables"); } } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL BOUND() function"); } break; case SparqlSpecsHelper.SparqlKeywordCeil: if (args.Count == 1) { sparqlFunc = new CeilFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL CEIL() function"); } break; case SparqlSpecsHelper.SparqlKeywordCoalesce: if (args.Count >= 1) { sparqlFunc = new CoalesceFunction(args); } else { throw new RdfParseException("The SPARQL COALESCE() function requires at least 1 argument"); } break; case SparqlSpecsHelper.SparqlKeywordConcat: if (args.Count >= 1) { sparqlFunc = new ConcatFunction(args); } else { throw new RdfParseException("The SPARQL CONCAT() function requires at least 1 argument"); } break; case SparqlSpecsHelper.SparqlKeywordContains: if (args.Count == 2) { sparqlFunc = new ContainsFunction(args[0], args[1]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL CONTAINS() function"); } break; case SparqlSpecsHelper.SparqlKeywordCount: //Q: What will the URIs be for the special forms of COUNT? if (args.Count == 1) { sparqlFunc = new AggregateExpressionTerm(new CountAggregate(args.First())); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL COUNT() aggregate"); } break; case SparqlSpecsHelper.SparqlKeywordDataType: if (args.Count == 1) { sparqlFunc = new DataTypeFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL DATATYPE() function"); } break; case SparqlSpecsHelper.SparqlKeywordDay: if (args.Count == 1) { sparqlFunc = new DayFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL DAY() function"); } break; case SparqlSpecsHelper.SparqlKeywordEncodeForUri: if (args.Count == 1) { sparqlFunc = new EncodeForUriFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ENCODE_FOR_URI() function"); } break; case SparqlSpecsHelper.SparqlKeywordFloor: if (args.Count == 1) { sparqlFunc = new FloorFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL FLOOR() function"); } break; case SparqlSpecsHelper.SparqlKeywordGroupConcat: if (args.Count == 1) { if (scalarArguments.ContainsKey(SparqlSpecsHelper.SparqlKeywordSeparator)) { sparqlFunc = new NonNumericAggregateExpressionTerm(new GroupConcatAggregate(args.First(), scalarArguments[SparqlSpecsHelper.SparqlKeywordSeparator])); } else { sparqlFunc = new NonNumericAggregateExpressionTerm(new GroupConcatAggregate(args.First())); } } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL GROUP_CONCAT() aggregate"); } break; case SparqlSpecsHelper.SparqlKeywordHours: if (args.Count == 1) { sparqlFunc = new HoursFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL HOURS() function"); } break; case SparqlSpecsHelper.SparqlKeywordIf: if (args.Count == 3) { sparqlFunc = new IfElseFunction(args[0], args[1], args[2]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL IF() function"); } break; case SparqlSpecsHelper.SparqlKeywordIri: if (args.Count == 1) { sparqlFunc = new IriFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL IRI() function"); } break; case SparqlSpecsHelper.SparqlKeywordIsBlank: if (args.Count == 1) { sparqlFunc = new IsBlankFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ISBLANK() function"); } break; case SparqlSpecsHelper.SparqlKeywordIsIri: if (args.Count == 1) { sparqlFunc = new IsIriFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ISIRI() function"); } break; case SparqlSpecsHelper.SparqlKeywordIsLiteral: if (args.Count == 1) { sparqlFunc = new IsLiteralFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ISLITERAL() function"); } break; case SparqlSpecsHelper.SparqlKeywordIsNumeric: if (args.Count == 1) { sparqlFunc = new IsNumericFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ISNUMERIC() function"); } break; case SparqlSpecsHelper.SparqlKeywordIsUri: if (args.Count == 1) { sparqlFunc = new IsUriFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ISURI() function"); } break; case SparqlSpecsHelper.SparqlKeywordLang: if (args.Count == 1) { sparqlFunc = new LangFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL LANG() function"); } break; case SparqlSpecsHelper.SparqlKeywordLangMatches: if (args.Count == 2) { sparqlFunc = new LangMatchesFunction(args[0], args[1]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL LANGMATCHES() function"); } break; case SparqlSpecsHelper.SparqlKeywordLCase: if (args.Count == 1) { sparqlFunc = new LCaseFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL LCASE() function"); } break; case SparqlSpecsHelper.SparqlKeywordMax: if (args.Count == 1) { sparqlFunc = new NonNumericAggregateExpressionTerm(new MaxAggregate(args.First())); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL MAX() aggregate"); } break; case SparqlSpecsHelper.SparqlKeywordMD5: if (args.Count == 1) { sparqlFunc = new MD5HashFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL CONTAINS() function"); } break; case SparqlSpecsHelper.SparqlKeywordMin: if (args.Count == 1) { sparqlFunc = new NonNumericAggregateExpressionTerm(new MinAggregate(args.First())); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL MIN() aggregate"); } break; case SparqlSpecsHelper.SparqlKeywordMinutes: if (args.Count == 1) { sparqlFunc = new MinutesFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL MINUTES() function"); } break; case SparqlSpecsHelper.SparqlKeywordMonth: if (args.Count == 1) { sparqlFunc = new MonthFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL MONTH() function"); } break; case SparqlSpecsHelper.SparqlKeywordNow: if (args.Count == 0) { sparqlFunc = new NowFunction(); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ABS() function"); } break; case SparqlSpecsHelper.SparqlKeywordRegex: if (args.Count == 2) { sparqlFunc = new RegexFunction(args[0], args[1]); } else if (args.Count == 3) { sparqlFunc = new RegexFunction(args[0], args[1], args[2]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL REGEX() function"); } break; case SparqlSpecsHelper.SparqlKeywordRound: if (args.Count == 1) { sparqlFunc = new RoundFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL ROUND() function"); } break; case SparqlSpecsHelper.SparqlKeywordSameTerm: if (args.Count == 2) { sparqlFunc = new SameTermFunction(args[0], args[1]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SAMETERM() function"); } break; case SparqlSpecsHelper.SparqlKeywordSample: if (args.Count == 1) { sparqlFunc = new NonNumericAggregateExpressionTerm(new SampleAggregate(args.First())); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL AVG() aggregate"); } break; case SparqlSpecsHelper.SparqlKeywordSeconds: if (args.Count == 1) { sparqlFunc = new SecondsFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SECONDS() function"); } break; case SparqlSpecsHelper.SparqlKeywordSha1: if (args.Count == 1) { sparqlFunc = new Sha1HashFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SHA1() function"); } break; case SparqlSpecsHelper.SparqlKeywordSha224: if (args.Count == 1) { sparqlFunc = new Sha224HashFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SHA224() function"); } break; case SparqlSpecsHelper.SparqlKeywordSha256: if (args.Count == 1) { sparqlFunc = new Sha256HashFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SHA256() function"); } break; case SparqlSpecsHelper.SparqlKeywordSha384: if (args.Count == 1) { sparqlFunc = new Sha384HashFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SHA384() function"); } break; case SparqlSpecsHelper.SparqlKeywordSha512: if (args.Count == 1) { sparqlFunc = new Sha512HashFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SHA512() function"); } break; case SparqlSpecsHelper.SparqlKeywordStr: if (args.Count == 1) { sparqlFunc = new StrFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL STR() function"); } break; case SparqlSpecsHelper.SparqlKeywordStrDt: if (args.Count == 2) { sparqlFunc = new StrDtFunction(args[0], args[1]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL STRDT() function"); } break; case SparqlSpecsHelper.SparqlKeywordStrEnds: if (args.Count == 2) { sparqlFunc = new StrEndsFunction(args[0], args[1]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL STRENDS() function"); } break; case SparqlSpecsHelper.SparqlKeywordStrLang: if (args.Count == 2) { sparqlFunc = new StrLangFunction(args[0], args[1]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL STRLANG() function"); } break; case SparqlSpecsHelper.SparqlKeywordStrLen: if (args.Count == 1) { sparqlFunc = new StrLenFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL STRKEN() function"); } break; case SparqlSpecsHelper.SparqlKeywordStrStarts: if (args.Count == 2) { sparqlFunc = new StrStartsFunction(args[0], args[1]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL STRSTARTS() function"); } break; case SparqlSpecsHelper.SparqlKeywordSubStr: if (args.Count == 2) { sparqlFunc = new SubStrFunction(args[0], args[1]); } else if (args.Count == 3) { sparqlFunc = new SubStrFunction(args[0], args[1], args[2]); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SUBSTR() function"); } break; case SparqlSpecsHelper.SparqlKeywordSum: if (args.Count == 1) { sparqlFunc = new AggregateExpressionTerm(new SumAggregate(args.First())); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL SUM() aggregate"); } break; case SparqlSpecsHelper.SparqlKeywordTimezone: if (args.Count == 1) { sparqlFunc = new TimezoneFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL TIMEZONE() function"); } break; case SparqlSpecsHelper.SparqlKeywordTz: if (args.Count == 1) { sparqlFunc = new TZFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL TZ() function"); } break; case SparqlSpecsHelper.SparqlKeywordUCase: if (args.Count == 1) { sparqlFunc = new UCaseFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL UCASE() function"); } break; case SparqlSpecsHelper.SparqlKeywordUri: if (args.Count == 1) { sparqlFunc = new IriFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL URI() function"); } break; case SparqlSpecsHelper.SparqlKeywordYear: if (args.Count == 1) { sparqlFunc = new YearFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the SPARQL YEAR() function"); } break; } if (sparqlFunc != null) { expr = sparqlFunc; return(true); } } expr = null; return(false); }
/// <summary> /// Tries to create an Leviathan Function expression if the function Uri correseponds to a supported Leviathan Function /// </summary> /// <param name="u">Function Uri</param> /// <param name="args">Function Arguments</param> /// <param name="scalarArgs">Scalar Arguments</param> /// <param name="expr">Generated Expression</param> /// <returns>Whether an expression was successfully generated</returns> public bool TryCreateExpression(Uri u, List<ISparqlExpression> args, Dictionary<String,ISparqlExpression> scalarArgs, out ISparqlExpression expr) { //If any Scalar Arguments are present then can't possibly be a Leviathan Function if (scalarArgs.Count > 0) { expr = null; return false; } String func = u.ToString(); if (func.StartsWith(LeviathanFunctionFactory.LeviathanFunctionsNamespace)) { func = func.Substring(LeviathanFunctionFactory.LeviathanFunctionsNamespace.Length); ISparqlExpression lvnFunc = null; switch (func) { case LeviathanFunctionFactory.All: if (args.Count == 1) { lvnFunc = new NonNumericAggregateExpressionTerm(new AllAggregate(args.First())); } else if (args.Count == 2 && args.First() is DistinctModifierExpression) { lvnFunc = new NonNumericAggregateExpressionTerm(new AllAggregate(args.Last(), true)); } else { throw new RdfParseException("Incorrect number of arguments for Leviathan all() aggregate"); } break; case LeviathanFunctionFactory.Any: if (args.Count == 1) { lvnFunc = new NonNumericAggregateExpressionTerm(new AnyAggregate(args.First())); } else if (args.Count == 2 && args.First() is DistinctModifierExpression) { lvnFunc = new NonNumericAggregateExpressionTerm(new AnyAggregate(args.Last(), true)); } else { throw new RdfParseException("Incorrect number of arguments for Leviathan any() aggregate"); } break; case LeviathanFunctionFactory.Cartesian: if (args.Count == 4) { lvnFunc = new LeviathanCartesianFunction(args[0], args[1], args[2], args[3]); } else if (args.Count == 6) { lvnFunc = new LeviathanCartesianFunction(args[0], args[1], args[2], args[3], args[4], args[5]); } else { throw new RdfParseException("Incorrect number of arguments for Leviathan cartesian() function"); } break; case LeviathanFunctionFactory.Cube: if (args.Count == 1) { lvnFunc = new LeviathanCubeFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan cube() function"); } break; case LeviathanFunctionFactory.DegreesToRadians: if (args.Count == 1) { lvnFunc = new LeviathanDegreesToRadiansFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan degrees-to-radians() function"); } break; case LeviathanFunctionFactory.E: if (args.Count == 1) { lvnFunc = new LeviathanEFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan e() function"); } break; case LeviathanFunctionFactory.Factorial: if (args.Count == 1) { lvnFunc = new LeviathanFactorialFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan factorial() function"); } break; case LeviathanFunctionFactory.Ln: if (args.Count == 1) { lvnFunc = new LeviathanNaturalLogFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan ln() function"); } break; case LeviathanFunctionFactory.Log: if (args.Count == 1) { lvnFunc = new LeviathanLogFunction(args.First()); } else if (args.Count == 2) { lvnFunc = new LeviathanLogFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan log() function"); } break; case LeviathanFunctionFactory.MD5Hash: if (args.Count == 1) { lvnFunc = new LeviathanMD5HashFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan md5hash() function"); } break; case LeviathanFunctionFactory.Median: if (args.Count == 1) { lvnFunc = new NonNumericAggregateExpressionTerm(new MedianAggregate(args.First())); } else if (args.Count == 2 && args.First() is DistinctModifierExpression) { lvnFunc = new NonNumericAggregateExpressionTerm(new MedianAggregate(args.Last(), true)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan median() aggregate"); } break; case LeviathanFunctionFactory.Mode: if (args.Count == 1) { lvnFunc = new NonNumericAggregateExpressionTerm(new ModeAggregate(args.First())); } else if (args.Count == 2 && args.First() is DistinctModifierExpression) { lvnFunc = new NonNumericAggregateExpressionTerm(new ModeAggregate(args.Last(), true)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan mode() aggregate"); } break; case LeviathanFunctionFactory.None: if (args.Count == 1) { lvnFunc = new NonNumericAggregateExpressionTerm(new NoneAggregate(args.First())); } else if (args.Count == 2 && args.First() is DistinctModifierExpression) { lvnFunc = new NonNumericAggregateExpressionTerm(new NoneAggregate(args.Last(), true)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan none() aggregate"); } break; case LeviathanFunctionFactory.NumericMax: if (args.Count == 1) { lvnFunc = new AggregateExpressionTerm(new NumericMaxAggregate(args.First())); } else if (args.Count == 2 && args.First() is DistinctModifierExpression) { lvnFunc = new NonNumericAggregateExpressionTerm(new NumericMaxAggregate(args.Last(), true)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan nmax() aggregate"); } break; case LeviathanFunctionFactory.NumericMin: if (args.Count == 1) { lvnFunc = new AggregateExpressionTerm(new NumericMinAggregate(args.First())); } else if (args.Count == 2 && args.First() is DistinctModifierExpression) { lvnFunc = new NonNumericAggregateExpressionTerm(new NumericMinAggregate(args.Last(), true)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan nmin() aggregate"); } break; case LeviathanFunctionFactory.Power: if (args.Count == 1) { lvnFunc = new LeviathanSquareFunction(args.First()); } else if (args.Count == 2) { lvnFunc = new LeviathanPowerFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan pow() function"); } break; case LeviathanFunctionFactory.Pythagoras: if (args.Count == 2) { lvnFunc = new LeviathanPyathagoreanDistanceFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan pythagoras() function"); } break; case LeviathanFunctionFactory.RadiansToDegrees: if (args.Count == 1) { lvnFunc = new LeviathanRadiansToDegreesFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan radians-to-degrees() function"); } break; case LeviathanFunctionFactory.Random: if (args.Count == 0) { lvnFunc = new LeviathanRandomFunction(); } else if (args.Count == 1) { lvnFunc = new LeviathanRandomFunction(args.First()); } else if (args.Count == 2) { lvnFunc = new LeviathanRandomFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan rnd() function"); } break; case LeviathanFunctionFactory.Reciprocal: if (args.Count == 1) { lvnFunc = new LeviathanReciprocalFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan reciprocal() function"); } break; case LeviathanFunctionFactory.Root: if (args.Count == 1) { lvnFunc = new LeviathanSquareRootFunction(args.First()); } else if (args.Count == 2) { lvnFunc = new LeviathanRootFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan root() function"); } break; case LeviathanFunctionFactory.Sha256Hash: if (args.Count == 1) { lvnFunc = new LeviathanSha256HashFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan sha256hash() function"); } break; case LeviathanFunctionFactory.Square: if (args.Count == 1) { lvnFunc = new LeviathanSquareFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan sq() function"); } break; case LeviathanFunctionFactory.SquareRoot: if (args.Count == 1) { lvnFunc = new LeviathanSquareRootFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan sqrt() function"); } break; case LeviathanFunctionFactory.Ten: if (args.Count == 1) { lvnFunc = new LeviathanTenFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan ten() function"); } break; case LeviathanFunctionFactory.TrigCos: case LeviathanFunctionFactory.TrigCosInv: if (args.Count == 1) { lvnFunc = new LeviathanCosineFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigCosInv)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function"); } break; case LeviathanFunctionFactory.TrigCosec: case LeviathanFunctionFactory.TrigCosecInv: if (args.Count == 1) { lvnFunc = new LeviathanCosecantFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigCosecInv)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function"); } break; case LeviathanFunctionFactory.TrigCotan: case LeviathanFunctionFactory.TrigCotanInv: if (args.Count == 1) { lvnFunc = new LeviathanCotangentFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigCotanInv)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function"); } break; case LeviathanFunctionFactory.TrigSec: case LeviathanFunctionFactory.TrigSecInv: if (args.Count == 1) { lvnFunc = new LeviathanSecantFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigSecInv)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function"); } break; case LeviathanFunctionFactory.TrigSin: case LeviathanFunctionFactory.TrigSinInv: if (args.Count == 1) { lvnFunc = new LeviathanSineFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigSinInv)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function"); } break; case LeviathanFunctionFactory.TrigTan: case LeviathanFunctionFactory.TrigTanInv: if (args.Count == 1) { lvnFunc = new LeviathanTangentFunction(args.First(), func.Equals(LeviathanFunctionFactory.TrigTanInv)); } else { throw new RdfParseException("Incorrect number of arguments for the Leviathan " + func + "() function"); } break; } if (lvnFunc != null) { expr = lvnFunc; return true; } } expr = null; return false; }