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); }
public AnomalousIngredientNode( Guid id, string name, UnitType convtype, Weight unitweight, DefaultPairings pairings) : base(id, name, convtype, unitweight, pairings) { }
public IngredientNode(Guid id, string name, UnitType convtype, Weight unitweight, DefaultPairings pairings) { this.id = id; this.pairings = pairings; this.convtype = convtype; this.unitweight = unitweight; this.IngredientName = name; }
} //How much a single unit weighs (from ShoppingIngredients) public IngredientNode(Guid id, string name, UnitType convtype, Weight unitweight, DefaultPairings pairings) { this.id = id; this.pairings = pairings; this.convtype = convtype; this.unitweight = unitweight; IngredientName = name; }
public AnomalousIngredientNode(Guid id, string name, UnitType convtype, Weight unitweight, DefaultPairings pairings) : base(id, name, convtype, unitweight, pairings) { }
private static void LoadDefaultForm(MatchData matchdata, IngredientUsage result, DefaultPairings pairings) { if (matchdata.Unit == null || matchdata.Unit.Unit == Units.Unit) //TODO: Is second part necessary? Only Units.Unit would be custom form types, and we'd have errored out already if that didn't match { result.Form = pairings.Unit; NlpTracer.ConditionalTrace(pairings.HasUnit, TraceLevel.Debug, "[BuildResult] Linking to default Unit paired form {0}", pairings.Unit); } else { switch (Unit.GetConvType(matchdata.Unit.Unit)) { case UnitType.Volume: result.Form = pairings.Volume; NlpTracer.ConditionalTrace(pairings.HasVolume, TraceLevel.Debug, "[BuildResult] Linking to default paired Volume form {0}", pairings.Volume); break; case UnitType.Weight: result.Form = pairings.Weight; NlpTracer.ConditionalTrace(pairings.HasWeight, TraceLevel.Debug, "[BuildResult] Linking to default paired Weight form {0}", pairings.Weight); break; } } if (result.Form == null && result.Amount.Unit == Units.Ounce && pairings.HasVolume) //Try as FluidOunces because so many recipes use oz when they mean fl oz { result.Form = pairings.Volume; result.Amount.Unit = Units.FluidOunce; NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] Interpretting reference to Ounces as Fluid Ounces and linking to volumetric form {0}", pairings.Volume); } if (result.Form == null) { NlpTracer.Trace(TraceLevel.Debug, "[BuildResult] Could not find any default pairing for the unit type: {0}", result.Amount.Unit); } }
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; }