public IEnumerable <IngredientNode> LoadSynonyms()
        {
            var eggPairings = new DefaultPairings()
            {
                Unit = new IngredientForm(FORM_EGG_UNIT, ING_EGGS, Units.Unit, null, "egg/eggs", 0, null)
            };

            var bananaPairings = new DefaultPairings()
            {
                Unit = new IngredientForm(FORM_BANANA_UNIT, ING_BANANAS, Units.Unit, null, "banana/bananas", 0, null)
            };

            var milkPairings = new DefaultPairings()
            {
                Volume = new IngredientForm(FORM_MILK_VOLUME, ING_MILK, Units.Cup, null, null, 0, null)
            };

            var flourPairings = new DefaultPairings()
            {
                Volume = new IngredientForm(FORM_FLOUR_VOLUME, ING_FLOUR, Units.Cup, null, null, 0, null),
                Weight = new IngredientForm(FORM_FLOUR_WEIGHT, ING_FLOUR, Units.Ounce, null, null, 0, null)
            };

            var cheese  = new IngredientNode(ING_CHEESE, "cheddar cheese", UnitType.Weight, 0, DefaultPairings.Empty);
            var eggs    = new IngredientNode(ING_EGGS, "eggs", UnitType.Unit, 0, eggPairings);
            var bananas = new IngredientNode(ING_BANANAS, "bananas", UnitType.Weight, 0, bananaPairings);
            var milk    = new IngredientNode(ING_MILK, "milk", UnitType.Volume, 0, milkPairings);
            var flour   = new IngredientNode(ING_FLOUR, "all-purpose flour", UnitType.Weight, 0, flourPairings);
            var lettuce = new IngredientNode(ING_LETTUCE, "lettuce", UnitType.Weight, 0, DefaultPairings.Empty);

            //Add in some test ingredients, but this will eventually come from a massive Synonyms database
            //DB will first load ShoppingIngredients and create root nodes for all of those, with default form data, then will load IngredientSynonyms for all aliases
            //TODO: Maybe there is a way to have ingredient nodes contain a singular and plural description so we don't need aliases for all the singulars
            IngredientNode[] ings =
            {
                //Load root nodes for ingredients
                cheese,
                eggs,
                bananas,
                milk,
                flour,
                lettuce,

                //Load any aliases for any ingredients
                new IngredientNode(eggs,   "egg",           null),
                new IngredientNode(bananas,"banana",        null),
                new IngredientNode(bananas,"ripe banana",   "ripe"),
                new IngredientNode(bananas,"ripe bananas",  "ripe"),
                new IngredientNode(milk,   "2% milk",       null),
                new IngredientNode(flour,  "flour",         null)
            };

            return(ings);
        }
