protected ParsedDirection[] ModifyDirections(IEnumerable <ParsedDirection> dirs, string token) { int altura; bool flag = int.TryParse(token, out altura); foreach (ParsedDirection current in dirs) { switch (this.NodeType) { case ParserNodeTypes.Calle: current.Calle = token + " " + current.Calle; break; case ParserNodeTypes.Equina: current.Esquina = token + " " + current.Esquina; break; case ParserNodeTypes.Altura: if (flag) { current.Altura = altura; } break; case ParserNodeTypes.Localidad: current.Localidad = token + " " + current.Localidad; break; case ParserNodeTypes.Provincia: current.Provincia = token + " " + current.Provincia; break; } bool flag2 = this.ParentNode == null || (this.ParentNode != null && this.ParentNode.NodeType != this.NodeType); current.Probabilidad *= (flag2 ? ProbsDic.GetTypeProb(this) : ProbsDic.GetProb(this)); if (flag && this.NodeType != ParserNodeTypes.Altura) { current.Probabilidad *= 0.1; } if (this.ParentNode != null && this.ParentNode.Tokens[0] == "y" && this.NodeType != ParserNodeTypes.Equina) { current.Probabilidad *= 0.2; } } return(new List <ParsedDirection>(dirs).ToArray()); }
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); }