コード例 #1
0
 //--------------------------------------------------------------------------
 public void CreateTable()
 {
     WordsDao.CreateTable();
     _wordIdIndex.Clear();
     _wordIndex.Clear();
     _words.Clear();
 }
コード例 #2
0
        //-------------------------------------------------------------------------
        public void Import(XmlDocument document)
        {
            _wordIndex.Clear();
            _wordIdIndex.Clear();
            _words.Clear();

            GlobalParamatersService.Delegate.OnDatabaseImportProgress(0);

            DatabaseConnectionService.Instance.SafeTransaction(_ => {
                XmlNodeList xmlWords = document.DocumentElement.SelectNodes(".//word");

                int total     = xmlWords.Count;
                int processed = 0;

                foreach (XmlNode xmlWord in xmlWords)
                {
                    Word word = WordsDao.Import(xmlWord);
                    _words.Add(word);
                    IndexWord(word);

                    processed++;
                    float percent = (float)processed / (float)total;
                    percent      *= 100;
                    GlobalParamatersService.Delegate.OnDatabaseImportProgress(
                        (int)percent);
                }
            });
        }
コード例 #3
0
 //--------------------------------------------------------------------------
 public void DropTable()
 {
     WordsDao.DropTable();
     _wordIdIndex.Clear();
     _wordIndex.Clear();
     _words.Clear();
 }
コード例 #4
0
        //--------------------------------------------------------------------------
        /// <summary>
        /// The function uses all information in SQL tables in the program mySQL and
        /// builds a new XML file containing all that information.
        /// The XML file describes all the books'information
        /// </summary>
        public void ExportDatabase(FileInfo filename)
        {
            Initialize();

            DataSet ds = new DataSet();

            ds.DataSetName = "books-concordance";
            DocumentsDao.FillDataSet(ds);
            WordsDao.FillDataSet(ds);
            ContainsDao.FillDataSet(ds);
            RelationsDao.FillDataSet(ds);
            GroupsDao.FillDataSet(ds);
            PhrasesDao.FillDataSet(ds);

            ds.WriteXml(filename.FullName);

            DocumentsService.Instance.ExportStorage(filename);
        }
コード例 #5
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// get a DB Word element for a given string
        /// If the word doesn't exist in-memory, we assume it doesn't exist in the
        /// DB and so we try to add it - if that fails, we try to query it -
        /// otherwise we throw an exception
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public Word GetWord(string value)
        {
            // we only want to store lower case words so that our DB dosn't explode
            // of word permutations
            value = value.ToLower();

            if (_wordIndex.ContainsKey(value))
            {
                return(_wordIndex[value]);
            }

            // doesn't exist - so we need to add it
            Word word = WordsDao.Insert(value);

            _words.Add(word);
            IndexWord(word);

            return(word);
        }
コード例 #6
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Should only be called once.
        ///
        /// Loads all the existing words from the DB and puts them into in-memory
        /// indices for optimized performance
        /// </summary>
        public bool Initialize()
        {
            // clear data structures
            if (_words != null)
            {
                _words.Clear();
            }

            _wordIndex.Clear();
            _wordIdIndex.Clear();

            try {
                WordsDao.GetAll(out _words);

                foreach (Word word in _words)
                {
                    IndexWord(word);
                }
            } catch (Exception e) {
                throw e;
            }

            return(true);
        }