Skip to content

Commit

Permalink
feat: #98 Validate that there are no dictionary code duplicates in th…
Browse files Browse the repository at this point in the history
…e json file.
  • Loading branch information
dmitry-weirdo committed Nov 27, 2024
1 parent fbfb209 commit d7530b4
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ enum class NonStandardDictionary(
MINI_MARATHON(6018, "Мини-марафон, 800 знаков", "Мини-марафоне, 800 знаков"),
CYBERTEXT(6562, "Кибертекст", "Кибертексте"),
CYBERTEXT_2(115606, "Кибертекст 2.0", "Кибертексте 2.0"),

// Пальцы
PINKIES_PLUS(3714, "Мизинцы+", "Мизинцах+"),
TRAINING_INDEX_FINGERS(226, "Тренируем указательные", "Тренируем указательные"),
RING_FINGERS(8223, "Безымянные", "Безымянных"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,40 @@ object NonStandardDictionariesCache : Logging {

val nonStandardDictionaries = JacksonUtils.parseNonStandardDictionaryData(fileName)

logger.info(
"Total non-standard dictionaries read from json file \"$NON_STANDARD_DICTIONARIES_JSON_RESOURCE\": " +
"${nonStandardDictionaries.size}."
)

// validate no duplicate ids
validate(nonStandardDictionaries)

return nonStandardDictionaries
}

private fun validate(dictionaries: List<NonStandardDictionaryData>) {
val repeatCodeToCount: Map<Int, Int> = dictionaries
.groupingBy { it.code }
.eachCount()
.filter { it.value > 1 }

if (repeatCodeToCount.isNotEmpty()) {
repeatCodeToCount.forEach {
logger.error("Duplicate dictionary code ${it.key}: used ${it.value} times.")
}
}

check(repeatCodeToCount.isEmpty()) {
"Duplicate dictionary codes: $repeatCodeToCount"
}

logger.info("No dictionary code duplicates.")
}

@JvmStatic
fun main(args: Array<String>) {
val nonStandardDictionaries = parse()

logger.info("Total non-standard dictionaries read from json file: ${nonStandardDictionaries.size}.")
logger.info("[main]: Total non-standard dictionaries read from json file: ${nonStandardDictionaries.size}.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@
}
},

{
"code": 192,
"displayName": "Частотный словарь",
"displayNamePrepositional": "Частотном словаре",
"tags": [
"FREQUENT"
],
"top": {
"loggerName": "FrequencyVocabulary",
"minRacesCount": 200,

// "topByBestSpeedExcelSheetName": "Топ по рекорду в «Частотном словаре»", // 36 chars
"topByBestSpeedExcelSheetName": "Топ по рекорду в «Частотном»", // 28 chars

// "topByRacesCountExcelSheetName": "Топ по пробегу в «Частотном словаре»", // 36 chars
"topByRacesCountExcelSheetName": "Топ по пробегу в «Частотном»", // 28 chars

// "topByHaulExcelSheetName": "Топ по времени в «Частотном словаре»", // 36 chars
"topByHaulExcelSheetName": "Топ по времени в «Частотном»" // 28 chars
}
},

{
"code": 5539,
"displayName": "Обычный in English",
Expand Down Expand Up @@ -65,5 +87,15 @@
"CYBERTEXT",
"FREQUENT"
]
},

{ // without generated top
"code": 115606,
"displayName": "Кибертекст 2.0",
"displayNamePrepositional": "Кибертексте 2.0",
"tags": [
"CYBERTEXT",
"FREQUENT"
]
}
]

0 comments on commit d7530b4

Please sign in to comment.