Commits

Doug Burke  committed b81548a

Version 0.23: updated to use swish v0.8 and because I lost my hasparql-client changes

  • Participants
  • Parent commits 799319f
  • Tags 0.0.0.23

Comments (0)

Files changed (11)

File CalcHistogram.hs

 
 import Control.Monad (liftM)
 
-import qualified Data.ByteString.Lazy as LB
+-- import qualified Data.ByteString.Lazy as LB
+import qualified Data.ByteString.Lazy.Char8 as LB
 
 import Database.HaSparqlClient (Query, BindingValue(..))
 

File CountTweets.hs

 
 module Main where
 
-import qualified Data.ByteString.Lazy as LB
+-- import qualified Data.ByteString.Lazy as LB
+import qualified Data.ByteString.Lazy.Char8 as LB
 
 import Database.HaSparqlClient (Query, BindingValue(..))
 

File FindRetweets.hs

 
 module Main where
 
+import qualified Data.Set as S
 import qualified Data.Text as T
 import qualified Data.Text.IO as T
 
 import Swish.RDF
-import Swish.RDF.TurtleFormatter (formatGraphAsText)
+import Swish.RDF.Formatter.Turtle (formatGraphAsText)
 import Swish.RDF.Vocabulary.SIOC (siocreply_of)
 
 import Database.HaSparqlClient (Query, NamedGraph, BindingValue(..))
 -- do not move to SPARQL yet as don't want to bother cascading up the
 -- network dependency.
 instance FromBinding URI where
-  fromBinding (URI u) = parseURI u
+  fromBinding (URI u) = parseURI (T.unpack u)
   fromBinding _ = Nothing
 
 {-
   res <- makeQuery getVals epoint (queryForRetweets stores)
   hPutStrLn stderr $ "Found " ++ show (length res) ++ " tweets"
   mms <- mapM (findMatchSimple epoint stores) res
-  return $ toRDFGraph $ concat $ catMaybes mms
+  return $ toRDFGraph $ S.fromList $ concat $ catMaybes mms
 
 findRetweetsDistance :: String -> IO RDFGraph
 findRetweetsDistance epoint = do
   res <- makeQuery getVals epoint (queryForRetweets stores)
   hPutStrLn stderr $ "Found " ++ show (length res) ++ " tweets"
   mms <- mapM (findMatchDistance epoint stores) res
-  return $ toRDFGraph $ concat $ catMaybes mms
+  return $ toRDFGraph $ S.fromList $ concat $ catMaybes mms
 
 findRetweetsUnknown :: String -> IO RDFGraph
 findRetweetsUnknown epoint = do
   res <- makeQuery getVals epoint (queryForRetweets stores)
   hPutStrLn stderr $ "Found " ++ show (length res) ++ " tweets"
   let ms = map (\(u,_,_) -> toRDFTriple u isRetweet True) res
-  return $ toRDFGraph ms
+  return $ toRDFGraph $ S.fromList ms
 
 findRetweetsComplex :: String -> IO RDFGraph
 findRetweetsComplex epoint = do
   res <- makeQuery getVals epoint (queryForRetweetsComplex stores)
   hPutStrLn stderr $ "Found " ++ show (length res) ++ " tweets"
   mms <- mapM (findMatchComplex epoint stores) res
-  return $ toRDFGraph $ concat $ catMaybes mms
+  return $ toRDFGraph $ S.fromList $ concat $ catMaybes mms
 
 usage :: IO ()
 usage = do

File GetUserConnections.hs

 module Main where
 
 import qualified Data.Text as T
-import qualified Data.ByteString.Lazy as LB
+import qualified Data.ByteString.Lazy.Char8 as LB
 
 import qualified Data.Set as S
 import qualified Data.HashMap.Strict as HM
 module Main where
 
 import qualified Data.Text as T
-import qualified Data.Text.Lazy.IO as TL
+import qualified Data.Text.IO as T
+-- import qualified Data.Text.Lazy.IO as TL
 
 import Control.Monad (when)
 import Database.HaSparqlClient
            ]
            
 showBinding :: BindingValue -> String
-showBinding (URI s) = '<' : s ++ ">"
+showBinding (URI s) = '<' : T.unpack s ++ ">"
 showBinding (Literal s) = T.unpack s
