Created
April 30, 2011 01:08
-
-
Save ijt/949308 to your computer and use it in GitHub Desktop.
Example of making a Freebase query from Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Network.HTTP (simpleHTTP, getRequest, getResponseBody, urlEncode) | |
main = do | |
resultJson <- queryFreebase "{\"query\":[{\"id\":null,\"name\":null,\"type\":\"/astronomy/planet\"}]}" | |
putStrLn resultJson | |
-- Runs a query against Freebase and returns the result in JSON format. | |
queryFreebase :: String -> IO String | |
queryFreebase jsonQuery = do | |
let query = urlEncode $ jsonQuery | |
url = "http://api.freebase.com/api/service/mqlread?query=" ++ query | |
get url | |
-- Fetches a document and returns it as a String. | |
get :: String -> IO String | |
get url = do | |
let request = getRequest url | |
response <- simpleHTTP request | |
getResponseBody response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment