module Main where import Database.HaSparqlClient {- See some SPARQL endpoints: http://www.w3.org/wiki/SparqlEndpoints All examples work with HGET and HPOST. -} {- Expected: Right True or Right False Is the Amazon river longer than the Nile River? Example found at: http://www.cambridgesemantics.com/2008/09/sparql-by-example/#%2837%29 -} ask = do let s = Sparql "http://dbpedia.org/sparql/" query Nothing [] [] res <- runAskQuery s HGET printf res where query = "PREFIX prop: " ++ "ASK { prop:length ?amazon ." ++ " prop:length ?nile ." ++ "FILTER(?amazon > ?nile) .} " select = do let s = Sparql "http://api.talis.com/stores/periodicals/services/sparql" "select ?x where {?x a ?z} limit 10" Nothing [][] res <- runSelectQuery s HGET printf res -- Find places near the Eiffel Tower in a radius of 20 Km. select2 = do let s = Sparql "http://dbpedia.org/sparql" query Nothing [] [] res <- runSelectQuery s HPOST printf res where query = "SELECT DISTINCT ?resource ?label (bif:st_distance( ?point1,?point2 )) AS ?distance " ++ "WHERE { geo:geometry ?point1." ++ "?resource geo:geometry ?point2." ++ "?resource rdfs:label ?label." ++ "?resource a ?type." ++ "FILTER ((?type = ) || (?type = ))." ++ "FILTER(bif:st_intersects(?point2,?point1,20))." ++ "FILTER( lang( ?label ) = \"en\")." ++ "FILTER(?resource != )." ++ "} ORDER BY ASC(?distance) LIMIT 20" {- Findl all musical artists. Example found at: http://dbtune.org/jamendo/ -} describe = do let s = Sparql "http://dbtune.org/jamendo/sparql/" "Describe " Nothing [] [] res <- runQuery s HGET printf res --Just print. printf x = case x of Left e -> print $ "Error:" ++ e Right s -> print s