Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
55
Task/Word-frequency/PureBasic/word-frequency.basic
Normal file
55
Task/Word-frequency/PureBasic/word-frequency.basic
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
EnableExplicit
|
||||
|
||||
Structure wordcount
|
||||
wkey$
|
||||
count.i
|
||||
EndStructure
|
||||
|
||||
Define token.c, word$, idx.i, start.i, arg$
|
||||
NewMap wordmap.i()
|
||||
NewList wordlist.wordcount()
|
||||
|
||||
If OpenConsole("")
|
||||
arg$ = ProgramParameter(0)
|
||||
If arg$ = "" : End 1 : EndIf
|
||||
start = ElapsedMilliseconds()
|
||||
If ReadFile(0, arg$, #PB_Ascii)
|
||||
While Not Eof(0)
|
||||
token = ReadCharacter(0, #PB_Ascii)
|
||||
Select token
|
||||
Case 'A' To 'Z', 'a' To 'z'
|
||||
word$ + LCase(Chr(token))
|
||||
Default
|
||||
If word$
|
||||
wordmap(word$) + 1
|
||||
word$ = ""
|
||||
EndIf
|
||||
EndSelect
|
||||
Wend
|
||||
CloseFile(0)
|
||||
ForEach wordmap()
|
||||
AddElement(wordlist())
|
||||
wordlist()\wkey$ = MapKey(wordmap())
|
||||
wordlist()\count = wordmap()
|
||||
Next
|
||||
SortStructuredList(wordlist(), #PB_Sort_Descending, OffsetOf(wordcount\count), TypeOf(wordcount\count))
|
||||
PrintN("Elapsed milliseconds: " + Str(ElapsedMilliseconds() - start))
|
||||
PrintN("File: " + GetFilePart(arg$))
|
||||
PrintN(~"Rank\tCount\t\t Word")
|
||||
If FirstElement(wordlist())
|
||||
For idx = 1 To 10
|
||||
Print(RSet(Str(idx), 2))
|
||||
Print(~"\t")
|
||||
Print(wordlist()\wkey$)
|
||||
Print(~"\t\t")
|
||||
PrintN(RSet(Str(wordlist()\count), 6))
|
||||
If NextElement(wordlist()) = 0
|
||||
Break
|
||||
EndIf
|
||||
Next
|
||||
EndIf
|
||||
EndIf
|
||||
Input()
|
||||
EndIf
|
||||
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue