/// <summary> /// Function to return the integer index values for functional groups corresponding to given trait and trait value pair combinations. /// Overloaded to accept a single string rather than an array in the traits to search and the trait values - both must be single strings /// </summary> /// <param name="searchTraits">String of Trait names to search for trait values within</param> /// <param name="searchTraitValues">String of string Trait Values to find functional group indices for</param> /// <param name="intersection">Boolean statement indicating if you want the intersection of the indices. Only valid if more than one Trait and Trait Value pair. /// True means give intersection. False means give the union of indices</param> /// <returns>Int array containing functional group indices corresponding to the given search conditions</returns> public int[] GetFunctionalGroupIndex(string searchTraits, string searchTraitValues, Boolean intersection) { //List to hold the index vectors for each trait trait value pair int[] IndexList; //Sorted dictionary to hold the trait value index list sorted dictionary from the lookup table SortedDictionary <string, int[]> TraitIndexList; //Check if the trait name is in the lookup table and if so pull out the <trait value, index vector> sorted dictionary for it if (IndexLookupFromTrait.TryGetValue(searchTraits.ToLower(), out TraitIndexList)) { //Check if the trait value string is found in the lookup table and if found pull out the index vector for it //and add it to the List of these for processing - intersection of union if (TraitIndexList.TryGetValue(searchTraitValues.ToLower(), out IndexList)) { ; } //If trait value string not found then show error message else { IndexList = null; Debug.Print("Trait Value to search for not found in lookup tables"); } } //If trait name string not found then show error message else { IndexList = null; Debug.Print("Trait to search for not found in lookup tables"); } return(IndexList); }
/// <summary> /// Get the functional group indices that have specified values of specified traits /// </summary> /// <param name="searchTraits">Vector of trait names to search for</param> /// <param name="searchTraitValues">Vector of trait values to search for</param> /// <param name="intersection">Whether the intersection of the indices for the traits should be returned, otherwise return the union of the indices</param> /// <returns>A vector of functional group indices with the specified values of the specified traits</returns> public int[] GetFunctionalGroupIndex(string[] searchTraits, string[] searchTraitValues, Boolean intersection) { // Check that the numbers of traits and of trait values specified are equal Debug.Assert((searchTraits.Length == searchTraitValues.Length), "Unequal search string arrays"); // List to hold the functional group indices for each trait-trait value pair List <int[]> IndexList = new List <int[]>(); int[] TempIndexList; //Sorted dictionary to hold the trait value index list sorted dictionary from the lookup table SortedDictionary <string, int[]> TraitIndexList; //Loop over the number of trait name and trait value pairs for (int nn = 0; nn < searchTraits.Length; nn++) { //Check if the trait name is in the lookup table and if so pull out the <trait value, index vector> sorted dictionary for it if (IndexLookupFromTrait.TryGetValue(searchTraits[nn].ToLower(), out TraitIndexList)) { //Check if the trait value string is found in the lookup table and if found pull out the index vector for it //and add it to the List of these for processing - intersection of union if (TraitIndexList.TryGetValue(searchTraitValues[nn], out TempIndexList)) { IndexList.Add(TempIndexList); } //If trait value string not found then show error message else { Debug.Fail("Trait Value to search for not found in lookup tables"); } } //If trait name string not found then show error message else { Debug.Fail("Trait to search for not found in lookup tables"); } } //If we are only searching for one traitname and trait value pair then return the index vector if (searchTraits.Length == 1) { return(IndexList[0]); } //Otherwise process the List of index vectors else { //Object to hold the array of index values found by the intersection method IEnumerable <int> ReturnList; //If intersection true then find the index values common to all traitname and trait value pairs if (intersection) { ReturnList = IndexList[0].Intersect(IndexList[1]); for (int nn = 2; nn < IndexList.Count; nn++) { ReturnList = ReturnList.Intersect(IndexList[nn]); } } //If intersection false then return all the index values found above else { ReturnList = IndexList[0].Union(IndexList[1]); for (int nn = 2; nn < IndexList.Count; nn++) { ReturnList = ReturnList.Union(IndexList[nn]); } } return(ReturnList.ToArray()); } }