Class: MathMetadata::CEDRAM

Inherits:
Site
  • Object
show all
Defined in:
lib/math_metadata_lookup/sites/cedram.rb

Overview

NUMDAM numdam.org/

Constant Summary collapse

ID =
:cedram
NAME =
"CEDRAM"
URL =
"http://cedram.org/"
AUTHOR_URL =

AUTHOR_URL % “Author, Name”

%~~
AUTHORS_RE =
%r{}mi
AUTHOR_RE =
%r{}mi
ARTICLE_ID_URL =
"http://aif.cedram.org/aif-bin/item?id=%s"
ARTICLE_ID_AFST_URL =
"http://afst.cedram.org/afst-bin/item?id=%s"
ARTICLE_URL =
"http://www.cedram.org/cedram-bin/search?ti=%s&au=%s&py1=%s&lang=en"
LIST_OF_ARTICLES_RE =

ARTICLE_URL = “www.cedram.org/cedram-bin/search

%r{matches(.*?)</td>}mi
ARTICLE_ENTRY_RE =
%r{<a href=".*?id=([^"]+)">Details</a>}mi
ARTICLE_ID_RE =
%r{<input type="hidden" name="id" value="([^"]+)" />}mi
ARTICLE_TITLE_RE =
%r{<span class="atitle">(.*?)</span>}mi
ARTICLE_LANGUAGE_RE =
%r{xxxxxxxxxxxxxxx}mi
ARTICLE_AUTHORS_RE =
%r{<hr />(<a.*?)<br />}mi
ARTICLE_AUTHOR_RE =
%r{<a.*?>(.*?)</a>}mi
ARTICLE_MSCS_RE =
%r{Class. Math.:(.*?)<br}mi
ARTICLE_MSC_RE =
%r{([^,]+),?\s*}mi
ARTICLE_PUBLICATION_RE =
%r{(<span class="jtitle">.*?</span>,\s*<a href="http://aif.cedram.org:80/aif-bin/get\?id=[^"]+">\d+</a>\s*no\.\s*<a href="http://aif.cedram.org:80/aif-bin/browse\?id=[^"]+">\d+</a>\s*\(<a href="http://aif.cedram.org:80/aif-bin/get\?id=[^"]+">\d+</a>\))}mi
ARTICLE_PUBLISHER_RE =
%r{xxxxxxxxxxxxxxxxx}mi
ARTICLE_RANGE_RE =
%r{(\d+\-\d+)\s*<br\s*/>\s*Article}mi
ARTICLE_YEAR_RE =
%r{<span class="jtitle">.*?</span>,\s*<a href="http://aif.cedram.org:80/aif-bin/get\?id=[^"]+">\d+</a>\s*no\.\s*<a href="http://aif.cedram.org:80/aif-bin/browse\?id=[^"]+">\d+</a>\s*\(<a href="http://aif.cedram.org:80/aif-bin/get\?id=[^"]+">(\d+)</a>\)}mi
ARTICLE_ISSNS_RE =
%r{xxxxxxxxxxxxxxxxx}mi
ARTICLE_ISSN_RE =
%r{xxxxxxxxxxxxxxxxx}mi
ARTICLE_KEYWORDS_RE =
%r{Keywords:(.*?)<div}mi
ARTICLE_KEYWORD_RE =
%r{([^,]+),?\s*}mi
ARTICLE_REFERENCES_RE =
%r{<P>\s*<B>\s*Bibliography\s*</B>\s*</P>\s*</DIV>\s*(.*?)\s*</td>}mi
ARTICLE_REFERENCE_RE =
%r{\[\d+\]\s*(.*?)(?:(?:<BR>)|(?:<br\s*/>)|(?:</div>))}mi

Instance Method Summary collapse

Methods inherited from Site

#article, #author, inherited, #initialize, #to_json

Constructor Details

This class inherits a constructor from MathMetadata::Site

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class MathMetadata::Site

Instance Method Details

#fetch_article(args = {}) ⇒ Object



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
# File 'lib/math_metadata_lookup/sites/cedram.rb', line 101

def fetch_article( args={} )
  opts = {:id => nil, :title => "", :year => "", :authors => []}.merge(args)
  url = ""
  unless opts[:id].to_s.strip.empty?
    pattern = self.class::ARTICLE_ID_URL
    pattern = self.class::ARTICLE_ID_AFST_URL if opts[:id] =~ /^AFST/mi
    url = pattern % URI.escape(opts[:id].to_s.strip)
  end
  form = {'submit' => " Start search "}
  if opts[:id].to_s.strip.empty?
    author =  opts[:authors]
    title = opts[:title]
    title = '' if not title.kind_of?(String)
    title = MathMetadata.normalize_text(title)
    title = nwords(title) if @options[:nwords]

    form['ti'] = title
    form['au'] = author unless author.empty?
    form['py1'] = opts[:year].to_s
    form['py2'] = ""
    form['pages'] = ""
    form['bibitems_text'] = ""
    form['maxdocs'] = "300"
    form['format'] = "short"
    form['ti_op'] = "and"
    form["au_op"] = "and"
    form["bibitems.text_op"] = "and"

    url = build_article_url title, author, opts[:year].to_s
  else
    return fetch_page(url, opts)
  end
  
  uri = URI.parse(url)
  puts uri if opts[:verbose]
  req = Net::HTTP::Post.new(uri.path, {
    'Host' => "www.cedram.org",
    'User-Agent'=> "Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20110429 Firefox/4.0.1",
    'Accept' => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    'Accept-Language' => "cs,en;q=0.7,en-us;q=0.3",
    'Accept-Encoding' => "gzip, deflated",
    'Accept-Charset' => "UTF-8,*",
    'Keep-Alive' => "115",
    'Connection' => "keep-alive",
    'Referer' => "http://www.cedram.org/cedram-bin/search",
    'Content-Type' => "application/x-www-form-urlencoded",
  })
  req.set_form_data(form)
  http = Net::HTTP.new(uri.host, uri.port)
  resp = http.request(req)
  page = normalize_page resp.body
  page
end

#get_article_publication(page) ⇒ Object



48
49
50
51
52
# File 'lib/math_metadata_lookup/sites/cedram.rb', line 48

def get_article_publication( page )
  page =~ ARTICLE_PUBLICATION_RE
  return nil unless $1
  $1.gsub(/<.*?>/, '')
end

#get_article_references(page) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
# File 'lib/math_metadata_lookup/sites/cedram.rb', line 54

def get_article_references( page )
  references = []

  refs = get_article_reference_s page

  i = 0;
  refs.each do |r|
    i+=1
    r.gsub!(/\r|\n/, ' ')
    r.gsub!(/ +/,' ')
    ref = Reference.new nil, i
    ref.source = r
    ref.article = Article.new

    r =~ %r{<span class="(?:atitle|btitre)">(.*?)</span>}im
    ref.article.title = $1.to_s.strip

    ref.article.authors = []
    r.split(%r{<span class="bauteur">\s?(.*?)\s*</span>}).each do |a|
      next if a.strip.empty? or a.strip == "-" or [',', '&'].include?(a.strip[0,1])
      author = a.gsub /<.*?>/, ''
      ref.article.authors << author
    end

    r =~ %r{<span class="(?:brevue|bjournal)">(.*?)</span>}mi
    ref.article.publication = $1.strip if $1

=begin
    r =~ %r{<bediteur>(.*?)</bediteur>}mi
    ref.article.publisher = $1.strip if $1

    r =~ %r{<blieued>(.*?)</blieued>}mi
    ref.article.place = $1.strip if $1
=end
    r =~ %r{(\d\d\d\d)}mi
    ref.article.year = $1.strip if $1

    r =~ %r{(\d+)\-(\d+)}mi
    ref.article.range = "#{$1.strip}-#{$2.strip}" if $1

    references << ref
  end

  references
end