Experiments into markov chains, n-grams, and text generation.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

40 lines
865 B

using System;
using System.Collections.Generic;
using System.Linq;
namespace MarkovGrams.Utilities
{
public static class LinqExtensions
{
public static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> action)
{
foreach (T item in enumerable)
{
action(item);
}
}
public static T ShiftAt<T>(this List<T> list, int index)
{
T item = list[index];
list.RemoveAt(index);
return item;
}
public static int CountCharInstances(this string str, char[] targets)
{
int result = 0;
for (int i = 0; i < str.Length; i++) {
for (int t = 0; t < targets.Length; t++)
if (str[i] == targets[t]) result++;
}
return result;
}
public static bool StartsWithFast(this string str, string target)
{
if (str.Length < target.Length) return false;
return str.Substring(0, target.Length) == target;
}
}
}