Skip to content

Commit

Permalink
docs:Better random-choice example.
Browse files Browse the repository at this point in the history
  • Loading branch information
antononcube committed Jan 28, 2023
1 parent 15d1ba6 commit 846a2ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README-work.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ ML::TriesWithFrequencies::Trie.^method_names
Generate random words using trie, make a new trie, and visualize it:

```perl6
my @randomWords = $ptr.random-choice.tail(*-1) xx 200;
my @randomWords = $ptr.random-choice(200):drop-root;
my $ptrRandom = trie-create(@randomWords).node-probabilities;
$ptrRandom.form;
```
Expand Down
51 changes: 26 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,25 +150,26 @@ ML::TriesWithFrequencies::Trie.^method_names
Generate random words using trie, make a new trie, and visualize it:

```perl6
my @randomWords = $ptr.random-choice.tail(*-1) xx 200;
my @randomWords = $ptr.random-choice(200):drop-root;
my $ptrRandom = trie-create(@randomWords).node-probabilities;
$ptrRandom.form;
```
```
# TRIEROOT => 1
# ├─b => 0.61
# │ └─a => 1
# │ ├─l => 0.32786885245901637
# │ │ └─m => 1
# │ └─r => 0.6721311475409836
# │ ├─k => 0.3780487804878049
# │ └─s => 0.524390243902439
# └─c => 0.39
# └─e => 1
# ├─l => 0.4358974358974359
# │ └─l => 1
# └─r => 0.5641025641025641
# └─t => 1
# └─TRIEROOT => 1
# ├─b => 0.645
# │ └─a => 1
# │ ├─l => 0.17054263565891473
# │ │ └─m => 1
# │ └─r => 0.8294573643410853
# │ ├─k => 0.48598130841121495
# │ └─s => 0.3925233644859813
# └─c => 0.355
# └─e => 1
# ├─l => 0.5915492957746479
# │ └─l => 1
# └─r => 0.4084507042253521
# └─t => 1
```

Compare with the original one:
Expand Down Expand Up @@ -232,7 +233,7 @@ representation with `ML::TriesWithFrequencies::Trie`:
say $tr.JSON;
```
```
# {"key":"TRIEROOT", "value":2, "children":[{"key":"cor", "value":2, "children":[{"key":"t", "value":1, "children":[]}, {"key":"e", "value":1, "children":[]}]}]}
# {"key":"TRIEROOT", "value":2, "children":[{"key":"cor", "value":2, "children":[{"key":"e", "value":1, "children":[]}, {"key":"t", "value":1, "children":[]}]}]}
```

### XML
Expand All @@ -248,12 +249,12 @@ say $tr.XML;
# <TRIEVALUE>2</TRIEVALUE>
# <cor>
# <TRIEVALUE>2</TRIEVALUE>
# <t>
# <TRIEVALUE>1</TRIEVALUE>
# </t>
# <e>
# <TRIEVALUE>1</TRIEVALUE>
# </e>
# <t>
# <TRIEVALUE>1</TRIEVALUE>
# </t>
# </cor>
# </TRIEROOT>
```
Expand Down Expand Up @@ -290,18 +291,18 @@ say $tr0.XML;
# <TRIEVALUE>2</TRIEVALUE>
# <e>
# <TRIEVALUE>2</TRIEVALUE>
# <s>
# <TRIEVALUE>1</TRIEVALUE>
# <t>
# <TRIEVALUE>1</TRIEVALUE>
# </t>
# </s>
# <l>
# <TRIEVALUE>1</TRIEVALUE>
# <l>
# <TRIEVALUE>1</TRIEVALUE>
# </l>
# </l>
# <s>
# <TRIEVALUE>1</TRIEVALUE>
# <t>
# <TRIEVALUE>1</TRIEVALUE>
# </t>
# </s>
# </e>
# </b>
# </TRIEROOT>
Expand Down Expand Up @@ -330,7 +331,7 @@ Hence, such WL format is provided by the Raku package:
say $tr.WL;
```
```
# <|$TrieRoot -> <|$TrieValue -> 2, "cor" -> <|$TrieValue -> 2, "t" -> <|$TrieValue -> 1|>, "e" -> <|$TrieValue -> 1|>|>|>|>
# <|$TrieRoot -> <|$TrieValue -> 2, "cor" -> <|$TrieValue -> 2, "e" -> <|$TrieValue -> 1|>, "t" -> <|$TrieValue -> 1|>|>|>|>
```

------
Expand Down

0 comments on commit 846a2ed

Please sign in to comment.