Created
June 14, 2011 00:27
-
-
Save swannodette/1024087 to your computer and use it in GitHub Desktop.
dcg.clj
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-->e verb [v] | |
([[:v 'eats]] '[eats])) | |
(def-->e noun [n] | |
([[:n 'bat]] '[bat]) | |
([[:n 'cat]] '[cat])) | |
(def-->e det [d] | |
([[:d 'the]] '[the]) | |
([[:d 'a]] '[a])) | |
(def-->e noun-phrase [n] | |
([[:np ?d ?n]] (det ?d) (noun ?n))) | |
(def-->e verb-phrase [n] | |
([[:vp ?v ?np]] (verb ?v) (noun-phrase ?np))) | |
(def-->e sentence [s] | |
([[:s ?np ?vp]] (noun-phrase ?np) (verb-phrase ?vp))) | |
(run* [parse-tree] | |
(sentence parse-tree '[the bat eats a cat] [])) | |
;; ([:s [:np [:d the] [:n bat]] [:vp [:v eats] [:np [:d a] [:n cat]]]]) | |
;; ~70ms | |
(dotimes [_ 10] | |
(time | |
(dotimes [_ 1e3] | |
(run* [parse-tree] | |
(sentence parse-tree '[the bat eats a cat] []))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment