Skip to content

Commit

Permalink
branching graph queries
Browse files Browse the repository at this point in the history
  • Loading branch information
OscarSouth committed Mar 28, 2024
1 parent 1f40fda commit 70803b0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 38 deletions.
100 changes: 64 additions & 36 deletions app/Main.hs
Expand Up @@ -806,42 +806,6 @@ retrieveSeq4 = do
return $ cadence0 : cadence1 : cadence2 : cadence3 : []


getNextCadences :: Bolt.BoltActionT IO [Cadence]
getNextCadences = do
records <- Bolt.query $ Text.pack " \
\ match (n:Cadence) \
\ with apoc.coll.randomItem(COLLECT(n)) AS n_0 \
\ call { \
\ with n_0 \
\ call { \
\ with n_0 \
\ match (n_0)-[r]->(n_1) \
\ return r, n_1 \
\ order by (r.confidence*rand()) desc \
\ limit 3 \
\ union all \
\ with n_0 \
\ match (n_0)-[r]->(n_1) \
\ return r, n_1 \
\ order by r.confidence desc \
\ limit 1 \
\ } \
\ return n_1 \
\ order by rand() \
\ limit 3 \
\ } \
\ return \
\ n_1.movement, n_1.chord; \
\ "
m1 <- forM records $ \record -> Text.unpack <$> (record `Bolt.at` "n_1.movement")
c1 <- forM records $ \record -> Text.unpack <$> (record `Bolt.at` "n_1.chord")
-- let cadence = head (constructCadence <$> zip m1 c1) :: Cadence
-- return $ cadence : []

-- how to deal with multiple rows?



-- |generate a sequence of Cadences
prog4 :: (Show a, Num a, Integral a) => IO [[a]]
prog4 = do
Expand Down Expand Up @@ -876,3 +840,67 @@ progToPatIO = do
let ctrlPat = progStringToPat progString
return ctrlPat


retrieveTest :: Bolt.BoltActionT IO [(String, String)]
retrieveTest = do
records <- Bolt.query $ Text.pack " \
\ match (n:Cadence) \
\ with apoc.coll.randomItem(COLLECT(n)) AS n_0 \
\ call { \
\ with n_0 \
\ call { \
\ with n_0 \
\ match (n_0)-[r]->(n_1) \
\ return r, n_1 \
\ order by (r.confidence*rand()) desc \
\ limit 3 \
\ union all \
\ with n_0 \
\ match (n_0)-[r]->(n_1) \
\ return r, n_1 \
\ order by r.confidence desc \
\ limit 1 \
\ } \
\ return n_1 \
\ order by rand() \
\ limit 3 \
\ } \
\ return \
\ n_1.movement, n_1.chord; \
\ "
m <- forM records $ \record -> Text.unpack <$> (record `Bolt.at` "n_1.chord")
c <- forM records $ \record -> Text.unpack <$> (record `Bolt.at` "n_1.movement")
-- let cadences = constructCadence <$> zip m c
let cadences = zip m c
return cadences


-- m1 <- forM records $ \record -> Text.unpack <$> (record `Bolt.at` "n_1.movement")
-- c1 <- forM records $ \record -> Text.unpack <$> (record `Bolt.at` "n_1.chord")
-- let cadence1 = head (constructCadence <$> zip m1 c1) :: Cadence
-- return $ cadence1 : []


--progTest :: (Show a, Num a, Integral a) => IO [[a]]
--progTest = do
-- pipe <- Bolt.connect $ def { Bolt.version = 3 }
-- cadences <- Bolt.run pipe retrieveTest
-- let roots = take 1 $ progRoots' 0 $ cycle cadences
-- let chords = (\(p,c) -> fromCadence' p c) <$> zip roots (cycle cadences)
-- let labels = show . toEnhTriad <$> chords
-- let promptLines = (++"| ") . concat . (`replicate`" ") . ((15-) . length) <$> labels
-- let patLines = (++", ") . concat . (`replicate`" ") . ((15-) . length) <$> (show <$> chords)
-- let printPat = zip ["1 | ", "5 | ", "9 | ", "13 | "]
-- (init . init . init <$> (fmap concat <$> chunksOf 4 $ zipWith (++) (show <$> chords) patLines))
-- let prompts = zip ["1 | ", "5 | ", "9 | ", "13 | "]
-- (init . init . init <$> (fmap concat <$> chunksOf 4 $ zipWith (++) labels promptLines))
---- forM_ ["generated by 'The Harmonic Algorithm' -> https://github.com/OscarSouth/theHarmonicAlgorithm"] print
-- forM_ prompts $ print . ("| "++) . concat
-- forM_ printPat $ print . ("[ "++) . (\ s -> init s ++ "]") . concat
-- return chords

--progTest :: (Show a, Num a, Integral a) => IO [[a]]
progTest = do
pipe <- Bolt.connect $ def { Bolt.version = 3 }
r <- Bolt.run pipe retrieveTest
return r
2 changes: 1 addition & 1 deletion graphdb/dev.cql
Expand Up @@ -11,7 +11,7 @@ WITH n
MATCH (n)-[r]->(to)
RETURN to.chord, to.movement, r.confidence
ORDER BY r.confidence DESC
LIMIT 10;
LIMIT 20;


match (n:Cadence{show:"( pedal -> min )"})
Expand Down
1 change: 0 additions & 1 deletion graphdb/test.cql
Expand Up @@ -99,5 +99,4 @@ return n_1
limit 3
}
return
// n_0.chord, n_0.movement,
n_1.chord, n_1.movement;

0 comments on commit 70803b0

Please sign in to comment.