Home > Clojure > CS Research Topic Generator, in Clojure

CS Research Topic Generator, in Clojure

September 14th, 2009

If you need a worthy topic for your CS research project, let this very simple CS topic generator spark some ideas.
http://www.cs.purdue.edu/homes/dec/essay.topic.generator.html

I’ve decided to get myself more familiarized with functional programming so I picked Clojure as my language of choice. It’s new, its a Lisp dialect, it has a great concurrency API and it runs on the already familiar JVM.

Here is my implementation of the “CS topic generator” in Clojure:

(ns com.alenribic.topic-generator
 (:use [clojure.contrib.str-utils :only (str-join)]
       [clojure.contrib.seq-utils :only (rand-elt)]))

(defn compute-article
  [word capitalize?]
  (let [vowels #{\a \e \i \o \u} a (if capitalize? \A \a)]
    (if (vowels (Character/toLowerCase (first word)))
      (str a \n) a)))

(defn gen-phrase
  [col1 col2 col3 first-phase?]
  (let [word1 (rand-elt col1) word2 (rand-elt col2) word3 (rand-elt col3)]
      (str-join " " [(compute-article word1 first-phase?) word1 word2 word3])))

(defn gen-random-topic []
  (let [col1 [
      "integrated", "parallel", "virtual", "interactive", "responsive",
      "synchronized", "balanced", "virtual", "meta-level", "optimized", "active", "parameterized",
      "conceptual", "scalable", "dynamic", "high-level", "collaborative", "type-safe"]
     col2 [
      "mobile", "functional", "programmable", "distributed", "logical",
      "digital", "concurrent", "knowledge-based", "multimedia", "binary", "object-oriented",
      "secure", "high-speed", "real-time", "functional", "parallelizing", "watermarking",
      "proxy"]
     col3 [
      "network", "preprocessor", "compiler", "system", "interface",
      "protocol", "architecture", "database", "algorithm", "toolkit", "display", "technology",
      "solution", "language", "agent", "theorem prover", "work cluster", "cache"]
     conn ["for", "related to", "derived from", "applied to", "embedded in"]]
    (str-join " " [(gen-phrase col1 col2 col3 true)
		   (rand-elt conn) (gen-phrase col1 col2 col3 false)])))

alen Clojure ,

  1. No comments yet.
  1. No trackbacks yet.