Re: more colloquial do x n times

2014-12-04 Thread Chris Freeman
Sam,

I'm not an expert, but I think making `co-occurrences` recursive is
slightly simpler. Something like:

(defn co-occurrences [db ht depth tags]

  (if (zero? depth)

tags
 (recur db ht (dec depth) (co-ocs db ht tags



You'll note that I'm not reducing into tags on the last line. My version of
`co-ocs` returns all of the tags you care about, which also helps simplify
`co-occurrences`.

I also formatted the `co-ocs` function with a thread-last macro to make it
easier to read and manipulate.

I had to add a filter step to `co-ocs` in order for this to work the way
you describe; otherwise, it just returns all of the hashtags I've ever
used. Let me know if you'd like to see that code.

Chris


On Wed, Dec 3, 2014 at 9:49 PM, Sam Raker sam.ra...@gmail.com wrote:

 EDIT

 On Wednesday, December 3, 2014 10:45:33 PM UTC-5, Sam Raker wrote:

 I've got a decent-sized corpus of tweets, organized by hashtag, in a
 CouchDB db. I'm doing some initial explorations of my data, and was curious
 about which hashtags show up together in tweets. I want to do a NSA-style
 hops kind of algorithm--get all the hashtags that show up in the same
 tweets as hashtags that show up in the same tweets as hashtags that show up
 in the same tweets as my target hashtag, to an arbitrary depth. I wrote
 this:

 (defn co-ocs [db ht  [s]]
 (reduce into (or s #{})
   (map #(map :text %)
  (map #(get-in % [:entities
 :hashtags])
   (:tweets (clutch/get-document db ht))

 (defn co-occurrences [db ht depth]
 (loop [tags (co-ocs db ht) i 1]
 (if (= i depth) (recur
 (reduce into tags
 (map (partial co-ocs db) tags))
 (inc i))
 tags)))

 It works, but loop + incrementing a counter seems profoundly un-clojuric.
 I suppose I could use `dotimes` + an atom, but that doesn't seem much
 better. Any suggestions?

  --
 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/d/optout.


-- 
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/d/optout.


more colloquial do x n times

2014-12-03 Thread Sam Raker
I've got a decent-sized corpus of tweets, organized by hashtag, in a 
CouchDB db. I'm doing some initial explorations of my data, and was curious 
about which hashtags show up together in tweets. I want to do a NSA-style 
hops kind of algorithm--get all the hashtags that show up in the same 
tweets as hashtags that show up in the same tweets as hashtags that show up 
in the same tweets as my target hashtag, to an arbitrary depth. I wrote 
this:

(defn co-ocs [db ht  [s]] 
(reduce into (or s #{})
  (map #(map :text %)
 (map #(get-in % [:entities :hashtags])
  (:tweets (clutch/get-document db ht))

(defn co-occurrences [db ht depth]
(loop [tags (co-ocs db 5sos) i 1]
(if (= i depth) (recur
(reduce into tags
(map (partial co-ocs db) tags))
(inc i))
tags)))

It works, but loop + incrementing a counter seems profoundly un-clojuric. I 
suppose I could use `dotimes` + an atom, but that doesn't seem much better. 
Any suggestions?

-- 
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/d/optout.


Re: more colloquial do x n times

2014-12-03 Thread Sam Raker
EDIT

On Wednesday, December 3, 2014 10:45:33 PM UTC-5, Sam Raker wrote:

 I've got a decent-sized corpus of tweets, organized by hashtag, in a 
 CouchDB db. I'm doing some initial explorations of my data, and was curious 
 about which hashtags show up together in tweets. I want to do a NSA-style 
 hops kind of algorithm--get all the hashtags that show up in the same 
 tweets as hashtags that show up in the same tweets as hashtags that show up 
 in the same tweets as my target hashtag, to an arbitrary depth. I wrote 
 this:

 (defn co-ocs [db ht  [s]] 
 (reduce into (or s #{})
   (map #(map :text %)
  (map #(get-in % [:entities 
 :hashtags])
   (:tweets (clutch/get-document db ht))

 (defn co-occurrences [db ht depth]
 (loop [tags (co-ocs db ht) i 1]
 (if (= i depth) (recur
 (reduce into tags
 (map (partial co-ocs db) tags))
 (inc i))
 tags)))

 It works, but loop + incrementing a counter seems profoundly un-clojuric. 
 I suppose I could use `dotimes` + an atom, but that doesn't seem much 
 better. Any suggestions?


-- 
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/d/optout.