filling out the DB
This commit is contained in:
parent
73aec57151
commit
52fad6e4a1
@ -23,14 +23,25 @@ data Value =
|
|||||||
ValueSymbol String
|
ValueSymbol String
|
||||||
|
|
||||||
data NaiveDatabase = NaiveDatabase {
|
data NaiveDatabase = NaiveDatabase {
|
||||||
relations :: Map Text Int,
|
relations :: Map RelationId Relation,
|
||||||
values :: Set Value
|
constants :: Set ConstantId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data Relation = Relation {
|
||||||
|
arity :: Int,
|
||||||
|
tuples :: Set [ConstantId]
|
||||||
|
}
|
||||||
|
|
||||||
|
newtype RelationId = RelationId Text
|
||||||
|
deriving (Eq, Ord, Show)
|
||||||
|
|
||||||
|
newtype ConstantId = ConstantId Text
|
||||||
|
deriving (Eq, Ord, Show)
|
||||||
|
|
||||||
emptyDB :: NaiveDatabase
|
emptyDB :: NaiveDatabase
|
||||||
emptyDB = NaiveDatabase {
|
emptyDB = NaiveDatabase {
|
||||||
relations = Map.empty,
|
relations = Map.empty,
|
||||||
values = Set.empty
|
constants = Set.empty
|
||||||
}
|
}
|
||||||
|
|
||||||
withFacts :: [Text] -> NaiveDatabase
|
withFacts :: [Text] -> NaiveDatabase
|
||||||
|
|||||||
@ -23,6 +23,19 @@ import qualified Datalog.NaiveDatabase as NaiveDatabase
|
|||||||
-- checkEval text expectedVal =
|
-- checkEval text expectedVal =
|
||||||
-- fmap eval (parse parseExpr "" text) `shouldBe` Right expectedVal
|
-- fmap eval (parse parseExpr "" text) `shouldBe` Right expectedVal
|
||||||
|
|
||||||
|
-- getConfig :: IO Config
|
||||||
|
-- getConfig = do
|
||||||
|
-- env <- lookupEnv "APP_ENV"
|
||||||
|
-- let fallbackHosts =
|
||||||
|
-- [ "localhost:8080"
|
||||||
|
-- , "127.0.0.1:9000"
|
||||||
|
-- , "backup.example.com"
|
||||||
|
-- ]
|
||||||
|
-- pure Config
|
||||||
|
-- { port = 3000
|
||||||
|
-- , hosts = fromMaybe fallbackHosts env
|
||||||
|
-- , logLevel = Info
|
||||||
|
-- }
|
||||||
|
|
||||||
spec :: Spec
|
spec :: Spec
|
||||||
spec = do
|
spec = do
|
||||||
@ -30,7 +43,26 @@ spec = do
|
|||||||
it "..." $ do
|
it "..." $ do
|
||||||
1 `shouldBe` (1 :: Int)
|
1 `shouldBe` (1 :: Int)
|
||||||
it "can accept facts and do basic queries" $ do
|
it "can accept facts and do basic queries" $ do
|
||||||
let twig = [ "xx", "yy "]
|
-- let fallbackHosts =
|
||||||
let pig = [ "parent(\"alice\", \"bob\").", "parent(\"bob\", \"carol\")." ]
|
-- [ "localhost:8080"
|
||||||
let db = NaiveDatabase.withFacts [ "parent(\"alice\", \"bob\").", "parent(\"bob\", \"carol\")." ]
|
-- , "127.0.0.1:9000"
|
||||||
|
-- , "backup.example.com"
|
||||||
|
-- ]
|
||||||
|
-- let names =
|
||||||
|
-- [ "Alice"
|
||||||
|
-- , "Bob"
|
||||||
|
-- , "Charlie"
|
||||||
|
-- , "Daphne"
|
||||||
|
-- , "Eve"
|
||||||
|
-- ]
|
||||||
|
-- let twig =
|
||||||
|
-- [ "xx"
|
||||||
|
-- , "yy " ]
|
||||||
|
-- let pig =
|
||||||
|
-- [ "parent(\"alice\", \"bob\")."
|
||||||
|
-- , "parent(\"bob\", \"carol\")."
|
||||||
|
-- ]
|
||||||
|
let db = NaiveDatabase.withFacts
|
||||||
|
[ "parent(\"alice\", \"bob\")."
|
||||||
|
, "parent(\"bob\", \"carol\")." ]
|
||||||
query db"?- parent(alice,X)." `shouldBe` "#NYI" -- ideally, 'bob'
|
query db"?- parent(alice,X)." `shouldBe` "#NYI" -- ideally, 'bob'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user