Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,10 @@ internal class SefariaBookPayloadReader(
output = output,
refEntries = refs,
refPrefix = "$bookEnTitle ",
heRefPrefix = "$bookHeTitle ",
// Comma after the title, like the named-nodes path above: consumers
// count ", "-separated address levels, and a space-glued title made
// the first level uncountable (e.g. "רש"י על חולין ו., ה, ב").
heRefPrefix = "$bookHeTitle, ",
bookEnTitle = bookEnTitle,
bookHeTitle = bookHeTitle,
headings = headings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ internal class SefariaCorpusIndex private constructor(

fun resolveRef(book: ManualBookIndex, ref: String): RefEntry = exactlyOne(book.refsByRef[ref], "ref '$ref' in ${book.enTitle}")

fun resolveHeRef(book: ManualBookIndex, heRef: String): RefEntry = exactlyOne(book.refsByHeRef[heRef], "heRef '$heRef' in ${book.enTitle}")
fun resolveHeRef(book: ManualBookIndex, heRef: String): RefEntry =
exactlyOne(book.refsByHeRef[legacyHeRefKey(book.heTitle, heRef)], "heRef '$heRef' in ${book.enTitle}")

fun resolveHeRefOrNullIfMissing(book: ManualBookIndex, heRef: String): RefEntry? {
val values = book.refsByHeRef[heRef].orEmpty()
val values = book.refsByHeRef[legacyHeRefKey(book.heTitle, heRef)].orEmpty()
require(values.size <= 1) { "heRef '$heRef' in ${book.enTitle} is ambiguous; found ${values.size}" }
return values.singleOrNull()
}
Expand Down Expand Up @@ -159,11 +160,20 @@ internal fun BookPayload.toManualIndex(
retainedLines = retained,
proofLines = lines.takeIf { retainFullLines },
refsByRef = refEntries.groupBy { it.ref },
refsByHeRef = refEntries.groupBy { it.heRef },
refsByHeRef = refEntries.groupBy { legacyHeRefKey(heTitle, it.heRef) },
refsByLineIndex = refEntries.groupBy { it.lineIndex },
)
}

/**
* Manual-links CSVs pin heRef_2 strings from before the reader put a comma after
* the book title ("רש"י על חולין ו., ה" vs "רש"י על חולין, ו., ה"). Index keys and
* lookups both pass through this, so either spelling resolves to the same entry.
*/
internal fun legacyHeRefKey(heTitle: String, heRef: String): String {
val separated = "$heTitle, "
return if (heRef.startsWith(separated)) "$heTitle ${heRef.removePrefix(separated)}" else heRef
}
internal fun sourceTitle(fileName: String): String {
require(fileName.endsWith("_links.json")) { "Not a links file: $fileName" }
return fileName.removeSuffix("_links.json").takeIf { it.isNotBlank() } ?: error("Empty source title")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class SefariaKeterMalkhutTest {
"stanza from chapter 1 should be present as a content line"
)

// Chapter 1 stanza is referenced as 'כתר מלכות א'
val refA = payload.refEntries.firstOrNull { it.heRef == "כתר מלכות א" }
assertTrue(refA != null, "chapter 1 should have heRef 'כתר מלכות א'")
// Chapter 1 stanza is referenced as 'כתר מלכות, א'
val refA = payload.refEntries.firstOrNull { it.heRef == "כתר מלכות, א" }
assertTrue(refA != null, "chapter 1 should have heRef 'כתר מלכות, א'")
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class SefariaResponsaTocTest {

// heRef for the first paragraph of the first teshuva should use the Hebrew label chain
assertTrue(
payload.refEntries.any { it.heRef == "חוות יאיר א, א" },
"expected refEntry heRef='חוות יאיר א, א'"
payload.refEntries.any { it.heRef == "חוות יאיר, א, א" },
"expected refEntry heRef='חוות יאיר, א, א'"
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.github.kdroidfilter.seforimlibrary.sefariasqlite.manuallinks

import kotlin.test.Test
import kotlin.test.assertEquals

class LegacyHeRefKeyTest {
@Test
fun separatedAndGluedSpellingsShareOneKey() {
assertEquals(
"רש\"י על חולין ו., ה, ב",
legacyHeRefKey("רש\"י על חולין", "רש\"י על חולין, ו., ה, ב"),
)
assertEquals(
"רש\"י על חולין ו., ה, ב",
legacyHeRefKey("רש\"י על חולין", "רש\"י על חולין ו., ה, ב"),
)
}

@Test
fun titlesContainingACommaKeepTheirOwnBoundary() {
assertEquals(
"שולחן ערוך, אורח חיים יא, ב",
legacyHeRefKey("שולחן ערוך, אורח חיים", "שולחן ערוך, אורח חיים, יא, ב"),
)
assertEquals(
"שולחן ערוך, אורח חיים יא, ב",
legacyHeRefKey("שולחן ערוך, אורח חיים", "שולחן ערוך, אורח חיים יא, ב"),
)
}

@Test
fun unrelatedRefsPassThroughVerbatim() {
assertEquals("יעד אחר, א", legacyHeRefKey("ספר", "יעד אחר, א"))
assertEquals("ספר", legacyHeRefKey("ספר", "ספר"))
}
}
Loading