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

More transpiler functionality and fixes from Sprint 2 (started Aug 29) #431

Merged
merged 58 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
28694e5
Experiment with using optics to derive prisms for L4 Rule datatype
ym-han Sep 4, 2023
54dbc8f
Replace "." with "dot" and "," with "comma", in the Pred txts of ABPa…
ym-han Sep 4, 2023
cc8173c
remove the old check refine prevalidation stuff for now
ym-han Sep 5, 2023
eb75155
idVars.hs: make `replacePunctn` safer by checking if input is empty
ym-han Sep 6, 2023
8af7cd1
LE.hs: clean up imports a bit
ym-han Sep 6, 2023
dcca73d
Support ditto syntax -- though note that
ym-han Sep 6, 2023
86c34d5
SimplifyL4.hs: simplify code in `simplifyL4rule`; add comments
ym-han Sep 6, 2023
6f1e10a
SimplifyL4.hs: remove `error` in `mte2cell`; add note abt MTB
ym-han Sep 6, 2023
f83ae40
clean up
ym-han Sep 6, 2023
f6fe846
Simplify some applicative code in `termIsNaryOpOf` with HLint's help
ym-han Sep 8, 2023
aee9f90
SimplifyL4.hs: Remove `error` from `gmtexpr2gvar`; add TODO for futur…
ym-han Sep 8, 2023
d582be0
Improve haddock annotations
ym-han Sep 8, 2023
833825e
SimplifyL4.hs: Simplify function for getting Givens with `generic-opt…
ym-han Sep 8, 2023
3210fbb
SimplifyL4.hs: remove viewpatterns -- didn't end up needing it
ym-han Sep 8, 2023
fa6c305
LogicalEnglish.Types: remove unused pragmas
ym-han Sep 9, 2023
2b94fc4
SimplifyL4.hs: clean up internal logic of `simpheadRPC`
ym-han Sep 9, 2023
81191f6
1. Improve the RPRel handling in SimplifyL4.hs --- in particular, str…
ym-han Sep 9, 2023
852da85
add README.md: some quick notes on LE syntax
ym-han Sep 11, 2023
354c4e9
LE Pretty.hs: remove some of the unnecessary imports
ym-han Sep 11, 2023
c0847e2
ValidateL4Input.hs: temporarily disable warnings for this file since …
ym-han Sep 11, 2023
d1ea453
GenLEHCs.hs: remove some redundant imports
ym-han Sep 11, 2023
a9fe34d
WIP: refactor NLAs to allow for adding partial info within the argume…
ym-han Sep 11, 2023
a26033a
LE Types.hs: streamline mkNLA by using the onNonEmpty hof
ym-han Sep 11, 2023
4570682
WIP: NLA refactoring to get smarter filtering and better NLAs for jus…
ym-han Sep 13, 2023
f9f2004
GenNLAs.hs: escape the pred txt for now (TODO: Add tests to check if …
ym-han Sep 13, 2023
4407256
GenNLAs.hs: first draft of `subsumes`
ym-han Sep 13, 2023
15bf0e5
GenNLAs.hs: fix `subsumes`
ym-han Sep 13, 2023
6fd34ea
clean up GenNLAs.hs some
ym-han Sep 13, 2023
aeced88
start of utils for providing english-y translations of optics abstrac…
ym-han Sep 13, 2023
0db02d7
GenNLA.hs: add simple implementation of `getNonSubsumed`
ym-han Sep 13, 2023
fa322b7
GenNLAs.hs: Stub out things to implement for parsing lib templates to…
ym-han Sep 13, 2023
7b28f5b
GenNLAs.hs: tweak regex traversal stuff
ym-han Sep 14, 2023
69ac373
GenNLAs.hs: quick clean up
ym-han Sep 14, 2023
99ce893
GenNLAs.hs: coarsen unnecessary structure (should have been EQ-ing, H…
ym-han Sep 14, 2023
b35daaf
WIP: incorporate `getNonSubsumed` into LE.hs, but need to look into w…
ym-han Sep 14, 2023
472dc47
GenNLAs.hs and LE.hs: feat. filter out subsumed NLAs (if the subsumin…
ym-han Sep 14, 2023
f5b83c4
LETypes.hs: clean up; export prisms for `TemplateVar`
ym-han Sep 14, 2023
9f74b2d
LE.hs and GenNLAs.hs: more clean up; remove `NLA` pattern and just ex…
ym-han Sep 14, 2023
6293f14
GenNLA.hs: make iso for newtype NLATxt and other misc clean up
ym-han Sep 14, 2023
7f7a9c4
WIP: filtering out lib templates
ym-han Sep 15, 2023
64e5e3f
GenNLAs.hs: more clean up, mostly to do with the `_MkNLATxt` iso
ym-han Sep 16, 2023
2fd2543
GenNLAs.hs: rename `removeSubsumed` to `removeRegexMatched`
ym-han Sep 16, 2023
415fcd4
GenNLAs.hs: clean up regextravify stuff; add comments to `rawregexify…
ym-han Sep 16, 2023
68c78b3
update lib hcs
ym-han Sep 16, 2023
6afc96a
update lib templates
ym-han Sep 16, 2023
5089129
WIP: first attempt at filtering out things subsumed by lib templates
ym-han Sep 16, 2023
a9f5bc9
some clean up
ym-han Sep 16, 2023
e253b17
IdVars.hs: replace '%' with ' percent' in Preds of VCells
ym-han Sep 16, 2023
ed12bec
LE Pretty.hs: make sure that only the last lib template ends with a p…
ym-han Sep 16, 2023
f9d50ef
LE utils.hs: move HS import into doctest setup
ym-han Sep 17, 2023
8f02faa
Consolidate all the 'top-level' orchestrating code for filtering out …
ym-han Sep 17, 2023
df1ec51
GenNLAs.hs: Implement `removeDisprefdAmongEquivUpToVarNames`, first pass
ym-han Sep 17, 2023
813d25c
move (<||>) to LS.Utils
ym-han Sep 17, 2023
d5e87dc
Implement core functionality for filtering out dispreferred equivalen…
ym-han Sep 17, 2023
c1cd7a7
LE Pretty.hs: include the filtered out templates that are equiv up to…
ym-han Sep 17, 2023
0601d08
LS.Rule: move the Data-Generics-Sum-Constructors to comments, instead…
ym-han Sep 17, 2023
63fda5f
cleanup
ym-han Sep 17, 2023
725a4c4
haskell.yml: try installing pcre as prereq
ym-han Sep 17, 2023
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
9 changes: 9 additions & 0 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ jobs:
${{ runner.os }}-build-
${{ runner.os }}-

- name: Install Ubuntu Prerequisites (libpcre)
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt-get install libpcre3-dev
- name: Install MacOS Prerequisites (libpcre)
if: startsWith(matrix.os, 'macOS')
run: |
brew install pcre

- name: Build explainable
run: stack build
working-directory: lib/haskell/explainable
Expand Down
9 changes: 9 additions & 0 deletions lib/haskell/natural4/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ dependencies:
- string-interpolate
- prettyprinter-interp
- json
- optics
- generic-optics
- nonempty-containers
- lens-regex-pcre
- pcre-heavy
- string-conversions
- raw-strings-qq



language: GHC2021

Expand Down
24 changes: 21 additions & 3 deletions lib/haskell/natural4/src/LS/Rule.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveAnyClass, DeriveGeneric, FlexibleContexts, TypeFamilies, TypeApplications, DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
Expand All @@ -20,6 +20,7 @@ import Data.Text qualified as Text
import Data.Void (Void)
import Flow ((|>))
import GHC.Generics (Generic)
import Data.Generics.Sum.Constructors
import LS.Types
( BoolStructP,
BoolStructR,
Expand Down Expand Up @@ -71,9 +72,25 @@ import Text.Megaparsec
)
import Data.Graph.Inductive (Gr, empty)
import LS.XPile.Logging (XPileLogW)
import Optics hiding ((|>), has) -- the Rule record has a `has` field
import Optics qualified as O

-- | [TODO] refactoring: these should be broken out into their own (new)types and have Rule include them all.
-- We should take advantage of NoFieldSelectors to reduce the hazards here
{- |
[TODO] refactoring: these should be broken out into their own (new)types and have Rule include them all.
We should take advantage of NoFieldSelectors to reduce the hazards here


The deriving Generics stuff allows us to do things like
>>> O.has (_Ctor @"Regulative") defaultHorn
False
>>> O.has (_Ctor @"Regulative") defaultReg
True

as well as extracting givens from a rule in an easy way (see the Logical English code).

See https://hackage.haskell.org/package/generic-optics-2.2.1.0/docs/Data-Generics-Sum-Constructors.html
for an explanation of how the Generics and optics stuff works
-}
data Rule = Regulative
{ subj :: BoolStructP -- man AND woman AND child
, rkeyword :: RegKeywords -- Every | Party | TokAll
Expand Down Expand Up @@ -181,6 +198,7 @@ instance Hashable Rule

type Parser = WriterT (DList Rule) PlainParser


-- | the more responsible version of head . words . show
ruleConstructor :: Rule -> String
ruleConstructor Regulative{} = "Regulative"
Expand Down
11 changes: 9 additions & 2 deletions lib/haskell/natural4/src/LS/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ module LS.Utils
mapThenSwallowErrs,
runMonoidValidate,
swallowErrs,
MonoidValidate
MonoidValidate,
(<||>)
)
where

import Control.Applicative (liftA2)
import Control.Monad.Validate
( MonadValidate (refute),
Validate,
Expand Down Expand Up @@ -72,4 +74,9 @@ swallowErrs :: [MonoidValidate e a] -> [a]
swallowErrs = mapThenSwallowErrs id

runMonoidValidate :: MonoidValidate e a -> Either e a
runMonoidValidate x = x |> coerce |> runValidate
runMonoidValidate x = x |> coerce |> runValidate

-- | A simple lifted ('||'), copied from Control.Bool
(<||>) :: Applicative f => f Bool -> f Bool -> f Bool
(<||>) = liftA2 (||)
{-# INLINE (<||>) #-}
6 changes: 2 additions & 4 deletions lib/haskell/natural4/src/LS/XPile/LogicalEnglish/GenLEHCs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@

module LS.XPile.LogicalEnglish.GenLEHCs (leHCFromVarsHC) where


import Data.Text qualified as T
import Data.HashSet qualified as HS
import Data.Foldable (toList)
-- import Data.Foldable (toList)
-- import Debug.Trace (trace)
import Data.Coerce (coerce)
-- import Data.String.Interpolate ( i )
import Data.Traversable
import Control.Monad.Identity (Identity)

import LS.XPile.LogicalEnglish.Types

Expand Down Expand Up @@ -150,7 +148,7 @@ simplifyVAtomicP = fmap simplifyVCells

simplifyVCells :: VCell -> LEhcCell
simplifyVCells = \case
Pred txt -> NotVar txt
Pred txt -> NotVar txt
TempVar tv -> tvar2lecell tv

tvar2lecell :: TemplateVar -> LEhcCell
Expand Down
Loading
Loading