/// <summary> /// This method is used to calculate the Second level of probability of a given command /// </summary> /// <param name="command"></param> public List <CommandType> CalculateSecondLevelProbabilityOfCommand(string command) { try { new NaiveCommandCategorization(_secondLevelCategoryCollection).CalculateProbabilityOfSegments( command.Split(' ').ToList(), true, out _secondLevelProbabilityScoreIndices); if (_secondLevelProbabilityScoreIndices == null) { return(null); } var highestProbabilityCategories = new NaiveCommandCategorization().GetHighestProbabilityScoreIndeces(_secondLevelProbabilityScoreIndices); if (highestProbabilityCategories == null) { return(null); } if (highestProbabilityCategories.Count != 1) { throw new Exception("Command Identification Failed From the Second Level. There are " + highestProbabilityCategories.Count + " probable categories which are " + DataManager.GetHighestProbableCommandTypesForException <SecondLevelCategory>(highestProbabilityCategories)); } var secondLevelHighestProbabilityCategory = highestProbabilityCategories.First(); var secondLevelCategory = Conversions.ConvertIntegerToEnum <SecondLevelCategory>( secondLevelHighestProbabilityCategory.ReferenceId); return(GetCommand(command, secondLevelCategory)); } catch (Exception ex) { Log.ErrorLog(ex); throw; } }
/// <summary> /// This method is used to calculate the Second level of probability of a given command /// </summary> /// <param name="command"></param> public List<CommandType> CalculateSecondLevelProbabilityOfCommand(string command) { try { new NaiveCommandCategorization(_secondLevelCategoryCollection).CalculateProbabilityOfSegments( command.Split(' ').ToList(), true, out _secondLevelProbabilityScoreIndices); if (_secondLevelProbabilityScoreIndices == null) return null; var highestProbabilityCategories = new NaiveCommandCategorization().GetHighestProbabilityScoreIndeces(_secondLevelProbabilityScoreIndices); if (highestProbabilityCategories == null) return null; if (highestProbabilityCategories.Count != 1) { throw new Exception("Command Identification Failed From the Second Level. There are " + highestProbabilityCategories.Count + " probable categories which are " + DataManager.GetHighestProbableCommandTypesForException<SecondLevelCategory>(highestProbabilityCategories)); } var secondLevelHighestProbabilityCategory = highestProbabilityCategories.First(); var secondLevelCategory = Conversions.ConvertIntegerToEnum<SecondLevelCategory>( secondLevelHighestProbabilityCategory.ReferenceId); return GetCommand(command, secondLevelCategory); } catch (Exception ex) { Log.ErrorLog(ex); throw; } }
/// <summary> /// This method is used to calculate the First level of probability of a given command /// </summary> /// <param name="command"></param> public Dictionary <CommandType, object> CalculateProbabilityOfCommand(string command) { try { var probableCommands = new List <CommandType>(); new NaiveCommandCategorization(_categoryCollection).CalculateProbabilityOfSegments( command.Split(' ').ToList(), true, out _probabilityScoreIndices); if (_probabilityScoreIndices == null) { return(null); } var highestProbabilityCategories = new NaiveCommandCategorization().GetHighestProbabilityScoreIndeces(_probabilityScoreIndices); if (highestProbabilityCategories.Count == 1) { var firstLevelHighestProbabilityCategory = highestProbabilityCategories.First(); if (firstLevelHighestProbabilityCategory.ReferenceId == Conversions.ConvertEnumToInt(FirstLevelCategory.FunctionalCommand)) { probableCommands = new SecondLevelCategorization().CalculateSecondLevelProbabilityOfCommand(command); } else if (firstLevelHighestProbabilityCategory.ReferenceId == Conversions.ConvertEnumToInt(FirstLevelCategory.KeyboardCommand)) { probableCommands = new KeyboardCommands(command).GetCommand(); } else if (firstLevelHighestProbabilityCategory.ReferenceId == Conversions.ConvertEnumToInt(FirstLevelCategory.MouseCommand)) { probableCommands = new MouseCommands(command).GetCommand(); } } else { throw new Exception("Command Identification Failed From the First Level. There are " + highestProbabilityCategories.Count + " probable categories which are " + DataManager.GetHighestProbableCommandTypesForException <FirstLevelCategory>(highestProbabilityCategories)); } var returnDict = GetCommandDetails(probableCommands, command); if (returnDict.Count == 1) { var identifiedCommandType = returnDict.First().Key; if (LearningManager.UnIdentifiedWords.Count > 0) { LearningManager.AddUnidentifiedWordsToCommandText(identifiedCommandType); } DataManager.AddToCommandCounter(identifiedCommandType); } return(returnDict); } catch (Exception ex) { Log.ErrorLog(ex); throw; } }
/// <summary> /// This method is used to calculate the First level of probability of a given command /// </summary> /// <param name="command"></param> public Dictionary<CommandType, object> CalculateProbabilityOfCommand(string command) { try { var probableCommands = new List<CommandType>(); new NaiveCommandCategorization(_categoryCollection).CalculateProbabilityOfSegments( command.Split(' ').ToList(), true, out _probabilityScoreIndices); if (_probabilityScoreIndices == null) return null; var highestProbabilityCategories = new NaiveCommandCategorization().GetHighestProbabilityScoreIndeces(_probabilityScoreIndices); if (highestProbabilityCategories.Count == 1) { var firstLevelHighestProbabilityCategory = highestProbabilityCategories.First(); if (firstLevelHighestProbabilityCategory.ReferenceId == Conversions.ConvertEnumToInt(FirstLevelCategory.FunctionalCommand)) probableCommands = new SecondLevelCategorization().CalculateSecondLevelProbabilityOfCommand(command); else if (firstLevelHighestProbabilityCategory.ReferenceId == Conversions.ConvertEnumToInt(FirstLevelCategory.KeyboardCommand)) probableCommands = new KeyboardCommands(command).GetCommand(); else if (firstLevelHighestProbabilityCategory.ReferenceId == Conversions.ConvertEnumToInt(FirstLevelCategory.MouseCommand)) probableCommands = new MouseCommands(command).GetCommand(); } else { throw new Exception("Command Identification Failed From the First Level. There are " + highestProbabilityCategories.Count + " probable categories which are " + DataManager.GetHighestProbableCommandTypesForException<FirstLevelCategory>(highestProbabilityCategories)); } var returnDict = GetCommandDetails(probableCommands, command); if (returnDict.Count == 1) { var identifiedCommandType = returnDict.First().Key; if (LearningManager.UnIdentifiedWords.Count > 0) LearningManager.AddUnidentifiedWordsToCommandText(identifiedCommandType); DataManager.AddToCommandCounter(identifiedCommandType); } return returnDict; } catch (Exception ex) { Log.ErrorLog(ex); throw; } }