Skip to content

Instantly share code, notes, and snippets.

@syou6162
Created November 9, 2013 07:46
Show Gist options
  • Save syou6162/7382871 to your computer and use it in GitHub Desktop.
Save syou6162/7382871 to your computer and use it in GitHub Desktop.
Clojure + Stanford ParserでS式を読み込んで色々操作する例
(import edu.stanford.nlp.trees.PennTreeReader)
(let [filename "/Users/yasuhisa/Desktop/PENN_TREEBANK3/PARSED/MRG/WSJ/00/WSJ_0001.MRG"]
(with-open [rdr (clojure.java.io/reader filename)]
(let [ptr (new PennTreeReader rdr)
trees (loop [result []]
(if-let [t (.readTree ptr)]
(recur (conj result t))
result))]
(for [^LabeledScoredTreeNode t trees]
(for [leaf (.getLeaves t)]
(.nodeString leaf))))))
;; (("Pierre" "Vinken" "," "61" "years" "old" "," "will" "join" "the" "board" "as" "a" "nonexecutive" "director" "Nov." "29" ".")
;; ("Mr." "Vinken" "is" "chairman" "of" "Elsevier" "N.V." "," "the" "Dutch" "publishing" "group" "."))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment