Created
November 9, 2013 07:46
-
-
Save syou6162/7382871 to your computer and use it in GitHub Desktop.
Clojure + Stanford ParserでS式を読み込んで色々操作する例
This file contains hidden or 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
(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