Class: SiSU_AO_References::Bibliography

Inherits:
Object
  • Object
show all
Defined in:
lib/sisu/ao_references.rb

Instance Method Summary collapse

Constructor Details

#initialize(md, data) ⇒ Bibliography

Returns a new instance of Bibliography.



59
60
61
# File 'lib/sisu/ao_references.rb', line 59

def initialize(md,data)
  @md,@data=md,data
end

Instance Method Details

#articleObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/sisu/ao_references.rb', line 71

def article
  {
     is:         :article,
     author_raw: nil,
     author:     nil,
     author_arr: nil,
     title:      nil,
     language:   nil,
     journal:    nil,
     volume:     nil,
     editor:     nil,
     year:       nil,
     where:      nil,
     url:        nil,
     note:       nil,
     short_name: nil,
     id:         nil,
  }
end

#biblio_extractionObject



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/sisu/ao_references.rb', line 202

def biblio_extraction
  bibliography=[]
  biblioflag=false
  code_flag=false
  flag_code_curly=:not_code_curly
  flag_code_tics=:not_code_tics
  @data=@data.select do |t_o|
    if t_o =~/^code\{/
      flag_code_curly=:code_curly
    elsif t_o =~/^\}code/
      flag_code_curly=:not_code_curly
    elsif t_o =~/^``` code/
      flag_code_tics=:code_tics
    elsif flag_code_tics ==:code_tics \
    and t_o =~/^```/
      flag_code_tics=:not_code_tics
    end
    code_flag=if flag_code_curly==:code_curly \
    or flag_code_tics==:code_tics
      true
    else false
    end
    unless code_flag
      if @md.flag_auto_biblio
        if t_o =~/^1~biblio(?:graphy)?/
          biblioflag = true
          t_o
        elsif t_o =~/^:?[B-D1]~/
          biblioflag = false
          t_o
        elsif biblioflag
          if t_o !~/\A%+ /
            bibliography << citation_in_prepared_bibliography(t_o).
            next
          else
            t_o
          end
        else t_o
        end
      elsif @md.flag_biblio
        if t_o =~/^1~biblio(?:graphy)?/
          biblioflag = true
          next
        elsif t_o =~/^:?[B-D]~/
          next
        elsif t_o =~/^:?[B-D1]~/
          biblioflag = false
          t_o
        elsif biblioflag
          if t_o !~/\A%+ /
            bibliography << t_o
            next
          else
            t_o
          end
        else t_o
        end
      else t_o
      end
    else t_o
    end
  end.compact
  if @md.flag_auto_biblio \
  and bibliography.length > 0
    data_new=[]
    bibliography=sort_bibliography_array_by_author_year_title(bibliography)
    @data.select do |t_o|
      if t_o =~/^1~biblio(?:graphy)?/
        bibliography.each do  |c|
          if c[:is]==:book
            <<-WOK

!_ #{c[:author]}
/{"#{c[:fulltitle]}"}/ #{c[:publisher]} (#{c[:year]})
            WOK
          elsif c[:is]==:article
            <<-WOK

!_ #{c[:author]}
/{"#{c[:title]}"}/ #{c[:journal]} (#{c[:year]})
            WOK
          end
        end
      else data_new << t_o
      end
    end
    @data=data_new
  end
  [@data,bibliography]
end

#bookObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/sisu/ao_references.rb', line 90

def book
  {
     is:         :book,
     author_raw: nil,
     author:     nil,
     author_arr: nil,
     #editor:     nil,
     title:      nil,
     subtitle:   nil,
     fulltitle:  nil,
     language:   nil,
     publisher:  nil,
     edition:    nil,
     year:       nil,
     where:      nil,
     url:        nil,
     note:       nil,
     short_name: nil,
     id:         nil,
  }
end

#citation_in_prepared_bibliography(cite) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/sisu/ao_references.rb', line 69

