Skip to content

Commit

Permalink
private
Browse files Browse the repository at this point in the history
  • Loading branch information
KoheiKanagu committed Sep 25, 2023
1 parent f824e14 commit 7f00632
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions lib/budoux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class BudouX {
BudouX(String modelJsonString) {
_model = json.decode(modelJsonString) as Map<String, dynamic>;

totalScore = _model.values
_totalScore = _model.values
.map(
(e) => (e as Map<String, dynamic>).values.map(
(e) => e as int,
Expand All @@ -24,9 +24,9 @@ class BudouX {

late final Map<String, dynamic> _model;

late final int totalScore;
late final int _totalScore;

int getScore(String featureKey, String sequence) {
int _getScore(String featureKey, String sequence) {
// ignore: avoid_dynamic_calls
return int.tryParse('${_model[featureKey][sequence]}') ?? 0;
}
Expand All @@ -39,39 +39,39 @@ class BudouX {
final result = <String>[sentence[0]];

for (var i = 1; i < sentence.length; i++) {
var score = -totalScore;
var score = -_totalScore;
if (i - 2 > 0) {
score += 2 * getScore('UW1', sentence.substring(i - 3, i - 2));
score += 2 * _getScore('UW1', sentence.substring(i - 3, i - 2));
}
if (i - 1 > 0) {
score += 2 * getScore('UW2', sentence.substring(i - 2, i - 1));
score += 2 * _getScore('UW2', sentence.substring(i - 2, i - 1));
}
score += 2 * getScore('UW3', sentence.substring(i - 1, i));
score += 2 * getScore('UW4', sentence.substring(i, i + 1));
score += 2 * _getScore('UW3', sentence.substring(i - 1, i));
score += 2 * _getScore('UW4', sentence.substring(i, i + 1));
if (i + 1 < sentence.length) {
score += 2 * getScore('UW5', sentence.substring(i + 1, i + 2));
score += 2 * _getScore('UW5', sentence.substring(i + 1, i + 2));
}
if (i + 2 < sentence.length) {
score += 2 * getScore('UW6', sentence.substring(i + 2, i + 3));
score += 2 * _getScore('UW6', sentence.substring(i + 2, i + 3));
}
if (i > 1) {
score += 2 * getScore('BW1', sentence.substring(i - 2, i));
score += 2 * _getScore('BW1', sentence.substring(i - 2, i));
}
score += 2 * getScore('BW2', sentence.substring(i - 1, i + 1));
score += 2 * _getScore('BW2', sentence.substring(i - 1, i + 1));
if (i + 1 < sentence.length) {
score += 2 * getScore('BW3', sentence.substring(i, i + 2));
score += 2 * _getScore('BW3', sentence.substring(i, i + 2));
}
if (i - 2 > 0) {
score += 2 * getScore('TW1', sentence.substring(i - 3, i));
score += 2 * _getScore('TW1', sentence.substring(i - 3, i));
}
if (i - 1 > 0) {
score += 2 * getScore('TW2', sentence.substring(i - 2, i + 1));
score += 2 * _getScore('TW2', sentence.substring(i - 2, i + 1));
}
if (i + 1 < sentence.length) {
score += 2 * getScore('TW3', sentence.substring(i - 1, i + 2));
score += 2 * _getScore('TW3', sentence.substring(i - 1, i + 2));
}
if (i + 2 < sentence.length) {
score += 2 * getScore('TW4', sentence.substring(i, i + 3));
score += 2 * _getScore('TW4', sentence.substring(i, i + 3));
}
if (score > 0) {
result.add('');
Expand Down

0 comments on commit 7f00632

Please sign in to comment.