コミットを比較
1 コミット
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
| ffebce36b9 |
@@ -125,64 +125,6 @@ npm run preview
|
|||||||
- TypeScript and TSX use 4-space logical indentation.
|
- TypeScript and TSX use 4-space logical indentation.
|
||||||
- In TypeScript and TSX only, replace every leading run of 8 spaces with a tab.
|
- In TypeScript and TSX only, replace every leading run of 8 spaces with a tab.
|
||||||
- Tabs are only for leading indentation, never for spaces after non-space text.
|
- Tabs are only for leading indentation, never for spaces after non-space text.
|
||||||
- TypeScript and TSX imports may stay on one line if they remain within the
|
|
||||||
line limit; do not expand short type-only imports mechanically.
|
|
||||||
- In TypeScript and TSX, when a function takes one destructured object
|
|
||||||
argument plus an inline type, prefer this shape when it fits locally:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const helper = (
|
|
||||||
{ value, flag }: { value: string
|
|
||||||
flag: boolean },
|
|
||||||
): Result => {
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
- In TypeScript and TSX, put `switch` case block braces on their own lines
|
|
||||||
when a case needs a lexical block:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
case 'yes':
|
|
||||||
case 'no':
|
|
||||||
{
|
|
||||||
const expected = valueFor (item)
|
|
||||||
return expected == null || expected === answer
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
- In TypeScript and TSX, use `value == null` and `value != null` as the
|
|
||||||
default nullish checks. Do not use `=== null`, `=== undefined`,
|
|
||||||
`!== null`, or `!== undefined`.
|
|
||||||
- If code appears to need a distinction between `null` and `undefined`, treat
|
|
||||||
that as a design smell and revise the logic to avoid the distinction.
|
|
||||||
External library APIs that explicitly require distinguishing the two are the
|
|
||||||
only exception.
|
|
||||||
- In TypeScript and TSX, keep short arrays on one line when they fit under the
|
|
||||||
line limit; break arrays only when readability or line length requires it.
|
|
||||||
- In TypeScript and TSX, when a ternary expression is split across multiple
|
|
||||||
lines, align `?` and `:` with the condition expression. Do not indent `?` and
|
|
||||||
`:` one extra level under the condition.
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const value =
|
|
||||||
condition
|
|
||||||
? consequent
|
|
||||||
: alternate
|
|
||||||
```
|
|
||||||
|
|
||||||
- In TypeScript and TSX, keep short ternary expressions on one line when they
|
|
||||||
fit cleanly under the line limit.
|
|
||||||
- In TypeScript and TSX, prefer ternary expressions for simple conditional
|
|
||||||
value selection. Do not replace a clear ternary with `if` statements, and do
|
|
||||||
not introduce immediately invoked functions just to avoid or reformat a
|
|
||||||
ternary expression.
|
|
||||||
- In TypeScript and TSX, do not write `let` followed by later `if` assignments
|
|
||||||
when the value can be expressed as a single `const` initializer. Prefer
|
|
||||||
`const` because it prevents accidental later reassignment.
|
|
||||||
- When fixing formatting, change formatting only. Do not change expression
|
|
||||||
structure, control flow, or variable mutability unless the requested style
|
|
||||||
explicitly requires it.
|
|
||||||
- Do not add production dependencies without explicit approval.
|
- Do not add production dependencies without explicit approval.
|
||||||
- Do not create, modify, or run tests unless the user explicitly asks for
|
- Do not create, modify, or run tests unless the user explicitly asks for
|
||||||
test work. When the user asks for tests, keep working and rerun them until
|
test work. When the user asks for tests, keep working and rerun them until
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class GekanatorGamesController < ApplicationController
|
|||||||
questions,
|
questions,
|
||||||
post_id: game.correct_post_id,
|
post_id: game.correct_post_id,
|
||||||
user: current_user,
|
user: current_user,
|
||||||
limit: 6)
|
limit: 2)
|
||||||
|
|
||||||
render json: {
|
render json: {
|
||||||
questions: selected.map { |question| extra_question_json(question) }
|
questions: selected.map { |question| extra_question_json(question) }
|
||||||
@@ -192,10 +192,7 @@ class GekanatorGamesController < ApplicationController
|
|||||||
answer_value = answer['answer'].to_s
|
answer_value = answer['answer'].to_s
|
||||||
next if answer_value.blank? || answer_value == 'unknown'
|
next if answer_value.blank? || answer_value == 'unknown'
|
||||||
|
|
||||||
question_id = game_answer_question_id(answer)
|
question = accepted_questions[answer['question_id'].to_s]
|
||||||
next if question_id.blank?
|
|
||||||
|
|
||||||
question = accepted_questions[question_id.to_s]
|
|
||||||
next unless learnable_game_answer_question?(question)
|
next unless learnable_game_answer_question?(question)
|
||||||
|
|
||||||
example =
|
example =
|
||||||
@@ -254,7 +251,6 @@ class GekanatorGamesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def learnable_game_answer_question? question
|
def learnable_game_answer_question? question
|
||||||
return false if question.nil?
|
|
||||||
return true if question.kind == 'post_similarity'
|
return true if question.kind == 'post_similarity'
|
||||||
return false unless question.kind == 'tag'
|
return false unless question.kind == 'tag'
|
||||||
|
|
||||||
@@ -262,11 +258,4 @@ class GekanatorGamesController < ApplicationController
|
|||||||
key = condition[:key].to_s
|
key = condition[:key].to_s
|
||||||
!key.start_with?('nico:')
|
!key.start_with?('nico:')
|
||||||
end
|
end
|
||||||
|
|
||||||
def game_answer_question_id answer
|
|
||||||
answer['question_id'] ||
|
|
||||||
answer[:question_id] ||
|
|
||||||
answer['questionId'] ||
|
|
||||||
answer[:questionId]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe TagNameSanitisationRule, type: :model do
|
RSpec.describe TagNameSanitisationRule, type: :model do
|
||||||
before do
|
|
||||||
described_class.unscoped.delete_all
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '.sanitise' do
|
describe '.sanitise' do
|
||||||
before do
|
before do
|
||||||
described_class.create!(priority: 10, source_pattern: '_', replacement: '')
|
described_class.create!(priority: 10, source_pattern: '_', replacement: '')
|
||||||
|
|||||||
@@ -151,188 +151,6 @@ RSpec.describe 'Gekanator learning API', type: :request do
|
|||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'learns accepted non-nico tag answers from camelCase main game logs' do
|
|
||||||
sign_in_as admin
|
|
||||||
|
|
||||||
tag_question = GekanatorQuestion.create!(
|
|
||||||
text: 'MAD 要素がある?',
|
|
||||||
kind: 'tag',
|
|
||||||
source: 'admin_curated',
|
|
||||||
status: 'accepted',
|
|
||||||
priority_weight: 1.0,
|
|
||||||
condition: { type: 'tag', key: 'meme:MAD' },
|
|
||||||
created_by: admin
|
|
||||||
)
|
|
||||||
|
|
||||||
expect {
|
|
||||||
post '/gekanator/games', params: {
|
|
||||||
guessed_post_id: guessed_post.id,
|
|
||||||
correct_post_id: correct_post.id,
|
|
||||||
answers: [
|
|
||||||
{
|
|
||||||
questionId: 'tag:meme:MAD',
|
|
||||||
question_text: 'MAD 要素がある?',
|
|
||||||
answer: 'yes',
|
|
||||||
original_answer: 'yes'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
questionId: 'tag:meme:missing',
|
|
||||||
question_text: '存在しない質問?',
|
|
||||||
answer: 'yes',
|
|
||||||
original_answer: 'yes'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
questionId: 'tag:meme:MAD',
|
|
||||||
question_text: 'MAD 要素がある?',
|
|
||||||
answer: 'unknown',
|
|
||||||
original_answer: 'unknown'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}.to change { GekanatorQuestionExample.count }.by(1)
|
|
||||||
|
|
||||||
expect(response).to have_http_status(:created)
|
|
||||||
expect(json['learned_example_count']).to eq(1)
|
|
||||||
|
|
||||||
example = GekanatorQuestionExample.last
|
|
||||||
expect(example).to have_attributes(
|
|
||||||
gekanator_question_id: tag_question.id,
|
|
||||||
post_id: correct_post.id,
|
|
||||||
user_id: admin.id,
|
|
||||||
answer: 'yes',
|
|
||||||
source: 'post_game_answer'
|
|
||||||
)
|
|
||||||
expect(example.gekanator_game_id).to eq(json['id'])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'learns accepted post_similarity answers from main game logs' do
|
|
||||||
sign_in_as admin
|
|
||||||
|
|
||||||
question = create_post_similarity_question!(text: '泣いてる?')
|
|
||||||
|
|
||||||
expect {
|
|
||||||
post '/gekanator/games', params: {
|
|
||||||
guessed_post_id: guessed_post.id,
|
|
||||||
correct_post_id: correct_post.id,
|
|
||||||
answers: [
|
|
||||||
{
|
|
||||||
question_id: "post-similarity:#{question.id}",
|
|
||||||
question_text: '泣いてる?',
|
|
||||||
answer: 'partial',
|
|
||||||
original_answer: 'partial'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}.to change { GekanatorQuestionExample.count }.by(1)
|
|
||||||
|
|
||||||
expect(response).to have_http_status(:created)
|
|
||||||
expect(json['learned_example_count']).to eq(1)
|
|
||||||
|
|
||||||
example = GekanatorQuestionExample.last
|
|
||||||
expect(example).to have_attributes(
|
|
||||||
gekanator_question_id: question.id,
|
|
||||||
post_id: correct_post.id,
|
|
||||||
user_id: admin.id,
|
|
||||||
answer: 'partial',
|
|
||||||
source: 'post_game_answer'
|
|
||||||
)
|
|
||||||
expect(example.gekanator_game_id).to eq(json['id'])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not learn fact questions or nico tag questions from main game logs' do
|
|
||||||
sign_in_as admin
|
|
||||||
|
|
||||||
[
|
|
||||||
{
|
|
||||||
text: 'example.com 由来?',
|
|
||||||
kind: 'source',
|
|
||||||
condition: { type: 'source', host: 'example.com' }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: '題名に結束バンドを含む?',
|
|
||||||
kind: 'title',
|
|
||||||
condition: { type: 'title-contains', text: '結束バンド' }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: '2024 年投稿?',
|
|
||||||
kind: 'original_date',
|
|
||||||
condition: { type: 'original-year', year: 2024 }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: 'ニコニコにぼっちタグ?',
|
|
||||||
kind: 'tag',
|
|
||||||
condition: { type: 'tag', key: 'nico:ぼっち' }
|
|
||||||
}
|
|
||||||
].each do |attributes|
|
|
||||||
GekanatorQuestion.create!(
|
|
||||||
text: attributes[:text],
|
|
||||||
kind: attributes[:kind],
|
|
||||||
source: 'admin_curated',
|
|
||||||
status: 'accepted',
|
|
||||||
priority_weight: 1.0,
|
|
||||||
condition: attributes[:condition],
|
|
||||||
created_by: admin
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
expect {
|
|
||||||
post '/gekanator/games', params: {
|
|
||||||
guessed_post_id: guessed_post.id,
|
|
||||||
correct_post_id: correct_post.id,
|
|
||||||
answers: [
|
|
||||||
{ question_id: 'source:example.com', answer: 'yes' },
|
|
||||||
{ question_id: 'title:contains:結束バンド', answer: 'yes' },
|
|
||||||
{ question_id: 'original-year:2024', answer: 'yes' },
|
|
||||||
{ question_id: 'tag:nico:ぼっち', answer: 'yes' }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}.not_to change { GekanatorQuestionExample.count }
|
|
||||||
|
|
||||||
expect(response).to have_http_status(:created)
|
|
||||||
expect(json['learned_example_count']).to eq(0)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'updates an existing main game example instead of duplicating it' do
|
|
||||||
sign_in_as admin
|
|
||||||
|
|
||||||
tag_question = GekanatorQuestion.create!(
|
|
||||||
text: '喜多ちゃんが関係してる?',
|
|
||||||
kind: 'tag',
|
|
||||||
source: 'admin_curated',
|
|
||||||
status: 'accepted',
|
|
||||||
priority_weight: 1.0,
|
|
||||||
condition: { type: 'tag', key: 'character:喜多郁代' },
|
|
||||||
created_by: admin
|
|
||||||
)
|
|
||||||
existing = GekanatorQuestionExample.create!(
|
|
||||||
gekanator_question: tag_question,
|
|
||||||
post: correct_post,
|
|
||||||
user: admin,
|
|
||||||
answer: 'no',
|
|
||||||
source: 'post_game_answer',
|
|
||||||
weight: 1.0
|
|
||||||
)
|
|
||||||
|
|
||||||
expect {
|
|
||||||
post '/gekanator/games', params: {
|
|
||||||
guessed_post_id: guessed_post.id,
|
|
||||||
correct_post_id: correct_post.id,
|
|
||||||
answers: [
|
|
||||||
{
|
|
||||||
question_id: 'tag:character:喜多郁代',
|
|
||||||
answer: 'yes',
|
|
||||||
original_answer: 'yes'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}.not_to change { GekanatorQuestionExample.count }
|
|
||||||
|
|
||||||
expect(response).to have_http_status(:created)
|
|
||||||
expect(json['learned_example_count']).to eq(1)
|
|
||||||
expect(existing.reload.answer).to eq('yes')
|
|
||||||
expect(existing.sample_count).to eq(2)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST /gekanator/question_suggestions' do
|
describe 'POST /gekanator/question_suggestions' do
|
||||||
@@ -431,7 +249,7 @@ RSpec.describe 'Gekanator learning API', type: :request do
|
|||||||
expect(GekanatorQuestionSuggestion.last.processed).to eq(false)
|
expect(GekanatorQuestionSuggestion.last.processed).to eq(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'allows more than three suggestions per game' do
|
it 'limits suggestions to three per game' do
|
||||||
sign_in_as admin
|
sign_in_as admin
|
||||||
|
|
||||||
3.times do |i|
|
3.times do |i|
|
||||||
@@ -449,10 +267,9 @@ RSpec.describe 'Gekanator learning API', type: :request do
|
|||||||
question_text: 'fourth question?',
|
question_text: 'fourth question?',
|
||||||
answer: 'yes'
|
answer: 'yes'
|
||||||
}
|
}
|
||||||
}.to change { GekanatorQuestionSuggestion.count }.by(1)
|
}.not_to change { GekanatorQuestionSuggestion.count }
|
||||||
|
|
||||||
expect(response).to have_http_status(:created)
|
expect(response).to have_http_status(:unprocessable_entity)
|
||||||
expect(json['count']).to eq(4)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'allows a non-admin user to suggest a question for their own game' do
|
it 'allows a non-admin user to suggest a question for their own game' do
|
||||||
@@ -509,59 +326,28 @@ RSpec.describe 'Gekanator learning API', type: :request do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET /gekanator/games/:id/extra_questions' do
|
describe 'GET /gekanator/games/:id/extra_questions' do
|
||||||
it 'returns at most six accepted user_suggested post_similarity questions without duplicates' do
|
it 'returns at most two accepted user_suggested post_similarity questions without duplicates' do
|
||||||
sign_in_as admin
|
sign_in_as admin
|
||||||
|
|
||||||
lowest = create_post_similarity_question!(
|
|
||||||
text: 'lowest?',
|
|
||||||
priority_weight: 0.5
|
|
||||||
)
|
|
||||||
low = create_post_similarity_question!(
|
low = create_post_similarity_question!(
|
||||||
text: 'low?',
|
text: 'low?',
|
||||||
priority_weight: 1.0
|
priority_weight: 1.0
|
||||||
)
|
)
|
||||||
middle = create_post_similarity_question!(
|
|
||||||
text: 'middle?',
|
|
||||||
priority_weight: 1.5
|
|
||||||
)
|
|
||||||
medium_high = create_post_similarity_question!(
|
|
||||||
text: 'medium high?',
|
|
||||||
priority_weight: 2.0
|
|
||||||
)
|
|
||||||
high = create_post_similarity_question!(
|
high = create_post_similarity_question!(
|
||||||
text: 'high?',
|
text: 'high?',
|
||||||
priority_weight: 2.5
|
|
||||||
)
|
|
||||||
higher = create_post_similarity_question!(
|
|
||||||
text: 'higher?',
|
|
||||||
priority_weight: 2.8
|
|
||||||
)
|
|
||||||
highest = create_post_similarity_question!(
|
|
||||||
text: 'highest?',
|
|
||||||
priority_weight: 3.0
|
priority_weight: 3.0
|
||||||
)
|
)
|
||||||
overflow = create_post_similarity_question!(
|
middle = create_post_similarity_question!(
|
||||||
text: 'overflow?',
|
text: 'middle?',
|
||||||
priority_weight: 2.2
|
priority_weight: 2.0
|
||||||
)
|
)
|
||||||
|
|
||||||
get "/gekanator/games/#{game.id}/extra_questions"
|
get "/gekanator/games/#{game.id}/extra_questions"
|
||||||
|
|
||||||
expect(response).to have_http_status(:ok)
|
expect(response).to have_http_status(:ok)
|
||||||
expect(json['questions'].length).to eq(6)
|
expect(json['questions'].length).to eq(2)
|
||||||
expect(json['questions'].map { _1['id'] }.uniq.length).to eq(6)
|
expect(json['questions'].map { _1['id'] }.uniq.length).to eq(2)
|
||||||
expect(json['questions'].map { _1['id'] }).to all(
|
expect(json['questions'].map { _1['id'] }).to all(be_in([low.id, high.id, middle.id]))
|
||||||
be_in([
|
|
||||||
lowest.id,
|
|
||||||
low.id,
|
|
||||||
middle.id,
|
|
||||||
medium_high.id,
|
|
||||||
high.id,
|
|
||||||
higher.id,
|
|
||||||
highest.id,
|
|
||||||
overflow.id,
|
|
||||||
])
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can return questions that already have an example for the correct post' do
|
it 'can return questions that already have an example for the correct post' do
|
||||||
@@ -584,37 +370,6 @@ RSpec.describe 'Gekanator learning API', type: :request do
|
|||||||
expect(json['questions'].map { _1['id'] }).to include(existing.id)
|
expect(json['questions'].map { _1['id'] }).to include(existing.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'prioritizes questions the current user has not answered' do
|
|
||||||
sign_in_as admin
|
|
||||||
|
|
||||||
answered = create_post_similarity_question!(
|
|
||||||
text: 'already answered?',
|
|
||||||
priority_weight: 3.0
|
|
||||||
)
|
|
||||||
GekanatorQuestionExample.create!(
|
|
||||||
gekanator_question: answered,
|
|
||||||
post: other_post,
|
|
||||||
user: admin,
|
|
||||||
answer: 'yes',
|
|
||||||
source: 'post_game_extra'
|
|
||||||
)
|
|
||||||
|
|
||||||
unanswered =
|
|
||||||
6.times.map { |index|
|
|
||||||
create_post_similarity_question!(
|
|
||||||
text: "unanswered #{index}?",
|
|
||||||
priority_weight: 0.5
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
get "/gekanator/games/#{game.id}/extra_questions"
|
|
||||||
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
expect(json['questions'].map { _1['id'] }).to match_array(
|
|
||||||
unanswered.map(&:id)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'can return questions already asked in the game using snake_case question_id' do
|
it 'can return questions already asked in the game using snake_case question_id' do
|
||||||
sign_in_as admin
|
sign_in_as admin
|
||||||
|
|
||||||
|
|||||||
バイナリファイルは表示されません.
|
変更後 幅: | 高さ: | サイズ: 559 KiB |
バイナリファイルは表示されません.
|
変更後 幅: | 高さ: | サイズ: 146 KiB |
バイナリファイルは表示されません.
|
変更後 幅: | 高さ: | サイズ: 1.2 MiB |
バイナリファイルは表示されません.
|
変更後 幅: | 高さ: | サイズ: 188 KiB |
バイナリファイルは表示されません.
|
変更後 幅: | 高さ: | サイズ: 201 KiB |
バイナリファイルは表示されません.
|
変更後 幅: | 高さ: | サイズ: 196 KiB |
バイナリファイルは表示されません.
|
変更後 幅: | 高さ: | サイズ: 179 KiB |
@@ -4,7 +4,6 @@ import { apiPost } from '@/lib/api'
|
|||||||
import {
|
import {
|
||||||
buildGekanatorQuestions,
|
buildGekanatorQuestions,
|
||||||
expectedAnswerForQuestion,
|
expectedAnswerForQuestion,
|
||||||
learnedSemanticSideForPost,
|
|
||||||
questionIdForCondition,
|
questionIdForCondition,
|
||||||
restoreGekanatorQuestion,
|
restoreGekanatorQuestion,
|
||||||
saveGekanatorExtraQuestionAnswers,
|
saveGekanatorExtraQuestionAnswers,
|
||||||
@@ -189,33 +188,6 @@ describe('expectedAnswerForQuestion', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('learnedSemanticSideForPost', () => {
|
|
||||||
it('classifies post_similarity examples as positive, negative, or unknown', () => {
|
|
||||||
const question: StoredGekanatorQuestion = {
|
|
||||||
id: 'post-similarity:10',
|
|
||||||
text: '喜多ちゃんが泣いてる?',
|
|
||||||
kind: 'post_similarity',
|
|
||||||
source: 'user_suggested',
|
|
||||||
priorityWeight: 1.2,
|
|
||||||
condition: {
|
|
||||||
type: 'post-similarity',
|
|
||||||
postId: 123,
|
|
||||||
answer: 'partial',
|
|
||||||
threshold: 0.65,
|
|
||||||
},
|
|
||||||
exampleAnswers: {
|
|
||||||
1: 'yes',
|
|
||||||
2: 'probably_no',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(learnedSemanticSideForPost(question, post({ id: 1 }))).toBe('positive')
|
|
||||||
expect(learnedSemanticSideForPost(question, post({ id: 2 }))).toBe('negative')
|
|
||||||
expect(learnedSemanticSideForPost(question, post({ id: 3 }))).toBe('unknown')
|
|
||||||
expect(learnedSemanticSideForPost(question, post({ id: 123 }))).toBe('positive')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('restoreGekanatorQuestion', () => {
|
describe('restoreGekanatorQuestion', () => {
|
||||||
it('uses default source and priority weight when omitted', () => {
|
it('uses default source and priority weight when omitted', () => {
|
||||||
const question = restoreGekanatorQuestion({
|
const question = restoreGekanatorQuestion({
|
||||||
@@ -276,7 +248,7 @@ describe('restoreGekanatorQuestion', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
expect(question.test(post({ id: 1 }))).toBe(true)
|
expect(question.test(post({ id: 1 }))).toBe(true)
|
||||||
expect(question.test(post({ id: 2 }))).toBe(true)
|
expect(question.test(post({ id: 2 }))).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('normalizes legacy title-length-greater-than questions', () => {
|
it('normalizes legacy title-length-greater-than questions', () => {
|
||||||
@@ -400,10 +372,6 @@ describe('Gekanator API writers', () => {
|
|||||||
type: 'tag',
|
type: 'tag',
|
||||||
key: 'character:喜多郁代',
|
key: 'character:喜多郁代',
|
||||||
},
|
},
|
||||||
questionMode: 'normal',
|
|
||||||
questionPurpose: 'effective_user_suggested',
|
|
||||||
effectiveQuestion: true,
|
|
||||||
learningQuestion: false,
|
|
||||||
answer: 'yes',
|
answer: 'yes',
|
||||||
originalAnswer: 'partial',
|
originalAnswer: 'partial',
|
||||||
},
|
},
|
||||||
@@ -428,10 +396,6 @@ describe('Gekanator API writers', () => {
|
|||||||
type: 'tag',
|
type: 'tag',
|
||||||
key: 'character:喜多郁代',
|
key: 'character:喜多郁代',
|
||||||
},
|
},
|
||||||
question_mode: 'normal',
|
|
||||||
question_purpose: 'effective_user_suggested',
|
|
||||||
effective_question: true,
|
|
||||||
learning_question: false,
|
|
||||||
answer: 'yes',
|
answer: 'yes',
|
||||||
original_answer: 'partial',
|
original_answer: 'partial',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,24 +9,11 @@ export type GekanatorAnswerValue =
|
|||||||
| 'probably_no'
|
| 'probably_no'
|
||||||
| 'unknown'
|
| 'unknown'
|
||||||
|
|
||||||
export type LearnedSemanticSide =
|
|
||||||
| 'positive'
|
|
||||||
| 'negative'
|
|
||||||
| 'unknown'
|
|
||||||
|
|
||||||
export type GekanatorQuestionPurpose =
|
|
||||||
| 'effective_user_suggested'
|
|
||||||
| 'learning_user_suggested'
|
|
||||||
| 'normal'
|
|
||||||
|
|
||||||
export type GekanatorAnswerLog = {
|
export type GekanatorAnswerLog = {
|
||||||
questionId: string
|
questionId: string
|
||||||
questionText: string
|
questionText: string
|
||||||
questionCondition?: GekanatorQuestionCondition
|
questionCondition?: GekanatorQuestionCondition
|
||||||
questionMode?: 'normal' | 'winning_run'
|
questionMode?: 'normal' | 'winning_run'
|
||||||
questionPurpose?: GekanatorQuestionPurpose
|
|
||||||
effectiveQuestion?: boolean
|
|
||||||
learningQuestion?: boolean
|
|
||||||
answer: GekanatorAnswerValue
|
answer: GekanatorAnswerValue
|
||||||
originalAnswer: GekanatorAnswerValue }
|
originalAnswer: GekanatorAnswerValue }
|
||||||
|
|
||||||
@@ -176,26 +163,6 @@ const directExampleAnswerFor = (
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const isLearnedSemanticQuestion = (
|
|
||||||
question: StoredGekanatorQuestion | GekanatorQuestion,
|
|
||||||
): boolean =>
|
|
||||||
question.kind === 'post_similarity'
|
|
||||||
&& question.source === 'user_suggested'
|
|
||||||
|
|
||||||
|
|
||||||
export const learnedSemanticSideForAnswer = (
|
|
||||||
answer: GekanatorAnswerValue | null,
|
|
||||||
): LearnedSemanticSide => {
|
|
||||||
if (answer === 'yes' || answer === 'partial')
|
|
||||||
return 'positive'
|
|
||||||
|
|
||||||
if (answer === 'no' || answer === 'probably_no')
|
|
||||||
return 'negative'
|
|
||||||
|
|
||||||
return 'unknown'
|
|
||||||
}
|
|
||||||
|
|
||||||
const countBy = <T extends string | number> (values: T[]): Map<T, number> => {
|
const countBy = <T extends string | number> (values: T[]): Map<T, number> => {
|
||||||
const counts = new Map<T, number> ()
|
const counts = new Map<T, number> ()
|
||||||
values.forEach (value => counts.set (value, (counts.get (value) ?? 0) + 1))
|
values.forEach (value => counts.set (value, (counts.get (value) ?? 0) + 1))
|
||||||
@@ -318,8 +285,8 @@ const questionMatches = (
|
|||||||
): boolean => {
|
): boolean => {
|
||||||
const directAnswer = directExampleAnswerFor (question, post)
|
const directAnswer = directExampleAnswerFor (question, post)
|
||||||
if (directAnswer)
|
if (directAnswer)
|
||||||
return question.kind === 'post_similarity'
|
return question.condition.type === 'post-similarity'
|
||||||
? learnedSemanticSideForAnswer (directAnswer) === 'positive'
|
? directAnswer === question.condition.answer
|
||||||
: directAnswer === 'yes'
|
: directAnswer === 'yes'
|
||||||
|
|
||||||
switch (question.condition.type)
|
switch (question.condition.type)
|
||||||
@@ -361,11 +328,6 @@ export const expectedAnswerForQuestion = (
|
|||||||
|
|
||||||
switch (question.condition.type)
|
switch (question.condition.type)
|
||||||
{
|
{
|
||||||
case 'post-similarity':
|
|
||||||
if (question.condition.postId === post.id)
|
|
||||||
return question.condition.answer
|
|
||||||
|
|
||||||
return null
|
|
||||||
case 'tag':
|
case 'tag':
|
||||||
case 'source':
|
case 'source':
|
||||||
case 'original-year':
|
case 'original-year':
|
||||||
@@ -376,17 +338,12 @@ export const expectedAnswerForQuestion = (
|
|||||||
case 'title-has-ascii':
|
case 'title-has-ascii':
|
||||||
case 'title-contains':
|
case 'title-contains':
|
||||||
return questionMatches (post, question) ? 'yes' : 'no'
|
return questionMatches (post, question) ? 'yes' : 'no'
|
||||||
|
case 'post-similarity':
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const learnedSemanticSideForPost = (
|
|
||||||
question: StoredGekanatorQuestion | GekanatorQuestion | undefined,
|
|
||||||
post: Post | null,
|
|
||||||
): LearnedSemanticSide =>
|
|
||||||
learnedSemanticSideForAnswer (expectedAnswerForQuestion (question, post))
|
|
||||||
|
|
||||||
|
|
||||||
export const restoreGekanatorQuestion = (
|
export const restoreGekanatorQuestion = (
|
||||||
question: StoredGekanatorQuestion,
|
question: StoredGekanatorQuestion,
|
||||||
): GekanatorQuestion => {
|
): GekanatorQuestion => {
|
||||||
@@ -466,15 +423,15 @@ export const buildGekanatorQuestions = (
|
|||||||
const originalYears = countBy (
|
const originalYears = countBy (
|
||||||
posts
|
posts
|
||||||
.map (originalYearOf)
|
.map (originalYearOf)
|
||||||
.filter ((year): year is number => year != null))
|
.filter ((year): year is number => year !== null))
|
||||||
const originalMonths = countBy (
|
const originalMonths = countBy (
|
||||||
posts
|
posts
|
||||||
.map (originalMonthOf)
|
.map (originalMonthOf)
|
||||||
.filter ((month): month is number => month != null))
|
.filter ((month): month is number => month !== null))
|
||||||
const originalMonthDays = countBy (
|
const originalMonthDays = countBy (
|
||||||
posts
|
posts
|
||||||
.map (originalMonthDayOf)
|
.map (originalMonthDayOf)
|
||||||
.filter ((monthDay): monthDay is string => monthDay != null))
|
.filter ((monthDay): monthDay is string => monthDay !== null))
|
||||||
const titleLengthMedian = median (posts.map (post => post.title?.length ?? 0))
|
const titleLengthMedian = median (posts.map (post => post.title?.length ?? 0))
|
||||||
const titleWordCounts =
|
const titleWordCounts =
|
||||||
includeTitleContains
|
includeTitleContains
|
||||||
@@ -636,10 +593,6 @@ export const saveGekanatorGame = async ({
|
|||||||
question_id: answer.questionId,
|
question_id: answer.questionId,
|
||||||
question_text: answer.questionText,
|
question_text: answer.questionText,
|
||||||
question_condition: answer.questionCondition ?? null,
|
question_condition: answer.questionCondition ?? null,
|
||||||
question_mode: answer.questionMode,
|
|
||||||
question_purpose: answer.questionPurpose,
|
|
||||||
effective_question: answer.effectiveQuestion,
|
|
||||||
learning_question: answer.learningQuestion,
|
|
||||||
answer: answer.answer,
|
answer: answer.answer,
|
||||||
original_answer: answer.originalAnswer })) })
|
original_answer: answer.originalAnswer })) })
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import type {
|
|||||||
GekanatorAnswerValue,
|
GekanatorAnswerValue,
|
||||||
GekanatorQuestion,
|
GekanatorQuestion,
|
||||||
} from '@/lib/gekanator'
|
} from '@/lib/gekanator'
|
||||||
import type { RecoveredCandidateState } from '@/lib/gekanatorCandidateRecovery'
|
|
||||||
import type { Post } from '@/types'
|
import type { Post } from '@/types'
|
||||||
|
|
||||||
|
|
||||||
@@ -52,21 +51,6 @@ const postSimilarityQuestion = (
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
const sourceQuestion = (
|
|
||||||
host: string,
|
|
||||||
): GekanatorQuestion => ({
|
|
||||||
id: `source:${ host }`,
|
|
||||||
text: `${ host }?`,
|
|
||||||
kind: 'source',
|
|
||||||
condition: {
|
|
||||||
type: 'source',
|
|
||||||
host },
|
|
||||||
source: 'default',
|
|
||||||
priorityWeight: 1,
|
|
||||||
test: candidate => new URL (candidate.url).hostname === host,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
const answer = (
|
const answer = (
|
||||||
question: GekanatorQuestion,
|
question: GekanatorQuestion,
|
||||||
value: GekanatorAnswerValue,
|
value: GekanatorAnswerValue,
|
||||||
@@ -79,17 +63,8 @@ const answer = (
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
const recoveredState = (
|
|
||||||
answerCountAtRecovery: number,
|
|
||||||
scoreAtRecovery = 0,
|
|
||||||
): RecoveredCandidateState => ({
|
|
||||||
answerCountAtRecovery,
|
|
||||||
scoreAtRecovery,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
describe('candidatePostsFor', () => {
|
describe('candidatePostsFor', () => {
|
||||||
it('does not hard-filter semantic post_similarity answers', () => {
|
it('lets recovered candidates ignore old answers but not later answers', () => {
|
||||||
const posts = [post (1), post (2), post (3)]
|
const posts = [post (1), post (2), post (3)]
|
||||||
const oldQuestion = postSimilarityQuestion ('old', {
|
const oldQuestion = postSimilarityQuestion ('old', {
|
||||||
1: 'no',
|
1: 'no',
|
||||||
@@ -109,31 +84,8 @@ describe('candidatePostsFor', () => {
|
|||||||
softenedQuestionIds: new Set (),
|
softenedQuestionIds: new Set (),
|
||||||
rejectedPostIds: new Set (),
|
rejectedPostIds: new Set (),
|
||||||
recoveredCandidatePosts: new Map ([
|
recoveredCandidatePosts: new Map ([
|
||||||
[1, recoveredState (1)],
|
[1, 1],
|
||||||
[3, recoveredState (1)],
|
[3, 1],
|
||||||
]) })
|
|
||||||
|
|
||||||
expect(candidates.map (candidate => candidate.id)).toEqual ([1, 2, 3])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('lets recovered candidates ignore old fact answers but not later fact answers', () => {
|
|
||||||
const posts = [
|
|
||||||
{ ...post (1), url: 'https://other.example/posts/1' },
|
|
||||||
post (2),
|
|
||||||
{ ...post (3), url: 'https://example.com/posts/3' },
|
|
||||||
]
|
|
||||||
const oldQuestion = sourceQuestion ('old.example.com')
|
|
||||||
const laterQuestion = sourceQuestion ('example.com')
|
|
||||||
|
|
||||||
const candidates = candidatePostsFor ({
|
|
||||||
posts,
|
|
||||||
questions: [oldQuestion, laterQuestion],
|
|
||||||
answers: [answer (oldQuestion, 'yes'), answer (laterQuestion, 'yes')],
|
|
||||||
softenedQuestionIds: new Set (),
|
|
||||||
rejectedPostIds: new Set (),
|
|
||||||
recoveredCandidatePosts: new Map ([
|
|
||||||
[1, recoveredState (1)],
|
|
||||||
[3, recoveredState (1)],
|
|
||||||
]) })
|
]) })
|
||||||
|
|
||||||
expect(candidates.map (candidate => candidate.id)).toEqual ([3])
|
expect(candidates.map (candidate => candidate.id)).toEqual ([3])
|
||||||
@@ -152,7 +104,7 @@ describe('candidatePostsFor', () => {
|
|||||||
answers: [answer (question, 'yes')],
|
answers: [answer (question, 'yes')],
|
||||||
softenedQuestionIds: new Set (),
|
softenedQuestionIds: new Set (),
|
||||||
rejectedPostIds: new Set ([1]),
|
rejectedPostIds: new Set ([1]),
|
||||||
recoveredCandidatePosts: new Map ([[1, recoveredState (1)]]) })
|
recoveredCandidatePosts: new Map ([[1, 1]]) })
|
||||||
|
|
||||||
expect(candidates.map (candidate => candidate.id)).toEqual ([2])
|
expect(candidates.map (candidate => candidate.id)).toEqual ([2])
|
||||||
})
|
})
|
||||||
@@ -160,7 +112,7 @@ describe('candidatePostsFor', () => {
|
|||||||
|
|
||||||
|
|
||||||
describe('hardFilteredPostsForAnswer', () => {
|
describe('hardFilteredPostsForAnswer', () => {
|
||||||
it('keeps the original pool for semantic post_similarity answers', () => {
|
it('returns zero candidates without falling back to the original pool', () => {
|
||||||
const posts = [post (1), post (2)]
|
const posts = [post (1), post (2)]
|
||||||
const question = postSimilarityQuestion ('question', {
|
const question = postSimilarityQuestion ('question', {
|
||||||
1: 'yes',
|
1: 'yes',
|
||||||
@@ -171,41 +123,7 @@ describe('hardFilteredPostsForAnswer', () => {
|
|||||||
posts,
|
posts,
|
||||||
question,
|
question,
|
||||||
answer: 'no',
|
answer: 'no',
|
||||||
})).toEqual (posts)
|
})).toEqual ([])
|
||||||
})
|
|
||||||
|
|
||||||
it('hard-filters fact answers only for yes and no', () => {
|
|
||||||
const posts = [
|
|
||||||
{ ...post (1), url: 'https://example.com/posts/1' },
|
|
||||||
{ ...post (2), url: 'https://other.example/posts/2' },
|
|
||||||
]
|
|
||||||
const question = sourceQuestion ('example.com')
|
|
||||||
|
|
||||||
expect(hardFilteredPostsForAnswer ({
|
|
||||||
posts,
|
|
||||||
question,
|
|
||||||
answer: 'yes',
|
|
||||||
}).map (candidate => candidate.id)).toEqual ([1])
|
|
||||||
expect(hardFilteredPostsForAnswer ({
|
|
||||||
posts,
|
|
||||||
question,
|
|
||||||
answer: 'no',
|
|
||||||
}).map (candidate => candidate.id)).toEqual ([2])
|
|
||||||
expect(hardFilteredPostsForAnswer ({
|
|
||||||
posts,
|
|
||||||
question,
|
|
||||||
answer: 'partial',
|
|
||||||
})).toEqual (posts)
|
|
||||||
expect(hardFilteredPostsForAnswer ({
|
|
||||||
posts,
|
|
||||||
question,
|
|
||||||
answer: 'probably_no',
|
|
||||||
})).toEqual (posts)
|
|
||||||
expect(hardFilteredPostsForAnswer ({
|
|
||||||
posts,
|
|
||||||
question,
|
|
||||||
answer: 'unknown',
|
|
||||||
})).toEqual (posts)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -219,7 +137,7 @@ describe('recoverCandidatePosts', () => {
|
|||||||
posts,
|
posts,
|
||||||
scores,
|
scores,
|
||||||
rejectedPostIds: new Set ([10]),
|
rejectedPostIds: new Set ([10]),
|
||||||
recoveredCandidatePosts: new Map ([[8, recoveredState (1, 8)]]),
|
recoveredCandidatePosts: new Map ([[8, 1]]),
|
||||||
eligiblePostIds: new Set ([9]),
|
eligiblePostIds: new Set ([9]),
|
||||||
answerCountAtRecovery: 2,
|
answerCountAtRecovery: 2,
|
||||||
recoveryStepCount: 0,
|
recoveryStepCount: 0,
|
||||||
@@ -228,10 +146,7 @@ describe('recoverCandidatePosts', () => {
|
|||||||
expect(recovered?.recoveryStepCount).toBe (1)
|
expect(recovered?.recoveryStepCount).toBe (1)
|
||||||
expect([...(recovered?.recoveredCandidatePosts.keys () ?? [])])
|
expect([...(recovered?.recoveredCandidatePosts.keys () ?? [])])
|
||||||
.toEqual ([8, 7, 6, 5, 4])
|
.toEqual ([8, 7, 6, 5, 4])
|
||||||
expect(recovered?.recoveredCandidatePosts.get (7)).toEqual ({
|
expect(recovered?.recoveredCandidatePosts.get (7)).toBe (2)
|
||||||
answerCountAtRecovery: 2,
|
|
||||||
scoreAtRecovery: 7,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not add posts when recovered and eligible candidates already hit the target', () => {
|
it('does not add posts when recovered and eligible candidates already hit the target', () => {
|
||||||
@@ -243,9 +158,9 @@ describe('recoverCandidatePosts', () => {
|
|||||||
scores,
|
scores,
|
||||||
rejectedPostIds: new Set (),
|
rejectedPostIds: new Set (),
|
||||||
recoveredCandidatePosts: new Map ([
|
recoveredCandidatePosts: new Map ([
|
||||||
[1, recoveredState (1, 1)],
|
[1, 1],
|
||||||
[2, recoveredState (1, 2)],
|
[2, 1],
|
||||||
[3, recoveredState (1, 3)],
|
[3, 1],
|
||||||
]),
|
]),
|
||||||
eligiblePostIds: new Set ([4, 5, 6]),
|
eligiblePostIds: new Set ([4, 5, 6]),
|
||||||
answerCountAtRecovery: 2,
|
answerCountAtRecovery: 2,
|
||||||
|
|||||||
@@ -1,49 +1,53 @@
|
|||||||
import { isLearnedSemanticQuestion,
|
import { expectedAnswerForQuestion } from '@/lib/gekanator'
|
||||||
learnedSemanticSideForPost } from '@/lib/gekanator'
|
|
||||||
|
|
||||||
import type { GekanatorAnswerLog, GekanatorAnswerValue, GekanatorQuestion } from '@/lib/gekanator'
|
import type {
|
||||||
|
GekanatorAnswerLog,
|
||||||
|
GekanatorAnswerValue,
|
||||||
|
GekanatorQuestion,
|
||||||
|
} from '@/lib/gekanator'
|
||||||
import type { Post } from '@/types'
|
import type { Post } from '@/types'
|
||||||
|
|
||||||
|
|
||||||
export type RecoveredCandidatePost = {
|
export type RecoveredCandidatePost = {
|
||||||
postId: number
|
postId: number
|
||||||
answerCountAtRecovery: number
|
answerCountAtRecovery: number }
|
||||||
scoreAtRecovery: number }
|
|
||||||
|
|
||||||
export type RecoveredCandidateState = {
|
|
||||||
answerCountAtRecovery: number
|
|
||||||
scoreAtRecovery: number }
|
|
||||||
|
|
||||||
|
|
||||||
const questionSupportsAnswerBasedHardFiltering = (question: GekanatorQuestion): boolean =>
|
const questionIsFactLikeForHardFiltering = (
|
||||||
!(isLearnedSemanticQuestion (question)
|
question: GekanatorQuestion,
|
||||||
|| (question.kind === 'tag'
|
): boolean =>
|
||||||
|
!(question.kind === 'post_similarity'
|
||||||
|
|| (
|
||||||
|
question.kind === 'tag'
|
||||||
&& question.condition.type === 'tag'
|
&& question.condition.type === 'tag'
|
||||||
&& !(question.condition.key.startsWith ('nico:'))))
|
&& !(question.condition.key.startsWith ('nico:'))))
|
||||||
|
|
||||||
|
|
||||||
export const candidatePostsFor = (
|
export const candidatePostsFor = ({
|
||||||
{ posts,
|
posts,
|
||||||
questions,
|
questions,
|
||||||
answers,
|
answers,
|
||||||
softenedQuestionIds,
|
softenedQuestionIds,
|
||||||
rejectedPostIds,
|
rejectedPostIds,
|
||||||
recoveredCandidatePosts }: { posts: Post[]
|
recoveredCandidatePosts,
|
||||||
questions: GekanatorQuestion[]
|
}: {
|
||||||
answers: GekanatorAnswerLog[]
|
posts: Post[]
|
||||||
softenedQuestionIds: Set<string>
|
questions: GekanatorQuestion[]
|
||||||
rejectedPostIds: Set<number>
|
answers: GekanatorAnswerLog[]
|
||||||
recoveredCandidatePosts: Map<number, RecoveredCandidateState> },
|
softenedQuestionIds: Set<string>
|
||||||
): Post[] => {
|
rejectedPostIds: Set<number>
|
||||||
|
recoveredCandidatePosts: Map<number, number>
|
||||||
|
}): Post[] => {
|
||||||
const questionById = new Map (questions.map (question => [question.id, question]))
|
const questionById = new Map (questions.map (question => [question.id, question]))
|
||||||
|
|
||||||
return posts.filter (post => {
|
return posts.filter (post => {
|
||||||
if (rejectedPostIds.has (post.id))
|
if (rejectedPostIds.has (post.id))
|
||||||
return false
|
return false
|
||||||
|
|
||||||
const recoveredCandidate = recoveredCandidatePosts.get (post.id)
|
const answerCountAtRecovery = recoveredCandidatePosts.get (post.id)
|
||||||
|
|
||||||
return answers.every ((answer, index) => {
|
return answers.every ((answer, index) => {
|
||||||
if (recoveredCandidate != null && index < recoveredCandidate.answerCountAtRecovery)
|
if (answerCountAtRecovery !== undefined && index < answerCountAtRecovery)
|
||||||
return true
|
return true
|
||||||
|
|
||||||
if (softenedQuestionIds.has (answer.questionId))
|
if (softenedQuestionIds.has (answer.questionId))
|
||||||
@@ -52,19 +56,16 @@ export const candidatePostsFor = (
|
|||||||
const question = questionById.get (answer.questionId)
|
const question = questionById.get (answer.questionId)
|
||||||
if (!(question))
|
if (!(question))
|
||||||
return true
|
return true
|
||||||
if (!(questionSupportsAnswerBasedHardFiltering (question)))
|
if (!(questionIsFactLikeForHardFiltering (question)))
|
||||||
return true
|
return true
|
||||||
|
|
||||||
switch (answer.answer)
|
switch (answer.answer)
|
||||||
{
|
{
|
||||||
case 'yes':
|
case 'yes':
|
||||||
case 'no':
|
case 'no': {
|
||||||
{
|
const expected = expectedAnswerForQuestion (question, post)
|
||||||
const expected = learnedSemanticSideForPost (question, post)
|
return expected === null || expected === 'unknown' || expected === answer.answer
|
||||||
return expected === 'unknown'
|
}
|
||||||
|| (answer.answer === 'yes' && expected === 'positive')
|
|
||||||
|| (answer.answer === 'no' && expected === 'negative')
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -73,27 +74,33 @@ export const candidatePostsFor = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const hardFilteredPostsForAnswer = (
|
export const hardFilteredPostsForAnswer = ({
|
||||||
{ posts, question, answer }: { posts: Post[]
|
posts,
|
||||||
question: GekanatorQuestion
|
question,
|
||||||
answer: GekanatorAnswerValue },
|
answer,
|
||||||
): Post[] => {
|
}: {
|
||||||
if (!(questionSupportsAnswerBasedHardFiltering (question)))
|
posts: Post[]
|
||||||
|
question: GekanatorQuestion
|
||||||
|
answer: GekanatorAnswerValue
|
||||||
|
}): Post[] => {
|
||||||
|
if (!(questionIsFactLikeForHardFiltering (question)))
|
||||||
return posts
|
return posts
|
||||||
|
|
||||||
if (!(answer === 'yes' || answer === 'no'))
|
if (answer === 'unknown')
|
||||||
return posts
|
return posts
|
||||||
|
|
||||||
return posts.filter (post => {
|
return posts.filter (post => {
|
||||||
const side = learnedSemanticSideForPost (question, post)
|
const expected = expectedAnswerForQuestion (question, post)
|
||||||
return side === 'unknown'
|
return expected === null || expected === 'unknown' || expected === answer
|
||||||
|| (answer === 'yes' && side === 'positive')
|
|
||||||
|| (answer === 'no' && side === 'negative')
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const concreteAnswerOptions: GekanatorAnswerValue[] = ['yes', 'no', 'partial', 'probably_no']
|
const concreteAnswerOptions: GekanatorAnswerValue[] = [
|
||||||
|
'yes',
|
||||||
|
'no',
|
||||||
|
'partial',
|
||||||
|
'probably_no']
|
||||||
|
|
||||||
|
|
||||||
export const allConcreteAnswerOptionsExhausted = (
|
export const allConcreteAnswerOptionsExhausted = (
|
||||||
@@ -112,48 +119,53 @@ const nextRecoveryTargetSize = (recoveryStepCount: number): number =>
|
|||||||
6 * (2 ** recoveryStepCount)
|
6 * (2 ** recoveryStepCount)
|
||||||
|
|
||||||
|
|
||||||
export const recoverCandidatePosts = (
|
export const recoverCandidatePosts = ({
|
||||||
{ posts,
|
posts,
|
||||||
scores,
|
scores,
|
||||||
rejectedPostIds,
|
rejectedPostIds,
|
||||||
recoveredCandidatePosts,
|
recoveredCandidatePosts,
|
||||||
eligiblePostIds,
|
eligiblePostIds,
|
||||||
answerCountAtRecovery,
|
answerCountAtRecovery,
|
||||||
recoveryStepCount }: { posts: Post[]
|
recoveryStepCount,
|
||||||
scores: Map<number, number>
|
}: {
|
||||||
rejectedPostIds: Set<number>
|
posts: Post[]
|
||||||
recoveredCandidatePosts: Map<number, RecoveredCandidateState>
|
scores: Map<number, number>
|
||||||
eligiblePostIds: Set<number>
|
rejectedPostIds: Set<number>
|
||||||
answerCountAtRecovery: number
|
recoveredCandidatePosts: Map<number, number>
|
||||||
recoveryStepCount: number },
|
eligiblePostIds: Set<number>
|
||||||
): { recoveredCandidatePosts: Map<number, RecoveredCandidateState>
|
answerCountAtRecovery: number
|
||||||
recoveryStepCount: number } | null => {
|
recoveryStepCount: number
|
||||||
|
}): {
|
||||||
|
recoveredCandidatePosts: Map<number, number>
|
||||||
|
recoveryStepCount: number
|
||||||
|
} | null => {
|
||||||
const recovered = new Map (recoveredCandidatePosts)
|
const recovered = new Map (recoveredCandidatePosts)
|
||||||
const targetSize = nextRecoveryTargetSize (recoveryStepCount)
|
const targetSize = nextRecoveryTargetSize (recoveryStepCount)
|
||||||
const countedPostIds = new Set ([...eligiblePostIds, ...recovered.keys ()])
|
const countedPostIds = new Set ([
|
||||||
|
...eligiblePostIds,
|
||||||
|
...recovered.keys ()])
|
||||||
const addCount = targetSize - countedPostIds.size
|
const addCount = targetSize - countedPostIds.size
|
||||||
if (addCount <= 0)
|
if (addCount <= 0)
|
||||||
{
|
return {
|
||||||
return { recoveredCandidatePosts: recovered,
|
recoveredCandidatePosts: recovered,
|
||||||
recoveryStepCount: recoveryStepCount + 1 }
|
recoveryStepCount: recoveryStepCount + 1 }
|
||||||
}
|
|
||||||
|
|
||||||
const candidates =
|
const candidates = posts
|
||||||
posts
|
.filter (post =>
|
||||||
.filter (post => (!(rejectedPostIds.has (post.id))
|
!(rejectedPostIds.has (post.id))
|
||||||
&& !(eligiblePostIds.has (post.id))
|
&& !(eligiblePostIds.has (post.id))
|
||||||
&& !(recovered.has (post.id))))
|
&& !(recovered.has (post.id)))
|
||||||
.sort ((a, b) => ((scores.get (b.id) ?? Number.NEGATIVE_INFINITY)
|
.sort ((a, b) =>
|
||||||
- (scores.get (a.id) ?? Number.NEGATIVE_INFINITY)))
|
(scores.get (b.id) ?? Number.NEGATIVE_INFINITY)
|
||||||
|
- (scores.get (a.id) ?? Number.NEGATIVE_INFINITY))
|
||||||
.slice (0, addCount)
|
.slice (0, addCount)
|
||||||
|
|
||||||
if (candidates.length === 0)
|
if (candidates.length === 0)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
candidates.forEach (post => recovered.set (post.id, {
|
candidates.forEach (post => recovered.set (post.id, answerCountAtRecovery))
|
||||||
answerCountAtRecovery,
|
|
||||||
scoreAtRecovery: scores.get (post.id) ?? 0 }))
|
|
||||||
|
|
||||||
return { recoveredCandidatePosts: recovered,
|
return {
|
||||||
recoveryStepCount: recoveryStepCount + 1 }
|
recoveredCandidatePosts: recovered,
|
||||||
|
recoveryStepCount: recoveryStepCount + 1 }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
import { readFileSync } from 'node:fs'
|
|
||||||
import { resolve } from 'node:path'
|
|
||||||
|
|
||||||
import { describe, expect, it } from 'vitest'
|
import { describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
import { isQuestionHardFilteredAfterAnswers } from '@/lib/gekanatorQuestionFilters'
|
import { isQuestionHardFilteredAfterAnswers } from '@/lib/gekanatorQuestionFilters'
|
||||||
@@ -52,89 +49,6 @@ const blocked = (
|
|||||||
isQuestionHardFilteredAfterAnswers (question (candidate), [answer (previous, value)])
|
isQuestionHardFilteredAfterAnswers (question (candidate), [answer (previous, value)])
|
||||||
|
|
||||||
|
|
||||||
const gekanatorPageSource = readFileSync (
|
|
||||||
resolve (process.cwd (), 'src/pages/GekanatorPage.tsx'),
|
|
||||||
'utf8')
|
|
||||||
|
|
||||||
const gekanatorBackdropSource = gekanatorPageSource.slice (
|
|
||||||
gekanatorPageSource.indexOf ('const GekanatorBackdrop'),
|
|
||||||
gekanatorPageSource.indexOf ('const expectedAnswerFor'))
|
|
||||||
|
|
||||||
const gekanatorChooseQuestionSource = gekanatorPageSource.slice (
|
|
||||||
gekanatorPageSource.indexOf ('const chooseQuestion'),
|
|
||||||
gekanatorPageSource.indexOf ('const winningRunPriorityFor'))
|
|
||||||
|
|
||||||
const gekanatorFallbackQuestionSource = gekanatorPageSource.slice (
|
|
||||||
gekanatorPageSource.indexOf ('const chooseFallbackQuestion'),
|
|
||||||
gekanatorPageSource.indexOf ('const shouldEnterGuessPhase'))
|
|
||||||
|
|
||||||
|
|
||||||
describe('GekanatorBackdrop regression structure', () => {
|
|
||||||
it('keeps displayedBackdropMode as the render-time source of truth', () => {
|
|
||||||
expect(gekanatorBackdropSource).not.toContain ('isLeavingGuessBackdrop')
|
|
||||||
expect(gekanatorBackdropSource).not.toContain ('renderBackdropMode')
|
|
||||||
expect(gekanatorBackdropSource).not.toContain ('renderWinningRunCount')
|
|
||||||
expect(gekanatorBackdropSource).not.toContain ('renderThumbnails')
|
|
||||||
expect(gekanatorBackdropSource).not.toContain ('renderIsCrossfading')
|
|
||||||
|
|
||||||
expect(gekanatorBackdropSource).toContain (
|
|
||||||
"const renderedSettings = settingsForMode (displayedBackdropMode)")
|
|
||||||
expect(gekanatorBackdropSource).toContain (
|
|
||||||
'scaleForMode (displayedBackdropMode, displayedWinningRunCount)')
|
|
||||||
expect(gekanatorBackdropSource).toContain (
|
|
||||||
"backdropMode === 'guess' || displayedBackdropMode === 'guess'")
|
|
||||||
})
|
|
||||||
|
|
||||||
it('does not split guess into a separate renderer or force a remount', () => {
|
|
||||||
expect(gekanatorBackdropSource).not.toContain ('renderStaticGuessBackdrop')
|
|
||||||
expect(gekanatorBackdropSource).not.toContain ('guessZoomAnimationKey')
|
|
||||||
expect(gekanatorBackdropSource).not.toContain ('shouldAnimateGuessZoomIn')
|
|
||||||
expect(gekanatorBackdropSource).not.toContain ('previousBackdropModeRef')
|
|
||||||
expect(gekanatorBackdropSource).not.toContain (
|
|
||||||
'if (isGuessPresentation && guessThumbnail)')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('keeps tile keys independent from backdrop mode', () => {
|
|
||||||
expect(gekanatorBackdropSource).toContain ('key={duplicate}')
|
|
||||||
expect(gekanatorBackdropSource).toContain ('key={`${ duplicate }:${ index }`}')
|
|
||||||
expect(gekanatorBackdropSource).not.toMatch (/key=\{`\$\{\s*mode/)
|
|
||||||
expect(gekanatorBackdropSource).not.toMatch (/key=\{`\$\{\s*displayedBackdropMode/)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('keeps guess on the shared scale, x, and y animation path', () => {
|
|
||||||
expect(gekanatorBackdropSource).toContain ('animate={{ scale: renderedScale')
|
|
||||||
expect(gekanatorBackdropSource).toContain (
|
|
||||||
"x: displayedBackdropMode === 'guess' ? guessFocusOffset.x : '0%'")
|
|
||||||
expect(gekanatorBackdropSource).toContain (
|
|
||||||
"y: displayedBackdropMode === 'guess' ? guessFocusOffset.y : '0%'")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
describe('Gekanator question selection regression structure', () => {
|
|
||||||
it('prefers normal questions after user_suggested quota has been met', () => {
|
|
||||||
const normalFallbackIndex = gekanatorChooseQuestionSource.indexOf (
|
|
||||||
'else if (normalPool.length > 0)')
|
|
||||||
const effectiveFallbackIndex = gekanatorChooseQuestionSource.indexOf (
|
|
||||||
'else if (effectiveUserSuggestedPool.length > 0)')
|
|
||||||
|
|
||||||
expect(normalFallbackIndex).toBeGreaterThan(0)
|
|
||||||
expect(effectiveFallbackIndex).toBeGreaterThan(0)
|
|
||||||
expect(normalFallbackIndex).toBeLessThan(effectiveFallbackIndex)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('does not let fallback questions bypass user_suggested purpose tracking', () => {
|
|
||||||
expect(gekanatorFallbackQuestionSource).toContain (
|
|
||||||
"question.source !== 'user_suggested'")
|
|
||||||
})
|
|
||||||
|
|
||||||
it('does not show a fixed extra-question count in the extra learning UI', () => {
|
|
||||||
expect(gekanatorPageSource).not.toContain ('追加で 2 問まで答えてください。')
|
|
||||||
expect(gekanatorPageSource).toContain ('追加で質問に答えてください。')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
describe('isQuestionHardFilteredAfterAnswers', () => {
|
describe('isQuestionHardFilteredAfterAnswers', () => {
|
||||||
it('blocks only contradictory or redundant month questions after a yes answer', () => {
|
it('blocks only contradictory or redundant month questions after a yes answer', () => {
|
||||||
const previous: GekanatorQuestionCondition = { type: 'original-month', month: 12 }
|
const previous: GekanatorQuestionCondition = { type: 'original-month', month: 12 }
|
||||||
|
|||||||
+703
-1437
ファイル差分が大きすぎるため省略します
差分を読込み
新しい課題から参照
ユーザをブロックする