Created
August 27, 2010 01:43
-
-
Save nathanmarz/552615 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def average | |
(<- [!val :> !avg]) | |
(c/count !count) | |
(c/sum !val :> !sum) | |
(div !sum !count :> !avg)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn people-older-than [threshold] | |
(<- [?person] | |
(age ?person ?age) | |
(> ?age threshold))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn popular-people [] | |
(<- [?person] | |
(follows ?person _) | |
(c/count ?count) | |
(> ?count 100))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn old-male-people [male-people] | |
(<- [?person] | |
(male-people ?person) | |
(age ?person ?age) | |
(> ?age 90))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(<- [?avg-age] | |
(age _ ?age) | |
(average ?age :> ?avg-age)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Find everyone who is 25 years old | |
"SELECT person FROM Age WHERE age = 25" | |
(<- [?person] (Age ?person 25)) | |
;; Find all the male people that Emily follows | |
"SELECT F.target AS person FROM Follows F, Gender G WHERE F.source = "Emily" AND G.gender = "m" AND F.target = G.person" | |
(<- [?person] (Follows "Emily" ?person) (Gender ?person "m")) | |
;; Find how many people each person follows | |
"SELECT source AS person, COUNT(*) AS followscount FROM Follows GROUP BY source" | |
(<- [?person ?count] (Follows ?person _) (c/count ?count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment