From a0de0489154e6ec7a867717ecf3b166b43b3bcdf Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Sat, 1 Nov 2025 14:02:40 +0100 Subject: [PATCH] Identify time uncertainty for "etwa" Close #37 --- src/NodaTimeSplitter.php | 10 ++++++++++ src/NodaUncertaintyHelper.php | 2 ++ tests/NodaTimeSplitterTest.php | 13 +++++++++++++ tests/NodaUncertaintyHelperTest.php | 1 + 4 files changed, 26 insertions(+) diff --git a/src/NodaTimeSplitter.php b/src/NodaTimeSplitter.php index 8ab32bc..7d41375 100644 --- a/src/NodaTimeSplitter.php +++ b/src/NodaTimeSplitter.php @@ -98,6 +98,7 @@ final class NodaTimeSplitter { ", ", " und ", "nach ", + "nach dem ", "um ", "ca.", "ab ", @@ -831,6 +832,15 @@ final class NodaTimeSplitter { } } + if (\preg_match("/^(Nach dem|nach dem)\ /", $datum)) { + if (($spacePos = \strpos($datum, " ", 6)) === false) { + return false; + } + if ($output = self::attempt_splitting(\substr($datum, $spacePos))) { + return self::_turn_noda_split_time_to_after($output); + } + } + if (\preg_match("/\ (\(nach|nach)$/", $datum)) { if (($spacePos = \strpos($datum, " ")) === false) { return false; diff --git a/src/NodaUncertaintyHelper.php b/src/NodaUncertaintyHelper.php index b5bd18e..861228a 100644 --- a/src/NodaUncertaintyHelper.php +++ b/src/NodaUncertaintyHelper.php @@ -107,6 +107,8 @@ final class NodaUncertaintyHelper { "za. ", "~", "circa ", + "etwa ", + "Etwa ", "gegen ", "um ", "Um ", diff --git a/tests/NodaTimeSplitterTest.php b/tests/NodaTimeSplitterTest.php index 82175df..cb9841a 100644 --- a/tests/NodaTimeSplitterTest.php +++ b/tests/NodaTimeSplitterTest.php @@ -776,6 +776,19 @@ final class NodaTimeSplitterTest extends TestCase { self::assertEquals($output->toTimeName(), "Vor 2020"); self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020); + $output = NodaTimeSplitter::attempt_splitting("Nach dem 02.1.25 v. Chr"); + self::assertNotEmpty($output); + self::assertEquals($output->toOldFormat(), [ + 0 => "-25", + 1 => "?", + 2 => "01", + 3 => "02", + 4 => "-", + 5 => "Nach", + ]); + self::assertEquals($output->toTimeName(), "Nach 02.01.25 v. Chr."); + self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 25); + $output = NodaTimeSplitter::attempt_splitting("Nach Januar 2020"); self::assertNotEmpty($output); self::assertEquals($output->toOldFormat(), [ diff --git a/tests/NodaUncertaintyHelperTest.php b/tests/NodaUncertaintyHelperTest.php index 9c40c0f..f95ad88 100644 --- a/tests/NodaUncertaintyHelperTest.php +++ b/tests/NodaUncertaintyHelperTest.php @@ -25,6 +25,7 @@ final class NodaUncertaintyHelperTest extends TestCase { return [ 'uncertainty prefix: "wohl 1950"' => ["wohl 1950", "1950", false], + 'uncertainty prefix: "etwa 1950"' => ["etwa 1950", "1950", false], 'uncertainty suffix: "1950?"' => ["1950?", "1950", false], 'uncertainty suffix and superfluous chars: "1950 ?,"' => ["1950 ?,", "1950", false], 'certain term with superfluous chars: "1950 ,"' => ["1950 ,", "1950", true],