Skip to content

Instantly share code, notes, and snippets.

@inukshuk inukshuk/style-gen.rb
Last active Sep 21, 2018

Embed
What would you like to do?
require 'anystyle'
require 'citeproc/ruby'
require 'csl/styles'
# Load all dependent CSL styles and create a Renderer
# Those should be cached!
styles = CSL::Style.list.map { |id| CSL::Style.load id }.reject { |s| s.bibliography.nil? }
cp = CiteProc::Ruby::Renderer.new
# Parse a reference to CSL/JSON
input = 'Knuth, Donald. (1968). The art of computer programming (Vol. 1). Boston: Addison-Wesley.'
items = AnyStyle.parse(input, format: 'csl')
# Generate a output hash for every style
refs = Hash[styles.map { |s|
# Convert the item for use with CiteProc
item = CiteProc::CitationItem.new { |c| c.data = CiteProc::Item.new(items[0]) }
# Render the item
ref = cp.render item, s.bibliography
# TODO compute Levenshtein distance to input (or similar)
score = 0
# Return style id and reference string and score
[s.id, ref, score]
}]
@dshorthouse

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.