Skip to content

Commit

Permalink
v0.17.2 - PyCon2019
Browse files Browse the repository at this point in the history
  • Loading branch information
arendsee committed May 5, 2019
2 parents 69a4a4f + b5f23df commit 87463f0
Show file tree
Hide file tree
Showing 30 changed files with 245 additions and 140 deletions.
2 changes: 1 addition & 1 deletion USAGE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
morloc version 0.17.1
morloc version 0.17.2

Usage:
morloc make [--expression] [--endpoint=<sparql-endpoint>] [--config=<config>] [--vanilla] <script>
Expand Down
12 changes: 6 additions & 6 deletions examples/sample-complex.loc
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ rand_uniform :: n:Int, a:Num, b:Num -> xs:[c:Num] where (
, c >= a
, c <= b
);
rand_uniform R :: Numeric, Numeric, Numeric -> Numeric;
# no R type defined, the generic packers are fine

sum :: [Num] -> Num;
# no R type defined, the generics packers are fine
sum R :: Numeric -> Num;

ceiling :: [Num] -> [Int];
# no R type defined, the generics packers are fine
ceiling R :: Numeric -> Integer;

transpose :: Matrix a -> Matrix a;
transpose R :: Matrix -> Matrix;
transpose :: Matrix a m n -> Matrix a n m;
transpose R :: Matrix a m n -> Matrix a n m;

nrow :: Table -> Int;
nrow R :: DataFrame -> Numeric;
nrow R :: DataFrame -> Int;

roll :: Int, Int -> [Int];
roll n d = ceiling (rand_uniform n 0.0 d);
Expand Down
2 changes: 1 addition & 1 deletion executable/Subcommands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Subcommands
) where

import Morloc.Operators
import Morloc.Types
import Morloc.Global
import qualified Morloc as M
import qualified Morloc.Monad as MM
import qualified Morloc.Data.RDF as MR
Expand Down
2 changes: 1 addition & 1 deletion library/Morloc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import qualified System.Directory as SD
import qualified Morloc.Monad as MM
import qualified Morloc.Data.Text as MT
import Morloc.Operators
import Morloc.Types
import Morloc.Global
import Morloc.Config (Config)
import qualified Morloc.Parser as MP
import qualified Morloc.Generator as MG
Expand Down
4 changes: 2 additions & 2 deletions library/Morloc/Component/MData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{-|
Module : Morloc.Component.MData
Description : Build manifolds for code generation from a SPARQL endpoint.
Description : Build MData objects for code generation from a SPARQL endpoint.
Copyright : (c) Zebulun Arendsee, 2018
License : GPL-3
Maintainer : zbwrnz@gmail.com
Expand All @@ -16,7 +16,7 @@ module Morloc.Component.MData
) where

import Morloc.Sparql
import Morloc.Types
import Morloc.Global
import Morloc.Operators
import qualified Morloc.Data.Text as MT
import qualified Morloc.Data.RDF as MR
Expand Down
4 changes: 2 additions & 2 deletions library/Morloc/Component/MType.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{-|
Module : Morloc.Component.MType
Description : Build manifolds for code generation from a SPARQL endpoint.
Description : Build MType objects for code generation from a SPARQL endpoint.
Copyright : (c) Zebulun Arendsee, 2018
License : GPL-3
Maintainer : zbwrnz@gmail.com
Expand All @@ -16,7 +16,7 @@ module Morloc.Component.MType
) where

import Morloc.Sparql
import Morloc.Types
import Morloc.Global
import Morloc.Operators
import Morloc.Data.Doc hiding ((<$>),(<>))
import qualified Morloc.Component.Util as MCU
Expand Down
13 changes: 2 additions & 11 deletions library/Morloc/Component/Manifold.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Morloc.Component.Manifold
, hsparql
) where

import Morloc.Types
import Morloc.Global
import Morloc.Operators
import Morloc.Sparql
import qualified Morloc.System as MS
Expand All @@ -29,7 +29,6 @@ import qualified Morloc.Data.Text as MT

import qualified Data.Map.Strict as Map
import qualified Data.List.Extra as DLE
import qualified System.Directory as SD

-- | Collect most of the info needed to build all manifolds
fromSparqlDb
Expand All @@ -45,15 +44,7 @@ fromSparqlDb ep = do
|>> setLangs
>>= setCalls
>>= unroll
>>= printManifoldsForDebugging -- write manifolds to tmp directory

printManifoldsForDebugging :: [Manifold] -> MorlocMonad [Manifold]
printManifoldsForDebugging manifolds = do
tmpdir <- MM.asks configTmpDir
MM.liftIO $ SD.createDirectoryIfMissing True (MT.unpack tmpdir)
let path = (MT.unpack tmpdir) <> "/" <> "manifolds.txt"
MM.liftIO $ writeFile path (show manifolds)
return manifolds
>>= MM.logFile "manifolds.txt"

asTuple
:: Map.Map Key MType
Expand Down
90 changes: 38 additions & 52 deletions library/Morloc/Component/Serializer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Morloc.Component.Serializer
, SerialMap(..)
) where

import Morloc.Types
import Morloc.Global
import Morloc.Operators
import Morloc.Sparql
import qualified Morloc.Error as ME
Expand All @@ -30,54 +30,65 @@ import qualified Data.Map.Strict as Map
type SerialData =
( Key -- type_id -
, Name -- property - "packs" or "unpackes"
, Bool -- is_generic - is this a generic packer/unpacker
, Name -- name
, Path -- path
, Path -- module path
)

-- TODO: update this to limit results to one language
-- OR return a hash of hashes by language
fromSparqlDb
:: SparqlDatabaseLike db
=> Lang -> db -> MorlocMonad SerialMap
fromSparqlDb l db = do
typemap <- MCM.fromSparqlDb db
serialData <- sparqlSelect "serializer" (hsparql l) db >>= mapM tuplify
toSerialMap typemap serialData
toSerialMap typemap serialData >>= MM.logFile ("serialMap-" <> MT.unpack l <> ".txt")
where
tuplify :: [Maybe MT.Text] -> MorlocMonad SerialData
tuplify [ Just t -- typename
, Just p -- property
, Just g -- is_generic
, Just n -- name
, Just s -- path (e.g., "rbase.R")
, Just m -- module path (e.g., "$HOME/.morloc/lib/rbase/main.loc")
] = return (t,p,g == "true",n,s,m)
] = return (t,p,n,s,m)
tuplify e = MM.throwError . SparqlFail $ "Unexpected SPARQL result: " <> MT.pretty e


toSerialMap
:: Map.Map Key ConcreteType
:: Map.Map Key ConcreteType
-> [SerialData]
-> MorlocMonad SerialMap
toSerialMap h xs = do
packers <- sequence [lookupOrDie t h >>= getIn p | (t, "packs" , False, p, _, _) <- xs]
unpackers <- sequence [lookupOrDie t h >>= getOut p | (t, "unpacks", False, p, _, _) <- xs]
case ( Map.fromList packers
, Map.fromList unpackers
, [p | (_, "packs" , True, p, _, _) <- xs]
, [p | (_, "unpacks", True, p, _, _) <- xs]
, MU.unique [makePath m s | (_, _, _, _, s, m) <- xs]
) of
(phash, uhash, [p], [u], srcs) -> return $ SerialMap
{ serialLang = l
, serialPacker = phash
, serialUnpacker = uhash
, serialGenericPacker = p
, serialGenericUnpacker = u
, serialSources = srcs
}
_ -> MM.throwError . TypeError $ "Expected exactly one generic packer/unpacker: " <> MT.pretty xs
toSerialMap h xs
= SerialMap
<$> pure l -- language
<*> (fmap Map.fromList . sequence $
[lookupOrDie t h >>= getIn p | (t, "packs" , p, _, _) <- xs]) -- packers
<*> (fmap Map.fromList . sequence $
[lookupOrDie t h >>= getOut p | (t, "unpacks", p, _, _) <- xs]) -- unpackers
<*> pure (MU.unique [makePath m s | (_, _, _, s, m) <- xs]) -- sources


-- toSerialMap
-- :: Map.Map Key ConcreteType
-- -> [SerialData]
-- -> MorlocMonad SerialMap
-- toSerialMap h xs = do
-- packers <- sequence [lookupOrDie t h >>= getIn p | (t, "packs" , False, p, _, _) <- xs]
-- unpackers <- sequence [lookupOrDie t h >>= getOut p | (t, "unpacks", False, p, _, _) <- xs]
-- case ( Map.fromList packers
-- , Map.fromList unpackers
-- , [p | (_, "packs" , True, p, _, _) <- xs]
-- , [p | (_, "unpacks", True, p, _, _) <- xs]
-- , MU.unique [makePath m s | (_, _, _, _, s, m) <- xs]
-- ) of
-- (phash, uhash, [p], [u], srcs) -> return $ SerialMap
-- { serialLang = l
-- , serialPacker = phash
-- , serialUnpacker = uhash
-- , serialGenericPacker = p
-- , serialGenericUnpacker = u
-- , serialSources = srcs
-- }
-- _ -> MM.throwError . TypeError $ "Expected exactly one generic packer/unpacker: " <> MT.pretty xs

makePath
:: MT.Text -- module path
Expand Down Expand Up @@ -107,7 +118,6 @@ hsparql lang' = do
basetype_ <- var
id_ <- var
importId_ <- var
isGeneric_ <- var
name_ <- var
output_ <- var
packerInput_ <- var
Expand Down Expand Up @@ -154,8 +164,6 @@ hsparql lang' = do
filterExpr (basetype_ .!=. OType)
)

bind (basetype_ .==. OAtomicGenericType) isGeneric_

