Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Text
- Module Module1
- Private Letters As String = "*abcdefghijklmnopqrstuvwxyz"
- Sub Main()
- Dim meh As New LetterAnalysis("C:\Users\TizzyT\Desktop\VBES 2 Analysis\words_alpha.txt")
- Dim sb As New StringBuilder
- If meh.AnalyzeSecond Then
- While meh.Analyzing
- End While
- sb.AppendLine("Analysis by TizzyT:")
- sb.AppendLine(meh.WordsCount & " words")
- sb.AppendLine(meh.LettersCount & " letters")
- sb.AppendLine()
- sb.AppendLine("=============================")
- For Each l As Char In Letters
- Dim Pop As Double = 0
- Dim ordr As New List(Of LetterStat)
- For Each ll As Char In Letters
- Dim c As Integer
- c = meh.SecondFrequency(l, ll)
- ordr.Add(New LetterStat(ll, c))
- Pop += c
- Next
- sb.AppendLine()
- ordr.Sort()
- ordr.Reverse()
- For Each e As LetterStat In ordr
- sb.AppendLine((" " & l & " | " & e.Ch & vbTab & e.Value.ToString.PadLeft(6, " ") & vbTab & "%" & ((e.Value / (Pop - 1)) * 100).ToString.PadRight(12, "0"c).Substring(0, 12)).Replace("*", " "))
- Next
- sb.AppendLine()
- sb.AppendLine((" Score :: " & Pop).Replace("*", " "))
- sb.AppendLine()
- sb.AppendLine("=============================")
- Next
- IO.File.WriteAllText("C:\Users\TizzyT\Desktop\VBES 2 Analysis\Frequency.txt", sb.ToString)
- Console.WriteLine("Done")
- Else
- Console.WriteLine("There was a problem in the analysis")
- End If
- End Sub
- Public Structure LetterStat
- Implements IComparable
- Public ReadOnly Value As Integer
- Public ReadOnly Ch As Char
- Public Sub New(ByVal Character As Char, ByVal Value As Integer)
- Ch = Character
- Me.Value = Value
- End Sub
- Public Function CompareTo(obj As Object) As Integer Implements IComparable.CompareTo
- Return Value.CompareTo(CType(obj, LetterStat).Value)
- End Function
- Public Shared Widening Operator CType(ByVal N As LetterStat) As Integer
- Return N.Value
- End Operator
- End Structure
- Public Class LetterAnalysis
- Private FrequencyCounter As New Dictionary(Of Char, Dictionary(Of Char, Integer))
- Public ReadOnly Property SecondFrequency(ByVal LetterA As Char, ByVal LetterB As Char) As Integer
- Get
- If FrequencyCounter.ContainsKey(LetterA) Then
- If FrequencyCounter(LetterA).ContainsKey(LetterB) Then
- Return FrequencyCounter(LetterA)(LetterB)
- End If
- End If
- Return 0
- End Get
- End Property
- Private AnalysisThread As Threading.Thread
- Private Words() As String
- Public ReadOnly Property WordsCount() As Integer
- Get
- Return Words.Length
- End Get
- End Property
- Private _LettersCount As Integer = 0
- Public ReadOnly Property LettersCount() As Integer
- Get
- Return _LettersCount
- End Get
- End Property
- Public Function AnalyzeSecond() As Boolean
- Try
- AnalysisThread = New Threading.Thread(AddressOf _AnalyzeSecond)
- AnalysisThread.Start()
- Return True
- Catch ex As Exception
- Return False
- End Try
- End Function
- Private Sub _AnalyzeSecond()
- _ProcessedLetters = 0
- _ProcessedWords = 0
- FrequencyCounter.Clear()
- For Each w As String In Words
- If w.Length > 0 Then
- Dim pl As Char = "*"c
- For Each l As Char In w
- If Not FrequencyCounter.ContainsKey(pl) Then FrequencyCounter.Add(pl, New Dictionary(Of Char, Integer))
- If FrequencyCounter(pl).ContainsKey(l) Then
- FrequencyCounter(pl)(l) += 1
- Else
- FrequencyCounter(pl).Add(l, 1)
- End If
- pl = l
- _ProcessedLetters += 1
- Next
- _ProcessedWords += 1
- End If
- Next
- End Sub
- Private _ProcessedLetters As Integer = 0
- Public ReadOnly Property ProcessedLetters() As Integer
- Get
- Return _ProcessedLetters
- End Get
- End Property
- Private _ProcessedWords As Integer = 0
- Public ReadOnly Property ProcessedWords() As Integer
- Get
- Return _ProcessedWords
- End Get
- End Property
- Private _Analyzing As Boolean = False
- Public ReadOnly Property Analyzing As Boolean
- Get
- SyncLock AnalysisThread
- If AnalysisThread.ThreadState = Threading.ThreadState.Running Then Return True
- End SyncLock
- Return False
- End Get
- End Property
- Private Sub New()
- End Sub
- Public Sub New(ByVal Path As String)
- Words = IO.File.ReadAllLines(Path)
- Dim PreviousWord As String = String.Empty
- For i = 0 To Words.Length - 1
- Dim _w As String = Words(i).Trim.ToLower
- If _w.Equals(PreviousWord) Then
- Words(i) = String.Empty
- Else
- _LettersCount += _w.Length
- PreviousWord = _w
- End If
- Next
- Console.WriteLine("Word List Loaded")
- End Sub
- End Class
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement