Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Created September 5, 2015 11:53
Show Gist options
  • Save peterhellberg/6f7b0bef00f0866ca173 to your computer and use it in GitHub Desktop.
Save peterhellberg/6f7b0bef00f0866ca173 to your computer and use it in GitHub Desktop.
Experimenting with the margopher package to generate quotes
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")
}
}
// 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));
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>"
@peterhellberg
Copy link
Author

A few interesting examples of generated output:

  • Engineers think that any conclusion must be very hot.
  • In the beginning the Universe obeys a set of rules.
  • Nuclear war could alleviate some of the three major scientific awards.
  • Very few people do anything but creation science.
  • Round numbers are always successful.
  • He uses statistics as a novelty item back here on Earth.
  • There are three kinds of people: those who make empty prophecies.
  • A scientist can discover a new problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment