)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Default (Ia.Islamic.Cl.Model.Business)

Public general use code classes and xml files that we've compiled and used over the years:

Koran Reference Network Class Library support functions: Business model

    1: using System.Collections;
    2: using System.Collections.Generic;
    3: using System.Linq;
    4: using System.Text.RegularExpressions;
    5:  
    6: namespace Ia.Islamic.Cl.Model.Business
    7: {
    8:     ////////////////////////////////////////////////////////////////////////////
    9:  
   10:     /// <summary publish="true">
   11:     /// Koran Reference Network Class Library support functions: Business model
   12:     /// </summary>
   13:     /// <value>
   14:     /// https://msdn.microsoft.com/en-us/library/z1hkazw7(v=vs.100).aspx
   15:     /// </value>
   16:     /// <remarks> 
   17:     /// Copyright © 2001-2020 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   18:     ///
   19:     /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
   20:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   21:     ///
   22:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   23:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   24:     /// 
   25:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   26:     /// 
   27:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   28:     /// </remarks> 
   29:     public class Default
   30:     {
   31:         ////////////////////////////////////////////////////////////////////////////
   32:  
   33:         /// <summary>
   34:         ///
   35:         /// </summary>
   36:         public Default()
   37:         {
   38:         }
   39:  
   40:         ////////////////////////////////////////////////////////////////////////////
   41:  
   42:         /// <summary>
   43:         ///
   44:         /// </summary>
   45:         public static List<Ia.Islamic.Cl.Model.Ui.VerseUi> Search(string searchWordLine, string _language, out Ia.Cl.Models.Result result)
   46:         {
   47:             const int maximumLengthOfVerseList = 100;
   48:             string wordRegularExpression;
   49:             List<string> variantList;
   50:             List<Ia.Islamic.Cl.Model.Ui.VerseUi> verseList;
   51:             Dictionary<string, List<string>> wordToVariantListDictionary;
   52:  
   53:             var language = new Ia.Cl.Models.Language(_language);
   54:             var translation = new Translation(language.Id);
   55:  
   56:             result = new Ia.Cl.Models.Result();
   57:             wordToVariantListDictionary = new Dictionary<string, List<string>>();
   58:  
   59:             if (!string.IsNullOrEmpty(searchWordLine))
   60:             {
   61:                 // below: replace all consecutive space characters with a single ' '
   62:                 searchWordLine = Regex.Replace(searchWordLine, @"\s+", " ");
   63:                 searchWordLine = searchWordLine.Trim();
   64:  
   65:                 if (language.Id == "ja" || language.Id == "ko" || language.Id == "zh")
   66:                 {
   67:                     wordRegularExpression = Ia.Cl.Models.Language.WordsRegularExpression(language.Symbol) + "|[" + Ia.Cl.Models.Language.Ideograph(language.Symbol) + "]{1}";
   68:                     wordRegularExpression = wordRegularExpression.Replace("|[]{1}", string.Empty);
   69:                 }
   70:                 else wordRegularExpression = Ia.Cl.Models.Language.WordsRegularExpression(language.Symbol);
   71:  
   72:                 var wordMatchCollection = Regex.Matches(searchWordLine, @"(" + wordRegularExpression + ")", RegexOptions.Compiled); // keep original line
   73:  
   74:                 foreach (Match wordMatch in wordMatchCollection)
   75:                 {
   76:                     variantList = new List<string>();
   77:  
   78:                     var word = wordMatch.Groups[1].Captures[0].Value;
   79:                     variantList.Add(word);
   80:  
   81:                     var basicWord = Ia.Cl.Models.Language.BasicForm(word);
   82:                     if (!variantList.Contains(basicWord)) variantList.Add(basicWord);
   83:  
   84:                     if (language.Id == "ar")
   85:                     {
   86:                         var list = Ia.Cl.Models.Language.ProduceSimilarArabicWords(word);
   87:  
   88:                         foreach (string s in list)
   89:                         {
   90:                             if (!variantList.Contains(s)) variantList.Add(s);
   91:                         }
   92:                     }
   93:  
   94:                     wordToVariantListDictionary[word] = variantList;
   95:                 }
   96:  
   97:                 wordToVariantListDictionary.Remove(" ");
   98:                 wordToVariantListDictionary.Remove(string.Empty);
   99:  
  100:                 verseList = Ia.Islamic.Cl.Model.Data.Default.VerseList(language, wordToVariantListDictionary.Values.ToList(), maximumLengthOfVerseList, out result);
  101:  
  102:                 if (verseList.Count() > 0)
  103:                 {
  104:                     if (wordToVariantListDictionary.Count == 1)
  105:                     {
  106:                         result.AddSuccess(translation.ResultSearchForWord + @": """ + searchWordLine + @""". " + translation.ResultNumberOfAppearWords + " " + verseList.Count());
  107:                     }
  108:                     else if (wordToVariantListDictionary.Count > 1)
  109:                     {
  110:                         result.AddSuccess(translation.ResultSearchForWords + @": """ + searchWordLine + @""". " + translation.ResultNumberOfAppearWords + " " + verseList.Count());
  111:                     }
  112:                 }
  113:                 else
  114:                 {
  115:                     if (wordToVariantListDictionary.Count == 1)
  116:                     {
  117:                         result.AddWarning(translation.ResultTheWord + @" """ + searchWordLine + @""" " + translation.ResultWasNotFound);
  118:                     }
  119:                     else if (wordToVariantListDictionary.Count > 1)
  120:                     {
  121:                         result.AddWarning(translation.ResultTheWords + @" """ + searchWordLine + @""" " + translation.ResultWereNotFound);
  122:                     }
  123:                 }
  124:             }
  125:             else
  126:             {
  127:                 verseList = new List<Ia.Islamic.Cl.Model.Ui.VerseUi>();
  128:  
  129:                 result.AddError(translation.ResultEmptyField);
  130:             }
  131:  
  132:             return verseList;
  133:         }
  134:  
  135:         ////////////////////////////////////////////////////////////////////////////
  136:  
  137:         /// <summary>
  138:         ///
  139:         /// </summary>
  140:         public static Ia.Islamic.Cl.Model.Ui.VerseUi Verse(Ia.Cl.Models.Language language, int chapterNumber, int verseNumber, out int op, out string result)
  141:         {
  142:             return Ia.Islamic.Cl.Model.Data.Default.Verse(language, chapterNumber, verseNumber, out op, out result);
  143:         }
  144:  
  145:         ////////////////////////////////////////////////////////////////////////////
  146:  
  147:         /// <summary>
  148:         ///
  149:         /// </summary>
  150:         public static Ia.Islamic.Cl.Model.Ui.VerseTopicUi VerseSpan(Ia.Cl.Models.Language language, int chapterNumber, int verseNumber, int numberOfVerses, out int op, out string result)
  151:         {
  152:             return Ia.Islamic.Cl.Model.Ui.VerseTopicUi.VerseTopic(language, chapterNumber, verseNumber, numberOfVerses, out op, out result);
  153:         }
  154:  
  155:         ////////////////////////////////////////////////////////////////////////////
  156:         ////////////////////////////////////////////////////////////////////////////
  157:     }
  158: }