//****************************************************************************************************** // Operations.cs - Gbtc // // Copyright © 2013, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may // not use this file except in compliance with the License. You may obtain a copy of the License at: // // http://www.opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 04/14/2013 - Kevin D. Jones // Generated original version of source code. // //****************************************************************************************************** using System.Collections.Generic; using System.Linq; // TODO: Please add comments to these classes #pragma warning disable 1591 namespace GSF.FuzzyStrings { public static class Operations { public static string Capitalize(this string source) { return source.ToUpper(); } public static string[] SplitIntoIndividualElements(string source) { string[] stringCollection = new string[source.Length]; for (int i = 0; i < stringCollection.Length; i++) { stringCollection[i] = source[i].ToString(); } return stringCollection; } public static string MergeIndividualElementsIntoString(IEnumerable source) { string returnString = ""; for (int i = 0; i < source.Count(); i++) { returnString += source.ElementAt(i); } return returnString; } public static List ListPrefixes(this string source) { List prefixes = new List(); for (int i = 0; i < source.Length; i++) { prefixes.Add(source.Substring(0, i)); } return prefixes; } public static List ListBigrams(this string source) { List bigrams = new List(); for (int i = 0; i < source.Length - 1; i++) { bigrams.Add(source.Substring(i, i + 1)); } return bigrams; } public static List ListTriGrams(this string source) { List trigrams = new List(); for (int i = 0; i < source.Length - 2; i++) { trigrams.Add(source.Substring(i, i + 2)); } return trigrams; } public static List ListNGrams(this string source, int n) { List ngrams = new List(); if (n > source.Length) { return null; } else if (n == source.Length) { ngrams.Add(source); return ngrams; } else { for (int i = 0; i < source.Length - n; i++) { ngrams.Add(source.Substring(i, i + n)); } return ngrams; } } } }