Esempio n. 1
0
        public void Setup()
        {
            //Initialize all the maps
             Trace.Write("Initializing NLP Grammar maps... ");

             IngredientSynonyms.InitIndex(new TestIngredientLoader());
             UnitSynonyms.InitIndex(new TestUnitLoader());
             FormSynonyms.InitIndex(new TestFormLoader());
             PrepNotes.InitIndex(new TestPrepLoader());
             NumericVocab.InitIndex();

             //Load parse templates
             parser = new Parser();
             Trace.Write("Loading parse templates... ");

             parser.LoadTemplates(
            "[ING]: [AMT] [UNIT]", //cheddar cheese: 5 cups
            "[AMT] [UNIT] [FORM] [ING]", //5 cups melted cheddar cheese
            "[AMT] [UNIT] [ING]", //5 cups cheddar cheese
            "[AMT] [UNIT] of [ING]", //5 cups of cheddar cheese
            "[AMT] [UNIT] of [FORM] [ING]", //two cups of shredded cheddar cheese
            "[AMT] [ING]", //5 eggs
            "[ING]: [AMT]", //eggs: 5
            "[FORM] [ING]: [AMT]", //shredded cheddar cheese: 1 cup
            "[FORM] [ING]: [AMT] [UNIT]", //shredded cheddar cheese: 1 cup

            "[ING]: [AMT] [UNIT], [PREP]", //cheddar cheese: 5 cups
            "[AMT] [UNIT] [FORM] [ING], [PREP]", //5 cups melted cheddar cheese
            "[AMT] [UNIT] [ING], [PREP]", //5 cups cheddar cheese
            "[AMT] [UNIT] of [ING], [PREP]", //5 cups of cheddar cheese
            "[AMT] [UNIT] of [FORM] [ING], [PREP]", //two cups of shredded cheddar cheese
            "[AMT] [ING], [PREP]", //5 eggs
            "[ING]: [AMT], [PREP]", //eggs: 5
            "[FORM] [ING]: [AMT], [PREP]", //shredded cheddar cheese: 1 cup
            "[FORM] [ING]: [AMT] [UNIT], [PREP]" //shredded cheddar cheese: 1 cup
            );
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes the context and loads necessary data into memory through the configured database adapter.
        /// This must be done before the context is usable.
        /// </summary>
        public virtual void Initialize()
        {
            if (this.Adapter == null)
            {
                throw new InvalidConfigurationException("DBContext requires a configured database adapter.  Please check your configuration.");
            }

            // Initiaze NHibernate session
            this.Adapter.Initialize(this);

            new Thread(delegate()
            {
                using (InitLock.WriteLock())
                {
                    // Initialize ingredient parser
                    this.ingredientParser = new IngredientParser();
                    var ingredientIndex = this.Adapter.LoadIngredientsForIndex();
                    this.ingredientParser.CreateIndex(ingredientIndex);

                    // Initialize modeler
                    this.modeler = new ModelerProxy(this);
                    this.modeler.LoadSnapshot();

                    // Initialize natural language parsing
                    IngredientSynonyms.InitIndex(this.Adapter.IngredientLoader);
                    UnitSynonyms.InitIndex(this.Adapter.UnitLoader);
                    FormSynonyms.InitIndex(this.Adapter.FormLoader);
                    PrepNotes.InitIndex(this.Adapter.PrepLoader);
                    Anomalies.InitIndex(this.Adapter.AnomalyLoader);
                    NumericVocab.InitIndex();

                    this.parser = new Parser();
                    this.LoadTemplates();
                }
            }).Start();

            Thread.Sleep(500); // Provides time for initialize thread to start and acquire InitLock
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes the context and loads necessary data into memory through the configured data file.
        /// This must be done before the context is usable.
        /// </summary>
        public void Initialize()
        {
            var file = CompressedStore ? "KPCData.gz" : "KPCData.xml";
             var path = Path.Combine(DataDirectory, file);
             KPCContext.Log.DebugFormat("Attempting to open local data file: {0}", path);

             if (!File.Exists(path))
            throw new FileNotFoundException("Could not initialize StaticContext.  Data file not found.", path);

             var serializer = new XmlSerializer(typeof (DataStore));
             using (var fileReader = new FileStream(path, FileMode.Open))
             {
            if (CompressedStore)
            {
               using (var reader = new GZipStream(fileReader, CompressionMode.Decompress))
               {
                  store = serializer.Deserialize(reader) as DataStore;
               }
            }
            else
            {
               store = serializer.Deserialize(fileReader) as DataStore;
            }

            if (store == null)
               throw new DataStoreException("Could not deserialize data store.  It might be correct or an invalid format.");
             }

             // Initialize ingredient parser
             ingParser = new IngredientParser();
             ingParser.CreateIndex(store.Ingredients.Select(i => new IngredientSource(i.IngredientId, i.DisplayName)));

             // Initialize modeler
             ModelerProxy = new ModelerProxy(this);
             ModelerProxy.LoadSnapshot();

             // Initialize natural language parsing
             IngredientSynonyms.InitIndex(new StaticIngredientLoader(store));
             UnitSynonyms.InitIndex(new StaticUnitLoader(store));
             FormSynonyms.InitIndex(new StaticFormLoader(store));
             PrepNotes.InitIndex(new StaticPrepLoader(store));
             Anomalies.InitIndex(new StaticAnomalyLoader(store));
             NumericVocab.InitIndex();

             Parser = new Parser();
             LoadTemplates();
        }