-
Notifications
You must be signed in to change notification settings - Fork 0
/
mypost.hs
78 lines (54 loc) · 2.44 KB
/
mypost.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{-# LANGUAGE OverloadedStrings #-}
import Network.Wreq
import Control.Lens hiding (noneOf)
import qualified Data.ByteString.Lazy as B
import Control.Applicative ((<$>))
import Data.List.Split
import Text.Parsec
-- let mybetween = (between (char 'X') (char 'X') (many $ noneOf "X")) >>= \x -> (char ',') >> return x)
-- ( many $ noneOf ",") >>= \x -> (char ',') >> return x
-- p (count 3 (choice [mybetween, magic ])) "aa1aa,XaaaaX,11111,22222,33333"
--
myEndpointStatements :: String
myEndpointStatements = myEndpointRepo ++ "/statements"
myEndpointRepo :: String
myEndpointRepo = "http://localhost:8080/openrdf-sesame/repositories/palko123"
insertOptions :: Options
insertOptions = defaults & headers %~ h'
where
h' = (++) [("Content-Type", "application/x-turtle;charset=UTF-8")]
listOptions :: Options
listOptions = defaults & headers %~ h'
where
h' = (++) [("Accept", "application/rdf+xml, */*;q=0.5"), ("Content-Type", "application/sparql-query")]
ddatta :: B.ByteString
ddatta = "<http://example.org/person/Mark_Twain33> <http://example.org/relation/author> <http://example.org/books/Huckleberry_Finn> ."
listAllQuery :: B.ByteString
listAllQuery = "construct {?s ?p ?o} where {?s ?p ?o}"
testPost :: IO (Response B.ByteString)
testPost = postWith insertOptions myEndpointStatements ddatta
testList :: IO (Response B.ByteString)
testList = postWith listOptions myEndpointRepo listAllQuery
readData :: IO [String]
readData = lines <$> readFile "data.csv"
-- let mybetween = (between (char 'X') (char 'X') (many $ noneOf "X")) >>= \x -> (char ',') >> return x)
-- ( many $ noneOf ",") >>= \x -> (char ',') >> return x
-- p (count 3 (choice [mybetween, magic ])) "aa1aa,XaaaaX,11111,22222,33333"
--
removeComma :: String -> ParsecT String () Identity String
removeComma x = char ',' >> return x
parseNormalEntry :: ParsecT String () Identity String
parseNormalEntry = many (noneOf ",") >>= removeComma
parseQuotaEntry :: ParsecT String () Identity String
parseQuotaEntry = between (char '"') (char '"') (many $ noneOf "\"") >>= removeComma
parseLine :: Int -> String -> [String]
parseLine es s = let Right x = parse (count es (choice [parseQuotaEntry, parseNormalEntry])) "" s
in x
main :: IO ()
main = do
csv <- readData
let headers = splitOn "," . head $ csv
let x = map (parseLine (length headers - 1)) $ tail csv
print $ x !! 111
-- l <- flip (!!) 1 <$> readData
-- print $ parseLine 10 l