Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Japanese test improvements #962

Merged
merged 4 commits into from
Jul 28, 2021
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 @@ -21,9 +21,7 @@ import docspell.common._
object DateFind {

def findDates(text: String, lang: Language): Stream[Pure, NerDateLabel] =
TextSplitter
.splitToken(text, " \t.,\n\r/年月日".toSet)
.filter(w => lang != Language.Latvian || w.value != "gada")
splitWords(text, lang)
.sliding(3)
.filter(_.size == 3)
.flatMap(q =>
Expand All @@ -44,6 +42,20 @@ object DateFind {
)
)

private[this] val jpnChars =
("年月日" + MonthName.getAll(Language.Japanese).map(_.mkString).mkString).toSet

private def splitWords(text: String, lang: Language): Stream[Pure, Word] = {
val stext =
if (lang == Language.Japanese) {
text.map(c => if (jpnChars.contains(c)) c else ' ')
} else text

TextSplitter
.splitToken(stext, " \t.,\n\r/年月日".toSet)
.filter(w => lang != Language.Latvian || w.value != "gada")
}

case class SimpleDate(year: Int, month: Int, day: Int) {
def toLocalDate: LocalDate =
LocalDate.of(if (year < 100) 2000 + year else year, month, day)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,34 @@ class DateFindSpec extends FunSuite {
test("find japanese dates") {
assertEquals(
DateFind
.findDates("some text in japanese 2021.7.21 and more", Language.Japanese)
.findDates("今日の日付は2021.7.21です。", Language.Japanese)
.toVector,
Vector(
NerDateLabel(
LocalDate.of(2021, 7, 21),
NerLabel("2021.7.21", NerTag.Date, 22, 31)
NerLabel("2021.7.21", NerTag.Date, 6, 15)
)
)
)
assertEquals(
DateFind
.findDates("some text in japanese 2021年7月21日 and more", Language.Japanese)
.findDates("今日の日付は2021年7月21日です。", Language.Japanese)
.toVector,
Vector(
NerDateLabel(
LocalDate.of(2021, 7, 21),
NerLabel("2021年7月21", NerTag.Date, 22, 31)
NerLabel("2021年7月21", NerTag.Date, 6, 15)
)
)
)
assertEquals(
DateFind
.findDates("年月日2021年7月21日(日)", Language.Japanese)
.toVector,
Vector(
NerDateLabel(
LocalDate.of(2021, 7, 21),
NerLabel("2021年7月21", NerTag.Date, 3, 12)
)
)
)
Expand Down