From 38cc08319f0aed3607fed262b23d093c8937433c Mon Sep 17 00:00:00 2001 From: Ruslan Khafizov Date: Thu, 3 Oct 2024 11:13:52 +0800 Subject: [PATCH] Partial work for AaJson --- lib/haskell/natural4/src/LS/XPile/AaJson.hs | 3 +- .../natural4/test/LS/XPile/AaJsonSpec.hs | 16 +- .../golden/AaJsonSpec/must_sing.json.expected | 31 +++ .../golden/AaJsonSpec/must_sing.purs.expected | 50 ---- .../golden/AaJsonSpec/rodents.json.expected | 87 ++++++ .../golden/AaJsonSpec/rodents.purs.expected | 251 ------------------ 6 files changed, 126 insertions(+), 312 deletions(-) create mode 100644 lib/haskell/natural4/test/testdata/golden/AaJsonSpec/must_sing.json.expected delete mode 100644 lib/haskell/natural4/test/testdata/golden/AaJsonSpec/must_sing.purs.expected create mode 100644 lib/haskell/natural4/test/testdata/golden/AaJsonSpec/rodents.json.expected delete mode 100644 lib/haskell/natural4/test/testdata/golden/AaJsonSpec/rodents.purs.expected diff --git a/lib/haskell/natural4/src/LS/XPile/AaJson.hs b/lib/haskell/natural4/src/LS/XPile/AaJson.hs index 7b987374b..e1597f577 100644 --- a/lib/haskell/natural4/src/LS/XPile/AaJson.hs +++ b/lib/haskell/natural4/src/LS/XPile/AaJson.hs @@ -309,8 +309,7 @@ translate2AaJson nlgEnvs eng l4i = do case hornByLang of Left err -> xpError err Right hornByLang -> xpReturn [__i| - #{nlgEnvStrLower} :: Object.Object (Item String) - #{nlgEnvStrLower} = Object.fromFoldable + { #{pShowNoColor $ DL.nub hornByLang} |] -- mutterdhsf 2 "qaHornsAllLangs" pShowNoColorS qaHornsRights diff --git a/lib/haskell/natural4/test/LS/XPile/AaJsonSpec.hs b/lib/haskell/natural4/test/LS/XPile/AaJsonSpec.hs index f39699c1a..bc695351d 100644 --- a/lib/haskell/natural4/test/LS/XPile/AaJsonSpec.hs +++ b/lib/haskell/natural4/test/LS/XPile/AaJsonSpec.hs @@ -65,8 +65,6 @@ loadNLGEnv tracer engE = transpileFile :: String -> IO TL.Text transpileFile filename = do let tracer = - -- Use the 'prettyTracer' if you need logs for debugging - -- prettyTracer mempty let testPath = "test" "testdata" "golden" "AaJsonSpec" filename <.> "csv" opts = SFL4.defaultOptions {SFL4.file = [testPath]} @@ -79,7 +77,7 @@ transpileFile filename = do nlgEnvs = justNLGDate.allEnv eng = justNLGDate.env (psResult, _) = xpLog do - fmapE (<> ("\n\n" <> "allLang = [\"" <> strLangs <> "\"]")) (translate2AaJson nlgEnvs eng l4i) + fmapE (<> ("\n\n" <> "allLang = [\"" <> strLangs <> "\"]")) (translate2AaJson [eng] eng l4i) case psResult of Left err -> do @@ -96,8 +94,8 @@ goldenGeneric name myoutput = encodePretty = TL.unpack, writeToFile = TL.writeFile, readFromFile = TL.readFile, - goldenFile = testPath <.> "purs.expected", - actualFile = Just (testPath <.> "purs.actual"), + goldenFile = testPath <.> "json.expected", + actualFile = Just (testPath <.> "json.actual"), failFirstTime = False } where @@ -112,7 +110,7 @@ spec = do must_sing_purs <- transpileFile "must_sing" pure $ goldenGeneric "must_sing" must_sing_purs - describe "rodents" do - it "convert must sing to AaJson" do - rodents_purs <- transpileFile "rodents" - pure $ goldenGeneric "rodents" rodents_purs + -- describe "rodents" do + -- it "convert must sing to AaJson" do + -- rodents_purs <- transpileFile "rodents" + -- pure $ goldenGeneric "rodents" rodents_purs diff --git a/lib/haskell/natural4/test/testdata/golden/AaJsonSpec/must_sing.json.expected b/lib/haskell/natural4/test/testdata/golden/AaJsonSpec/must_sing.json.expected new file mode 100644 index 000000000..1732de545 --- /dev/null +++ b/lib/haskell/natural4/test/testdata/golden/AaJsonSpec/must_sing.json.expected @@ -0,0 +1,31 @@ + + +{ + "Person": { + "All": { + "label": { + "Pre": "all of:" + }, + "children": [ + { + "Leaf": "does the person walk?" + }, + { + "Any": { + "label": { + "Pre": "any of:" + }, + "children": [ + { + "Leaf": "does the person eat?" + }, + { + "Leaf": "does the person drink?" + } + ] + } + } + ] + } + } +} \ No newline at end of file diff --git a/lib/haskell/natural4/test/testdata/golden/AaJsonSpec/must_sing.purs.expected b/lib/haskell/natural4/test/testdata/golden/AaJsonSpec/must_sing.purs.expected deleted file mode 100644 index ba3762dda..000000000 --- a/lib/haskell/natural4/test/testdata/golden/AaJsonSpec/must_sing.purs.expected +++ /dev/null @@ -1,50 +0,0 @@ - - -nl4chi :: Object.Object (Item String) -nl4chi = Object.fromFoldable - [ Tuple "Person" - ( All - ( Pre "all of:" ) - [ Leaf "人 走 吗?" - , Any - ( Pre "any of:" ) - [ Leaf "人 吃 吗?" - , Leaf "人 喝 吗?" - ] - ] - ) -] - -nl4eng :: Object.Object (Item String) -nl4eng = Object.fromFoldable - [ Tuple "Person" - ( All - ( Pre "all of:" ) - [ Leaf "does the person walk?" - , Any - ( Pre "any of:" ) - [ Leaf "does the person eat?" - , Leaf "does the person drink?" - ] - ] - ) -] - -nl4may :: Object.Object (Item String) -nl4may = Object.fromFoldable - [ Tuple "Person" - ( All - ( Pre "all of:" ) - [ Leaf "adakah seseorang berjalan?" - , Any - ( Pre "any of:" ) - [ Leaf "adakah seseorang makan?" - , Leaf "adakah seseorang minum?" - ] - ] - ) -] - - - -allLang = ["nl4chi", "nl4eng", "nl4may"] \ No newline at end of file diff --git a/lib/haskell/natural4/test/testdata/golden/AaJsonSpec/rodents.json.expected b/lib/haskell/natural4/test/testdata/golden/AaJsonSpec/rodents.json.expected new file mode 100644 index 000000000..40075c054 --- /dev/null +++ b/lib/haskell/natural4/test/testdata/golden/AaJsonSpec/rodents.json.expected @@ -0,0 +1,87 @@ + + +nl4eng :: Object.Object (Item String) +nl4eng = Object.fromFoldable + [ Tuple "Covered If …" + ( Not + ( All + ( Pre "all of:" ) + [ Any + ( Pre "Is the Loss or Damage caused by" ) + [ Leaf "rodents?" + , Leaf "insects?" + , Leaf "vermin?" + , Leaf "birds?" + ] + , Not + ( Any + ( Pre "any of:" ) + [ All + ( Pre "all of:" ) + [ Leaf "is Loss or Damage to contents?" + , Leaf "is Loss or Damage caused by birds?" + ] + , All + ( Pre "all of:" ) + [ Leaf "is Loss or Damage ensuing covered loss?" + , Not + ( Any + ( Pre "any of:" ) + [ Leaf "does any other exclusion apply?" + , Any + ( Pre "did an animal cause water to escape from" ) + [ Leaf "a household appliance?" + , Leaf "a swimming pool?" + , Leaf "a plumbing, heating, or air conditioning system?" + ] + ] + ) + ] + ] + ) + ] + ) + ) +, Tuple "Not Covered If …" + ( All + ( Pre "all of:" ) + [ Any + ( Pre "Is the Loss or Damage caused by" ) + [ Leaf "rodents?" + , Leaf "insects?" + , Leaf "vermin?" + , Leaf "birds?" + ] + , Not + ( Any + ( Pre "any of:" ) + [ All + ( Pre "all of:" ) + [ Leaf "is Loss or Damage to contents?" + , Leaf "is Loss or Damage caused by birds?" + ] + , All + ( Pre "all of:" ) + [ Leaf "is Loss or Damage ensuing covered loss?" + , Not + ( Any + ( Pre "any of:" ) + [ Leaf "does any other exclusion apply?" + , Any + ( Pre "did an animal cause water to escape from" ) + [ Leaf "a household appliance?" + , Leaf "a swimming pool?" + , Leaf "a plumbing, heating, or air conditioning system?" + ] + ] + ) + ] + ] + ) + ] + ) +] + + + +allLang = ["nl4chi", "nl4eng", "nl4may"] \ No newline at end of file diff --git a/lib/haskell/natural4/test/testdata/golden/AaJsonSpec/rodents.purs.expected b/lib/haskell/natural4/test/testdata/golden/AaJsonSpec/rodents.purs.expected deleted file mode 100644 index 1c2e17554..000000000 --- a/lib/haskell/natural4/test/testdata/golden/AaJsonSpec/rodents.purs.expected +++ /dev/null @@ -1,251 +0,0 @@ - - -nl4chi :: Object.Object (Item String) -nl4chi = Object.fromFoldable - [ Tuple "Covered If …" - ( Not - ( All - ( Pre "all of:" ) - [ Any - ( Pre "那 个 损 失 或 损 害 的 原 因" ) - [ Leaf "些 啮 齿?" - , Leaf "些 昆 虫?" - , Leaf "蠹 虫?" - , Leaf "些 鸟?" - ] - , Not - ( Any - ( Pre "any of:" ) - [ All - ( Pre "all of:" ) - [ Leaf "" - , Leaf "损 失 或 损 害 是 被 些 鸟 的 原 因 的 吗?" - ] - , All - ( Pre "all of:" ) - [ Leaf "损 失 或 损 害 是 保 户 [UseN] 接 着 的 吗?" - , Not - ( Any - ( Pre "any of:" ) - [ Leaf "任 何 其 他 排 除 [UseV] [UseV] [UseV] [UseV] 吗?" - , Any - ( Pre "" ) - [ Leaf "一 个 家 用 电 器?" - , Leaf "一 个 游 泳 池?" - , Leaf "管 路 系 统 或 暖 通 空 调?" - ] - ] - ) - ] - ] - ) - ] - ) - ) -, Tuple "Not Covered If …" - ( All - ( Pre "all of:" ) - [ Any - ( Pre "那 个 损 失 或 损 害 的 原 因" ) - [ Leaf "些 啮 齿?" - , Leaf "些 昆 虫?" - , Leaf "蠹 虫?" - , Leaf "些 鸟?" - ] - , Not - ( Any - ( Pre "any of:" ) - [ All - ( Pre "all of:" ) - [ Leaf "" - , Leaf "损 失 或 损 害 是 被 些 鸟 的 原 因 的 吗?" - ] - , All - ( Pre "all of:" ) - [ Leaf "损 失 或 损 害 是 保 户 [UseN] 接 着 的 吗?" - , Not - ( Any - ( Pre "any of:" ) - [ Leaf "任 何 其 他 排 除 [UseV] [UseV] [UseV] [UseV] 吗?" - , Any - ( Pre "" ) - [ Leaf "一 个 家 用 电 器?" - , Leaf "一 个 游 泳 池?" - , Leaf "管 路 系 统 或 暖 通 空 调?" - ] - ] - ) - ] - ] - ) - ] - ) -] - -nl4eng :: Object.Object (Item String) -nl4eng = Object.fromFoldable - [ Tuple "Covered If …" - ( Not - ( All - ( Pre "all of:" ) - [ Any - ( Pre "Is the Loss or Damage caused by" ) - [ Leaf "rodents?" - , Leaf "insects?" - , Leaf "vermin?" - , Leaf "birds?" - ] - , Not - ( Any - ( Pre "any of:" ) - [ All - ( Pre "all of:" ) - [ Leaf "is Loss or Damage to contents?" - , Leaf "is Loss or Damage caused by birds?" - ] - , All - ( Pre "all of:" ) - [ Leaf "is Loss or Damage ensuing covered loss?" - , Not - ( Any - ( Pre "any of:" ) - [ Leaf "does any other exclusion apply?" - , Any - ( Pre "did an animal cause water to escape from" ) - [ Leaf "a household appliance?" - , Leaf "a swimming pool?" - , Leaf "a plumbing, heating, or air conditioning system?" - ] - ] - ) - ] - ] - ) - ] - ) - ) -, Tuple "Not Covered If …" - ( All - ( Pre "all of:" ) - [ Any - ( Pre "Is the Loss or Damage caused by" ) - [ Leaf "rodents?" - , Leaf "insects?" - , Leaf "vermin?" - , Leaf "birds?" - ] - , Not - ( Any - ( Pre "any of:" ) - [ All - ( Pre "all of:" ) - [ Leaf "is Loss or Damage to contents?" - , Leaf "is Loss or Damage caused by birds?" - ] - , All - ( Pre "all of:" ) - [ Leaf "is Loss or Damage ensuing covered loss?" - , Not - ( Any - ( Pre "any of:" ) - [ Leaf "does any other exclusion apply?" - , Any - ( Pre "did an animal cause water to escape from" ) - [ Leaf "a household appliance?" - , Leaf "a swimming pool?" - , Leaf "a plumbing, heating, or air conditioning system?" - ] - ] - ) - ] - ] - ) - ] - ) -] - -nl4may :: Object.Object (Item String) -nl4may = Object.fromFoldable - [ Tuple "Covered If …" - ( Not - ( All - ( Pre "all of:" ) - [ Any - ( Pre "Adakah Kerugian atau Kerosakan disebabkan oleh" ) - [ Leaf "rodensia-rodensia?" - , Leaf "serangga-serangga?" - , Leaf "binatang perosak?" - , Leaf "burung-burung?" - ] - , Not - ( Any - ( Pre "any of:" ) - [ All - ( Pre "all of:" ) - [ Leaf "" - , Leaf "adakah Kerugian atau Kerosakan disebabkan burung-burung?" - ] - , All - ( Pre "all of:" ) - [ Leaf "adakah Kerugian atau Kerosakan berlaku akibat [UseN] yang dilindungi [UseN]?" - , Not - ( Any - ( Pre "any of:" ) - [ Leaf "adakah sebarang pengecualian lain [UseV]?" - , Any - ( Pre "" ) - [ Leaf "perkakas rumah?" - , Leaf "kolam renang?" - , Leaf "sistem paip atau HVAC?" - ] - ] - ) - ] - ] - ) - ] - ) - ) -, Tuple "Not Covered If …" - ( All - ( Pre "all of:" ) - [ Any - ( Pre "Adakah Kerugian atau Kerosakan disebabkan oleh" ) - [ Leaf "rodensia-rodensia?" - , Leaf "serangga-serangga?" - , Leaf "binatang perosak?" - , Leaf "burung-burung?" - ] - , Not - ( Any - ( Pre "any of:" ) - [ All - ( Pre "all of:" ) - [ Leaf "" - , Leaf "adakah Kerugian atau Kerosakan disebabkan burung-burung?" - ] - , All - ( Pre "all of:" ) - [ Leaf "adakah Kerugian atau Kerosakan berlaku akibat [UseN] yang dilindungi [UseN]?" - , Not - ( Any - ( Pre "any of:" ) - [ Leaf "adakah sebarang pengecualian lain [UseV]?" - , Any - ( Pre "" ) - [ Leaf "perkakas rumah?" - , Leaf "kolam renang?" - , Leaf "sistem paip atau HVAC?" - ] - ] - ) - ] - ] - ) - ] - ) -] - - - -allLang = ["nl4chi", "nl4eng", "nl4may"] \ No newline at end of file