Skip to content

Instantly share code, notes, and snippets.

@jirkamarsik
Created December 17, 2012 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jirkamarsik/4323409 to your computer and use it in GitHub Desktop.
Save jirkamarsik/4323409 to your computer and use it in GitHub Desktop.
Tree-rewriting rules using unification.
(defn simple-rule [in-tree]
(if-let [res (seq (run 1 [out-tree]
(fresh [X Y Z W]
(== in-tree ['VP X Y ['PP Z W]])
(== out-tree ['VP ['VP X Y] ['PP Z W]]))))]
(first res)
in-tree))
;=> #'user/simple-rule
(simple-rule '[VP [VB plays] [NP piano] [PP [IN for] [NP fun]]])
;=> [VP [VP [VB plays] [NP piano]] [PP [IN for] [NP fun]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment