Commit 8ae401ed authored by Alexandre Delanoë's avatar Alexandre Delanoë

[READING]

parent 28461a06
...@@ -84,8 +84,6 @@ nodeTable = Table "nodes" (pNode Node { node_id = optional "id" ...@@ -84,8 +84,6 @@ nodeTable = Table "nodes" (pNode Node { node_id = optional "id"
) )
selectNodes :: Column PGInt4 -> Query (Column PGText) selectNodes :: Column PGInt4 -> Query (Column PGText)
selectNodes node_id = proc () -> do selectNodes node_id = proc () -> do
(Node n_id _tn _u _p n _d _h) <- queryNodeTable -< () (Node n_id _tn _u _p n _d _h) <- queryNodeTable -< ()
......
...@@ -27,27 +27,13 @@ import Path.IO (resolveFile') ...@@ -27,27 +27,13 @@ import Path.IO (resolveFile')
-- import qualified Data.ByteString.Lazy as B -- import qualified Data.ByteString.Lazy as B
import Control.Applicative ( (<$>) ) import Control.Applicative ( (<$>) )
zipFiles :: FilePath -> IO [ByteString]
zipFiles fp = do
path <- resolveFile' fp
entries <- withArchive path (DM.keys <$> getEntries)
bs <- mapConcurrently (\s -> withArchive path (getEntry s)) entries
pure bs
parseFile :: ParserType -> ByteString -> IO Int
parseFile p x = case runParser p x of
Left _ -> pure 0
Right r -> pure $ length r
testWos :: FilePath -> IO [Int]
testWos fp = join $ mapConcurrently (parseFile WOS) <$> zipFiles fp
-- type Parser a = a -> Text -> [Document] -- type Parser a = a -> Text -> [Document]
data ParserType = WOS | CSV data ParserType = WOS | CSV
wosParser :: Parser [Maybe [ByteString]] type WosDoc = ByteString
wosParser :: Parser [Maybe [WosDoc]]
wosParser = do wosParser = do
-- TODO Warning if version /= 1.0 -- TODO Warning if version /= 1.0
-- FIXME anyChar (string ..) /= exact string "\nVR 1.0" ? -- FIXME anyChar (string ..) /= exact string "\nVR 1.0" ?
...@@ -55,13 +41,15 @@ wosParser = do ...@@ -55,13 +41,15 @@ wosParser = do
ns <- many1 wosNotice <* (string $ pack "\nEF") ns <- many1 wosNotice <* (string $ pack "\nEF")
return ns return ns
wosNotice :: Parser (Maybe [WosDoc])
wosNotice = startNotice *> wosFields <* endNotice
endNotice :: Parser [Char]
endNotice = manyTill anyChar (string $ pack "\nER\n")
startNotice :: Parser ByteString startNotice :: Parser ByteString
startNotice = "\nPT " *> takeTill isEndOfLine startNotice = "\nPT " *> takeTill isEndOfLine
wosNotice :: Parser (Maybe [ByteString])
wosNotice = do
n <- startNotice *> wosFields <* manyTill anyChar (string $ pack "\nER\n")
return n
field' :: Parser (ByteString, [ByteString]) field' :: Parser (ByteString, [ByteString])
field' = do field' = do
...@@ -101,7 +89,7 @@ wosLines = many line ...@@ -101,7 +89,7 @@ wosLines = many line
line :: Parser ByteString line :: Parser ByteString
line = "\n " *> takeTill isEndOfLine line = "\n " *> takeTill isEndOfLine
runParser :: ParserType -> ByteString -> Either String [Maybe [ByteString]] runParser :: ParserType -> ByteString -> Either String [Maybe [WosDoc]]
runParser p x = parseOnly parser x runParser p x = parseOnly parser x
where where
parser = case p of parser = case p of
...@@ -111,3 +99,22 @@ runParser p x = parseOnly parser x ...@@ -111,3 +99,22 @@ runParser p x = parseOnly parser x
-- isTokenChar :: Word8 -> Bool -- isTokenChar :: Word8 -> Bool
-- isTokenChar = inClass "!#$%&'()*+./0-9:<=>?@a-zA-Z[]^_`{|}~-\n" -- isTokenChar = inClass "!#$%&'()*+./0-9:<=>?@a-zA-Z[]^_`{|}~-\n"
zipFiles :: FilePath -> IO [ByteString]
zipFiles fp = do
path <- resolveFile' fp
entries <- withArchive path (DM.keys <$> getEntries)
bs <- mapConcurrently (\s -> withArchive path (getEntry s)) entries
pure bs
parseFile :: ParserType -> ByteString -> IO Int
parseFile p x = case runParser p x of
Left _ -> pure 0
Right r -> pure $ length r
testWos :: FilePath -> IO [Int]
testWos fp = join $ mapConcurrently (parseFile WOS) <$> zipFiles fp
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment