public DictionaryEntry(string dictionaryCode, string word, int entryIndex, IEnumerable <string> html) { DictionaryCode = dictionaryCode; EntryIndex = entryIndex; Word = ArabicHelper.SubstituteAndOmit(word); Html = html.ToList().AsReadOnly(); }
public ActionResult Root(string root) { root = ArabicHelper.LetterNamesToArabic(root); var model = new Analysis_Root(root); return(View(model)); }
public ActionResult Root(string root) { /* * root = ArabicHelper.LetterNamesToArabic(root); * var model = SharedData.Document.RootWordsDocument[root]; * return View(model); */ root = ArabicHelper.LetterNamesToArabic(root); var model = new Analysis_Root(root); return(View(model)); }
public void Migrate(string code) { string jsonFilePath = Path.Combine(Configuration.DictionariesDirectoryPath, $"{code}"); var jsonDictionary = ReadJsonObject <JsonDictionary>(jsonFilePath + ".json"); var jsonDictionaryMeta = ReadJsonObject <DictionaryMeta>(jsonFilePath + "-meta.json"); WriteDictionary(code, jsonDictionary.Name, jsonDictionaryMeta.Copyright); int index = 0; foreach (var entry in jsonDictionary.Entries) { index++; string root = ArabicHelper.Substitute(entry.Name); string rootLetterNames = ArabicHelper.ArabicToLetterNames(root); string html = entry.Text; html = HeaderRegex.Replace(entry.Text, ""); html = EmptyElementRegex.Replace(html, m => m.Groups[1].Value + m.Groups[2].Value); html = html.Replace("\r\n", " ").Replace("\r", " ").Replace("\n", " "); if (jsonDictionaryMeta.RemoveNewLines) { html = NewLineRegex.Replace(html, " "); } else { html = NewLineRegex.Replace(html, "\r"); } //TODO: Not until we know we are not already inside a html element //html = ArabicRegex.Replace(html, m => $"<span class=\"arabic\">{m.Value}</span>"); string[] htmlLines = html.Split('\r'); var dictionaryEntry = new DictionaryEntry( dictionaryCode: code, word: root, entryIndex: index, html: htmlLines); DictionaryEntryWriteRepository.Write(dictionaryEntry); if (index % 100 == 0) { Logger.Debug($"{code} {rootLetterNames}"); } } }
static void SanitizeQueryString(ref string queryString) { if (string.IsNullOrEmpty(queryString)) { return; } queryString = ArabicHelper.Substitute(queryString); string[] specialCharacters = new string[] { "&", "|", "!", "(", ")", "{", "}", "[", "]", "^", "\"", "~", "?", ":", "\\" }; foreach (string s in specialCharacters) { queryString = queryString.Replace(s, @"\" + s); } queryString = "+(" + queryString + ")"; }
public ActionResult Index(string dictionaryCode, string word) { Dictionary dictionary = DictionaryRepository.Get(dictionaryCode); if (dictionary == null) { return(HttpNotFound()); } string indexValue = ArabicHelper.Substitute(word); IEnumerable <DictionaryEntry> entries = DictionaryEntryRepository.Get( dictionaryCode: dictionaryCode, word: indexValue); if (!entries.Any()) { return(HttpNotFound()); } var viewModel = new ViewModel(word, dictionary, entries); return(View("DictionaryEntry", viewModel)); }
public async Task <ApiResponse <string> > ReindexVanDyke() { var directoryName = @"..\App_Data\Bibles\VanDyke\";// @"C:\Suzette\TheArabicBible\The Arabic Bible\BibleCopies\VanDyke\"; var books = System.IO.Directory.GetFiles(directoryName); foreach (var book in books) { var bookText = string.Empty; using (var reader = new System.IO.StreamReader(book)) { bookText = reader.ReadToEnd(); } if (!string.IsNullOrEmpty(bookText)) { var bookId = Convert.ToInt16(book.Replace(directoryName, "").Substring(0, 2)); var groupId = GetGroupId(bookId); bookText = bookText.Replace("الأصحَاحُ", "@"); bookText = System.Text.RegularExpressions.Regex.Replace(bookText, "[0-9]", "$"); //replace verse number/digit with $ bookText = bookText.Replace("$$$", "$").Replace("$$", "$"); //if verse number has more than digit replace them all with one $ var chapters = bookText.Split('@'); var chapterCounter = 0; foreach (var chapter in chapters) { var verses = chapter.Split('$'); var verseCounter = 0; for (var i = 1; i < verses.Count(); i++) { var verse = verses[i]; var trimedVerse = verse.Replace("\n", "").Replace("\r", "").Trim(); var doc = new BibleVerse() { BibleId = 1 , TestmentId = (bookId <= 39 ? 1 : 2) , GroupId = groupId , BookId = bookId , ChapterId = chapterCounter , VerseNo = i , VerseText = trimedVerse , SearchText = ArabicHelper.MapArabicToEnglishLetters(trimedVerse) }; if (!string.IsNullOrEmpty(trimedVerse)) { chapterCounter = chapterCounter == 0 ? 1 : chapterCounter; verseCounter = verseCounter == 0 ? 1 : verseCounter; // return new ApiResponse<string>() { Data = JsonConvert.SerializeObject(doc) }; var response = await _bibleRepository.AddDocument(doc); } verseCounter++; } chapterCounter++; } } } return(new ApiResponse <string>());//todo set status to false }
public async Task <ApiResponse <List <BibleVerse> > > Query(int pageIndex, List <int> bibleIds, Bible bibleFilter, SearchCriteria searchCriteria) { var response = new ApiResponse <List <BibleVerse> >(); var currentPage = pageIndex; var recPerPage = 20; var startIndex = recPerPage * (currentPage - 1); var searchTerm = searchCriteria.SearchItems[0].SearchTerm; if (bibleFilter.Language.Equals("arabic", StringComparison.OrdinalIgnoreCase)) { searchTerm = ArabicHelper.MapArabicToEnglishLetters(searchCriteria.SearchItems[0].SearchTerm); } var filterItems = GetFilter(bibleIds, bibleFilter); var searchStart = $" ( "; var boolQueryStart = $" 'query' : ( 'bool' : ("; var queryMustClause = $" 'must' : [ ('wildcard' : ('SearchText' : '*{searchTerm}*' )) ]"; // must works like and var boolQueryEnd = $" )) "; var boolFilterStart = $" , 'filter' : ( 'bool' : ("; var filterShouldClause = $" 'should' : [] "; //should works like or var filterMustClause = $" , 'must' : [ {filterItems.Item1} ] "; //must works like and var filterMustNotClause = $" , 'must_not' : [ {filterItems.Item2} ]"; //must_not works like and not var boolFilterEnd = $" )) "; var sort = $" , 'sort' : ['BookId' , 'ChapterId' , 'VerseNo' ]"; var from = $" , 'from' : {startIndex} "; var size = $" , 'size' : {recPerPage} "; var searchEnd = $" ) "; var boolQuery = $" {boolQueryStart} {queryMustClause} {boolQueryEnd} "; var boolFilter = $" {boolFilterStart} {filterShouldClause} {filterMustClause} {filterMustNotClause} {boolFilterEnd} "; var query = $"{searchStart} {boolQuery} {boolFilter} {sort} {from} {size} {searchEnd} "; query = query.Replace("(", "{").Replace(")", "}").Replace("'", "\""); var endpoint = new EndPoint(); endpoint.ApiMethod = _readIndex + "_search"; endpoint.HttpMethod = "POST"; var esResponse = await _requestManager.ExecuteRequest <ElasticSearchResponse <ElasticSearchBibleDocument>, string>(endpoint, query); if (esResponse.Status.Ok) { response.Pagination = new ApiPagination { RecPerPage = recPerPage, CurrentPage = currentPage, TotalRecCount = esResponse.Data.hits.total, TotalPageCount = Convert.ToInt16(Math.Ceiling(Convert.ToDecimal(esResponse.Data.hits.total) / recPerPage)) }; response.Data = new List <BibleVerse>(); foreach (var hit in esResponse.Data.hits.hits) { var verse = new BibleVerse() { BibleId = Convert.ToInt16(hit._source.BibleId) , BookId = Convert.ToInt16(hit._source.BookId) , ChapterId = Convert.ToInt16(hit._source.ChapterId) , VerseNo = Convert.ToInt16(hit._source.VerseNo) , VerseText = hit._source.VerseText }; response.Data.Add(verse); } } else { response.Status = esResponse.Status; } return(response); }
public void SetUp() { AH = new ArabicHelper(); }
public static string GetIndexForArabic(string word) => ArabicHelper.ArabicToLetterNames(ArabicHelper.SubstituteAndOmit(word)).Replace('-', 'x');
public ActionResult Index(string rootLetterNames) { string root = ArabicHelper.LetterNamesToArabic(rootLetterNames); IEnumerable <VerseAnalysis> verses = VerseAnalysisRepository.GetForRoot(root) .OrderBy(x => x.ChapterNumber) .ThenBy(x => x.VerseNumber); var extracts = new List <VerseViewModel>(); foreach (VerseAnalysis verseAnalysis in verses) { foreach (VerseAnalysisWord analysisWord in verseAnalysis.Words) { IEnumerable <VerseAnalysisWordPart> wordParts = analysisWord.WordParts.Where(x => x.Root == root); foreach (VerseAnalysisWordPart wordPart in wordParts) { VerseViewModel extract = CreateVerseViewModel(verseAnalysis, analysisWord, wordPart); extracts.Add(extract); } } } var romanNumerals = new List <string> { "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X" }; var wordFormsData = extracts .GroupBy(x => new { Type = x.SelectedWordPart.Description, x.SelectedWordPart.Form }) .OrderBy(x => romanNumerals.IndexOf(x.Key.Form)); var wordTypesData = wordFormsData .GroupBy(x => x.Key.Type) .OrderBy(x => x.Key); var wordTypesViewModel = wordTypesData .Select(t => new WordTypeViewModel( type: t.Key, wordForms: t.Select(f => new WordFormViewModel( form: f.Key.Form, extracts: f ) ) ) ); IEnumerable <DictionaryEntry> dictionaryEntries = DictionaryEntryRepository.Get(root); IEnumerable <Dictionary> dictionaries = dictionaryEntries .Select(x => x.DictionaryCode) .Distinct() .Select(DictionaryRepository.Get) .OrderBy(x => x.Name); var viewModel = new ViewModel( arabicRoot: root, rootLetterNames: rootLetterNames, dictionaries: dictionaries, types: wordTypesViewModel); return(View("RootAnalysis", viewModel)); }