You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by gi...@apache.org on 2023/02/10 08:10:15 UTC
[groovy-dev-site] branch asf-site updated: 2023/02/10 08:10:11: Generated dev website from groovy-website@3aff6d3
This is an automated email from the ASF dual-hosted git repository.
git-site-role pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/groovy-dev-site.git
The following commit(s) were added to refs/heads/asf-site by this push:
new 099e5fb 2023/02/10 08:10:11: Generated dev website from groovy-website@3aff6d3
099e5fb is described below
commit 099e5fbac937037e3744d6f15709e8cde3dbc4fb
Author: jenkins <bu...@apache.org>
AuthorDate: Fri Feb 10 08:10:11 2023 +0000
2023/02/10 08:10:11: Generated dev website from groovy-website@3aff6d3
---
blog/fruity-eclipse-collections.html | 96 ++++++++++++++++-----
blog/img/apple_images.png | Bin 0 -> 39121 bytes
blog/img/banana_images.png | Bin 0 -> 38507 bytes
blog/img/cherry_images.png | Bin 0 -> 41220 bytes
blog/img/fruit_emoji.png | Bin 0 -> 59657 bytes
.../img/fruity_eclipse_collections_color_vs_xy.png | Bin 0 -> 76246 bytes
...y_eclipse_collections_peach_color_histogram.png | Bin 0 -> 49346 bytes
...y_eclipse_collections_peach_range_histogram.png | Bin 0 -> 14908 bytes
blog/img/grape_images.png | Bin 0 -> 42137 bytes
blog/img/kmeans_step1.png | Bin 0 -> 12053 bytes
blog/img/kmeans_step2.png | Bin 0 -> 10997 bytes
blog/img/kmeans_step3.png | Bin 0 -> 18312 bytes
blog/img/orange_images.png | Bin 0 -> 36475 bytes
blog/img/peach_centroid_sizes.png | Bin 0 -> 11785 bytes
blog/img/peach_images.png | Bin 0 -> 79987 bytes
blog/img/rgb_peach3d.png | Bin 0 -> 105498 bytes
16 files changed, 76 insertions(+), 20 deletions(-)
diff --git a/blog/fruity-eclipse-collections.html b/blog/fruity-eclipse-collections.html
index a0ca363..e0989f0 100644
--- a/blog/fruity-eclipse-collections.html
+++ b/blog/fruity-eclipse-collections.html
@@ -56,7 +56,7 @@
</div><div id='content' class='page-1'><div class='row'><div class='row-fluid'><div class='col-lg-3'><ul class='nav-sidebar'><li><a href='/blog/'>Blog index</a></li><li class='active'><a href='#doc'>Fruity Eclipse Collections</a></li><li><a href='#_eclipse_collections_fruit_salad' class='anchor-link'>Eclipse Collections Fruit Salad</a></li><li><a href='#_exploring_emoji_colors' class='anchor-link'>Exploring emoji colors</a></li><li><a href='#_putting_it_all_togeth [...]
<div class="sectionbody">
<div class="paragraph">
-<p>This blog post continues on to some degree from the
+<p>This blog post continues on the theme of using fruit emoji from the
<a href="https://blogs.apache.org/groovy/entry/deep-learning-and-eclipse-collections">previous post</a>,
but instead of deep learning, we’ll look at clustering using k-means after first exploring some top methods of <a href="https://www.eclipse.org/collections/">Eclipse Collections</a> with fruit emoji examples.</p>
</div>
@@ -69,14 +69,70 @@ but instead of deep learning, we’ll look at clustering using k-means after
<p>First, we’ll define a Fruit enum (it adds one additional fruit compared to the related
<a href="https://github.com/eclipse/eclipse-collections-kata/tree/master/top-methods-kata-solutions">Eclipse Collections kata</a>):</p>
</div>
-<div class="paragraph">
-<p><span class="image"><img src="https://blogs.apache.org/groovy/mediaresource/8d0d5468-f58a-445a-8e79-854c7815d861" alt="code for fruit enum"></span></p>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code data-lang="groovy">enum Fruit {
+ APPLE('🍎', Color.RED),
+ PEACH('🍑', Color.ORANGE),
+ BANANA('🍌', Color.YELLOW),
+ CHERRY('🍒', Color.RED),
+ ORANGE('🍊', Color.ORANGE),
+ GRAPE('🍇', Color.MAGENTA)
+
+ public static ImmutableList<Fruit> ALL = Lists.immutable.with(values())
+ public static ImmutableList<String> ALL_EMOJI = Lists.immutable.with(*values()*.emoji)
+ final String emoji
+ final Color color
+
+ Fruit(String emoji, Color color) {
+ this.emoji = emoji
+ this.color = color
+ }
+
+ static Fruit of(String emoji) {
+ values().find{it.emoji == emoji }
+ }
+}</code></pre>
+</div>
</div>
<div class="paragraph">
<p>We can use this enum in the following examples which show off numerous common Eclipse Collections methods:</p>
</div>
-<div class="paragraph">
-<p><span class="image"><img src="https://blogs.apache.org/groovy/mediaresource/c272dd74-9d35-49b7-8857-c7fccf1989f0" alt="exploring common eclipse collections methods"></span></p>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code data-lang="groovy">assert Lists.mutable.with('🍎', '🍎', '🍌', '🍌').distinct() ==
+ Lists.mutable.with('🍎', '🍌')
+
+var onlyBanana = Sets.immutable.with('🍌')
+
+assert Fruit.ALL_EMOJI.select(onlyBanana::contains) == List.of('🍌')
+
+assert Fruit.ALL_EMOJI.reject(onlyBanana::contains) ==
+ List.of('🍎', '🍑', '🍒', '🍊', '🍇')
+
+assert Fruit.ALL.groupBy(Fruit::getColor) ==
+ Multimaps.mutable.list.empty()
+ .withKeyMultiValues(RED, Fruit.of('🍎'), Fruit.of('🍒'))
+ .withKeyMultiValues(YELLOW, Fruit.of('🍌'))
+ .withKeyMultiValues(ORANGE, Fruit.of('🍑'), Fruit.of('🍊'))
+ .withKeyMultiValues(MAGENTA, Fruit.of('🍇'))
+
+assert Fruit.ALL.countBy(Fruit::getColor) ==
+ Bags.immutable.withOccurrences(RED, 2, YELLOW, 1, ORANGE, 2, MAGENTA, 1)
+
+Fruit.ALL_EMOJI.chunk(4).with {
+ assert first == Lists.mutable.with('🍎', '🍑', '🍌', '🍒')
+ assert last == Lists.mutable.with('🍊', '🍇')
+}
+
+// For normal threads, replace 'withExistingPool' line of code with:
+//GParsExecutorsPool.withPool { pool ->
+GParsExecutorsPool.withExistingPool(Executors.newVirtualThreadPerTaskExecutor()) { pool ->
+ var parallelFruit = Fruit.ALL.asParallel(pool, 1)
+ var redFruit = parallelFruit.select(fruit -> fruit.color == RED).toList()
+ assert redFruit == Lists.mutable.with(Fruit.of('🍎'), Fruit.of('🍒'))
+}</code></pre>
+</div>
</div>
<div class="paragraph">
<p>The last example calculates red fruit in parallel threads.
@@ -95,7 +151,7 @@ Here we are only using one method which is managing pool lifecycle for us.</p>
of the related emoji. As in the previous blog, we’ll use the slightly nicer
<a href="https://fonts.google.com/noto/specimen/Noto+Color+Emoji?preview.text=%F0%9F%8D%8E%F0%9F%8D%91%F0%9F%8D%8C%F0%9F%8D%92%F0%9F%8D%8A%F0%9F%8D%87&preview.text_type=custom">Noto Color Emoji</a>
fonts for our fruit as shown here:
-<span class="image"><img src="https://blogs.apache.org/groovy/mediaresource/4e4f1abe-0775-442d-ba17-7488e3eeca49" alt="Noto Color Emoji"></span>
+<span class="image"><img src="img/fruit_emoji.png" alt="Noto Color Emoji"></span>
We’ll use an Eclipse Collection <code>BiMap</code> to switch back and forth between the color names
and java.awt colors:</p>
</div>
@@ -169,7 +225,7 @@ static range(int deg) {
<div class="paragraph">
<p>We used a <a href="https://plotly.com/javascript/">Plotly</a> 3D interactive scatterplot
(as supported by the <a href="https://jtablesaw.github.io/tablesaw/userguide/Introduction_to_Plotting">Tablesaw</a> Java dataframe and visualization library to visualize our emoji colors (as degrees on the color spectrum) vs the XY coordinates:
-<span class="image"><img src="https://blogs.apache.org/groovy/mediaresource/85b4c127-52a3-4cc6-a7fc-1e72aa49e8b8" alt="Color vs xy plot"></span></p>
+<span class="image"><img src="img/fruity_eclipse_collections_color_vs_xy.png" alt="Color vs xy plot"></span></p>
</div>
<div class="paragraph">
<p>We are going to try out 3 approaches for determining the predominant color of each emoji:</p>
@@ -191,14 +247,14 @@ static range(int deg) {
<h3 id="_most_common_color">Most Common Color</h3>
<div class="paragraph">
<p>Ignoring the background white color, the most common color for our PEACH emoji is a shade of orange. The graph below shows the count of each color:
-<span class="image"><img src="https://blogs.apache.org/groovy/mediaresource/b9f82465-62e2-45c0-926f-634568381be8" alt="Color histogram for PEACH"></span></p>
+<span class="image"><img src="img/fruity_eclipse_collections_peach_color_histogram.png" alt="Color histogram for PEACH"></span></p>
</div>
</div>
<div class="sect2">
<h3 id="_most_common_range">Most Common Range</h3>
<div class="paragraph">
<p>If instead of counting each color, we group colors into their range and count the numbers in each range, we get the following graph for PEACH:
-<span class="image"><img src="https://blogs.apache.org/groovy/mediaresource/4ce2ac0e-87ac-4509-9fa8-10928419f4a0" alt="Range histogram for PEACH"></span></p>
+<span class="image"><img src="img/fruity_eclipse_collections_peach_range_histogram.png" alt="Range histogram for PEACH"></span></p>
</div>
</div>
<div class="sect2">
@@ -208,19 +264,19 @@ static range(int deg) {
3 random points as our starting centroids.</p>
</div>
<div class="paragraph">
-<p><span class="image"><img src="https://blogs.apache.org/groovy/mediaresource/6192d3b7-a3c7-4ce5-b0c0-a3286619dd12" alt="kmeans step 1"></span></p>
+<p><span class="image"><img src="img/kmeans_step1.png" alt="kmeans step 1"></span></p>
</div>
<div class="paragraph">
<p>We allocate all points to their closest centroid:</p>
</div>
<div class="paragraph">
-<p><span class="image"><img src="https://blogs.apache.org/groovy/mediaresource/751eaac0-5ba2-448d-8f67-6ebf53613ac9" alt="kmeans step 2"></span></p>
+<p><span class="image"><img src="img/kmeans_step2.png" alt="kmeans step 2"></span></p>
</div>
<div class="paragraph">
<p>Given this allocation, we re-calculate each centroid from all of its points:</p>
</div>
<div class="paragraph">
-<p><span class="image"><img src="https://blogs.apache.org/groovy/mediaresource/daa9530e-fc5d-458d-8029-a1fd8a62d521" alt="kmeans step 3"></span></p>
+<p><span class="image"><img src="img/kmeans_step3.png" alt="kmeans step 3"></span></p>
</div>
<div class="paragraph">
<p>We repeat this process until either a stable centroid selection
@@ -236,11 +292,11 @@ The centroid with the most points allocated to it should be the
most predominant color. (This is another interactive 3D scatterplot.)</p>
</div>
<div class="paragraph">
-<p><span class="image"><img src="https://blogs.apache.org/groovy/mediaresource/f6bf5f7e-f384-4316-a1da-f8ec62ebae47" alt="RgbPeach3d"></span>
+<p><span class="image"><img src="img/rgb_peach3d.png" alt="RgbPeach3d"></span>
We can plot the number of points allocated to each cluster as a
bar chart. (We used a <a href="https://github.com/alexarchambault/plotly-scala">Scala plotting library</a>
to show Groovy integration with Scala.)
-<span class="image"><img src="https://blogs.apache.org/groovy/mediaresource/9bfd0a6e-85a8-4615-b0d7-f719a9459ad3" alt="Peach colour centroid sizes"></span></p>
+<span class="image"><img src="img/peach_centroid_sizes.png" alt="Peach colour centroid sizes"></span></p>
</div>
<div class="paragraph">
<p>The code for drawing the above chart looks like this:</p>
@@ -368,12 +424,12 @@ results.each { fruit, maxRange, maxColor, maxCentroid ->
<p>Here are the resulting images:</p>
</div>
<div class="paragraph">
-<p><span class="image"><img src="https://blogs.apache.org/groovy/mediaresource/442d7100-5023-43ce-a525-0db682fc7b60" alt="peach images"></span>
-<span class="image"><img src="https://blogs.apache.org/groovy/mediaresource/1fc50ff2-7881-4bd3-a8c7-a6283222d91d" alt="banana images"></span>
-<span class="image"><img src="https://blogs.apache.org/groovy/mediaresource/6b35338d-be4b-40a4-81dc-e317a68fbb1e" alt="cherry images"></span>
-<span class="image"><img src="https://blogs.apache.org/groovy/mediaresource/d3ff8625-d429-4c7c-bfcd-531df53a8256" alt="orange images"></span>
-<span class="image"><img src="https://blogs.apache.org/groovy/mediaresource/1f1b755a-7dcf-4c53-b930-07c3ef8f0a2f" alt="grape images"></span>
-<span class="image"><img src="https://blogs.apache.org/groovy/mediaresource/d166e557-2ba2-4058-9bde-fb8b682d4c4b" alt="apple images"></span></p>
+<p><span class="image"><img src="img/peach_images.png" alt="peach images"></span>
+<span class="image"><img src="img/banana_images.png" alt="banana images"></span>
+<span class="image"><img src="img/cherry_images.png" alt="cherry images"></span>
+<span class="image"><img src="img/orange_images.png" alt="orange images"></span>
+<span class="image"><img src="img/grape_images.png" alt="grape images"></span>
+<span class="image"><img src="img/apple_images.png" alt="apple images"></span></p>
</div>
<div class="paragraph">
<p>And, here are the final results:</p>
diff --git a/blog/img/apple_images.png b/blog/img/apple_images.png
new file mode 100644
index 0000000..0916cb7
Binary files /dev/null and b/blog/img/apple_images.png differ
diff --git a/blog/img/banana_images.png b/blog/img/banana_images.png
new file mode 100644
index 0000000..50ab463
Binary files /dev/null and b/blog/img/banana_images.png differ
diff --git a/blog/img/cherry_images.png b/blog/img/cherry_images.png
new file mode 100644
index 0000000..e933455
Binary files /dev/null and b/blog/img/cherry_images.png differ
diff --git a/blog/img/fruit_emoji.png b/blog/img/fruit_emoji.png
new file mode 100644
index 0000000..c5948b4
Binary files /dev/null and b/blog/img/fruit_emoji.png differ
diff --git a/blog/img/fruity_eclipse_collections_color_vs_xy.png b/blog/img/fruity_eclipse_collections_color_vs_xy.png
new file mode 100644
index 0000000..a69b701
Binary files /dev/null and b/blog/img/fruity_eclipse_collections_color_vs_xy.png differ
diff --git a/blog/img/fruity_eclipse_collections_peach_color_histogram.png b/blog/img/fruity_eclipse_collections_peach_color_histogram.png
new file mode 100644
index 0000000..0338730
Binary files /dev/null and b/blog/img/fruity_eclipse_collections_peach_color_histogram.png differ
diff --git a/blog/img/fruity_eclipse_collections_peach_range_histogram.png b/blog/img/fruity_eclipse_collections_peach_range_histogram.png
new file mode 100644
index 0000000..d28ba96
Binary files /dev/null and b/blog/img/fruity_eclipse_collections_peach_range_histogram.png differ
diff --git a/blog/img/grape_images.png b/blog/img/grape_images.png
new file mode 100644
index 0000000..7e75e76
Binary files /dev/null and b/blog/img/grape_images.png differ
diff --git a/blog/img/kmeans_step1.png b/blog/img/kmeans_step1.png
new file mode 100644
index 0000000..80196f7
Binary files /dev/null and b/blog/img/kmeans_step1.png differ
diff --git a/blog/img/kmeans_step2.png b/blog/img/kmeans_step2.png
new file mode 100644
index 0000000..f573138
Binary files /dev/null and b/blog/img/kmeans_step2.png differ
diff --git a/blog/img/kmeans_step3.png b/blog/img/kmeans_step3.png
new file mode 100644
index 0000000..5c66dce
Binary files /dev/null and b/blog/img/kmeans_step3.png differ
diff --git a/blog/img/orange_images.png b/blog/img/orange_images.png
new file mode 100644
index 0000000..8424df1
Binary files /dev/null and b/blog/img/orange_images.png differ
diff --git a/blog/img/peach_centroid_sizes.png b/blog/img/peach_centroid_sizes.png
new file mode 100644
index 0000000..4decec0
Binary files /dev/null and b/blog/img/peach_centroid_sizes.png differ
diff --git a/blog/img/peach_images.png b/blog/img/peach_images.png
new file mode 100644
index 0000000..a3e318c
Binary files /dev/null and b/blog/img/peach_images.png differ
diff --git a/blog/img/rgb_peach3d.png b/blog/img/rgb_peach3d.png
new file mode 100644
index 0000000..35862d4
Binary files /dev/null and b/blog/img/rgb_peach3d.png differ