Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

freebase categorization. #4

Merged
merged 1 commit into from

2 participants

Nick Niemeir Brian Shaler
Nick Niemeir

Sorry guys, I've been sitting on this for a couple of weeks. I'm not sure where to put this or hook it up, but it takes an array of strings that are possible topics (or a string if just one) and fetches all the possible categories it can find from freebase.

If you provide a callback it will call it with an array of answers, if not it will act as a stream.

It has no smarts in it, so it returns all the answers, i'm not sure how we want to try and weight those to come up with good topics.

--nick

Brian Shaler
Owner

@akavlie might find this interesting :-3)

It has no smarts in it, so it returns all the answers, i'm not sure how we want to try and weight those to come up with good topics.

Looks like it's a wrapper for the Freebase API, which should come in handy. We just need to figure out what kind of smarts to add to it, and how to integrate this into the ActivityItem processing functionality..

Brian Shaler brianshaler merged commit 2d3ded6 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 21, 2012
  1. Nick Niemeir
This page is out of date. Refresh to see the latest.
Showing with 73 additions and 2 deletions.
  1. +68 −0 freeCat.js
  2. +5 −2 package.json
68 freeCat.js
View
@@ -0,0 +1,68 @@
+var util = require('util')
+ , qs = require('querystring')
+ // Dependencies
+ , request = require('request')
+ , es = require('event-stream')
+ , clarinet = require('clarinet')
+ // vars
+ , freeCat
+ ;
+
+freeCat = function (topics, cb) {
+ if (typeof topics === 'string') topics = [ topics ]
+ var lookup
+ , results = []
+ ;
+
+ lookup = function (item) {
+ var q =
+ { query: JSON.stringify({ query:
+ { name: item
+ , type: [{ name: null }]
+ }
+ })}
+ , parse = clarinet.createStream()
+ , topic = false
+ , isTopic = function (name) {
+ if (name === 'name') topic = true
+ }
+
+
+ parse.write = function (data) {
+ this._parser.write(data.toString())
+ return true
+ }
+ parse.on('openobject', isTopic)
+ parse.on('key', isTopic)
+ parse.on('value', function (value) {
+ if (topic) {
+ parse.emit('data', value)
+ topic = false
+ }
+ })
+ return request(
+ 'http://www.freebase.com/api/service/mqlread?' + qs.stringify(q)
+ ).pipe(parse)
+ }
+
+ results = topics.map(lookup)
+ if (typeof cb === 'function') {
+ es.concat.apply(null, results)
+ .pipe(es.writeArray(cb))
+ } else {
+ return es.concat.apply(null, results)
+ }
+
+}
+
+module.exports = exports = freeCat
+
+// Example usage
+
+// freeCat(['Jon Snow', 'Arya Stark', 'Ghost'], function (e, results) {
+// if (e) throw e
+// console.log(results.reverse())
+// })
+//
+// freeCat(['Doc Watson', 'Earl Scrugs', 'Woody Guthrie']).pipe(es.log())
+
7 package.json
View
@@ -44,10 +44,13 @@
"cron" : "0.1.3",
"twitter" : "0.1.18",
"node-foursquare" : "0.1.3",
- "instagram-node-lib" : "0.0.7"
+ "instagram-node-lib" : "0.0.7",
+ "clarinet" : "*",
+ "event-stream" : "*",
+ "request" : "*"
},
"license": "MIT",
"engine": {
"node": ">=0.6"
}
-}
+}
Something went wrong with that request. Please try again.