Compare commits
No commits in common. "045a07fc0a5ae1967beee8f9371d18fcb70862a8" and "3e4a3949f8cdb8aa423f82d9fade887fb0f54037" have entirely different histories.
045a07fc0a
...
3e4a3949f8
8
.gitignore
vendored
8
.gitignore
vendored
@ -77,11 +77,3 @@ fabric.properties
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
*/bin
|
||||
*/obj
|
||||
*/bin/*
|
||||
*/obj/*
|
||||
*obj/
|
||||
*bin/
|
||||
wordlist*
|
||||
*DotSettings*
|
||||
|
10
Tarpit/.idea/.idea.Tarpit/.idea/.gitignore
vendored
10
Tarpit/.idea/.idea.Tarpit/.idea/.gitignore
vendored
@ -1,10 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/modules.xml
|
||||
/contentModel.xml
|
||||
/projectSettingsUpdater.xml
|
||||
/.idea.Tarpit.iml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -1,16 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tarpit", "Tarpit\Tarpit.csproj", "{9AABA4AF-ECB0-4307-B4D3-201A10A19F31}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9AABA4AF-ECB0-4307-B4D3-201A10A19F31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9AABA4AF-ECB0-4307-B4D3-201A10A19F31}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9AABA4AF-ECB0-4307-B4D3-201A10A19F31}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9AABA4AF-ECB0-4307-B4D3-201A10A19F31}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
@ -1,40 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using Tarpit;
|
||||
/*
|
||||
const string filePath = "/home/skingging/Documents/Projects/CSharp/AI-Tarpit/Tarpit/words/wordlist.txt";
|
||||
WordPredictor predictor = new(filePath);
|
||||
string inputWord = Console.ReadLine() ?? string.Empty;
|
||||
List<string?> predictedWord = predictor.PredictNextWord(inputWord.ToLower());
|
||||
*/
|
||||
|
||||
|
||||
const string baseAddress = "http://localhost:10000/";
|
||||
|
||||
|
||||
HttpListener listener = new();
|
||||
listener.Prefixes.Add(baseAddress);
|
||||
|
||||
ServerUtils serverUtils = new();
|
||||
|
||||
try
|
||||
{
|
||||
listener.Start();
|
||||
Console.WriteLine("Listening on " + baseAddress);
|
||||
|
||||
while (true)
|
||||
{
|
||||
HttpListenerContext context = await listener.GetContextAsync();
|
||||
await serverUtils.ProcessRequestAsync(context);
|
||||
}
|
||||
}
|
||||
catch (HttpListenerException ex)
|
||||
{
|
||||
Console.WriteLine("Error starting or running the listener: " + ex.Message);
|
||||
Console.WriteLine("Make sure you have the necessary permissions (requires running as administrator sometimes)");
|
||||
}
|
||||
finally
|
||||
{
|
||||
listener.Stop();
|
||||
listener.Close();
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace Tarpit;
|
||||
|
||||
public class ServerUtils
|
||||
{
|
||||
private int _step = 0;
|
||||
|
||||
public async Task ProcessRequestAsync(HttpListenerContext context)
|
||||
{
|
||||
HttpListenerResponse response = context.Response;
|
||||
|
||||
response.ContentType = "text/html; charset=utf-8";
|
||||
|
||||
Stream outputStream = response.OutputStream;
|
||||
|
||||
int i = 0;
|
||||
while (true)
|
||||
{
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(GetNextHtmlChunk());
|
||||
await outputStream.WriteAsync(buffer, 0, buffer.Length);
|
||||
await outputStream.FlushAsync();
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
outputStream.Close();
|
||||
}
|
||||
|
||||
string GetNextHtmlChunk()
|
||||
{
|
||||
Task.Delay(1).Wait();
|
||||
|
||||
switch (_step)
|
||||
{
|
||||
case 0:
|
||||
_step++;
|
||||
return "<html><head><title>Progressive HTML</title></head><body><h1>Starting...</h1>";
|
||||
case 1:
|
||||
_step++;
|
||||
return "<p>This is the first paragraph.</p>";
|
||||
case 2:
|
||||
_step++;
|
||||
return "<p>Here's another paragraph with some <strong>bold text</strong>.</p>";
|
||||
case 3:
|
||||
_step++;
|
||||
return "<ul><li>Item 1</li><li>Item 2</li></ul>";
|
||||
case 4:
|
||||
_step++;
|
||||
return "<img src=\"https://via.placeholder.com/150\" alt=\"Placeholder Image\">";
|
||||
default:
|
||||
_step = 0;
|
||||
return "</body></html>";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
@ -1,75 +0,0 @@
|
||||
namespace Tarpit;
|
||||
|
||||
public class WordPredictor
|
||||
{
|
||||
private Dictionary<string, List<string>> _wordFrequencies = new();
|
||||
|
||||
public WordPredictor(string filePath)
|
||||
{
|
||||
LoadData(filePath);
|
||||
}
|
||||
|
||||
private void LoadData(string filePath)
|
||||
{
|
||||
_wordFrequencies = new();
|
||||
|
||||
try
|
||||
{
|
||||
using StreamReader reader = new(filePath);
|
||||
string? previousWord = null;
|
||||
|
||||
while (reader.ReadLine() is { } line)
|
||||
{
|
||||
string[] words = line.Split(new char[] { ' ', '.', ',', '!', '?', ';', ':', '(', ')', '\n', '\r', '\t' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (string word in words)
|
||||
{
|
||||
if (previousWord != null)
|
||||
{
|
||||
if (!_wordFrequencies.ContainsKey(previousWord))
|
||||
{
|
||||
_wordFrequencies[previousWord] = [];
|
||||
}
|
||||
_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 List<string?> PredictNextWord(string inputWord)
|
||||
{
|
||||
if (!_wordFrequencies.ContainsKey(inputWord.ToLower()))
|
||||
{
|
||||
return ["Word not found in training data."];
|
||||
}
|
||||
|
||||
List<string> nextWords = _wordFrequencies[inputWord.ToLower()];
|
||||
|
||||
List<string?> words = [];
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
string? mostFrequentWord = nextWords
|
||||
.GroupBy(w => w)
|
||||
.OrderByDescending(g => g.Count())
|
||||
.ElementAtOrDefault(i)
|
||||
?.Key;
|
||||
|
||||
words.Add(mostFrequentWord);
|
||||
}
|
||||
|
||||
return words;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user