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

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

Kanji class

    1: using System.Reflection;
    2: using System.Data;
    3: using System.Xml.Linq;
    4: using System;
    5: using System.Linq;
    6: using System.Collections.Generic;
    7: using System.IO;
    8:  
    9: namespace Ia.TentPlay.Cl.Model.Memorise
   10: {
   11:     ////////////////////////////////////////////////////////////////////////////
   12:  
   13:     /// <summary publish="true">
   14:     /// Kanji class
   15:     /// </summary>
   16:     /// <value>
   17:     /// https://msdn.microsoft.com/en-us/library/z1hkazw7(v=vs.100).aspx
   18:     /// </value>
   19:     /// <remarks> 
   20:     /// Copyright © 2008-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   21:     ///
   22:     /// 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
   23:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   24:     ///
   25:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   26:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   27:     /// 
   28:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   29:     /// 
   30:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   31:     /// </remarks> 
   32:     public class Kanji : Test
   33:     {
   34:         // <char id="1" wiki_id="1" name="一" grade="1" wiki_en="one" en="one" stroke="1" onyomi_ja="イチ、イツ" onyomi_en="ichi, itsu" kunyomi_ja="ひと、ひと-つ" kunyomi_en="hito, hito-tsu" />
   35:  
   36:         private static XDocument xDocument;
   37:  
   38:         protected override TestTopic testTopic
   39:         {
   40:             get
   41:             {
   42:                 return Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.Kanji;
   43:             }
   44:         }
   45:  
   46:         ////////////////////////////////////////////////////////////////////////////
   47:  
   48:         /// <summary>
   49:         ///
   50:         /// </summary>
   51:         //public enum WordType { Verb = 1, Noun, Adjective, Adverb, Unspecified };
   52:  
   53:         ////////////////////////////////////////////////////////////////////////////
   54:  
   55:         /// <summary>
   56:         ///
   57:         /// </summary>
   58:         public struct Symbol
   59:         {
   60:             public int Id;
   61:             public int WikiId;
   62:             public string Name;
   63:             public int Grade;
   64:             public string WikiEnglish;
   65:             public string English;
   66:             public int Stroke;
   67:             public string JapaneseOnyomi;
   68:             public string EnglishOnyomi;
   69:             public string JapaneseKunyomi;
   70:             public string EnglishKunyomi;
   71:  
   72:             public Symbol(int id, int wikiId, string name, int grade, string wikiEnglish, string english, int stroke, string japaneseOnyomi, string englishOnyomi, string japaneseKunyomi, string englishKunyomi)
   73:             {
   74:                 this.Id = id;
   75:                 this.WikiId = wikiId;
   76:                 this.Name = name;
   77:                 this.Grade = grade;
   78:                 this.WikiEnglish = wikiEnglish;
   79:                 this.English = english;
   80:                 this.Stroke = stroke;
   81:                 this.JapaneseOnyomi = japaneseOnyomi;
   82:                 this.EnglishOnyomi = englishOnyomi;
   83:                 this.JapaneseKunyomi = japaneseKunyomi;
   84:                 this.EnglishKunyomi = englishKunyomi;
   85:             }
   86:         }
   87:  
   88:         ////////////////////////////////////////////////////////////////////////////
   89:  
   90:         /// <summary>
   91:         ///
   92:         /// </summary>
   93:         public Kanji() { }
   94:  
   95:         ////////////////////////////////////////////////////////////////////////////
   96:  
   97:         /// <summary>
   98:         ///
   99:         /// </summary>
  100:         public override void PopulateTestDatabaseTableWithInitialQuestionsIfEmpty(Guid userId)
  101:         {
  102:             int count;
  103:             string question, answer;
  104:             //WordType wordType;
  105:             Ia.TentPlay.Cl.Model.Memorise.Score score;
  106:             List<Ia.TentPlay.Cl.Model.Memorise.Score> scoreList;
  107:  
  108:             // below: synch database words with XML list
  109:             using (var db = new Ia.TentPlay.Db())
  110:             {
  111:                 count = (from s in db.Scores where s.TestId == (int)Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.Kanji select s).Count();
  112:  
  113:                 if (count == 0)
  114:                 {
  115:                     scoreList = Ia.TentPlay.Cl.Model.Memorise.Score.KanjiScoreList(userId);
  116:  
  117:                     foreach (var symbol in List)
  118:                     {
  119:                         question = symbol.Name;
  120:                         answer = symbol.English;
  121:  
  122:                         score = (from s in scoreList where s.TestId == (int)testTopic && s.Question == question && s.Answer == answer /*&& s.TypeId == (int)wordType*/ select s).FirstOrDefault();
  123:  
  124:                         if (score == null)
  125:                         {
  126:                             score = new Ia.TentPlay.Cl.Model.Memorise.Score
  127:                             {
  128:                                 Question = question,
  129:                                 Answer = answer,
  130:                                 TestId = (int)testTopic,
  131:                                 TypeId = 0, //(int)wordType
  132:                                 Created = DateTime.UtcNow.AddHours(3),
  133:                                 Updated = DateTime.UtcNow.AddHours(3),
  134:                                 Viewed = DateTime.UtcNow.AddHours(3),
  135:                                 UserId = userId
  136:                             };
  137:  
  138:                             db.Scores.Add(score);
  139:                         }
  140:                     }
  141:  
  142:                     db.SaveChanges();
  143:                 }
  144:             }
  145:         }
  146:  
  147:         ////////////////////////////////////////////////////////////////////////////
  148:  
  149:         /// <summary>
  150:         ///
  151:         /// </summary>
  152:         public override int WeightedRandomTypeIdAccordingTypeDistribution(Guid userId)
  153:         {
  154:             /*
  155:             int countOfAllTypes, countOfTypeId1, countOfTypeId2, countOfTypeId3, countOfTypeId4, countOfTypeId5, typeId;
  156:             ArrayList countArrayList;
  157: 
  158:             // public enum WordType { Verb = 1, Noun, Adjective, Adverb, Unspecified };
  159: 
  160:             using (var db = new Ia.TentPlay.Db())
  161:             {
  162:                 countOfAllTypes = (from s in db.Scores where s.TestId == (int)testTopic select s).Count();
  163:                 countOfTypeId1 = (from s in db.Scores where s.TestId == (int)testTopic && s.TypeId == (int)WordType.Verb select s).Count();
  164:                 countOfTypeId2 = (from s in db.Scores where s.TestId == (int)testTopic && s.TypeId == (int)WordType.Noun select s).Count();
  165:                 countOfTypeId3 = (from s in db.Scores where s.TestId == (int)testTopic && s.TypeId == (int)WordType.Adjective select s).Count();
  166:                 countOfTypeId4 = (from s in db.Scores where s.TestId == (int)testTopic && s.TypeId == (int)WordType.Adverb select s).Count();
  167:                 countOfTypeId5 = (from s in db.Scores where s.TestId == (int)testTopic && s.TypeId == (int)WordType.Unspecified select s).Count();
  168: 
  169:                 countArrayList = new ArrayList(countOfAllTypes);
  170: 
  171:                 // below: populate ArrayList with TypeId keys a number of times equal to its count
  172:                 for (int i = 0; i < countOfTypeId1; i++) countArrayList.Add((int)WordType.Verb);
  173:                 for (int i = 0; i < countOfTypeId2; i++) countArrayList.Add((int)Noun.Verb);
  174:                 for (int i = 0; i < countOfTypeId3; i++) countArrayList.Add((int)Adjective.Verb);
  175:                 for (int i = 0; i < countOfTypeId4; i++) countArrayList.Add((int)Adverb.Verb);
  176:                 for (int i = 0; i < countOfTypeId5; i++) countArrayList.Add((int)Unspecified.Verb);
  177: 
  178:                 typeId = (int)countArrayList[random.Next(countOfAllTypes)];
  179:             }
  180:             */
  181:  
  182:             return 0; // typeId;
  183:         }
  184:  
  185:         ////////////////////////////////////////////////////////////////////////////
  186:  
  187:         /// <summary>
  188:         /// Read all Kanji symbol characters
  189:         /// </summary>
  190:         public static List<Ia.TentPlay.Cl.Model.Memorise.Kanji.Symbol> List
  191:         {
  192:             get
  193:             {
  194:                 Ia.TentPlay.Cl.Model.Memorise.Kanji.Symbol symbol;
  195:                 List<Ia.TentPlay.Cl.Model.Memorise.Kanji.Symbol> symbolList;
  196:  
  197:                 symbolList = new List<Ia.TentPlay.Cl.Model.Memorise.Kanji.Symbol>(2000);
  198:  
  199:                 foreach (XElement xe in XDocument.Element("kanji").Elements("char"))
  200:                 {
  201:                     //  <char id="1" wikiId="1" name="一" grade="1" wikiEnglish="one" english="one" stroke="1" onyomiJapanese="イチ、イツ" onyomiEnglish="ichi, itsu" kunyomiJapanese="ひと、ひと-つ" kunyomiEnglish="hito, hito-tsu" />
  202:  
  203:                     symbol = new Ia.TentPlay.Cl.Model.Memorise.Kanji.Symbol(
  204:                     int.Parse(xe.Attribute("id").Value),
  205:                     int.Parse(xe.Attribute("wikiId").Value),
  206:                     xe.Attribute("name").Value,
  207:                     int.Parse(xe.Attribute("grade").Value),
  208:                     xe.Attribute("wikiEnglish").Value,
  209:                     xe.Attribute("english").Value,
  210:                     int.Parse(xe.Attribute("stroke").Value),
  211:                     xe.Attribute("japaneseOnyomi").Value,
  212:                     xe.Attribute("englishOnyomi").Value,
  213:                     xe.Attribute("japaneseKunyomi").Value,
  214:                     xe.Attribute("englishKunyomi").Value);
  215:  
  216:                     symbolList.Add(symbol);
  217:                 }
  218:  
  219:                 return symbolList;
  220:             }
  221:         }
  222:  
  223:         ////////////////////////////////////////////////////////////////////////////
  224:         ////////////////////////////////////////////////////////////////////////////
  225:  
  226:         /// <summary>
  227:         /// 
  228:         /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
  229:         /// 
  230:         /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
  231:         /// 2. Add "using System.Reflection".
  232:         /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
  233:         /// 
  234:         /// </summary>
  235:         public static XDocument XDocument
  236:         {
  237:             get
  238:             {
  239:                 if (xDocument == null)
  240:                 {
  241:                     Assembly _assembly;
  242:                     StreamReader streamReader;
  243:  
  244:                     _assembly = Assembly.GetExecutingAssembly();
  245:                     streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.TentPlay.Cl.model.data.memorise.kanji.xml"));
  246:  
  247:                     try
  248:                     {
  249:                         if (streamReader.Peek() != -1)
  250:                         {
  251:                             xDocument = System.Xml.Linq.XDocument.Load(streamReader);
  252:                         }
  253:                     }
  254:                     catch (Exception)
  255:                     {
  256:                     }
  257:                     finally
  258:                     {
  259:                     }
  260:                 }
  261:  
  262:                 return xDocument;
  263:             }
  264:         }
  265:  
  266:         ////////////////////////////////////////////////////////////////////////////
  267:         ////////////////////////////////////////////////////////////////////////////    
  268:     }
  269: }