def citation_in_prepared_bibliography(cite)
  @cite=cite
  def article
    {
       is:         :article,
       author_raw: nil,
       author:     nil,
       author_arr: nil,
       title:      nil,
       language:   nil,
       journal:    nil,
       volume:     nil,
       editor:     nil,
       year:       nil,
       where:      nil,
       url:        nil,
       note:       nil,
       short_name: nil,
       id:         nil,
    }
  end
  def book
    {
       is:         :book,
       author_raw: nil,
       author:     nil,
       author_arr: nil,
       #editor:     nil,
       title:      nil,
       subtitle:   nil,
       fulltitle:  nil,
       language:   nil,
       publisher:  nil,
       edition:    nil,
       year:       nil,
       where:      nil,
       url:        nil,
       note:       nil,
       short_name: nil,
       id:         nil,
    }
  end
  def 
    type=if @cite =~/^jo: \S+/m
      :article
    elsif @cite =~/^au: \S+/m
      :book
    end
    if type
      citeblock=@cite.split("\n")
      if type == :article
        citation=article
        citeblock.select do |meta|
          case meta
          when /^((?:au|author):\s+)\S+/ #req
            citation[:author_raw]=/^#{$1}(.+)/.match(meta)[1]
          when /^((?:ti|title):\s+)\S+/ #req
            citation[:title]=/^#{$1}(.+)/.match(meta)[1]
          when /^((?:lng|language):\s+)\S+/
            citation[:language]=/^#{$1}(.+)/.match(meta)[1]
          when /^((?:jo|journal):\s+)\S+/ #req?
            citation[:journal]=/^#{$1}(.+)/.match(meta)[1]
          when /^((?:vo|volume):\s+)\S+/
            citation[:volume]=/^#{$1}(.+)/.match(meta)[1]
          when /^((?:edr|editor):\s+)\S+/
            citation[:editor]=/^#{$1}(.+)/.match(meta)[1]
          when /^((?:yr|year):\s+)\S+/ #req?
            citation[:year]=/^#{$1}(.+)/.match(meta)[1]
          when /^((?:pst|publisher_state):\s+)\S+/
            citation[:where]=/^#{$1}(.+)/.match(meta)[1]
          when /^(url:\s+)\S+/
            citation[:url]=/^#{$1}(.+)/.match(meta)[1]
          when /^(note:\s+)\S+/
            citation[:note]=/^#{$1}(.+)/.match(meta)[1]
          when /^((?:sn|shortname):\s+)\S+/
            citation[:short_name]=/^#{$1}(.+)/.match(meta)[1]
          when /^(id:\s+)\S+/
            citation[:id]=/^#{$1}(.+)/.match(meta)[1]
          end
        end
      end
      if type == :book
        citation=book
        citeblock.select do |meta|
          case meta
          when /^((?:au|author):\s+)\S+/ #req
            citation[:author_raw]=/^#{$1}(.+)/.match(meta)[1]
          when /^((?:ti|title):\s+)\S+/ #req
            citation[:title]=/^#{$1}(.+)/.match(meta)[1]
          when /^((?:st|subtitle):\s+)\S+/
            citation[:subtitle]=/^#{$1}(.+)/.match(meta)[1]
          when /^((?:lng|language):\s+)\S+/
            citation[:language]=/^#{$1}(.+)/.match(meta)[1]
          when /^((?:pb|publisher):\s+)\S+/
            citation[:publisher]=/^#{$1}(.+)/.match(meta)[1]
          when /^((?:edn|edition):\s+)\S+/
            citation[:edition]=/^#{$1}(.+)/.match(meta)[1]
          when /^((?:yr|year):\s+)\S+/ #req?
            citation[:year]=/^#{$1}(.+)/.match(meta)[1]
          when /^((?:pst|publisher_state):\s+)\S+/
            citation[:where]=/^#{$1}(.+)/.match(meta)[1]
          when /^(url:\s+)\S+/
            citation[:url]=/^#{$1}(.+)/.match(meta)[1]
          when /^(note:\s+)\S+/
            citation[:note]=/^#{$1}(.+)/.match(meta)[1]
          when /^((?:sn|shortname):\s+)\S+/
            citation[:short_name]=/^#{$1}(.+)/.match(meta)[1]
          when /^(id:\s+)\S+/
            citation[:id]=/^#{$1}(.+)/.match(meta)[1]
          end
        end
      end
      if citation[:is]==:book
        if citation[:subtitle]
          citation[:fulltitle] = citation[:title] \
          + ' - ' \
          + citation[:subtitle]
        else
          citation[:fulltitle] = citation[:title]
        end
      end
      citation[:author_arr]=citation[:author_raw].split(/;\s*/)
      citation[:author]=citation[:author_arr].map do |author|
        author.gsub(/(.+?),\s+(.+)/,'\2 \1').strip
      end.join(', ').strip
      unless citation[:short_name]
        citation[:short_name]=%{#{c[:author]}, "#{c[:short_name]}" (#{c[:date]})}
      end
    end
    citation
  end
  self
end

#citation_metadataObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/sisu/ao_references.rb', line 111

def 
  type=if @cite =~/^jo: \S+/m
    :article
  elsif @cite =~/^au: \S+/m
    :book
  end
  if type
    citeblock=@cite.split("\n")
    if type == :article
      citation=article
      citeblock.select do |meta|
        case meta
        when /^((?:au|author):\s+)\S+/ #req
          citation[:author_raw]=/^#{$1}(.+)/.match(meta)[1]
        when /^((?:ti|title):\s+)\S+/ #req
          citation[:title]=/^#{$1}(.+)/.match(meta)[1]
        when /^((?:lng|language):\s+)\S+/
          citation[:language]=/^#{$1}(.+)/.match(meta)[1]
        when /^((?:jo|journal):\s+)\S+/ #req?
          citation[:journal]=/^#{$1}(.+)/.match(meta)[1]
        when /^((?:vo|volume):\s+)\S+/
          citation[:volume]=/^#{$1}(.+)/.match(meta)[1]
        when /^((?:edr|editor):\s+)\S+/
          citation[:editor]=/^#{$1}(.+)/.match(meta)[1]
        when /^((?:yr|year):\s+)\S+/ #req?
          citation[:year]=/^#{$1}(.+)/.match(meta)[1]
        when /^((?:pst|publisher_state):\s+)\S+/
          citation[:where]=/^#{$1}(.+)/.match(meta)[1]
        when /^(url:\s+)\S+/
          citation[:url]=/^#{$1}(.+)/.match(meta)[1]
        when /^(note:\s+)\S+/
          citation[:note]=/^#{$1}(.+)/.match(meta)[1]
        when /^((?:sn|shortname):\s+)\S+/
          citation[:short_name]=/^#{$1}(.+)/.match(meta)[1]
        when /^(id:\s+)\S+/
          citation[:id]=/^#{$1}(.+)/.match(meta)[1]
        end
      end
    end
    if type == :book
      citation=book
      citeblock.select do |meta|
        case meta
        when /^((?:au|author):\s+)\S+/ #req
          citation[:author_raw]=/^#{$1}(.+)/.match(meta)[1]
        when /^((?:ti|title):\s+)\S+/ #req
          citation[:title]=/^#{$1}(.+)/.match(meta)[1]
        when /^((?:st|subtitle):\s+)\S+/
          citation[:subtitle]=/^#{$1}(.+)/.match(meta)[1]
        when /^((?:lng|language):\s+)\S+/
          citation[:language]=/^#{$1}(.+)/.match(meta)[1]
        when /^((?:pb|publisher):\s+)\S+/
          citation[:publisher]=/^#{$1}(.+)/.match(meta)[1]
        when /^((?:edn|edition):\s+)\S+/
          citation[:edition]=/^#{$1}(.+)/.match(meta)[1]
        when /^((?:yr|year):\s+)\S+/ #req?
          citation[:year]=/^#{$1}(.+)/.match(meta)[1]
        when /^((?:pst|publisher_state):\s+)\S+/
          citation[:where]=/^#{$1}(.+)/.match(meta)[1]
        when /^(url:\s+)\S+/
          citation[:url]=/^#{$1}(.+)/.match(meta)[1]
        when /^(note:\s+)\S+/
          citation[:note]=/^#{$1}(.+)/.match(meta)[1]
        when /^((?:sn|shortname):\s+)\S+/
          citation[:short_name]=/^#{$1}(.+)/.match(meta)[1]
        when /^(id:\s+)\S+/
          citation[:id]=/^#{$1}(.+)/.match(meta)[1]
        end
      end
    end
    if citation[:is]==:book
      if citation[:subtitle]
        citation[:fulltitle] = citation[:title] \
        + ' - ' \
        + citation[:subtitle]
      else
        citation[:fulltitle] = citation[:title]
      end
    end
    citation[:author_arr]=citation[:author_raw].split(/;\s*/)
    citation[:author]=citation[:author_arr].map do |author|
      author.gsub(/(.+?),\s+(.+)/,'\2 \1').strip
    end.join(', ').strip
    unless citation[:short_name]
      citation[:short_name]=%{#{c[:author]}, "#{c[:short_name]}" (#{c[:date]})}
    end
  end
  citation
end

#sort_bibliography_array_by_author_year_title(bib) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/sisu/ao_references.rb', line 62

def sort_bibliography_array_by_author_year_title(bib)
  if bib
    bib.compact.sort_by do |c|
      [c[:author_arr][0],c[:year],c[:title]]
    end
  end
end