On 02/08/13 12:46, Jim - FooBar(); wrote:
or programmatically emit identical extension points for all subinterfaces/subclasses

;;adopted from clojure/core/protocols.clj

(def ^:private co-stub
'(run [this text]
  (if (instance? edu.stanford.nlp.pipeline.Annotation text)
      (do (.annotate this text) text)
   (let [ann (edu.stanford.nlp.pipeline.Annotation. ^String text)]
     (.annotate this ann) ann))))

(defn- emit-IComponent-impls* [syms]
  (mapcat
    (fn [s]
      [(symbol (str "edu.stanford.nlp.pipeline." s)) co-stub])
    syms))

(defmacro ^:private emit-IComponent-impls [& syms]
  `(extend-protocol IComponent
     ~@(emit-IComponent-impls* syms)))

and finally you call it like this:

(emit-IComponent-impls ;nice trick to avoid enumerating all the identical implementations POSTaggerAnnotator PTBTokenizerAnnotator WordsToSentencesAnnotator TokenizerAnnotator
  CleanXmlAnnotator MorphaAnnotator NERCombinerAnnotator RegexNERAnnotator
  TrueCaseAnnotator ParserAnnotator DeterministicCorefAnnotator)

neat trick imo :)

Jim

--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to