Exemplo n.º 1
0
        public Result Parse(string input)
        {
            ReplaceAccents(ref input);
             var normalizedInput = reWhitespace.Replace(input, " ").ToLower(); //Replace 2 or more spaces with a single space since whitespace doesn't really matter

             //Loop through all loaded templates looking for a match - return that match, or return null if unknown
             var bestResult = MatchResult.NoMatch;
             foreach (var t in templates)
             {
            var result = t.Parse(normalizedInput);
            if (result is Match)
            {
               Stats[t]++;
               return result;
            }
            else
            {
               if (result.Status > bestResult)
               {
                  bestResult = result.Status;
               }
            }
             }

             NlpTracer.Trace(TraceLevel.Info, "Could not find match for usage: {0}", input);
             var ret = new NoMatch(input, bestResult);
             if (this.OnNoMatch != null)
             {
            OnNoMatch(ret, input);
             }

             return ret; //TODO: Save best match to get error code
        }
Exemplo n.º 2
0
        public Result Parse(string input)
        {
            ReplaceAccents(ref input);
            var normalizedInput = reWhitespace.Replace(input, " ").ToLower(); //Replace 2 or more spaces with a single space since whitespace doesn't really matter

            //Loop through all loaded templates looking for a match - return that match, or return null if unknown
            var bestResult = MatchResult.NoMatch;

            foreach (var t in templates)
            {
                var result = t.Parse(normalizedInput);
                if (result is Match)
                {
                    Stats[t]++;
                    return(result);
                }
                else
                {
                    if (result.Status > bestResult)
                    {
                        bestResult = result.Status;
                    }
                }
            }

            NlpTracer.Trace(TraceLevel.Info, "Could not find match for usage: {0}", input);
            var ret = new NoMatch(input, bestResult);

            if (this.OnNoMatch != null)
            {
                OnNoMatch(ret, input);
            }

            return(ret); //TODO: Save best match to get error code
        }
Exemplo n.º 3
0
        private static bool ProcessCustimUnitNode(string input, MatchData matchdata, IngredientUsage result, out Result noMatch)
        {
            IngredientForm form;

            if (UnitSynonyms.TryGetFormForIngredient(matchdata.Unit.Name, matchdata.Ingredient.Id, out form))
            {
                NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] Based on unit name {0}, linking to form id {1}",
                                matchdata.Unit.Name, form.FormId);
                result.Form = form;
            }
            else
            {
                NlpTracer.Trace(TraceLevel.Debug,
                                "[BuildResult] ERROR: Unable to find link between unit '{0}' and ingredient '{1}'.", matchdata.Unit.Name,
                                result.Ingredient.Name);
                {
                    noMatch = new NoMatch(input, MatchResult.UnknownUnit);
                    return(true);
                }
            }
            noMatch = null;
            return(false);
        }
Exemplo n.º 4
0
        private static bool ProcessMatchDataNullForm(string input, MatchData matchdata, IngredientUsage result,
                                                     out Result buildResultNullForm)
        {
            IngredientForm form;

            if (FormSynonyms.TryGetFormForIngredient(matchdata.Form.FormName, matchdata.Ingredient.Id, out form))
            {
                NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] Based on reference to form {0}, linking to form id {1}",
                                matchdata.Form.FormName, form.FormId);
                result.Form = form;
            }
            else
            {
                NlpTracer.Trace(TraceLevel.Debug,
                                "[BuildResult] ERROR: Unable to find link between form '{0}' and ingredient '{1}.", matchdata.Form.FormName,
                                result.Ingredient.Name);
                {
                    buildResultNullForm = new NoMatch(input, MatchResult.UnknownForm);
                    return(true);
                }
            }
            buildResultNullForm = null;
            return(false);
        }
Exemplo n.º 5
0
 private static bool ProcessMatchDataNullForm(string input, MatchData matchdata, IngredientUsage result,
    out Result buildResultNullForm)
 {
     IngredientForm form;
        if (FormSynonyms.TryGetFormForIngredient(matchdata.Form.FormName, matchdata.Ingredient.Id, out form))
        {
        NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] Based on reference to form {0}, linking to form id {1}",
            matchdata.Form.FormName, form.FormId);
        result.Form = form;
        }
        else
        {
        NlpTracer.Trace(TraceLevel.Debug,
            "[BuildResult] ERROR: Unable to find link between form '{0}' and ingredient '{1}.", matchdata.Form.FormName,
            result.Ingredient.Name);
        {
            buildResultNullForm = new NoMatch(input, MatchResult.UnknownForm);
            return true;
        }
        }
        buildResultNullForm = null;
        return false;
 }
Exemplo n.º 6
0
 private static bool ProcessCustimUnitNode(string input, MatchData matchdata, IngredientUsage result, out Result noMatch)
 {
     IngredientForm form;
        if (UnitSynonyms.TryGetFormForIngredient(matchdata.Unit.Name, matchdata.Ingredient.Id, out form))
        {
        NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] Based on unit name {0}, linking to form id {1}",
            matchdata.Unit.Name, form.FormId);
        result.Form = form;
        }
        else
        {
        NlpTracer.Trace(TraceLevel.Debug,
            "[BuildResult] ERROR: Unable to find link between unit '{0}' and ingredient '{1}'.", matchdata.Unit.Name,
            result.Ingredient.Name);
        {
            noMatch = new NoMatch(input, MatchResult.UnknownUnit);
            return true;
        }
        }
        noMatch = null;
        return false;
 }