optional_
( do
triple_ sourceId_ PType OSource
Expand All @@ -172,26 +180,4 @@ hsparql lang' = do
orderNextAsc typeId_
orderNextAsc property_

selectVars [rhs_, property_, isGeneric_, name_, path_, modulePath_]

---- expected output for `sample.loc`
-- -----------------------------------------------------------------------------------------------------------------------
-- | rhs | property | isGeneric | name | path | modulePath |
-- =======================================================================================================================
-- | mlc:rbase__main.loc_55 | "packs" | true | "packGeneric" | "rbase.R" | "$HOME/.morloc/lib/rbase/main.loc" |
-- | mlc:rbase__main.loc_20 | "packs" | false | "packCharacter" | "rbase.R" | "$HOME/.morloc/lib/rbase/main.loc" |
-- | mlc:rbase__main.loc_25 | "packs" | false | "packDataFrame" | "rbase.R" | "$HOME/.morloc/lib/rbase/main.loc" |
-- | mlc:rbase__main.loc_30 | "packs" | false | "packDataTable" | "rbase.R" | "$HOME/.morloc/lib/rbase/main.loc" |
-- | mlc:rbase__main.loc_35 | "packs" | false | "packList" | "rbase.R" | "$HOME/.morloc/lib/rbase/main.loc" |
-- | mlc:rbase__main.loc_40 | "packs" | false | "packLogical" | "rbase.R" | "$HOME/.morloc/lib/rbase/main.loc" |
-- | mlc:rbase__main.loc_45 | "packs" | false | "packMatrix" | "rbase.R" | "$HOME/.morloc/lib/rbase/main.loc" |
-- | mlc:rbase__main.loc_50 | "packs" | false | "packNumeric" | "rbase.R" | "$HOME/.morloc/lib/rbase/main.loc" |
-- | mlc:rbase__main.loc_60 | "unpacks" | true | "unpackGeneric" | "rbase.R" | "$HOME/.morloc/lib/rbase/main.loc" |
-- | mlc:rbase__main.loc_65 | "unpacks" | false | "unpackCharacter" | "rbase.R" | "$HOME/.morloc/lib/rbase/main.loc" |
-- | mlc:rbase__main.loc_70 | "unpacks" | false | "unpackDataFrame" | "rbase.R" | "$HOME/.morloc/lib/rbase/main.loc" |
-- | mlc:rbase__main.loc_75 | "unpacks" | false | "unpackDataTable" | "rbase.R" | "$HOME/.morloc/lib/rbase/main.loc" |
-- | mlc:rbase__main.loc_80 | "unpacks" | false | "unpackList" | "rbase.R" | "$HOME/.morloc/lib/rbase/main.loc" |
-- | mlc:rbase__main.loc_85 | "unpacks" | false | "unpackLogical" | "rbase.R" | "$HOME/.morloc/lib/rbase/main.loc" |
-- | mlc:rbase__main.loc_90 | "unpacks" | false | "unpackMatrix" | "rbase.R" | "$HOME/.morloc/lib/rbase/main.loc" |
-- | mlc:rbase__main.loc_95 | "unpacks" | false | "unpackNumeric" | "rbase.R" | "$HOME/.morloc/lib/rbase/main.loc" |
-- -----------------------------------------------------------------------------------------------------------------------
selectVars [rhs_, property_, name_, path_, modulePath_]
2 changes: 1 addition & 1 deletion library/Morloc/Component/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Morloc.Component.Util (
, isElement_
) where

import Morloc.Types
import Morloc.Global
import Morloc.Operators
import Morloc.Sparql
import qualified Morloc.Data.Text as MT
Expand Down
2 changes: 1 addition & 1 deletion library/Morloc/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Morloc.Config (
, makeLibSourceString
) where

import Morloc.Types
import Morloc.Global
import Morloc.Operators
import qualified Morloc.Monad as MM
import qualified Morloc.Data.Text as MT
Expand Down
2 changes: 1 addition & 1 deletion library/Morloc/Data/RDF.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module Morloc.Data.RDF (
, rdfAppend
) where

import Morloc.Types
import Morloc.Global
import Morloc.Operators
import qualified Morloc.Error as ME
import qualified Morloc.Data.Text as MT
Expand Down
2 changes: 0 additions & 2 deletions library/Morloc/Data/Yaml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ module Morloc.Data.Yaml (
import qualified Data.ByteString.Char8 as BS
import qualified Data.Yaml as Y
import qualified Data.HashMap.Strict as H


2 changes: 1 addition & 1 deletion library/Morloc/Environment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Morloc.Environment
) where

import Morloc.Operators
import Morloc.Types
import Morloc.Global
import qualified Morloc.Monad as MM
import qualified Morloc.Data.Text as MT
import qualified Morloc.Config as MC
Expand Down
2 changes: 1 addition & 1 deletion library/Morloc/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ program. New entries can be added to describe new types of error.

module Morloc.Error () where

import Morloc.Types
import Morloc.Global
import Morloc.Operators
import qualified Morloc.Data.Text as MT

Expand Down
2 changes: 1 addition & 1 deletion library/Morloc/Generator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Morloc.Generator
, generate
) where

import Morloc.Types
import Morloc.Global
import Morloc.Config (Config)
import qualified Morloc.Monad as MM
import qualified Morloc.Nexus.Nexus as MN
Expand Down
Loading

0 comments on commit 87463f0

Please sign in to comment.