Skip to content

Commit 4733327

Browse files
committed
Add a new page to generate random trained message
to verify the quantity of Jieba tokenization
1 parent 35394c0 commit 4733327

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class TokenizationSamplesController < ApplicationController
2+
def new
3+
@trained_messages = TrainedMessage.order("RANDOM()").limit(5)
4+
if @trained_messages.any?
5+
service = SpamClassifierService.new(0, "dummy")
6+
@samples = @trained_messages.map do |msg|
7+
{
8+
original: msg.message,
9+
cleaned: service.clean_text(msg.message),
10+
tokens: service.tokenize(msg.message)
11+
}
12+
end
13+
else
14+
@samples = []
15+
end
16+
end
17+
end

app/views/layouts/application.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747

4848
<%= link_to "Banned Users", banned_users_path,
4949
class: "#{current_page?(banned_users_path) ? 'border-indigo-500 text-gray-900' : 'border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700'} inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium" %>
50+
<%= link_to "Tokenization Samples", new_tokenization_sample_path,
51+
class: "#{current_page?(new_tokenization_sample_path) ? 'border-indigo-500 text-gray-900' : 'border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700'} inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium" %>
5052
<%= link_to "Solid Queue Dashboard", solid_queue_dashboard.root_path,
5153
class: "#{current_page?(solid_queue_dashboard.root_path) ? 'border-indigo-500 text-gray-900' : 'border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700'} inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium" %>
5254
</div>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<div class="container mx-auto px-4">
2+
<h1 class="text-2xl font-bold mb-4">Tokenization Samples</h1>
3+
4+
<%= link_to "Get Another Random Samples",
5+
new_tokenization_sample_path,
6+
data: { turbo_frame: "sample" },
7+
class: "bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" %>
8+
9+
<turbo-frame id="sample">
10+
<% if @samples.any? %>
11+
<% @samples.each_with_index do |sample, index| %>
12+
<div class="mt-6 p-4 border rounded shadow bg-white">
13+
<h2 class="text-xl font-semibold">Sample <%= index + 1 %></h2>
14+
15+
<div class="mt-2">
16+
<h3 class="text-lg font-medium">Original Message</h3>
17+
<p class="bg-gray-100 p-2 rounded"><%= sample[:original] %></p>
18+
</div>
19+
20+
<div class="mt-2">
21+
<h3 class="text-lg font-medium">Cleaned Message</h3>
22+
<p class="bg-gray-100 p-2 rounded"><%= sample[:cleaned] %></p>
23+
</div>
24+
25+
<div class="mt-2">
26+
<h3 class="text-lg font-medium">Tokens</h3>
27+
<div class="bg-gray-100 p-2 rounded flex flex-wrap">
28+
<% sample[:tokens].each do |token| %>
29+
<span class="inline-block bg-gray-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2 mb-2">
30+
<%= token %>
31+
</span>
32+
<% end %>
33+
</div>
34+
</div>
35+
</div>
36+
<% end %>
37+
<% else %>
38+
<p class="mt-4">No trained messages found in the database.</p>
39+
<% end %>
40+
</turbo-frame>
41+
</div>

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
resources :trained_messages do
66
post :bulk_update, on: :collection
77
end
8+
resources :tokenization_samples, only: [ :new ]
89
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
910

1011
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.

0 commit comments

Comments
 (0)