-showBinding (LangLiteral s l)  = T.unpack s ++ "@@" ++ l
+showBinding (LangLiteral s l)  = T.unpack s ++ "@@" ++ T.unpack l
 showBinding (TypedLiteral s "http://www.w3.org/2001/XMLSchema#boolean") = show (T.toLower s == "true")
 showBinding (TypedLiteral s "http://www.w3.org/2001/XMLSchema#integer") = T.unpack s
 showBinding (TypedLiteral s "http://www.w3.org/2001/XMLSchema#double") = T.unpack s
 showBinding (TypedLiteral s "http://www.w3.org/2001/XMLSchema#dateTime") = T.unpack s
-showBinding (TypedLiteral s t) = T.unpack s ++ "^^" ++ t
-showBinding (BNode s) = "bnode:" ++ s
+showBinding (TypedLiteral s t) = T.unpack s ++ "^^" ++ T.unpack t
+showBinding (BNode s) = "bnode:" ++ T.unpack s
 showBinding Unbound = "<UNBOUND>"
 
 showResult :: [BindingValue] -> String
   [("turtle", mtTurtle),
    ("ntriples", mtNTriples),
    ("rdfxml", mtRDFXML),
-   ("trig", mtTrig),
-   ("trix", mtXTrix)]
+   ("trig", mtTriG),
+   ("trix", mtTriX)]
 
 usage :: IO ()
 usage = do
 doRawQuery :: Service -> Method -> MIMEType -> IO ()
 doRawQuery src m fmt = do
   out $ "*** Running raw query: " ++ show m
-  sel <- runQuery src m [fmt]
+  -- sel <- runQuery src m [fmt] -- TODO: work out what I was doing with m
+  sel <- runQuery src m
   case sel of
     Left emsg -> out $ "ERROR: " ++ emsg
     Right rs -> do
       out "*** Results"
-      TL.putStrLn rs
+      -- TL.putStrLn rs
+      T.putStrLn rs
       out "***"

File IdentifyUsers.hs

 import qualified Data.Text as T
 import qualified Data.Text.IO as T
 import qualified Data.ByteString.Lazy as BL
+import qualified Data.Set as S
 
 import Database.HaSparqlClient (Query, NamedGraph, BindingValue(..))
 
 import Swish.RDF.Vocabulary.FOAF (foafname)
 import Swish.RDF.Vocabulary.SIOC (siocUserAccount, siocid, siocname)
 
-import Swish.RDF.TurtleFormatter (formatGraphAsText)
+import Swish.RDF.Formatter.Turtle (formatGraphAsText)
 
-import Data.List ((\\), isPrefixOf, intercalate)
+import Data.List ((\\), intercalate)
 import Data.Maybe (fromJust)
 
 import System.Environment (getArgs, getProgName)
 queryUsr :: String -> [NamedGraph] -> IO [UserInfo]
 queryUsr endpoint = makeQuery getUI endpoint . queryUsers
 
-twURI :: String
+twURI :: T.Text
 twURI = "http://twitter.com/"
 
+-- extract the "fragment" of the twitter URI
+getTWFrag :: T.Text -> Maybe String
+getTWFrag u | twURI `T.isPrefixOf` u = Just $ T.unpack $ T.drop (T.length twURI) u
+            | otherwise              = Nothing
+
 getURIFrag :: [BindingValue] -> Maybe String
