public ParsedDirection[] ParseTokens(string str) { var array = SplitString(str); ParsedDirection[] result; if (array.Length == 0) { result = new ParsedDirection[0]; } else { var list = new List <ParsedDirection>(); var possibleNext = ProbsDic.GetPossibleNext(null); var array2 = possibleNext; for (var i = 0; i < array2.Length; i++) { var nodeType = array2[i]; var parserNode = new ParserNode(nodeType, null); var collection = parserNode.ParseTokens(array); list.AddRange(collection); } var num = 0.0; for (var j = list.Count - 1; j >= 0; j--) { var parsedDirection = list[j]; int num2; if (parsedDirection.Probabilidad == 0.0 || string.IsNullOrEmpty(parsedDirection.Calle) || (string.IsNullOrEmpty(parsedDirection.Esquina) && parsedDirection.Altura <= 0) || int.TryParse(parsedDirection.Calle, out num2) || int.TryParse(parsedDirection.Esquina, out num2) || int.TryParse(parsedDirection.Localidad, out num2)) { list.RemoveAt(j); } else { num += parsedDirection.Probabilidad; } } foreach (var parsedDirection in list) { parsedDirection.Probabilidad /= num; } list.Sort(new ParsedDirectionComparer()); result = list.GetRange(0, Math.Min(5, list.Count)).ToArray(); } return(result); }
public ParsedDirection[] ParseTokens(string[] tokens) { this.Tokens = tokens; ParsedDirection[] result; if (this.Tokens.Length == 0 || !this.IsValidByToken()) { result = ParserNode.Empty; } else { if (this.Tokens.Length == 1) { result = this.CreateDirection(this.Tokens[0]); } else { string[] tokens2 = this.NextTokens(); List <ParsedDirection> list = new List <ParsedDirection>(); ParserNodeTypes[] array = (this.Tokens[1] == ",") ? new ParserNodeTypes[] { this.NodeType } : ProbsDic.GetPossibleNext(this); ParserNodeTypes[] array2 = array; for (int i = 0; i < array2.Length; i++) { ParserNodeTypes parserNodeTypes = array2[i]; ParserNode parserNode = new ParserNode(parserNodeTypes, this); ParsedDirection[] collection = parserNode.ParseTokens(tokens2); list.AddRange(collection); } if (!this.OmitToken) { this.ModifyDirections(list, this.Tokens[0]); } result = list.ToArray(); } } return(result); }