private ChainKey[] CreateKeysArray(ChainMap map, Predicate <ChainKey> keyCondition) { List <ChainKey> newKeys = new List <ChainKey>(); List <ChainKey> origKeys = map.GetAllKeys(); foreach (ChainKey origKey in origKeys) { if (keyCondition.Invoke(origKey)) { //Add key multiple times to ensure probability of picking it is proportional to the //number of values foreach (string val in map.GetValues(origKey)) { newKeys.Add(origKey); } } } return(newKeys.ToArray()); }
/// <summary> /// Get subchain of chainkeys and words that satisfies the passed in condition /// </summary> /// <param name="condition"></param> /// <returns></returns> internal ChainMap GetSubChain(ChainCondition condition) { //If conditions won't be applied return original chains if (condition == null || condition == _alwaysTrueCondition || (condition.WordCondition == null && condition.KeyCondition == null)) { return(_chains); } ChainMap newMap = new ChainMap(); bool valuesFound = false; foreach (ChainKey key in _chains.GetAllKeys()) { if (condition.KeyCondition != null) { if (condition.KeyCondition.Invoke(key)) { foreach (string word in _chains.GetValues(key)) { if (condition.WordCondition != null) { if (condition.WordCondition.Invoke(word)) { newMap.AddToChain(key, word); valuesFound = true; } } } } } } if (!valuesFound) { throw new Exceptions.NoPossibleElements("Chain map filter filtered everything out"); } return(newMap); }
public static Dictionary<ChainKey, List<string>> GetUnderlyingDictionary(ChainMap inputChainMap) { Dictionary<ChainKey, List<string>> retValues = new Dictionary<ChainKey, List<string>>() ; List<ChainKey> keys = inputChainMap.GetAllKeys() ; foreach(ChainKey key in keys) { retValues.Add(key, inputChainMap.GetValues(key)) ; } return retValues; }
private ChainKey[] CreateKeysArray(ChainMap map, Predicate<ChainKey> keyCondition) { List<ChainKey> newKeys = new List<ChainKey>() ; List<ChainKey> origKeys = map.GetAllKeys() ; foreach(ChainKey origKey in origKeys) { if(keyCondition.Invoke(origKey)) { //Add key multiple times to ensure probability of picking it is proportional to the //number of values foreach(string val in map.GetValues(origKey)) { newKeys.Add(origKey) ; } } } return newKeys.ToArray() ; }