Skip to content

Commit

Permalink
permutation works better
Browse files Browse the repository at this point in the history
  • Loading branch information
mengwong committed Oct 19, 2021
1 parent 8afebc6 commit 54adf3f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
5 changes: 3 additions & 2 deletions mengwong/mp/mp.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ library
Paths_mp
hs-source-dirs:
src
ghc-options: -Wall
build-depends:
anyall
, base >=4.7 && <5
Expand All @@ -59,7 +60,7 @@ executable mp-exe
Paths_mp
hs-source-dirs:
app
ghc-options: -threaded -rtsopts -with-rtsopts=-N
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
build-depends:
anyall
, base >=4.7 && <5
Expand Down Expand Up @@ -87,7 +88,7 @@ test-suite mp-test
Paths_mp
hs-source-dirs:
test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
build-depends:
anyall
, base >=4.7 && <5
Expand Down
10 changes: 5 additions & 5 deletions mengwong/mp/src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,10 @@ data RuleBody = RuleBody { rbaction :: ActionType -- pay(to=Seller, amount=$10
deriving (Eq, Show, Generic)

permutations :: [MyToken] -> Parser RuleBody
permutations whos = do
permutations whoifwhen = do
toreturn <- permute ( RuleBody
<$$> pAction
<||> many (preambleBoolRules whos) -- WHO xxx, IF yyy
<|?> ([], some $ preambleBoolRules whoifwhen) -- syntactic constraint, all the if/when need to be contiguous.
<||> pDeontic <* dnl
<|?> (Nothing , Just <$> pTemporal )
)
Expand All @@ -450,15 +450,15 @@ newPre t (AA.Any (AA.Pre _p) x) = AA.Any (AA.Pre t ) x
newPre t (AA.Any (AA.PrePost _p pp) x) = AA.Any (AA.PrePost t pp) x

preambleBoolRules :: [MyToken] -> Parser (Preamble, BoolRules)
preambleBoolRules whos = do
preambleBoolRules whoifwhen = do
leftX <- lookAhead pXLocation -- this is the column where we expect IF/AND/OR etc.
myTraceM ("preambleBoolRules: x location is " ++ show leftX)
checkDepth
depth <- asks callDepth
myTraceM ("preambleBoolRules: passed guard! depth is " ++ show depth)
myTraceM $ "preambleBoolRules: Expecting one of: " ++ show whos
myTraceM $ "preambleBoolRules: Expecting one of: " ++ show whoifwhen
debugPrint "preambleBoolRules"
condWord <- choice (try . pToken <$> whos)
condWord <- choice (try . pToken <$> whoifwhen)
myTraceM ("preambleBoolRules: found condWord: " ++ show condWord)
(ands,rs) <- withDepth leftX dBoolRules -- (foo AND (bar OR baz), [constitutive and regulative sub-rules])
-- let bs = if subForest ands) == 1 -- upgrade the single OR child of the AND group to the top level
Expand Down
16 changes: 15 additions & 1 deletion mengwong/mp/test/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ Below we use pilcrows to set off two stanzas which are identical but for permuta
| IF | the King wishes | // | scope quantification slightly different vs 4 |
| -> | sing | // | suggests that the King is consulted for each person |

** with multiple preambleBoolRules
:PROPERTIES:
:TABLE_EXPORT_FILE: if-king-wishes-queen.csv
:TABLE_EXPORT_FORMAT: orgtbl-to-csv
:END:

| EVERY | person |
| WHO | walks |
| AND | eats |
| MUST | |
| IF | the King wishes |
| WHEN | the Queen is not looking |
| -> | sing |

** in a different order 2
:PROPERTIES:
:TABLE_EXPORT_FILE: if-king-wishes-2.csv
Expand Down Expand Up @@ -295,7 +309,7 @@ Because this is really more of a meta-rule situation.
| | MUST | | |
| | -> | sing | |

Let's not support this case 4 in any form until we have a more principled approach to meta-rule relationships. Then we can put in IF/THEN/ELSE for a closed-world binary logic? and IF/THEN/ELSE/SHRUG for a Maybe Ternary lol
Let's not support this case 4 until we have a more principled approach to meta-rule relationships. Then we can put in IF/THEN/ELSE for a closed-world binary logic? and IF/THEN/ELSE/SHRUG for a Maybe Ternary lol

** chained regulatives
:PROPERTIES:
Expand Down
6 changes: 6 additions & 0 deletions mengwong/mp/test/if-king-wishes-4.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
IF,the King wishes,,
EVERY,person,,
WHO,walks,,
AND,eats,,
MUST,,,
->,sing,,
7 changes: 7 additions & 0 deletions mengwong/mp/test/if-king-wishes-queen.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
EVERY,person
WHO,walks
AND,eats
MUST,
IF,the King wishes
WHEN,the Queen is not looking
->,sing

0 comments on commit 54adf3f

Please sign in to comment.