Esempio n. 1
0
        //--------------------------------------------------------------------------
        public Phrase AddPhrase(string phrase)
        {
            DocumentParser parsedPhrase = DocumentParser.FromPhrase(phrase);

            DocumentWord documentWord = null;
            List <Word>  words        = new List <Word>();

            while (parsedPhrase.GetNextWord(out documentWord))
            {
                Word word = WordsService.Instance.GetWord(documentWord.Text);
                words.Add(word);
            }

            if (words.Count < kMinimalWordsInPhrase)
            {
                throw new Exception("Phrases must have, at least, " +
                                    kMinimalWordsInPhrase + " words!");
            }

            Phrase resultPhrase = new Phrase()
            {
                Words = words
            };

            PhrasesDao.Insert(ref resultPhrase);
            return(resultPhrase);
        }
Esempio n. 2
0
        //--------------------------------------------------------------------------
        public List <Phrase> GetAll()
        {
            // we first get InternalPhrases and then map them to Phrases
            List <InternalPhrase> internalPhrases = PhrasesDao.GetAll();

            List <Phrase> phrases = new List <Phrase>();

            foreach (InternalPhrase internalPhrase in internalPhrases)
            {
                Phrase phrase = new Phrase()
                {
                    Id    = internalPhrase.Id,
                    Words = new List <Word>()
                };

                foreach (long wordId in internalPhrase.WordIds)
                {
                    Word word = WordsService.Instance.GetWordById(wordId);
                    phrase.Words.Add(word);
                }

                phrases.Add(phrase);
            }

            return(phrases);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        //--------------------------------------------------------------------------
        public void Import(XmlDocument document)
        {
            GlobalParamatersService.Delegate.OnDatabaseImportProgress(0);

            DatabaseConnectionService.Instance.SafeTransaction(_ => {
                XmlNodeList xmlPhraseList =
                    document.DocumentElement.SelectNodes(".//phrase");
                XmlNodeList xmlPraseWordsList =
                    document.DocumentElement.SelectNodes(".//phrases_words");

                int total     = xmlPhraseList.Count + xmlPraseWordsList.Count;
                int processed = 0;

                foreach (XmlNode xmlPhrase in xmlPhraseList)
                {
                    Phrase phrase = PhrasesDao.ImportPhrase(xmlPhrase);

                    processed++;
                    float percent = (float)processed / (float)total;
                    percent      *= 100;
                    GlobalParamatersService.Delegate.OnDatabaseImportProgress(
                        (int)percent);
                }

                foreach (XmlNode xmlPhraseWord in xmlPraseWordsList)
                {
                    PhrasesDao.ImportPhraseWord(xmlPhraseWord);

                    processed++;
                    float percent = (float)processed / (float)total;
                    percent      *= 100;
                    GlobalParamatersService.Delegate.OnDatabaseImportProgress(
                        (int)percent);
                }
            });
        }
Esempio n. 5
0
 //--------------------------------------------------------------------------
 public void DropTable()
 {
     PhrasesDao.DropTable();
 }
Esempio n. 6
0
 //--------------------------------------------------------------------------
 public void RemovePhrase(Phrase phrase)
 {
     PhrasesDao.Delete(phrase);
 }
Esempio n. 7
0
 //--------------------------------------------------------------------------
 public void CreateTable()
 {
     PhrasesDao.CreateTable();
 }
Esempio n. 8
0
 //--------------------------------------------------------------------------
 public Int64 GetCount()
 {
     return(PhrasesDao.GetCount());
 }