public IActionResult Index(VerbModel model) { ProgressData sessionData; if (HttpContext.Session.Keys.Any(k => k == SessionKeys.UserProgressKey)) { sessionData = HttpContext.Session.Get <ProgressData>(SessionKeys.UserProgressKey); } else { return(RedirectToAction("Index")); } sessionData.TotalCount++; var verb = verbsQuery.GetVerbByIndex(sessionData.Indexes.Last()); var resultModel = new ResultViewModel { Infinitive = verb.Infinitief, English = verb.English, ImperfectumSingular = new TenseModel(verb.ImperfectumSg, model.ImperfectumSingular), ImperfectumPlural = new TenseModel(verb.ImperfectumPl, model.ImperfectumPlural), Perfectum = new TenseModel(verb.Perfectum, model.Perfectum) }; if (resultModel.IsAnswerCorrect) { sessionData.SuccessCount++; } resultModel.CorrectCount = sessionData.SuccessCount; HttpContext.Session.Set(SessionKeys.UserProgressKey, sessionData); return(View("ResultView", resultModel)); }
private static List <int> GetIndexOfCompatibleWord(string comp, string sen) { var result = new List <int>(); if (sen.ContainsInsensitive(comp, true)) { var indexes = sen.IndexesFrom(comp, true); AddUniqueValues(result, indexes); } VerbModel staticVerb = new VerbModel(); if (VerbsController.Get().Any(v => v.Infinitive.EqualsNoCase(comp))) { staticVerb = VerbsController.Get().First(v => v.Infinitive.EqualsNoCase(comp)); //else // staticVerb = VerbsController.ConjugateUnknownVerb(comp); if (sen.ContainsInsensitive(staticVerb.Gerund, true)) { var indexes = sen.IndexesFrom(staticVerb.Gerund, true); AddUniqueValues(result, indexes); } if (sen.ContainsInsensitive(staticVerb.Past, true)) { var indexes = sen.IndexesFrom(staticVerb.Past, true); AddUniqueValues(result, indexes); } if (sen.ContainsInsensitive(staticVerb.PastParticiple, true)) { var indexes = sen.IndexesFrom(staticVerb.PastParticiple, true); AddUniqueValues(result, indexes); } if (sen.ContainsInsensitive(staticVerb.Person, true)) { var indexes = sen.IndexesFrom(staticVerb.Person, true); AddUniqueValues(result, indexes); } } var service = PluralizationService.CreateService(System.Globalization.CultureInfo.CurrentCulture); if (service.IsSingular(comp)) { var plural = service.Pluralize(comp); if (sen.ContainsInsensitive(plural, true)) { var indexes = sen.IndexesFrom(plural, true); AddUniqueValues(result, indexes); } } return(result); }
public object Create(VerbModel model, BinaryStatement statement) { var verb = this.execution.Operators.Models.Sources .Select(source => source.Assembly) .SelectMany(assembly => assembly.GetTypes()) .Where(type => type.GetInterfaces().Any(i => i.IsGenericType && typeof(IVerb <>) == i.GetGenericTypeDefinition()) && !type.IsAbstract) .SingleOrDefault(type => type.GetConstructors().Any(ctor => ctor.GetParameters().Any(p => p.ParameterType.IsInstanceOfType(model)))); if (verb == null) { throw new Exception("Cannot find verb for the model " + model.GetType().FullName); } return(Activator.CreateInstance(verb, model, statement)); }
public IActionResult Index() { ProgressData sessionData; if (HttpContext.Session.Keys.Any(k => k == SessionKeys.UserProgressKey)) { sessionData = HttpContext.Session.Get <ProgressData>(SessionKeys.UserProgressKey); } else { sessionData = new ProgressData(); } var totalCount = verbsQuery.Count(); if (sessionData.Indexes.Length == totalCount) { var finishedModel = new FinishedModel { TotalCount = sessionData.TotalCount, SuccessCount = sessionData.SuccessCount }; sessionData = new ProgressData(); HttpContext.Session.Set(SessionKeys.UserProgressKey, sessionData); return(View("Finished", finishedModel)); } var nextVerbIndex = randomizer.GetNextIndex(totalCount, sessionData.Indexes); Verb verb = verbsQuery.GetVerbByIndex(nextVerbIndex); List <int> newIndexes = new List <int>(sessionData.Indexes) { nextVerbIndex }; sessionData.Indexes = newIndexes.ToArray(); HttpContext.Session.Set(SessionKeys.UserProgressKey, sessionData); var model = new VerbModel { SuccessCount = sessionData.SuccessCount, TotalCount = sessionData.TotalCount, Infinitive = verb.Infinitief, English = verb.English }; return(View(model)); }
//private static bool DoesSenContainsComp(string comp, bool isVerb, string sentence) //{ // var compatible = GetCompatibleWord(comp, sentence); // if (!compatible.IsEmpty()) // return true; // return false; //} public static string GetCompatibleWord(string comp, string sen) { if (sen.ContainsInsensitive(comp)) { return(comp); } VerbModel staticVerb = new VerbModel(); if (VerbsController.Get().Any(v => v.Infinitive.EqualsNoCase(comp))) { staticVerb = VerbsController.Get().First(v => v.Infinitive.EqualsNoCase(comp)); //else // staticVerb = VerbsController.ConjugateUnknownVerb(comp); if (sen.ContainsInsensitive(staticVerb.Gerund)) { return(staticVerb.Gerund); } else if (sen.ContainsInsensitive(staticVerb.Past)) { return(staticVerb.Past); } else if (sen.ContainsInsensitive(staticVerb.PastParticiple)) { return(staticVerb.PastParticiple); } else if (sen.ContainsInsensitive(staticVerb.Person)) { return(staticVerb.Person); } } var service = PluralizationService.CreateService(System.Globalization.CultureInfo.CurrentCulture); if (service.IsSingular(comp)) { var plural = service.Pluralize(comp); if (sen.ContainsInsensitive(plural)) { return(plural); } } return(string.Empty); }
public static void WriteVerbOnFile(VerbModel verb) { var actualFile = File.ReadAllLines(CakePaths.ScriptVerbs); using (var tw = new StreamWriter(CakePaths.ScriptVerbs, true)) { if (!actualFile.Any(s => s.Contains(verb.Infinitive))) { tw.WriteLine("insert into Verb values(NULL, '" + verb.Infinitive + "', '" + verb.Past + "', '" + verb.PastParticiple + "', '" + verb.Person + "', '" + verb.Gerund + "');"); } else { Console.WriteLine("Verb already stored: " + verb); } } }
protected static bool InsertVerb(VerbModel verb) { string query = string.Format(InsertSQL + "'{1}', '{2}', '{3}', '{4}', '{5}')", Model.Verb.ToDesc(), verb.Infinitive, verb.Past, verb.PastParticiple, verb.Person, verb.Gerund); if (!SendQuery(query)) { return(false); } var inserted = GetLast(Model.Verb.ToDesc()); Verbs.Add(inserted.Tables[0].AsEnumerable(). Select(GetDatarowVerbs()).First()); return(true); }