Created
June 22, 2012 03:23
-
-
Save brendano/2969996 to your computer and use it in GitHub Desktop.
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
| # handle the wikipedia dump format | |
| module WikiDump | |
| def self.yield_page_strings(stream) | |
| buf = "" | |
| stream.each do |line| | |
| if line =~ /^\s* <page> \s*$/x | |
| buf = "" | |
| end | |
| buf << line | |
| if line =~ /^\s* <\/page> \s*$/x | |
| yield buf | |
| end | |
| end | |
| end | |
| def self.yield_pages(stream) | |
| yield_page_strings(stream) do |pagestr| | |
| yield WikiPage.new(pagestr) | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment