Changed gitignore
This commit is contained in:
parent
3e4a3949f8
commit
6282edcc13
4
.gitignore
vendored
4
.gitignore
vendored
@ -77,3 +77,7 @@ fabric.properties
|
|||||||
# Android studio 3.1+ serialized cache file
|
# Android studio 3.1+ serialized cache file
|
||||||
.idea/caches/build_file_checksums.ser
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
|
*/bin
|
||||||
|
*/obj
|
||||||
|
*/bin/*
|
||||||
|
*/obj/*
|
||||||
|
35
Tarpit/Tarpit/ServerUtils.cs
Normal file
35
Tarpit/Tarpit/ServerUtils.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Tarpit;
|
||||||
|
|
||||||
|
public static class ServerUtils
|
||||||
|
{
|
||||||
|
public static async Task ProcessRequestAsync(HttpListenerContext context)
|
||||||
|
{
|
||||||
|
HttpListenerRequest request = context.Request;
|
||||||
|
HttpListenerResponse response = context.Response;
|
||||||
|
|
||||||
|
// Determine the next HTML chunk to send
|
||||||
|
const string htmlChunk = "<html><head><title>Progressive HTML</title></head><body><h1>Starting...</h1>";
|
||||||
|
|
||||||
|
// Set the content type
|
||||||
|
response.ContentType = "text/html";
|
||||||
|
|
||||||
|
// Write the HTML chunk to the response stream
|
||||||
|
byte[] buffer = Encoding.UTF8.GetBytes(htmlChunk);
|
||||||
|
response.ContentLength64 = buffer.Length;
|
||||||
|
|
||||||
|
Stream outputStream = response.OutputStream;
|
||||||
|
await outputStream.WriteAsync(buffer, 0, buffer.Length);
|
||||||
|
|
||||||
|
// Close the output stream
|
||||||
|
outputStream.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
90
Tarpit/Tarpit/WordPredictor.cs
Normal file
90
Tarpit/Tarpit/WordPredictor.cs
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
namespace Tarpit;
|
||||||
|
|
||||||
|
public class WordPredictor
|
||||||
|
{
|
||||||
|
private Dictionary<string, List<string>> wordFrequencies;
|
||||||
|
|
||||||
|
public WordPredictor(string filePath)
|
||||||
|
{
|
||||||
|
LoadData(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData(string filePath)
|
||||||
|
{
|
||||||
|
wordFrequencies = new Dictionary<string, List<string>>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (StreamReader reader = new StreamReader(filePath))
|
||||||
|
{
|
||||||
|
string line;
|
||||||
|
string previousWord = null;
|
||||||
|
|
||||||
|
while ((line = reader.ReadLine()) != null)
|
||||||
|
{
|
||||||
|
string[] words = line.ToLower().Split(new char[] { ' ', '.', ',', '!', '?', ';', ':', '\n', '\r', '\t' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
foreach (string word in words)
|
||||||
|
{
|
||||||
|
if (previousWord != null)
|
||||||
|
{
|
||||||
|
if (!wordFrequencies.ContainsKey(previousWord))
|
||||||
|
{
|
||||||
|
wordFrequencies[previousWord] = new List<string>();
|
||||||
|
}
|
||||||
|
wordFrequencies[previousWord].Add(word);
|
||||||
|
}
|
||||||
|
previousWord = word;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error: File not found at {filePath}");
|
||||||
|
Environment.Exit(1); // Exit the program if the file isn't found. Important!
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"An error occurred while reading the file: {ex.Message}");
|
||||||
|
Environment.Exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string PredictNextWord(string inputWord)
|
||||||
|
{
|
||||||
|
if (!wordFrequencies.ContainsKey(inputWord.ToLower()))
|
||||||
|
{
|
||||||
|
return "Word not found in training data.";
|
||||||
|
}
|
||||||
|
|
||||||
|
List<string> nextWords = wordFrequencies[inputWord.ToLower()];
|
||||||
|
|
||||||
|
// Find the most frequent next word
|
||||||
|
string mostFrequentWord = nextWords
|
||||||
|
.GroupBy(w => w)
|
||||||
|
.OrderByDescending(g => g.Count())
|
||||||
|
.First()
|
||||||
|
.Key;
|
||||||
|
|
||||||
|
return mostFrequentWord;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
// Replace "your_text_file.txt" with the path to your text file.
|
||||||
|
string filePath = "your_text_file.txt";
|
||||||
|
|
||||||
|
WordPredictor predictor = new WordPredictor(filePath);
|
||||||
|
|
||||||
|
Console.WriteLine("Enter a word:");
|
||||||
|
string inputWord = Console.ReadLine();
|
||||||
|
|
||||||
|
string predictedWord = predictor.PredictNextWord(inputWord);
|
||||||
|
|
||||||
|
Console.WriteLine($"The most common word after '{inputWord}' is: '{predictedWord}'");
|
||||||
|
|
||||||
|
Console.ReadKey(); // Keep the console window open until a key is pressed
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user