Skip to content

Commit

Permalink
[NFC] datasource tools: generate dataset tsv
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Mar 3, 2025
1 parent 26bd0a8 commit 9d1cfd8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions datasource/api/test-codegen/src/main/GenerateTests.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
/*
* Copyright (C) 2024-2025 OpenAni and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link.
*
* https://github.com/open-ani/ani/blob/main/LICENSE
*/

package me.him188.ani.datasources.api.test.codegen.main

import me.him188.ani.datasources.api.test.codegen.TestGenerator
import me.him188.ani.datasources.api.test.codegen.json
import me.him188.ani.datasources.api.topic.titles.PatternBasedRawTitleParser
import me.him188.ani.datasources.api.topic.titles.RawTitleParser
import me.him188.ani.datasources.api.topic.titles.parse
import java.io.File

/**
Expand All @@ -24,6 +35,25 @@ fun main(args: Array<String>) { // 直接 run 就行

println("Found ${suites.size} test data, total ${suites.sumOf { it.topics.size }} topics")

val output = buildString {
appendLine(
"raw\tchinese_title\tother_title\ttags",
)
val parser = PatternBasedRawTitleParser()
for (data in suites) {
for (topic in data.topics) {
val parsed = parser.parse(topic.rawTitle)
appendLine(
"${topic.rawTitle}\t" +
"${parsed.chineseTitle}\t" +
"${parsed.otherTitles.getOrNull(0).orEmpty()}\t" +
parsed.tags.joinToString(","),
)
}
}
}
outputDir.resolve("dataset.tsv").writeText(output)

TestGenerator(RawTitleParser.getDefault()).run {
for (data in suites) {
// val out = outputDir.resolve(data.kotlinClassName + ".kt")
Expand Down

0 comments on commit 9d1cfd8

Please sign in to comment.