 (ns conexp.fca.applications.wikidata
-  (:require [conexp.fca.contexts :refer [attributes objects make-context incidence-relation]]
-            [conexp.fca.implications :refer [make-implication premise conclusion]]
+  (:require [conexp.fca.contexts :refer [attributes objects
+                                         make-context incidence-relation]]
+            [conexp.fca.implications :refer [make-implication premise
+                                             conclusion]]
             [conexp.fca.fast :refer :all]
             [conexp.io.contexts :refer :all]
             [clojure.java.io :as io]
+            [clojure.string :as str]
             [clojure.set :refer :all]
             [clj-http.client :as client]
             [clojure.data.json :as json])
   (:import org.apache.http.impl.client.HttpClientBuilder))
 
 (def ^:dynamic *sparql-endpoint*
+  "Wikidata SPARQL query endpoint URI"
   "https://query.wikidata.org/bigdata/namespace/wdq/sparql")
 
 (def ^:dynamic *tool-banner*
+  "tool banner to send with SPARQL queries"
   "#TOOL:conexp-clj, https://github.com/exot/conexp-clj")
 
 (def ^:dynamic *max-entities-per-query*
-  500)
+  "maximum number of entities requested in a single query (entities
+  will be split over multiple queries if above this threshold)" 500)
 
 (def ^:dynamic *query-delay*
+  "delay between two queries, in milliseconds"
   500)
 
 (defn- disable-cookies [^HttpClientBuilder builder
                         request]
+  "helper to disable cookie management in HTTP requests"
   (.disableCookieManagement builder))
 
 (defn sparql-query

(defn- entity-id-from-uri
  "retrieve an entity id from a Wikidata entity URI"
  [uri]
  (let [slash (clojure.string/last-index-of uri "/")]
    (subs uri (+ 1 slash))))

(defn- label-query-for-entities
  ""
  [entities & {:keys [lang] :or {lang "en"}}]
  (str "SELECT ?entity ?label WHERE { VALUES ?entity {"
       (clojure.string/join " "
                            (map entity-add-sparql-prefix entities))
       "} ?entity rdfs:label ?label FILTER(LANG(?label)=\""
       lang

  (make-implication
   (map id-from-label (premise implication))
   (map id-from-label (conclusion implication))))

(defn- pattern-for-premise
  "generate a graph pattern matching a premise"
