Skip to content

Commit

Permalink
#3326 Fix multiple consequtive strongs numbers issue
Browse files Browse the repository at this point in the history
Supports now 3 strongs for one word
  • Loading branch information
tuomas2 committed Nov 28, 2024
1 parent 2d27176 commit e78810f
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions app/src/main/java/net/bible/service/sword/mysword/MySwordBook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -341,36 +341,39 @@ class SqliteBackend(val state: SqliteVerseBackendState, metadata: SwordBookMetaD
}

private val strongsMorphRe = Regex("""(\w+)<W([GH])(\d+)><WT([a-zA-Z\d\-]+)( l="([^"]+)")?>""")
private val strongsRe = Regex("""(\w+)<W([GH])(\d+)>""")
private val strongsRe = Regex("""(\w+)<W([GH]\d+)>(<W([GH]\d+)>)?(<W([GH]\d+)>)?""")
private val morphRe = Regex("""<WT([a-zA-Z\d\-]+)( l="([^"]+)")?>""")
private val tagEndRe = Regex("""<(Ts|Fi|Fo|q|e|t|x|h|g)>""")
private val singleTagRe = Regex("""<(CM|CL|PF\d|Pl\d|Cl|D|wh|wg|wt|br)>""")

// MySword has weird non-xml tags, so we need to do some transformation here.
// https://www.mysword.info/modules-format
private fun transformMySwordTags(mySwordText: String): String =
mySwordText
.replace(strongsMorphRe) { m ->
val word = m.groups[1]!!.value
val lang = m.groups[2]!!.value
val strongsNum = m.groups[3]!!.value
val morphCode = m.groups[4]!!.value
"<w lemma=\"strong:${lang}${strongsNum}\" morph=\"strongMorph:${morphCode}\">${word}</w>"
}
.replace(strongsRe) { m ->
val (word, lang, num) = m.destructured
"<w lemma=\"strong:${lang}${num}\">${word}</w>"
}
.replace(morphRe) { m ->
val morphCode = m.groups[1]!!.value
"<w morph=\"strongMorph:${morphCode}\">${morphCode}</w>"
}
.replace(tagEndRe) {m ->
"</${m.groups[1]!!.value.uppercase()}>"
}
.replace(singleTagRe) {m ->
"<${m.groups[1]!!.value}/>"
}
private fun transformMySwordTags(mySwordText: String): String = mySwordText
.replace(strongsMorphRe) { m ->
val word = m.groups[1]!!.value
val lang = m.groups[2]!!.value
val strongsNum = m.groups[3]!!.value
val morphCode = m.groups[4]!!.value
"<w lemma=\"strong:${lang}${strongsNum}\" morph=\"strongMorph:${morphCode}\">${word}</w>"
}
.replace(strongsRe) { m ->
val word = m.groups[1]!!.value
val strongs1 = m.groups[2]!!.value
val strongs2 = m.groups[4]?.value
val strongs3 = m.groups[6]?.value
val strongs = listOf(strongs1, strongs2, strongs3).filterNotNull().joinToString(" ") { "strong:$it" }
"<w lemma=\"$strongs\">${word}</w>"
}
.replace(morphRe) { m ->
val morphCode = m.groups[1]!!.value
"<w morph=\"strongMorph:${morphCode}\">${morphCode}</w>"
}
.replace(tagEndRe) { m ->
"</${m.groups[1]!!.value.uppercase()}>"
}
.replace(singleTagRe) { m ->
"<${m.groups[1]!!.value}/>"
}

override fun readRawContent(state: SqliteVerseBackendState, key: Key): String = try {
when (bookMetaData.bookCategory) {
Expand Down

0 comments on commit e78810f

Please sign in to comment.