Last active
September 21, 2018 14:50
-
-
Save inukshuk/1c2431c02a800c534386571c4d4a9d59 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
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] | |
}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FWIW, see https://github.com/GlobalNamesArchitecture/damerau-levenshtein