示例#1
0
        //--------------------------------------------------------------------------
        // we return a list of location pairs - each pair contains the first and
        // last word in the phrase with their location details
        public List <Tuple <LocationDetail, LocationDetail> > Query(Phrase phrase)
        {
            // first, get a list of Contains which build potential phrases
            List <Contains> potentialPhrases = ContainsDao.Query(phrase);

            // break the list into sublists (by unique doc,sentence)
            Dictionary <Tuple <long, long>, List <Contains> > phraseContainsMap =
                new Dictionary <Tuple <long, long>, List <Contains> >();

            foreach (Contains item in potentialPhrases)
            {
                Tuple <long, long> currentKey =
                    new Tuple <long, long>(item.DocumentId, item.Sentence);

                if (!phraseContainsMap.ContainsKey(currentKey))
                {
                    phraseContainsMap[currentKey] = new List <Contains>();
                }

                phraseContainsMap[currentKey].Add(item);
            }

            List <Tuple <LocationDetail, LocationDetail> > result =
                new List <Tuple <LocationDetail, LocationDetail> >();

            // now check which phrase contains all our words
            foreach (var containsPhrase in phraseContainsMap.Values)
            {
                int startIndex = 0;
                int foundIndex = 0;
                // we have a while to support sentences that have our phrase more than
                // once in them
                while (ContainsPhraseEqualsPhrase(containsPhrase,
                                                  startIndex,
                                                  phrase,
                                                  out foundIndex))
                {
                    Tuple <LocationDetail, LocationDetail> pair =
                        new Tuple <LocationDetail, LocationDetail>(
                            new LocationDetail()
                    {
                        Document = DocumentsService.Instance.GetById(
                            containsPhrase[0].DocumentId),
                        Location = containsPhrase[foundIndex]
                    },
                            new LocationDetail()
                    {
                        Document = DocumentsService.Instance.GetById(
                            containsPhrase[0].DocumentId),
                        Location = containsPhrase[foundIndex + phrase.Words.Count - 1]
                    });
                    result.Add(pair);

                    startIndex = foundIndex + phrase.Words.Count;
                }
            }

            return(result);
        }
示例#2
0
        //--------------------------------------------------------------------------
        private void CleanupDocument(Document doc)
        {
            if (doc == null)
            {
                return;
            }

            ContainsDao.DeleteByDocument(doc);

            _documentCache.Remove(doc.Id);
            DocumentsDao.Delete(doc);
        }
示例#3
0
 //-------------------------------------------------------------------------
 public Tuple <long, long> GetSurroundingOffsets(Contains location,
                                                 bool lines,
                                                 long delta)
 {
     if (lines)
     {
         return(ContainsDao.GetSurroundingLinesOffsets(
                    location, delta, delta));
     }
     else
     {
         return(ContainsDao.GetSurroundingSentencesOffsets(
                    location, delta, delta));
     }
 }
示例#4
0
        //-------------------------------------------------------------------------
        public List <WordLocationDetails> Query(
            List <Document> documents,
            List <WordLocationProperty> wordLocationProperties)
        {
            if (wordLocationProperties.Count <= 0)
            {
                throw new Exception("You must use, at least, ONE word location filter");
            }

            // query the DB
            List <Contains> contains = ContainsDao.Query(documents,
                                                         wordLocationProperties);

            // we want to return a grouped result (as-in grouped by words)
            // so we use a dictionary to collect all location details per word and
            // then we can build a grouped result of List<WordLocationDetails>
            Dictionary <long, List <LocationDetail> > wordLocationDetailsMap =
                new Dictionary <long, List <LocationDetail> >();

            foreach (Contains containsItem in contains)
            {
                if (!wordLocationDetailsMap.ContainsKey(containsItem.WordId))
                {
                    wordLocationDetailsMap[containsItem.WordId] =
                        new List <LocationDetail>();
                }

                wordLocationDetailsMap[containsItem.WordId].Add(new LocationDetail()
                {
                    Document = DocumentsService.Instance.GetById(containsItem.DocumentId),
                    Location = containsItem
                });
            }

            // now we can convert to List<WordLocationDetails>
            List <WordLocationDetails> result = new List <WordLocationDetails>();

            foreach (var item in wordLocationDetailsMap.Keys)
            {
                result.Add(new WordLocationDetails()
                {
                    Word            = WordsService.Instance.GetWordById(item),
                    LocationDetails = wordLocationDetailsMap[item]
                });
            }

            return(result);
        }
示例#5
0
        //-------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="word"></param>
        /// <param name="documentWord"></param>
        public void Insert(Document doc, Word word, DocumentWord documentWord)
        {
            Contains contains = new Contains()
            {
                DocumentId      = doc.Id,
                WordId          = word.Id,
                Line            = documentWord.Line,
                FileOffset      = documentWord.OffsetInFile,
                IndexInSentence = documentWord.IndexInSentence,
                Sentence        = documentWord.Sentence,
                Paragraph       = documentWord.Paragraph,
                Page            = documentWord.Page
            };

            ContainsDao.Insert(contains);
        }
示例#6
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);
        }
示例#7
0
        //-------------------------------------------------------------------------
        public WordLocationDetails Query(List <Document> documents, Word word)
        {
            // query the DB
            List <Contains> contains = ContainsDao.Query(documents, word);

            WordLocationDetails locationDetails = new WordLocationDetails();

            locationDetails.Word            = word;
            locationDetails.LocationDetails = new List <LocationDetail>();

            foreach (Contains item in contains)
            {
                locationDetails.LocationDetails.Add(new LocationDetail()
                {
                    Document = DocumentsService.Instance.GetById(item.DocumentId),
                    Location = item
                });
            }

            return(locationDetails);
        }
示例#8
0
        //-------------------------------------------------------------------------
        public List <WordLocationDetails> Query(Group group)
        {
            // query the DB
            List <Contains> contains = ContainsDao.Query(group);

            // we want to return a grouped result (as-in grouped by words)
            // so we use a dictionary to collect all location details per word and
            // then we can build a grouped result of List<WordLocationDetails>
            Dictionary <long, List <LocationDetail> > wordLocationDetailsMap =
                new Dictionary <long, List <LocationDetail> >();

            foreach (Contains containsItem in contains)
            {
                if (!wordLocationDetailsMap.ContainsKey(containsItem.WordId))
                {
                    wordLocationDetailsMap[containsItem.WordId] =
                        new List <LocationDetail>();
                }

                wordLocationDetailsMap[containsItem.WordId].Add(new LocationDetail()
                {
                    Document = DocumentsService.Instance.GetById(containsItem.DocumentId),
                    Location = containsItem
                });
            }

            // now we can convert to List<WordLocationDetails>
            List <WordLocationDetails> result = new List <WordLocationDetails>();

            foreach (var item in wordLocationDetailsMap.Keys)
            {
                result.Add(new WordLocationDetails()
                {
                    Word            = WordsService.Instance.GetWordById(item),
                    LocationDetails = wordLocationDetailsMap[item]
                });
            }

            return(result);
        }
示例#9
0
        //-------------------------------------------------------------------------
        public void Import(XmlDocument document)
        {
            GlobalParamatersService.Delegate.OnDatabaseImportProgress(0);

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

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

                foreach (XmlNode xmlContains in xmlContainsList)
                {
                    Contains contains = ContainsDao.Import(xmlContains);

                    processed++;
                    float percent = (float)processed / (float)total;
                    percent      *= 100;
                    GlobalParamatersService.Delegate.OnDatabaseImportProgress(
                        (int)percent);
                }
            });
        }
示例#10
0
 //--------------------------------------------------------------------------
 public void DropTable()
 {
     ContainsDao.DropTable();
 }
示例#11
0
 //-------------------------------------------------------------------------
 public List <long> QueryWordIds(
     List <Document> documents, List <WordLocationProperty> properties)
 {
     return(ContainsDao.QueryWordIds(documents, properties));
 }
示例#12
0
 //--------------------------------------------------------------------------
 public void CreateTable()
 {
     ContainsDao.CreateTable();
 }
示例#13
0
 //--------------------------------------------------------------------------
 public Int64 GetUniqueWordsCount()
 {
     return(ContainsDao.GetUniqueWordsCount());
 }
示例#14
0
 //--------------------------------------------------------------------------
 public Int64 GetCount()
 {
     return(ContainsDao.GetCount());
 }