//******************************************************************************************************// 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<string> source) { string returnString = ""; for (int i = 0; i < source.Count(); i++) { returnString += source.ElementAt(i); } return returnString; } public static List<string> ListPrefixes(this string source) { List<string> prefixes = new List<string>(); for (int i = 0; i < source.Length; i++) { prefixes.Add(source.Substring(0, i)); } return prefixes; } public static List<string> ListBigrams(this string source) { List<string> bigrams = new List<string>(); for (int i = 0; i < source.Length - 1; i++) { bigrams.Add(source.Substring(i, i + 1)); } return bigrams; } public static List<string> ListTriGrams(this string source) { List<string> trigrams = new List<string>(); for (int i = 0; i < source.Length - 2; i++) { trigrams.Add(source.Substring(i, i + 2)); } return trigrams; } public static List<string> ListNGrams(this string source, int n) { List<string> ngrams = new List<string>(); 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; } } }}
//******************************************************************************************************
// 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<string> source)
{
string returnString = "";
for (int i = 0; i < source.Count(); i++)
{
returnString += source.ElementAt(i);
}
return returnString;
}
public static List<string> ListPrefixes(this string source)
{
List<string> prefixes = new List<string>();
for (int i = 0; i < source.Length; i++)
{
prefixes.Add(source.Substring(0, i));
}
return prefixes;
}
public static List<string> ListBigrams(this string source)
{
List<string> bigrams = new List<string>();
for (int i = 0; i < source.Length - 1; i++)
{
bigrams.Add(source.Substring(i, i + 1));
}
return bigrams;
}
public static List<string> ListTriGrams(this string source)
{
List<string> trigrams = new List<string>();
for (int i = 0; i < source.Length - 2; i++)
{
trigrams.Add(source.Substring(i, i + 2));
}
return trigrams;
}
public static List<string> ListNGrams(this string source, int n)
{
List<string> ngrams = new List<string>();
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;
}
}
}
}