Example #1
0
        public static ParserNodeTypes[] GetPossibleNext(ParserNode node)
        {
            List <ParserNodeTypes> list = new List <ParserNodeTypes>();

            ParserNodeTypes[] result;
            if (node == null)
            {
                list.Add(ParserNodeTypes.Calle);
                list.Add(ParserNodeTypes.Localidad);
                list.Add(ParserNodeTypes.Provincia);
                result = list.ToArray();
            }
            else
            {
                if (!ProbsDic.probs.ContainsKey(node.TypePath))
                {
                    result = list.ToArray();
                }
                else
                {
                    switch (node.NodeType)
                    {
                    case ParserNodeTypes.Calle:
                        list.Add(ParserNodeTypes.Calle);
                        list.Add(ParserNodeTypes.Altura);
                        list.Add(ParserNodeTypes.Equina);
                        break;

                    case ParserNodeTypes.Equina:
                        list.Add(ParserNodeTypes.Equina);
                        list.Add(ParserNodeTypes.Localidad);
                        list.Add(ParserNodeTypes.Provincia);
                        break;

                    case ParserNodeTypes.Altura:
                        list.Add(ParserNodeTypes.Localidad);
                        list.Add(ParserNodeTypes.Provincia);
                        break;

                    case ParserNodeTypes.Localidad:
                        list.Add(ParserNodeTypes.Calle);
                        list.Add(ParserNodeTypes.Altura);
                        list.Add(ParserNodeTypes.Localidad);
                        list.Add(ParserNodeTypes.Provincia);
                        break;

                    case ParserNodeTypes.Provincia:
                        list.Add(ParserNodeTypes.Calle);
                        list.Add(ParserNodeTypes.Altura);
                        list.Add(ParserNodeTypes.Localidad);
                        list.Add(ParserNodeTypes.Provincia);
                        break;
                    }
                    result = list.ToArray();
                }
            }
            return(result);
        }
Example #2
0
        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);
        }
Example #3
0
 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);
 }
Example #4
0
        public static double GetTypeProb(ParserNode node)
        {
            ParserNode parserNode = node;
            bool       flag       = false;
            double     result;

            while (parserNode.ParentNode != null)
            {
                if (flag && parserNode.ParentNode.NodeType == node.NodeType)
                {
                    result = 0.0;
                    return(result);
                }
                if (!flag && parserNode.ParentNode.NodeType != node.NodeType)
                {
                    flag = true;
                }
                parserNode = parserNode.ParentNode;
            }
            result = (ProbsDic.probs.ContainsKey(node.TypePath) ? ProbsDic.probs[node.TypePath] : 0.0);
            return(result);
        }
Example #5
0
 public ParserNode(ParserNodeTypes nodeType, ParserNode parentNode)
 {
     this.NodeType   = nodeType;
     this.ParentNode = parentNode;
 }
Example #6
0
        public static double GetProb(ParserNode node)
        {
            double result;

            switch (node.NodeType)
            {
            case ParserNodeTypes.Calle:
                if (ProbsDic.calles.Length <= node.NodeTypeIndex)
                {
                    result = 0.0;
                }
                else
                {
                    result = ProbsDic.calles[node.NodeTypeIndex];
                }
                break;

            case ParserNodeTypes.Equina:
                if (ProbsDic.calles.Length <= node.NodeTypeIndex)
                {
                    result = 0.0;
                }
                else
                {
                    result = ProbsDic.calles[node.NodeTypeIndex];
                }
                break;

            case ParserNodeTypes.Altura:
                if (ProbsDic.alturas.Length <= node.NodeTypeIndex)
                {
                    result = 0.0;
                }
                else
                {
                    result = ProbsDic.alturas[node.NodeTypeIndex];
                }
                break;

            case ParserNodeTypes.Localidad:
                if (ProbsDic.localidades.Length <= node.NodeTypeIndex)
                {
                    result = 0.0;
                }
                else
                {
                    result = ProbsDic.localidades[node.NodeTypeIndex];
                }
                break;

            case ParserNodeTypes.Provincia:
                if (ProbsDic.provincias.Length <= node.NodeTypeIndex)
                {
                    result = 0.0;
                }
                else
                {
                    result = ProbsDic.provincias[node.NodeTypeIndex];
                }
                break;

            default:
                result = 0.0;
                break;
            }
            return(result);
        }