1 (in-package #:metabang.gsn
)
4 Need to account for different kinds of links
5 in gsn-nodes-from-json
, need to return pairs of node and attributes
7 hash-table for nodes to prevent duplicates
8 queue or stack for nodes to expand
9 hash-table for links
(triples of A link B?
) to handle duplicates
12 (defgeneric expand-node
(context node
)
15 (defgeneric find-neighbors
(context node
)
18 (defgeneric expand-node-p
(context node
)
21 (defgeneric add-node
(context node
)
24 (defgeneric add-link
(context node neighbor direction
)
27 (defgeneric update-node-data
(context node data
)
30 (defclass abstract-context
()
33 (defclass gsn-context
(abstract-context)
36 (defparameter +gsn-root
+ "http://socialgraph.apis.google.com/")
38 (defmethod expand-node ((context abstract-context
) node
)
39 (bind (((to from
) (find-neighbors context node
)))
41 (add-node context neighbor
)
42 (add-link context node neighbor
:to
))
43 (dolist (neighbor from
)
44 (add-node context neighbor
)
45 (add-link context node neighbor
:from
))))
49 (defmethod find-neighbors ((context gsn-context
) node
)
50 (bind (((result headers stream
)
52 (format nil
"~alookup?edo=1&edi=1&pretty=1&q=~a"
56 (setf json
(json:decode-json stream
))
58 (update-node-data context node json
)
59 (list (gsn-nodes-from-json json
:to
)
60 (gsn-nodes-from-json json
:from
))))
62 (gsn-nodes-from-json x
:from
)
65 (destructuring-bind (result headers stream
)
67 (format nil
"http://socialgraph.apis.google.com/lookup?edo=1&edi=1&pretty=1&q=~a" who
))
68 (declare (ignore result headers
))
69 (json:decode-json stream
)))
71 (assoc :nodes_referenced
72 (assoc :nodes
(gsn-test "TWITTER.COM/GWKING") :key
#'first
))
75 (setf x
(gsn-test "TWITTER.COM/GWKING"))