-
-
Save peterhellberg/6f7b0bef00f0866ca173 to your computer and use it in GitHub Desktop.
Experimenting with the margopher package to generate quotes
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
package main | |
import ( | |
"flag" | |
"fmt" | |
"github.com/AhmedZaleh/margopher" | |
) | |
var ( | |
url = flag.String("url", "http://data.c7.se/quotes/science.html", "The URL to read from") | |
count = flag.Int("n", 3, "The number of sentences to generate") | |
) | |
func main() { | |
flag.Parse() | |
margopher := margopher.New() | |
margopher.ReadURL(*url) | |
for i := 1; i <= *count; i++ { | |
fmt.Println(margopher.Generate() + "\n") | |
} | |
} |
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
// Run on http://www.gdargaud.net/Humor/QuotesScience.html in order to get the quotes a JSON string | |
// Save as q.json | |
var d = []; | |
for each (q in document.getElementsByTagName("blockquote")) { d.push(q.textContent) }; | |
window.prompt("Copy!", JSON.stringify(d)); |
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
require 'json' | |
data = JSON.parse(File.read('q.json')) | |
puts "<article>" | |
data.compact.each do |d| | |
s = (d.split("—")[0]. | |
gsub("\n", ""). | |
gsub('"', ""). | |
gsub(" ?", "?"). | |
gsub(" !", "!"). | |
gsub("?A", "? A")).strip | |
puts " <p>#{s}</p>" if s.size > 10 | |
end | |
puts "</article>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A few interesting examples of generated output: