tidying up rule data structures
This commit is contained in:
parent
42ce5a3284
commit
04dcb4e8f7
@ -11,12 +11,10 @@ import Data.Map (Map)
|
||||
import Data.Set (Set)
|
||||
import Data.Set qualified as Set
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import Datalog.DatalogParser(parseDatalog, Literal(..), Statement(..), Term (..), Head (HeadSingle))
|
||||
import qualified Data.Map as Map
|
||||
import Text.Megaparsec (ParseErrorBundle)
|
||||
import Data.Void
|
||||
import Control.Exception (Exception)
|
||||
import Control.Exception.Base
|
||||
import Data.List
|
||||
import Data.Maybe
|
||||
@ -36,7 +34,7 @@ data RuleElement = -- entry occurring in a head or body relation - constant or v
|
||||
deriving (Show, Eq)
|
||||
|
||||
data RelationRule = RelationRule {
|
||||
headVariables :: [RuleElement],
|
||||
headVariables :: [Text],
|
||||
body :: [(Relation, [RuleElement])]
|
||||
} deriving (Show, Eq)
|
||||
|
||||
@ -195,7 +193,9 @@ withFactsAndRules facts rules =
|
||||
toConstraintElement :: RuleElement -> ConstraintElement
|
||||
toConstraintElement (RuleElementConstant constant) = ConstraintElementConstant constant
|
||||
toConstraintElement (RuleElementVariable varName) = ConstraintElementIndex (varIndex varName)
|
||||
|
||||
extractVarName :: RuleElement -> Text
|
||||
extractVarName (RuleElementVariable varName) = varName
|
||||
extractVarName (RuleElementConstant constant) = throw $ UnexpectedConstantException constant
|
||||
-- toBodyConstraint :: (Relation, [RuleElement]) -> BodyConstraint
|
||||
-- toBodyConstraint (subRelation, ruleElements) =
|
||||
-- BodyConstraint {
|
||||
@ -203,7 +203,7 @@ withFactsAndRules facts rules =
|
||||
-- _elements = toConstraintElement <$> ruleElements
|
||||
-- }
|
||||
newRule = RelationRule {
|
||||
headVariables = variables',
|
||||
headVariables = extractVarName <$> variables',
|
||||
body = fromBodyConstraint <$> (_bodyConstraints context'')
|
||||
} where
|
||||
fromBodyConstraint :: BodyConstraint -> (Relation, [RuleElement])
|
||||
@ -237,7 +237,8 @@ data NaiveDatabaseException
|
||||
NonRuleException Text Statement |
|
||||
NonQueryException Text Statement |
|
||||
BadArityException Text Int |
|
||||
VariableLookupException Text [RuleElement]
|
||||
VariableLookupException Text [RuleElement] |
|
||||
UnexpectedConstantException Constant
|
||||
deriving (Show)
|
||||
|
||||
instance Exception NaiveDatabaseException
|
||||
@ -53,11 +53,7 @@ spec = do
|
||||
],
|
||||
_rules = [
|
||||
RelationRule {
|
||||
headVariables = [
|
||||
RuleElementVariable "X",
|
||||
RuleElementVariable "Y",
|
||||
RuleElementVariable "Z"
|
||||
],
|
||||
headVariables = [ "X", "Y", "Z" ],
|
||||
body = [
|
||||
(
|
||||
Relation {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user