rbibtex 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,6 @@
1
+ 0.0.1
2
+ * Removed unneccessary dependency on pp
3
+ * Added rbib2bib pretty printer
4
+
5
+ 0.0.0
6
+ * Initial Release
data/README ADDED
@@ -0,0 +1,63 @@
1
+ # rbibtex
2
+
3
+ ## Description
4
+ A bibtex parsing library written in pure ruby.
5
+ With some additional executables that transform bibtex files.
6
+
7
+ This is my first attempt at racc so be patient with me. I hope to improve this
8
+ into a full bibtex parser in the near future, at the moment it parses the
9
+ bibtex subset that I need.
10
+
11
+ Another problem is that nearly no work went into the added scripts, which can
12
+ therefore be seen as usage examples, but may not help you with the work you
13
+ want to do.
14
+
15
+ I hope this will be a starting point for a more complete bibtex library for
16
+ ruby.
17
+
18
+ Cheers,
19
+
20
+ Brian
21
+
22
+ ## Find it at
23
+
24
+ http://ruby.brian-schroeder.de/rbibtex/
25
+
26
+ ## Installation:
27
+
28
+ wget http://ruby.brian-schroeder.de/rbibtex/releases/current.tar.bz2
29
+ tar -xvvjf current.tar.bz2
30
+ cd rbibtex-X.Y.Z
31
+ ruby setup.rb
32
+
33
+ ### As a gem
34
+
35
+ $ su
36
+ # gem install rbibtex
37
+
38
+ ## Usage:
39
+
40
+ rbib2html infiles > outfile
41
+
42
+ ### or as a library:
43
+
44
+ require "rbibtex"
45
+
46
+ parser = BibTeX::Parser.new
47
+ file = parser.parse( ARGF.read )
48
+ file.each do | entry |
49
+ p entry
50
+ end
51
+
52
+ ## ToDo
53
+ * The binaries are only quick hacks for my specific applications right now,
54
+ they should be rewritten and extended.
55
+ * The full bibtex format is not parsed, I only allow for a specific subset
56
+ right now.
57
+ * Escaping is not implemented.
58
+
59
+ ## Authors
60
+ This was implemented by Brian Schroeder.
61
+
62
+ ## License
63
+ This library is under the ruby license
data/bin/rbib2bib ADDED
@@ -0,0 +1,76 @@
1
+ #! /usr/bin/ruby
2
+
3
+ $:.unshift("~/lib/ruby")
4
+
5
+ require "rbibtex"
6
+
7
+ file = BibTeX::Parser.new.parse( ARGF.read )
8
+
9
+ first = [:author, :title, :year]
10
+ last = [:note, :pdf, :ps, :www]
11
+
12
+ puts "@comment { Pretty Printed using rbib2bib }"
13
+
14
+ max_key_length = file.inject(0) { | r, entry |
15
+ entry.properties.inject(r) { | r, (k, _) |
16
+ [r, k.to_s.length].max
17
+ }
18
+ }
19
+
20
+ p max_key_length
21
+
22
+ class String
23
+ def wrap(width = 78, tabwidth = 8)
24
+ raise "Invalid width" if width < 0
25
+ self.untabify(tabwidth).
26
+ gsub(/.{1,#{width}}(?:\s|\Z)/) { ($& + 5.chr).gsub(/\n\005/,"\n").gsub(/\005/,"\n") }.
27
+ gsub(/\s*\Z/m, "")
28
+ end
29
+
30
+ def indent_hanging(indent = 2)
31
+ self.gsub(/\n/, "\n#{" " * indent}")
32
+ end
33
+
34
+ def indent(indent = 2)
35
+ self.gsub(/^/, " " * indent)
36
+ end
37
+
38
+
39
+ def untabify(tab_width = 8)
40
+ self.gsub(/\t/, " "*tab_width)
41
+ end
42
+
43
+ def deindent_hanging(indent = [self[/^\s*/].untabify.length, self[/\n(\s*)/, 1].to_s.untabify.length].max)
44
+ self.untabify.gsub(/^\s{0,#{indent}}/, "")
45
+ end
46
+
47
+ def deindent(indent = self[/^\s*/].untabify.length)
48
+ self.untabify.gsub(/^\s{0,#{indent}}/, "")
49
+ end
50
+
51
+ def unwrap
52
+ self.split(/\n\n+/).map { | paragraph |
53
+ paragraph.gsub(/\n(?=\S)/, " ")
54
+ }.join("\n\n")
55
+ end
56
+ end
57
+
58
+ file.each do | entry |
59
+
60
+ p = entry.properties.dup
61
+ f = first.map { | k | [k, p.delete(k)] }
62
+ l = last.map { | k | [k, p.delete(k)] }
63
+ p = p.to_a.map{ | (k, v) | [k.to_s, v] }.sort
64
+
65
+ puts "@#{entry.type}{#{entry.key},"
66
+ (f + p + l).each do | (k, v) |
67
+ next unless v
68
+
69
+ print %( #{k}).ljust(max_key_length+2) + " = {"
70
+ print v.deindent_hanging.unwrap.wrap(78-(max_key_length+6)).indent_hanging(max_key_length+6)
71
+ puts "},"
72
+ end
73
+ puts "}"
74
+ puts
75
+ end
76
+
data/bin/rbib2html ADDED
@@ -0,0 +1,51 @@
1
+ #! /usr/bin/ruby
2
+
3
+ $:.unshift("~/lib/ruby")
4
+
5
+ require "rbibtex"
6
+
7
+ parser = BibTeX::Parser.new
8
+ file = parser.parse( ARGF.read )
9
+
10
+ puts <<HTML_HEADER
11
+ <html>
12
+ <head>
13
+ <style type="text/css">
14
+ div.entry { margin-bottom: 1em; padding-bottom: 1em; border-bottom: 1px dashed silver; }
15
+ span.title { font-weight: bold; }
16
+ span.author { font-style: oblique; }
17
+ .links a { background: silver; }
18
+ span.note { display: block; margin: 0.5em; margin-left: 5em; margin-right: 5em; }
19
+ </style>
20
+ </head>
21
+ <body>
22
+ HTML_HEADER
23
+
24
+ first = [:author, :title, :year]
25
+ last = [:note]
26
+ links = [:pdf, :ps]
27
+
28
+ file.each do | entry |
29
+
30
+ p = entry.properties.dup
31
+ f = first.map { | k | [k, p.delete(k)] }
32
+ l = last.map { | k | [k, p.delete(k)] }
33
+ a = links.map { | k | [k, p.delete(k)] }
34
+ p = p.to_a.map{ | (k, v) | [k.to_s, v] }.sort
35
+
36
+ puts %(<div class="entry">)
37
+ (f + p).each do | (k, v) |
38
+ puts %(<span class="#{k}">#{v}</span>)
39
+ end
40
+ puts %(<span class="links")
41
+ a.each do | k, v |
42
+ puts %(<a href="#{v}">#{k}</a>)
43
+ end
44
+ puts %(</span)
45
+ (l).each do | (k, v) |
46
+ puts %(<span class="#{k}">#{v}</span>)
47
+ end
48
+ puts %(</div>)
49
+ end
50
+
51
+ puts "</body></html>"
data/bin/rbib2txt ADDED
@@ -0,0 +1,41 @@
1
+ #! /usr/bin/ruby
2
+
3
+ $:.unshift("~/lib/ruby")
4
+
5
+ require "rbibtex"
6
+
7
+ parser = BibTeX::Parser.new
8
+ file = parser.parse( ARGF.read )
9
+
10
+ first = [:author, :title, :year]
11
+ last = [:note]
12
+ links = [:pdf, :ps]
13
+
14
+ file.each do | entry |
15
+
16
+ p = entry.properties.dup
17
+ f = first.map { | k | [k, p.delete(k)] }
18
+ l = last.map { | k | [k, p.delete(k)] }
19
+ a = links.map { | k | [k, p.delete(k)] }
20
+ p = p.to_a.map{ | (k, v) | [k.to_s, v] }.sort
21
+
22
+ puts
23
+ (f + p).each do | (k, v) |
24
+ next unless v
25
+ print %( #{k}: ).ljust(20)
26
+ puts v.gsub(/\n\s*/, "\n" + (" " * 20))
27
+ end
28
+ (l).each do | (k, v) |
29
+ next unless v
30
+ print %( #{k}: ).ljust(20)
31
+ puts v.gsub(/\n\s*/, "\n" + (" " * 20))
32
+ end
33
+ a.each do | k, v |
34
+ next unless v
35
+ print %( #{k}: ).ljust(20)
36
+ puts v.gsub(/\n\s*/, "\n" + (" " * 20))
37
+ end
38
+ puts
39
+ puts "-" * 80
40
+ end
41
+
data/lib/rbibtex.rb ADDED
@@ -0,0 +1 @@
1
+ require "rbibtex/rbibtex.tab"
@@ -0,0 +1,5 @@
1
+ # pre-setup.rb
2
+
3
+ # process grammer file
4
+ system "racc rbibtex.y"
5
+
@@ -0,0 +1,164 @@
1
+ class BibTeX::Parser
2
+
3
+ rule
4
+
5
+ file : opt_space { result = val[0] }
6
+ | opt_space object_list opt_space { result = val[1] }
7
+ ;
8
+
9
+ object_list : object { result = [val[0]] }
10
+ | object_list opt_space object { result << val[2] }
11
+ ;
12
+
13
+ object : AT opt_space at_object { result = val[2] }
14
+ ;
15
+
16
+ at_object : comment { result = val[0] }
17
+ | entry { result = val[0] }
18
+ ;
19
+
20
+ comment : COMMENT opt_space value { result = [:comment, val[2]] }
21
+ ;
22
+
23
+ entry : entry_head assignment_list
24
+ RBRACE { val[0].properties = val[1]; result = val[0] }
25
+ | entry_head assignment_list /* Allow additional comma after last entry */
26
+ COMMA opt_space RBRACE { val[0].properties = val[1]; result = val[0] }
27
+ | entry_head RBRACE { result = val[0] } /* Empty entry */
28
+ ;
29
+
30
+ entry_head : entry_name opt_space
31
+ LBRACE opt_space
32
+ key_name opt_space
33
+ COMMA opt_space { result = Entry.new(val[0], val[4]) }
34
+ ;
35
+
36
+ entry_name : WORD
37
+ ;
38
+
39
+ key_name : { result = "" }
40
+ | CHARACTER
41
+ | WORD
42
+ | key_name CHARACTER { result << val[1] }
43
+ | key_name WORD { result << val[1] }
44
+ ;
45
+
46
+ assignment_list : assignment { result = val[0] }
47
+ | assignment_list COMMA opt_space
48
+ assignment { result.merge!(val[3]) }
49
+ ;
50
+
51
+ assignment : assignment_lhs opt_space
52
+ EQUALS opt_space
53
+ value opt_space { result = {val[0].downcase.to_sym => val[4]} }
54
+ ;
55
+
56
+ assignment_lhs : WORD
57
+ ;
58
+
59
+ value : LBRACE value_content RBRACE { result = val[1] }
60
+ | SINGLE_ANFZ value_content_single_del SINGLE_ANFZ { result = val[1] }
61
+ | DOUBLE_ANFZ value_content_double_del DOUBLE_ANFZ { result = val[1] }
62
+ | WORD
63
+ ;
64
+
65
+ value_content_single_del : { result = "" }
66
+ | value_content SPACE { result << val[1] }
67
+ | value_content WORD { result << val[1] }
68
+ | value_content COMMA { result << val[1] }
69
+ /* | value_content "\\" SINGLE_ANFZ { result << val[1] << val[2]} */
70
+ | value_content DOUBLE_ANFZ { result << val[1] }
71
+ | value_content CHARACTER { result << val[1] }
72
+ | value_content AT { result << val[1] }
73
+ | value_content LBRACE { result << val[1] }
74
+ | value_content RBRACE { result << val[1] }
75
+ ;
76
+
77
+ value_content_double_del : { result = "" }
78
+ | value_content SPACE { result << val[1] }
79
+ | value_content WORD { result << val[1] }
80
+ | value_content COMMA { result << val[1] }
81
+ | value_content SINGLE_ANFZ { result << val[1] }
82
+ /* | value_content "\\" DOUBLE_ANFZ { result << val[1] << val[2] } */
83
+ | value_content CHARACTER { result << val[1] }
84
+ | value_content AT { result << val[1] }
85
+ | value_content LBRACE { result << val[1] }
86
+ | value_content RBRACE { result << val[1] }
87
+ ;
88
+
89
+ value_content : { result = "" }
90
+ | value_content SPACE { result << val[1] }
91
+ | value_content WORD { result << val[1] }
92
+ | value_content COMMA { result << val[1] }
93
+ | value_content SINGLE_ANFZ { result << val[1] }
94
+ | value_content DOUBLE_ANFZ { result << val[1] }
95
+ | value_content CHARACTER { result << val[1] }
96
+ | value_content AT { result << val[1] }
97
+ | value_content
98
+ LBRACE value_content RBRACE { result << val[1] << val[2] << val[3] }
99
+ ;
100
+
101
+ opt_space :
102
+ | SPACE
103
+ ;
104
+
105
+ end
106
+
107
+
108
+ ---- header ----
109
+
110
+ module BibTeX
111
+ Entry = Struct.new(:type, :key, :properties)
112
+ end
113
+
114
+ ---- inner ----
115
+
116
+ def report(*args)
117
+ p args
118
+ end
119
+
120
+ def parse( str )
121
+ @q = []
122
+
123
+ @yydebug = true
124
+
125
+ while str.size > 0 do
126
+ case str
127
+ when /\A[\t\n\s]+/o
128
+ @q.push [:SPACE, $&]
129
+ when /\ACOMMENT/o
130
+ @q.push [:COMMENT, $&]
131
+ when /\A\,/o
132
+ @q.push [:COMMA, $&]
133
+ when /\A@/o
134
+ @q.push [:AT, $&]
135
+ when /\A\{/o
136
+ @q.push [:LBRACE, $&]
137
+ when /\A\}/o
138
+ @q.push [:RBRACE, $&]
139
+ when /\A\=/o
140
+ @q.push [:EQUALS, $&]
141
+ when /\A\'/o
142
+ @q.push [:SINGLE_ANFZ, $&]
143
+ when /\A\"/o
144
+ @q.push [:DOUBLE_ANFZ, $&]
145
+ when /\A\w+/o
146
+ @q.push [:WORD, $&]
147
+ when /\A./o
148
+ @q.push [:CHARACTER, $&]
149
+ when /\A\d+/o
150
+ @q.push [:NUMBER, $&.to_i]
151
+ end
152
+ str = $'
153
+ end
154
+ @q.push [false, '$end']
155
+
156
+ do_parse
157
+ end
158
+
159
+ def next_token
160
+ @q.shift
161
+ end
162
+
163
+
164
+ ---- footer ----
data/papers.bib ADDED
@@ -0,0 +1,199 @@
1
+
2
+ @InProceedings{DBLP:conf/iccv/WangA03,
3
+ Author = {Hongcheng Wang and Narendra Ahuja},
4
+ Title = {Facial Expression Decomposition},
5
+ BookTitle = {ICCV},
6
+ Pages = {958-965},
7
+ note = {Using a 2D Deformable Face Model they do a HOSVD used
8
+ to decompose a Tensor like in
9
+ \ref{vlasic05:multilinear}. Sped up HOSVD by PCA to
10
+ reduce dimensionality of face description. },
11
+ ps = {local/iccv03_facial.ps.gz},
12
+ year = 2003
13
+ }
14
+
15
+ @InProceedings{DBLP:conf/cvpr/KolmogorovCBCR05,
16
+ Author = {Vladimir Kolmogorov and Antonio Criminisi and Andrew
17
+ Blake and Geoff Cross and Carsten Rother},
18
+ Title = {Bi-Layer Segmentation of Binocular Stereo Video.},
19
+ BookTitle = {CVPR (2)},
20
+ Pages = {407-414},
21
+ pdf = {local/Criminisi_cvpr2005.pdf},
22
+ year = 2005
23
+ }
24
+
25
+ @Proceedings{DBLP:conf/cvpr/2005,
26
+ Title = {2005 IEEE Computer Society Conference on Computer
27
+ Vision and Pattern Recognition (CVPR 2005), 20-26 June
28
+ 2005, San Diego, CA, USA},
29
+ Publisher = {IEEE Computer Society},
30
+ booktitle = {CVPR},
31
+ isbn = {0-7695-2372-2},
32
+ year = 2005
33
+ }
34
+
35
+ @InProceedings{WangCGF04,
36
+ Author = "Yang Wang and Xiaolei Huang and Chan-Su Lee and Song Zhang and
37
+ Zhiguo Li and Dimitris Samaras and Dimitris Metaxas and Ahmed
38
+ Elgammal and Peisen Huang",
39
+ Title = "High Resolution Acquisition, Learning and Transfer of
40
+ Dynamic 3-D Facial Expressions",
41
+ BookTitle = "Computer Graphics Forum",
42
+ Pages = "III: 677-686",
43
+ Note = {Mapping 3D Scans expression trajectories onto a low
44
+ dimensional manifold -> warping the manifolds of the
45
+ same expression of different people into the same shape
46
+ -> Learning mappings from the warped manifolds to the
47
+ original high-dimensional manifolds. They claim that
48
+ the warped manifolds contain the essence of a smile,
49
+ while the mapping function contains the person specific
50
+ style. Their morphs are not very convincing, the
51
+ intermediate faces are not mixtures of the original
52
+ faces. Maybe because of the nonlinearity of the model
53
+ and the linear warping.},
54
+ year = 2004,
55
+ pdf = {local/hr_transfer/paper1044.pdf}
56
+ }
57
+
58
+ @InProceedings{946637,
59
+ Author = {A. Criminisi and J. Shotton and A. Blake and P. H. S.
60
+ Torr},
61
+ Title = {Gaze Manipulation for One-to-one Teleconferencing},
62
+ BookTitle = {ICCV '03: Proceedings of the Ninth IEEE International
63
+ Conference on Computer Vision},
64
+ Pages = {191},
65
+ Address = {Washington, DC, USA},
66
+ Publisher = {IEEE Computer Society},
67
+ isbn = {0-7695-1950-4},
68
+ pdf = {local/criminisi_iccv03.pdf},
69
+ year = 2003
70
+ }
71
+
72
+ @InProceedings{blanz03:component_based,
73
+ Author = {Jennifer Huang and Bernd Heisele and Volker Blanz},
74
+ Title = {Component-based Face Recognition with 3D Morphable
75
+ Models},
76
+ BookTitle = {International Conference on Audio- and Video-Based
77
+ Biometric Person Authentication (AVBPA-03)},
78
+ Editor = {Kittler, Josef and Nixon, Mark S.},
79
+ Volume = {2688},
80
+ Number = {-},
81
+ Series = {Lecture Notes in Computer Science},
82
+ Pages = {27--34},
83
+ Address = {Surrey, UK},
84
+ Publisher = {Springer},
85
+ Note = {},
86
+ pdf = {local/avbpa2003.pdf},
87
+ year = 2003
88
+ }
89
+
90
+ @Article{vlasic05:multilinear,
91
+ Author = {Daniel Vlasic and Matthew Brand and Hanspeter Pfister
92
+ and Jovan Popovi{'c}},
93
+ Title = {Face transfer with multilinear models},
94
+ Journal = {ACM Trans. Graph.},
95
+ Volume = {24},
96
+ Number = {3},
97
+ Pages = {426--433},
98
+ address = {New York, NY, USA},
99
+ doi = {http://doi.acm.org/10.1145/1073204.1073209},
100
+ issn = {0730-0301},
101
+ note = {Quite similar to the approach in Basel, but with
102
+ multilinear models based on tensor decomposition. Quite
103
+ good results with only a few example images. Inputation
104
+ of missing datasets. },
105
+ pdf = {local/face_transfer/vlasic-2005-ftm.pdf},
106
+ publisher = {ACM Press},
107
+ year = 2005
108
+ }
109
+
110
+ @InProceedings{HuangANM04,
111
+ Author = "Xiaolei Huang and Song Zhang and Yang Wang and Dimitris
112
+ Metaxas and Dimitris Samaras",
113
+ Title = "A Hierarchical Framework for Hight Resolution Facial
114
+ Expression Tracking",
115
+ BookTitle = "IEEE Workshop on Articulated and Nonridgid Motion",
116
+ Pages = "22",
117
+ Note = {Detailed high framerate aquisition of frontal mesh and
118
+ texture data of faces using structured light. Tracking
119
+ of correspondences along frames by a simple two step
120
+ algorithm. First fitting of coarse mesh using a
121
+ gradient descent algorithms where source surface points
122
+ move to the closest target surface point, then bspline
123
+ deformation of fine mesh initialized bu coarse mesh.},
124
+ pdf = {local/anm04-face-tracking.pdf},
125
+ year = 2004
126
+ }
127
+
128
+ @Proceedings{DBLP:conf/iccv/2003,
129
+ Title = {9th IEEE International Conference on Computer Vision
130
+ (ICCV 2003), 14-17 October 2003, Nice, France},
131
+ Publisher = {IEEE Computer Society},
132
+ isbn = {0-7695-1950-4},
133
+ year = 2003
134
+ }
135
+
136
+ @Article{Perez03a,
137
+ Author = {P�rez, P. and Gangnet, M. and Blake, A.},
138
+ Title = {Poisson image editing},
139
+ Journal = {ACM Transactions on Graphics (SIGGRAPH'03)},
140
+ Volume = {22},
141
+ Number = {3},
142
+ Pages = {313--318},
143
+ pdf = {local/perez_siggraph03.pdf},
144
+ year = 2003
145
+ }
146
+
147
+ @InProceedings{BlaBasVetPog2003,
148
+ Author = {Volker Blanz and Curzio Basso and Thomas Vetter and
149
+ Tomaso Poggio},
150
+ Title = {Reanimating Faces in Images and Video},
151
+ BookTitle = {EUROGRAPHICS 2003 (EUROGRAPHICS-03) : the European
152
+ Association for Computer Graphics, 24th Annual
153
+ Conference},
154
+ Editor = {Brunet, Pere and Fellner, Dieter W.},
155
+ Volume = {22},
156
+ Number = {3},
157
+ Series = {Computer Graphics Forum},
158
+ Pages = {641--650},
159
+ Address = {Granada, Spain},
160
+ Organization = {The Eurographics Association},
161
+ Publisher = {Blackwell},
162
+ Note = {Lineares Modell mit Visemen fuer den Mundebereich.
163
+ Keine Koartikulation. The Morphable model with tracking
164
+ and inpainting.},
165
+ isbn = {0167-7055},
166
+ pdf = {local/blanz_eg03.pdf},
167
+ year = 2003
168
+ }
169
+
170
+ @PhdThesis{romdhani05:mff,
171
+ Author = {Sami Romdhani},
172
+ Title = {Face Image Analysis using a Multiple Feature Fitting
173
+ Strateg},
174
+ School = {University of basel},
175
+ pdf = {local/romdhani_thesis.pdf},
176
+ year = 2005
177
+ }
178
+
179
+ @InProceedings{goecke05:trends,
180
+ title = {Current Trends in Joint Audio-Video Signal Processing: A Review},
181
+ Author = {Roland G�cke},
182
+ Address = {Sydney, Australia},
183
+ BookTitle = {Proceedings of the IEEE 8th International Symposium on Signal Processing and Its Applications ISSPA 2005},
184
+ pages = {70--73},
185
+ year = 2005,
186
+ Organization = {IEEE},
187
+ note = {A short overview of applications and methods for lip tracking, automated speech recogniton, person recogniton, etc. Pointers to databases with joint AV material and relevant Publications.}
188
+ }
189
+
190
+ @Article{seyadarabi:facial,
191
+ title = {Facial Expressions Animation and Lip Tracking Using Facial Characteristic Points and Deformable Model},
192
+ Journal = {International Journal of Information Technology},
193
+ VOLUME = 1 ,
194
+ NUMBER = 4 ,
195
+ year = 2004 ,
196
+ ISSN = {1305-239X},
197
+ Author = {Hadi Seyedarabi and Ali Aghagolzadeh and Sohrab Khanmohammadi},
198
+ note = {Written in very bad english and does not contain too much information. They track feature points in 2D video data using optical flow and use these points to interpolate a triangle mesh. They claim to have a muscle-based model, but that shows nowhere.}
199
+ }