start docu
This commit is contained in:
parent
e2db0aca19
commit
32b8025fda
4 changed files with 31 additions and 20 deletions
|
@ -1,4 +1,4 @@
|
|||
module analyze
|
||||
module analyse
|
||||
|
||||
go 1.18
|
||||
|
||||
|
|
|
@ -35,18 +35,14 @@ func (l letterList) Swap(i, j int) {
|
|||
}
|
||||
|
||||
const LettersInTheAlphabet = 26
|
||||
|
||||
var alphabet = [LettersInTheAlphabet]rune{
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
}
|
||||
const startUpperCase = 65
|
||||
|
||||
var letters = make([]letter, LettersInTheAlphabet)
|
||||
|
||||
func initLetterStruct() {
|
||||
for index := range alphabet {
|
||||
letters[index].upperCase = string(alphabet[index])
|
||||
letters[index].lowerCase = string(alphabet[index] + 32)
|
||||
for i := 0; i < LettersInTheAlphabet; i++ {
|
||||
letters[i].upperCase = string(rune(startUpperCase + i))
|
||||
letters[i].lowerCase = string(rune(startUpperCase + i + 32))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,24 +56,24 @@ func readFile(relativePath string) string {
|
|||
|
||||
func countLetters(inputText string) int {
|
||||
totalCount := 0
|
||||
for index := range alphabet {
|
||||
letters[index].count +=
|
||||
strings.Count(inputText, letters[index].lowerCase) +
|
||||
strings.Count(inputText, letters[index].upperCase)
|
||||
totalCount += letters[index].count
|
||||
for i := 0; i < LettersInTheAlphabet; i++ {
|
||||
letters[i].count +=
|
||||
strings.Count(inputText, letters[i].lowerCase) +
|
||||
strings.Count(inputText, letters[i].upperCase)
|
||||
totalCount += letters[i].count
|
||||
}
|
||||
return totalCount
|
||||
}
|
||||
|
||||
func calculateFrequency(totalCount int) {
|
||||
for index := range alphabet {
|
||||
letters[index].frequency = percent.PercentOf(letters[index].count, totalCount)
|
||||
for i := 0; i < LettersInTheAlphabet; i++ {
|
||||
letters[i].frequency = percent.PercentOf(letters[i].count, totalCount)
|
||||
}
|
||||
}
|
||||
|
||||
func printResult() {
|
||||
for index := range alphabet {
|
||||
l := letters[index]
|
||||
for i := 0; i < LettersInTheAlphabet; i++ {
|
||||
l := letters[i]
|
||||
fmt.Printf(
|
||||
"The letter %s (%s) occurs %d times in the text and the frequencyArray in percent is %0.2f\n",
|
||||
l.upperCase, l.lowerCase, l.count, l.frequency,
|
||||
|
@ -87,8 +83,8 @@ func printResult() {
|
|||
|
||||
func plotResult() {
|
||||
var count plotter.Values
|
||||
for index := range alphabet {
|
||||
count = append(count, float64(letters[index].count))
|
||||
for i := 0; i < LettersInTheAlphabet; i++ {
|
||||
count = append(count, float64(letters[i].count))
|
||||
}
|
||||
p := plot.New()
|
||||
p.Title.Text = "Letter count"
|
||||
|
|
Reference in a new issue