Permalink
Browse files

Added scripts

  • Loading branch information...
1 parent be56342 commit f6a92ce7d8a8aed499b3c762cafa7502ca4b59b0 @wdenton committed Aug 21, 2011
Showing with 431 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +41 −0 949-extractifier.rb
  3. +34 −0 convert-lc-to-numbers.rb
  4. +35 −0 dentograph.R
  5. +14 −0 extract-tpl-ddc-from-090.rb
  6. +212 −0 lc-map.txt
  7. +23 −0 make-one-by-one-data.rb
  8. +23 −0 make-one-by-two-data.rb
  9. +25 −0 make-two-by-two-data.rb
  10. +22 −0 x-axis-labels.csv
View
@@ -0,0 +1,2 @@
+*~
+#*#
View
@@ -0,0 +1,41 @@
+#!/usr/bin/ruby
+
+# Given a file filled with 949 fields, dump out
+# BRANCH:CALL_NUMBER
+#
+# Input should look like
+# 949 $a JL65 1954 .M34 1976 ERI $w LC $c 1 $i 31761035750132 $l STACKS $m ROBARTS $r Y $s Y $t BOOK $u 11/6/1993
+# 949 $a B1246 .S7 $w LC $c 1 $i 34444000259283 $l STORAGE $m ROBARTS $r Y $s Y $t BOOK $u 12/8/1994
+#
+# Output will be
+#
+# ROBARTS:JL 65
+# ROBARTS:B 1246
+
+file = ARGV[0]
+
+File.open(file).each_with_index do |line, index|
+ h = Hash.new
+ line.split("$").each do |part|
+ next unless /[a-z]/.match(part[0,1]) # Skip the 949
+ subfield = part[0,1]
+ subfield_value = part[2..-1]
+ h[subfield] = subfield_value.strip
+ end
+ callNum = h['a']
+ branch = h['m']
+ scheme = h['w']
+ next unless scheme == "LC" # Ignore maps, gov docs, other special classifications
+
+ begin
+ callNum.gsub!(/\..*/, '') # Remove everything after the first decimal point
+ callNum.strip.upcase!
+ m = /([A-Z]+)(\d+)/.match(callNum)
+ next if m.nil? # Skip the rare call number with letters but no numbers
+ next if m[1].nil?
+ next unless m[2].to_i > 0
+ puts branch + ":" + m[1] + " " + m[2]
+ rescue Exception => e
+ STDERR.puts "Skipped #{callNum}: #{e}"
+ end
+end
View
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+
+data_file = ARGV[0]
+
+# First, make a hash that maps LC class letters to numbers
+map_file = 'lc-map.txt'
+
+lcmap = {}
+
+# Write out a 0 entry for each LC class letter,
+# so that the number of things on the x-axis is
+# constant for all libraries. (If a library only
+# has things in Q, then they need to line up with
+# what other libraries have in Q, not be all jammed
+# up against the y-axis because there's nothing from
+# A-P.)
+File.open(map_file).each_with_index do |class_letters, i|
+ lcmap[class_letters.chomp] = i
+ puts "#{i} 0"
+end
+
+# Mark the y-axis all the way out to 10,000
+10000.times do |i|
+ puts "0 #{i}"
+end
+#puts "0 10000"
+
+File.open(data_file).each do |lc|
+ callNum = lc.split
+ next unless lcmap[callNum[0]] # Avoid K and strange letters
+ next unless callNum[1]
+ next unless callNum[1].to_i < 10000 # Avoid strangely large numbers
+ puts "#{lcmap[callNum[0]]} #{callNum[1]}"
+end
View
@@ -0,0 +1,35 @@
+#!/usr/bin/env Rscript
+
+# Usage: dentograph.R mountain-data.txt filename.png "Library Name"
+
+args <- commandArgs(TRUE)
+datafile <- args[1]
+output <- args[2]
+library_name <- args[3]
+
+png(filename=output, height=1600, width=1600, units="px")
+
+d <- read.table(datafile)
+table <- table(d)
+x <- 1:nrow(table)
+y <- 1:ncol(table)
+res <- persp(x, y, table,
+ zlim = c(0,20000), # Change as necessary, or comment out
+ theta = -5, phi = 20,
+ scale = TRUE,
+ border = NA,
+ axes = F,
+ box = F,
+ col = "cyan",
+ shade = 0.5,
+ main = library_name, cex.main = 5)
+
+xpoints = read.csv("x-axis-labels.csv")
+
+for (i in 1:nrow(xpoints)) {
+ points(trans3d(xpoints$Point[i], 5, 0, pmat = res), col = "#000000", pch = xpoints$Label[i], cex = 2)
+}
+
+# for (i in 1:nrow(xpoints)) {
+# lines(trans3d(x=xpoints$Point[i], y, z=0, pmat = res), col = "#00ffff")
+# }
@@ -0,0 +1,14 @@
+#!/usr/bin/ruby
+
+file = ARGV[0]
+
+File.read(file).each do |line|
+ line.chomp!
+ begin
+ call_number = (/.* \$a (.*)[$\s]/.match(line))[1]
+ call_number.gsub!(/[A-Za-z\/].*/, '') # Remove any letters and slashes (/)
+ puts call_number if call_number.to_i < 1000 && call_number.length > 0
+ rescue Exception => e
+ STDERR.puts "(Error #{e}) #{line}"
+ end
+end
View
@@ -0,0 +1,212 @@
+A
+AC
+AE
+AG
+AI
+AM
+AN
+AP
+AS
+AY
+AZ
+B
+BC
+BD
+BF
+BH
+BJ
+BL
+BM
+BP
+BQ
+BR
+BS
+BT
+BV
+BX
+C
+CB
+CC
+CD
+CE
+CJ
+CN
+CR
+CS
+CT
+D
+DA
+DAW
+DB
+DC
+DD
+DE
+DF
+DG
+DH
+DJ
+DJK
+DK
+DL
+DP
+DQ
+DR
+DS
+DT
+DU
+DX
+E
+F
+FC
+G
+GA
+GB
+GC
+GE
+GF
+GN
+GR
+GT
+GV
+H
+HA
+HB
+HC
+HD
+HE
+HF
+HG
+HJ
+HM
+HN
+HQ
+HS
+HT
+HV
+HX
+J
+JA
+JC
+JF
+JJ
+JK
+JL
+JN
+JQ
+JS
+JV
+JZ
+L
+LA
+LB
+LC
+LD
+LE
+LF
+LG
+LH
+LJ
+LT
+M
+ML
+MT
+N
+NA
+NB
+NC
+ND
+NE
+NK
+NX
+P
+PA
+PB
+PC
+PD
+PE
+PF
+PG
+PH
+PJ
+PK
+PL
+PM
+PN
+PQ
+PR
+PS
+PT
+PZ
+Q
+QA
+QB
+QC
+QD
+QE
+QH
+QK
+QL
+QM
+QP
+QR
+R
+RA
+RB
+RC
+RD
+RE
+RF
+RG
+RJ
+RK
+RL
+RM
+RS
+RT
+RV
+RX
+RZ
+S
+SB
+SD
+SF
+SH
+SK
+T
+TA
+TC
+TD
+TE
+TF
+TG
+TH
+TJ
+TK
+TL
+TN
+TP
+TR
+TS
+TT
+TX
+U
+UA
+UB
+UC
+UD
+UE
+UF
+UG
+UH
+V
+VA
+VB
+VC
+VD
+VE
+VF
+VG
+VK
+VM
+Z
+ZA
View
@@ -0,0 +1,23 @@
+#!/usr/bin/ruby
+
+# Given a file of Dewey call numbers,
+# it outputs a file ready to be used
+# to make a hundreds-by-tens levelplot
+# dentogram, by printing the hundreds and
+# tens numbers separated by a space
+#
+# 614.59939 -> 6 1
+# 598.29729 -> 5 9
+# 767 -> 7 6
+
+file = ARGV[0]
+
+File.read(file).each do |line|
+ next unless line.length > 2
+ line.chomp!
+ hundreds = line.slice(0,1)
+ tens = line.slice(1,1)
+ next unless (/\d/).match(hundreds)
+ next unless (/\d/).match(tens)
+ puts "#{hundreds} #{tens}"
+end
View
@@ -0,0 +1,23 @@
+#!/usr/bin/ruby
+
+# Given a file of Dewey call numbers,
+# output a file ready to be used
+# to make a hundreds-by-tens-and-ones levelplot
+# dentogram, by printing the hundreds and
+# tens-and-ones numbers separated by a space
+#
+# 614.59939 -> 6 14
+# 598.29729 -> 5 98
+# 767 -> 7 67
+
+file = ARGV[0]
+
+File.read(file).each do |line|
+ next unless line.length > 2
+ line.chomp!
+ hundreds = line.slice(0,1)
+ tensandones = line.slice(1,2)
+ next unless (/\d/).match(hundreds)
+ next unless (/\d\d/).match(tensandones)
+ puts "#{hundreds} #{tensandones}"
+end
Oops, something went wrong.

0 comments on commit f6a92ce

Please sign in to comment.