private static bool ProcessAnomalousMatch(string input, MatchData matchdata, IngredientUsage result, UnitType parsedType, out Result anomalousMatch) { NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] Checking for form matching prep note: {0}", matchdata.Preps); IngredientForm form; if (FormSynonyms.TryGetFormForPrep(matchdata.Preps, matchdata.Ingredient, true, out form)) { result.Form = form; if (parsedType == Unit.GetConvType(result.Form.FormUnitType)) { NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] SUCCESS: Found matching volumetric form, allowing prep to form fall-through."); result.PrepNote = matchdata.Preps.ToString(); { anomalousMatch = new AnomalousMatch(input, AnomalousResult.Fallthrough, result); return(true); } } else { NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] Found matching form, but form is not compatible with volumetric usage."); } } anomalousMatch = null; return(false); }
private static bool AutoFormConvert(string input, MatchData matchdata, IngredientUsage result, UnitType parsedType, DefaultPairings pairings, out Result autoConvertResult) { NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] Form and unit incompatible - attempting to auto-convert form {0}", result.Form); var formType = Unit.GetConvType(result.Form.FormUnitType); if (parsedType == UnitType.Weight && formType == UnitType.Volume && pairings.HasWeight) //Something like 3oz shredded cheddar cheese, we need to use a weight form and set prep note { NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] SUCCESS: Converting to default weight pairing, and setting prep note to: {0}", result.Form.FormDisplayName); result.PrepNote = result.Form.FormDisplayName; result.Form = pairings.Weight; { autoConvertResult = new AnomalousMatch(input, AnomalousResult.AutoConvert, result); return(true); } } else if (parsedType == UnitType.Unit && formType == UnitType.Volume) //Something like 3 mashed bananas { if (pairings.HasUnit && (matchdata.Unit == null || String.IsNullOrEmpty(matchdata.Unit.Name))) //No custom unit, just use default pairing { NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] SUCCESS: Converting to default unit pairing, and setting prep note to: {0}", result.Form.FormDisplayName); result.PrepNote = result.Form.FormDisplayName; result.Form = pairings.Unit; { autoConvertResult = new AnomalousMatch(input, AnomalousResult.AutoConvert, result); return(true); } } if (matchdata.Unit != null && false == String.IsNullOrEmpty(matchdata.Unit.Name)) //We have a custom unit { IngredientForm form; NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] Attempting to convert volumetric usage to unit form for custom unit: {0}", matchdata.Unit.Name); if (UnitSynonyms.TryGetFormForIngredient(matchdata.Unit.Name, matchdata.Ingredient.Id, out form)) { NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] SUCCESS: Converting to custom unit pairing, and setting prep note to: {0}", result.Form.FormDisplayName); result.PrepNote = result.Form.FormDisplayName; result.Form = form; { autoConvertResult = new AnomalousMatch(input, AnomalousResult.AutoConvert, result); return(true); } } } } autoConvertResult = null; return(false); }
private static bool ProcessAnomalousMatch(string input, MatchData matchdata, IngredientUsage result, UnitType parsedType, out Result anomalousMatch) { NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] Checking for form matching prep note: {0}", matchdata.Preps); IngredientForm form; if (FormSynonyms.TryGetFormForPrep(matchdata.Preps, matchdata.Ingredient, true, out form)) { result.Form = form; if (parsedType == Unit.GetConvType(result.Form.FormUnitType)) { NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] SUCCESS: Found matching volumetric form, allowing prep to form fall-through."); result.PrepNote = matchdata.Preps.ToString(); { anomalousMatch = new AnomalousMatch(input, AnomalousResult.Fallthrough, result); return true; } } else { NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] Found matching form, but form is not compatible with volumetric usage."); } } anomalousMatch = null; return false; }
private static bool AutoFormConvert(string input, MatchData matchdata, IngredientUsage result, UnitType parsedType, DefaultPairings pairings, out Result autoConvertResult) { NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] Form and unit incompatible - attempting to auto-convert form {0}", result.Form); var formType = Unit.GetConvType(result.Form.FormUnitType); if (parsedType == UnitType.Weight && formType == UnitType.Volume && pairings.HasWeight) //Something like 3oz shredded cheddar cheese, we need to use a weight form and set prep note { NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] SUCCESS: Converting to default weight pairing, and setting prep note to: {0}", result.Form.FormDisplayName); result.PrepNote = result.Form.FormDisplayName; result.Form = pairings.Weight; { autoConvertResult = new AnomalousMatch(input, AnomalousResult.AutoConvert, result); return true; } } else if (parsedType == UnitType.Unit && formType == UnitType.Volume) //Something like 3 mashed bananas { if (pairings.HasUnit && (matchdata.Unit == null || String.IsNullOrEmpty(matchdata.Unit.Name))) //No custom unit, just use default pairing { NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] SUCCESS: Converting to default unit pairing, and setting prep note to: {0}", result.Form.FormDisplayName); result.PrepNote = result.Form.FormDisplayName; result.Form = pairings.Unit; { autoConvertResult = new AnomalousMatch(input, AnomalousResult.AutoConvert, result); return true; } } if (matchdata.Unit != null && false == String.IsNullOrEmpty(matchdata.Unit.Name)) //We have a custom unit { IngredientForm form; NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] Attempting to convert volumetric usage to unit form for custom unit: {0}", matchdata.Unit.Name); if (UnitSynonyms.TryGetFormForIngredient(matchdata.Unit.Name, matchdata.Ingredient.Id, out form)) { NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] SUCCESS: Converting to custom unit pairing, and setting prep note to: {0}", result.Form.FormDisplayName); result.PrepNote = result.Form.FormDisplayName; result.Form = form; { autoConvertResult = new AnomalousMatch(input, AnomalousResult.AutoConvert, result); return true; } } } } autoConvertResult = null; return false; }