-getURIFrag [URI u] | twURI `isPrefixOf` u = Just $ drop (length twURI) u
-                   | otherwise = Nothing
+getURIFrag [URI u] = getTWFrag u
 getURIFrag _       = Nothing
 
 {-
 
 getUI :: [BindingValue] -> Maybe UserInfo
 getUI (URI u : idbv : hbv : nbv : []) = do
-  hdl <- if twURI `isPrefixOf` u then Just (drop (length twURI) u) else Nothing
+  hdl <- getTWFrag u
   let hasId = isBound idbv
       hasHdl = isBound hbv
       hasName = isBound nbv
       us2 <- queryUsr endpoint stores
       t2 <- addUserInfo us2
       
-      T.putStrLn $ formatGraphAsText $ toRDFGraph $ t1 ++ t2
+      T.putStrLn $ formatGraphAsText $ toRDFGraph $ S.fromList $ t1 ++ t2
       
     _ -> usage
   
 import qualified Data.Text.Lazy.IO as LT
 
 import Swish.RDF  
-import Swish.RDF.RDFQuery
-import Swish.RDF.N3Parser (parseN3fromText)
-import Swish.RDF.TurtleParser (parseTurtlefromText)
-import Swish.RDF.Vocabulary (isLang)
+import Swish.RDF.Query
+import Swish.RDF.Parser.N3 (parseN3fromText)
+import Swish.RDF.Parser.Turtle (parseTurtlefromText)
 import Swish.RDF.Vocabulary.RDF (rdfType)
 import Swish.RDF.Vocabulary.SIOC (siocUserAccount)
 
-import Swish.Utils.Namespace (ScopedName, makeScopedName)
+import Swish.Namespace (ScopedName, makeScopedName)
+import Swish.QName (LName)
 
 import Network.URI (URI, parseURI)
 
 import Utils (getJust)
 
 instance FromRDFLabel T.Text where
-  fromRDFLabel (Lit x Nothing) = Just x
-  fromRDFLabel (Lit x (Just y)) | isLang y  = Just x
-                                | otherwise = Nothing
-  fromRDFLabel _ = Nothing
+  fromRDFLabel (Lit x)        = Just x
+  fromRDFLabel (LangLit x _)  = Just x
+  fromRDFLabel _              = Nothing
 
 instance ToRDFLabel T.Text where
-  toRDFLabel = flip Lit Nothing
+  toRDFLabel = Lit
   
 pURI :: String -> URI
 pURI u = getJust ("parseURI sent '" ++ u ++ "'") $ parseURI u
 
-toRL :: Maybe T.Text -> URI -> T.Text -> RDFLabel
+toRL :: Maybe T.Text -> URI -> LName -> RDFLabel
 toRL a b = Res . makeScopedName a b
 
 -- will not resolve
-{-# LANGUAGE OverloadedStrings, TypeSynonymInstances #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE OverloadedStrings #-}
 
 module SPARQL
        (
   $ "SELECT ?gr " ++ fromStores [graphMetadata] ++ " { ?gr a <http://purl.org/net/djburke/demo/twitter#TweetStore> . }"
 
 getNG :: [BindingValue] -> Maybe NamedGraph
-getNG [URI u] = Just u
+getNG [URI u] = Just (T.unpack u)
 getNG _       = Nothing
 
 {-
 
 import qualified Data.Text as T
 import qualified Data.Text.IO as T
-import qualified Data.ByteString.Lazy as LB
+import qualified Data.ByteString.Lazy.Char8 as LB
 
 import qualified Data.HashMap.Strict as HM
 

File TweetsToRDF.hs

 import Swish.RDF.Vocabulary.FOAF (foafbased_near, foafname)
 import Swish.RDF.Vocabulary.Geo (geolat, geolong)
 import Swish.RDF.Vocabulary.DublinCore (dctcreated, dctpublisher, dcttitle, dctreferences)
-import Swish.RDF.TurtleFormatter (formatGraphAsText)
+import Swish.RDF.Formatter.Turtle (formatGraphAsText)
 
 import Network.URI (URI, parseURI)
 
       uR  = fromMaybe (error ("UNEXPECTED: unable to find user for " ++ show tw ++ " in " ++ show ulabels)) $ HM.lookup twUserId ulabels 
       
       -- txt = Lit ((uDecode . replaceEntities) twMessage) (fmap langName twISO)
-      txt = Lit ((uDecode . replaceEntities) twMessage) Nothing
+      txt = Lit $ (uDecode . replaceEntities) twMessage
       
       logoArc = triple uR siocavatar <$> fmap pURI twProfile
       

File grabtweets.cabal

 Name:           grabtweets
-Version:        0.0.0.22
+Version:        0.0.0.23
 Stability:      experimental
 License:        LGPL
 License-file:   LICENSE
   Other-Modules: Paths_grabtweets
                  Utils
 
+  -- NOTES:
+  --     aeson now at 0.6
+  --     http-conduit now at 1.6
+  --     haskeline now at 0.7
   ghc-options: -Wall
   Build-Depends:
     aeson == 0.5.*,
-    -- attoparsec >= 0.8 && < 0.11,
     base >= 3 && < 5,
     bytestring == 0.9.*,
-    -- containers == 0.3.*,
-    unordered-containers >= 0.1.3,
+    unordered-containers >= 0.1.3 && < 0.3,
     directory >= 1.0 && < 1.2,
-    http-conduit == 1.2.*,
+    http-conduit == 1.5.*,
     text == 0.11.*,
-    time == 1.2.*,
+    time >= 1.2 && < 1.5,
     vector == 0.9.*
 
 Executable       tweetstordf
   Main-Is:       TweetsToRDF.hs
   Other-Modules: RDFUtils
 
-  ghc-options: -Wall
+  ghc-options: -Wall -fno-warn-orphans
   Build-Depends:
-    -- aeson == 0.3.*,
     aeson == 0.5.*,
     base >= 3 && < 5,
     bytestring == 0.9.*,
-    containers >= 0.3 && < 0.5,
-    unordered-containers >= 0.1.3,
+    containers >= 0.3 && < 0.6,
+    unordered-containers >= 0.1.3 && < 0.3,
     directory >= 1.0 && < 1.2,
     hashable == 1.1.*,
-    mtl == 2.0.*,
+    mtl >= 2.0 && < 2.2,
     network >= 2.2 && < 2.4,
     old-locale == 1.0.*,
-    swish >= 0.6.3.0 && < 0.7,
+    swish == 0.8.*,
     text == 0.11.*,
-    time == 1.2.*,
+    time >= 1.2 && < 1.5,
     vector == 0.9.*
 
 Executable       getuserconnections
     hasparql-client == 0.3.*,
     old-locale == 1.0.*,
     text == 0.11.*,
-    time == 1.2.*,
-    unordered-containers == 0.1.*
+    time >= 1.2 && < 1.5,
+    unordered-containers >= 0.1 && < 0.3
 
 Executable       identifyusers
   Main-Is:       IdentifyUsers.hs
                  SPARQL
                  Utils
 
-  ghc-options: -Wall
+  ghc-options: -Wall -fno-warn-orphans
   Build-Depends:
     aeson == 0.5.*,
     base >= 3 && < 5,
     bytestring == 0.9.*,
-    containers >= 0.3 && < 0.5,
+    containers >= 0.3 && < 0.6,
     hasparql-client == 0.3.*,
-    http-conduit == 1.2.*,
+    http-conduit == 1.5.*,
     network >= 2.2 && < 2.4,
     old-locale == 1.0.*,
-    swish >= 0.6.3.0 && < 0.7,
+    swish == 0.8.*,
     text == 0.11.*,
-    time == 1.2.*,
+    time >= 1.2 && < 1.5,
     vector == 0.9.*
 
 Executable       counttweets
     hasparql-client == 0.3.*,
     old-locale == 1.0.*,
     text == 0.11.*,
-    time == 1.2.*
+    time >= 1.2 && < 1.5
 
 Executable       gettweets
   Main-Is:       GetTweets.hs
     hasparql-client == 0.3.*,
     old-locale == 1.0.*,
     text == 0.11.*,
-    time == 1.2.*
+    time >= 1.2 && < 1.5
 
 Executable     calchistogram
   Main-Is:     CalcHistogram.hs
                  TimeUtils
                  Utils
 
-  ghc-options: -Wall
+  ghc-options: -Wall -fno-warn-orphans
   Build-Depends:
     aeson == 0.5.*,
     base >= 3 && < 5,
     hasparql-client == 0.3.*,
     old-locale == 1.0.*,
     statistics == 0.10.*,
-    time == 1.2.*,
+    time >= 1.2 && < 1.5,
     vector == 0.9.*,
     text == 0.11.*
 
     bytestring == 0.9.*,
     text == 0.11.*,
     -- tokenize == 0.1.*,
-    unordered-containers == 0.1.*
+    unordered-containers >= 0.1 && < 0.3
 
 Executable     hquery
   Main-Is:     HQuery.hs
   Other-Modules: SPARQL
                  Utils
 
-  ghc-options: -Wall
+  ghc-options: -Wall -fno-warn-orphans
   Build-Depends:
     base >= 3 && < 5,
+    containers,
     edit-distance == 0.2.*,
     hasparql-client == 0.3.*,
-    -- http-conduit == 1.2.*,
     network >= 2.2 && < 2.4,
     old-locale == 1.0.*,
-    swish >= 0.6.3.0 && < 0.7,
+    swish == 0.8.*,
     text == 0.11.*,
-    time == 1.2.*
+    time >= 1.2 && < 1.5