Exemple #2
0
        public IEnumerable <AnomalousNode> LoadSynonyms()
        {
            using (var session = adapter.GetStatelessSession())
            {
                var anomalies = session.QueryOver <NlpAnomalousIngredients>()
                                .Fetch(prop => prop.Ingredient).Eager()
                                .Fetch(prop => prop.WeightForm).Eager()
                                .Fetch(prop => prop.VolumeForm).Eager()
                                .Fetch(prop => prop.UnitForm).Eager()
                                .List();

                var ret = new List <AnomalousNode>();

                foreach (var anon in anomalies)
                {
                    var name    = anon.Name;
                    var ing     = anon.Ingredient.IngredientId;
                    var ingName = anon.Ingredient.DisplayName;

                    IngredientForm weightForm = null, volumeForm = null, unitForm = null;
                    if (anon.WeightForm != null)
                    {
                        weightForm = new IngredientForm(
                            anon.WeightForm.IngredientFormId,
                            ing,
                            anon.WeightForm.UnitType,
                            anon.WeightForm.FormDisplayName,
                            anon.WeightForm.UnitName,
                            anon.WeightForm.ConvMultiplier,
                            new Amount(anon.WeightForm.FormAmount, anon.WeightForm.FormUnit));
                    }

                    if (anon.VolumeForm != null)
                    {
                        volumeForm = new IngredientForm(
                            anon.VolumeForm.IngredientFormId,
                            ing,
                            anon.VolumeForm.UnitType,
                            anon.VolumeForm.FormDisplayName,
                            anon.VolumeForm.UnitName,
                            anon.VolumeForm.ConvMultiplier,
                            new Amount(anon.VolumeForm.FormAmount, anon.VolumeForm.FormUnit));
                    }

                    if (anon.UnitForm != null)
                    {
                        unitForm = new IngredientForm(
                            anon.UnitForm.IngredientFormId,
                            ing,
                            anon.UnitForm.UnitType,
                            anon.UnitForm.FormDisplayName,
                            anon.UnitForm.UnitName,
                            anon.UnitForm.ConvMultiplier,
                            new Amount(anon.UnitForm.FormAmount, anon.UnitForm.FormUnit));
                    }

                    var pairings = new DefaultPairings()
                    {
                        Weight = weightForm, Volume = volumeForm, Unit = unitForm
                    };
                    var ingNode = new AnomalousIngredientNode(ing, ingName, UnitType.Unit, 0, pairings); //TODO: Must load conv type and unit weight
                    ret.Add(new AnomalousNode(name, ingNode));
                }

                return(ret);
            }
        }
        public IEnumerable <IngredientNode> LoadSynonyms()
        {
            using (var session = adapter.GetStatelessSession())
            {
                var nodes = new Dictionary <Guid, IngredientNode>();

                var ingsForNlp = session.QueryOver <Models.Ingredients>().List();
                var pairingMap = session.QueryOver <NlpDefaultPairings>()
                                 .Fetch(prop => prop.WeightForm).Eager()
                                 .Fetch(prop => prop.VolumeForm).Eager()
                                 .Fetch(prop => prop.UnitForm).Eager()
                                 .List()
                                 .ToDictionary(p => p.Ingredient.IngredientId);

                foreach (var ing in ingsForNlp)
                {
                    var    ingId      = ing.IngredientId;
                    var    name       = ing.DisplayName;
                    var    convType   = ing.ConversionType;
                    Weight unitWeight = ing.UnitWeight;
                    var    pairings   = new DefaultPairings();

                    NlpDefaultPairings defaultPairing;
                    if (pairingMap.TryGetValue(ingId, out defaultPairing))
                    {
                        if (defaultPairing.WeightForm != null)
                        {
                            var wfAmount = new Amount(defaultPairing.WeightForm.FormAmount, defaultPairing.WeightForm.FormUnit);
                            pairings.Weight = new IngredientForm(defaultPairing.WeightForm.IngredientFormId, ingId, Units.Ounce, null, null, defaultPairing.WeightForm.ConvMultiplier, wfAmount);
                        }

                        if (defaultPairing.VolumeForm != null)
                        {
                            var vfAmount = new Amount(defaultPairing.VolumeForm.FormAmount, defaultPairing.VolumeForm.FormUnit);
                            pairings.Volume = new IngredientForm(defaultPairing.VolumeForm.IngredientFormId, ingId, Units.Cup, null, null, defaultPairing.VolumeForm.ConvMultiplier, vfAmount);
                        }

                        if (defaultPairing.UnitForm != null)
                        {
                            var ufAmount = new Amount(defaultPairing.UnitForm.FormAmount, defaultPairing.UnitForm.FormUnit);
                            pairings.Unit = new IngredientForm(defaultPairing.UnitForm.IngredientFormId, ingId, Units.Unit, null, null, defaultPairing.UnitForm.ConvMultiplier, ufAmount);
                        }
                    }

                    if (nodes.ContainsKey(ingId))
                    {
                        Parser.Log.ErrorFormat("[NLP Loader] Duplicate ingredient key due to bad DB data: {0} ({1})", name, ingId);
                    }
                    else
                    {
                        nodes.Add(ingId, new IngredientNode(ingId, name, convType, unitWeight, pairings));
                    }
                }

                //Load synonyms
                var ingSynonyms = session.QueryOver <NlpIngredientSynonyms>().List();

                var ret = new List <IngredientNode>();
                foreach (var syn in ingSynonyms)
                {
                    var ingId    = syn.Ingredient.IngredientId;
                    var alias    = syn.Alias;
                    var prepnote = syn.Prepnote;

                    IngredientNode node;
                    if (nodes.TryGetValue(ingId, out node)) //TODO: If this fails, maybe throw an exception?
                    {
                        ret.Add(new IngredientNode(node, alias, prepnote));
                    }
                }

                ret.AddRange(nodes.Values);

                return(ret);
            }
        }
Exemple #4
0
        public IEnumerable <AnomalousNode> LoadSynonyms()
        {
            var forms       = store.GetIndexedIngredientForms();
            var ingredients = store.GetIndexedIngredients();
            var anomalies   = store.NlpAnomalousIngredients;

            var ret = new List <AnomalousNode>();

            foreach (var anon in anomalies)
            {
                var ingredient = ingredients[anon.IngredientId];

                var name    = anon.Name;
                var ing     = anon.IngredientId;
                var ingName = ingredient.DisplayName;

                IngredientForm weightForm = null, volumeForm = null, unitForm = null;
                if (anon.WeightFormId.HasValue)
                {
                    var wf = forms[anon.WeightFormId.Value];

                    weightForm = new IngredientForm(
                        wf.IngredientFormId,
                        ing,
                        wf.UnitType,
                        wf.FormDisplayName,
                        wf.UnitName,
                        wf.ConvMultiplier,
                        new Amount(wf.FormAmount, wf.FormUnit));
                }

                if (anon.VolumeFormId.HasValue)
                {
                    var vf = forms[anon.VolumeFormId.Value];

                    volumeForm = new IngredientForm(
                        vf.IngredientFormId,
                        ing,
                        vf.UnitType,
                        vf.FormDisplayName,
                        vf.UnitName,
                        vf.ConvMultiplier,
                        new Amount(vf.FormAmount, vf.FormUnit));
                }

                if (anon.UnitFormId.HasValue)
                {
                    var uf = forms[anon.UnitFormId.Value];

                    unitForm = new IngredientForm(
                        uf.IngredientFormId,
                        ing,
                        uf.UnitType,
                        uf.FormDisplayName,
                        uf.UnitName,
                        uf.ConvMultiplier,
                        new Amount(uf.FormAmount, uf.FormUnit));
                }

                var pairings = new DefaultPairings()
                {
                    Weight = weightForm, Volume = volumeForm, Unit = unitForm
                };
                var ingNode = new AnomalousIngredientNode(ing, ingName, UnitType.Unit, 0, pairings); //TODO: Must load conv type and unit weight
                ret.Add(new AnomalousNode(name, ingNode));
            }

            return(ret);
        }
        public IEnumerable <NLP.IngredientNode> LoadSynonyms()
        {
            var nodes = new Dictionary <Guid, NLP.IngredientNode>();

            var forms      = store.GetIndexedIngredientForms();
            var ingsForNlp = store.Ingredients;
            var pairingMap = store.NlpDefaultPairings.ToDictionary(p => p.IngredientId);

            foreach (var ing in ingsForNlp)
            {
                var    ingId      = ing.IngredientId;
                var    name       = ing.DisplayName;
                var    convType   = ing.ConversionType;
                Weight unitWeight = ing.UnitWeight;
                var    pairings   = new DefaultPairings();

                NlpDefaultPairings defaultPairing;
                if (pairingMap.TryGetValue(ingId, out defaultPairing))
                {
                    if (defaultPairing.WeightFormId.HasValue)
                    {
                        var wf       = forms[defaultPairing.WeightFormId.Value];
                        var wfAmount = new Amount(wf.FormAmount, wf.FormUnit);
                        pairings.Weight = new IngredientForm(wf.IngredientFormId, ingId, Units.Ounce, null, null, wf.ConvMultiplier, wfAmount);
                    }

                    if (defaultPairing.VolumeFormId.HasValue)
                    {
                        var vf       = forms[defaultPairing.VolumeFormId.Value];
                        var vfAmount = new Amount(vf.FormAmount, vf.FormUnit);
                        pairings.Volume = new IngredientForm(vf.IngredientFormId, ingId, Units.Cup, null, null, vf.ConvMultiplier, vfAmount);
                    }

                    if (defaultPairing.UnitFormId.HasValue)
                    {
                        var uf       = forms[defaultPairing.UnitFormId.Value];
                        var ufAmount = new Amount(uf.FormAmount, uf.FormUnit);
                        pairings.Unit = new IngredientForm(uf.IngredientFormId, ingId, Units.Unit, null, null, uf.ConvMultiplier, ufAmount);
                    }
                }

                if (nodes.ContainsKey(ingId))
                {
                    Parser.Log.ErrorFormat("[NLP Loader] Duplicate ingredient key due to bad DB data: {0} ({1})", name, ingId);
                }
                else
                {
                    nodes.Add(ingId, new NLP.IngredientNode(ingId, name, convType, unitWeight, pairings));
                }
            }

            //Load synonyms
            var ingSynonyms = store.NlpIngredientSynonyms;

            var ret = new List <NLP.IngredientNode>();

            foreach (var syn in ingSynonyms)
            {
                var ingId    = syn.IngredientId;
                var alias    = syn.Alias;
                var prepnote = syn.Prepnote;

                NLP.IngredientNode node;
                if (nodes.TryGetValue(ingId, out node)) //TODO: If this fails, maybe throw an exception?
                {
                    ret.Add(new NLP.IngredientNode(node, alias, prepnote));
                }
            }

            ret.AddRange(nodes.Values);

            return(ret);
        }