Class: ElsevierApi::XMLResponse::Abstractsretrievalresponse
- Inherits:
-
XMLResponseGeneric
- Object
- XMLResponseGeneric
- ElsevierApi::XMLResponse::Abstractsretrievalresponse
- Defined in:
- lib/elsevier_api/xml_response/abstract_retrieval_response.rb
Constant Summary collapse
- NA_AFFILIATION =
"NAFD:**NA**"- NA_AFFILIATION_NAME =
"__No affiliation__"
Instance Attribute Summary collapse
-
#abstract ⇒ Object
readonly
Returns the value of attribute abstract.
-
#affiliations ⇒ Object
readonly
Returns the value of attribute affiliations.
-
#author_groups ⇒ Object
readonly
Returns the value of attribute author_groups.
-
#author_keywords ⇒ Object
readonly
Returns the value of attribute author_keywords.
-
#authors ⇒ Object
readonly
Returns the value of attribute authors.
-
#book_title ⇒ Object
readonly
Returns the value of attribute book_title.
-
#cited_by_count ⇒ Object
readonly
Returns the value of attribute cited_by_count.
-
#doi ⇒ Object
readonly
Returns the value of attribute doi.
-
#eid ⇒ Object
readonly
Returns the value of attribute eid.
-
#ending_page ⇒ Object
readonly
Returns the value of attribute ending_page.
-
#issue ⇒ Object
readonly
Returns the value of attribute issue.
-
#journal ⇒ Object
readonly
Returns the value of attribute journal.
-
#scopus_id ⇒ Object
readonly
Returns the value of attribute scopus_id.
-
#starting_page ⇒ Object
readonly
Returns the value of attribute starting_page.
-
#subject_areas ⇒ Object
readonly
Returns the value of attribute subject_areas.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#type_code ⇒ Object
readonly
Returns the value of attribute type_code.
-
#volume ⇒ Object
readonly
Returns the value of attribute volume.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Attributes inherited from XMLResponseGeneric
Instance Method Summary collapse
- #add_no_affiliation_case(auid) ⇒ Object
- #add_unidentified_affilitations ⇒ Object
- #get_affiliation_data(aff) ⇒ Object
- #get_affiliation_id(aff) ⇒ Object
-
#get_id_affiliation(name, city, country) ⇒ Object
Some affiliations doesn’t have an id.
- #inspect ⇒ Object
- #process ⇒ Object
- #process_affiliations ⇒ Object
-
#process_author_groups ⇒ Object
Author groups gives us information about the authors groups as appears on the head.
- #process_authors ⇒ Object
- #process_basic_metadata ⇒ Object
- #process_taxonomy ⇒ Object
-
#search_affiliation(afid) ⇒ Object
We can’t find the affiliation the ussual way we have to improvise Given the afid, we search on every <affiliation> tag until we find the desired one.
- #search_affiliation_country(id) ⇒ Object
-
#search_doi ⇒ Object
We have to find doi on.
Methods inherited from XMLResponseGeneric
Constructor Details
This class inherits a constructor from ElsevierApi::XMLResponse::XMLResponseGeneric
Instance Attribute Details
#abstract ⇒ Object (readonly)
Returns the value of attribute abstract.
52 53 54 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 52 def abstract @abstract end |
#affiliations ⇒ Object (readonly)
Returns the value of attribute affiliations.
51 52 53 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 51 def affiliations @affiliations end |
#author_groups ⇒ Object (readonly)
Returns the value of attribute author_groups.
56 57 58 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 56 def end |
#author_keywords ⇒ Object (readonly)
Returns the value of attribute author_keywords.
54 55 56 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 54 def end |
#authors ⇒ Object (readonly)
Returns the value of attribute authors.
45 46 47 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 45 def end |
#book_title ⇒ Object (readonly)
Returns the value of attribute book_title.
55 56 57 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 55 def book_title @book_title end |
#cited_by_count ⇒ Object (readonly)
Returns the value of attribute cited_by_count.
38 39 40 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 38 def cited_by_count @cited_by_count end |
#doi ⇒ Object (readonly)
Returns the value of attribute doi.
50 51 52 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 50 def doi @doi end |
#eid ⇒ Object (readonly)
Returns the value of attribute eid.
40 41 42 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 40 def eid @eid end |
#ending_page ⇒ Object (readonly)
Returns the value of attribute ending_page.
49 50 51 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 49 def ending_page @ending_page end |
#issue ⇒ Object (readonly)
Returns the value of attribute issue.
47 48 49 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 47 def issue @issue end |
#journal ⇒ Object (readonly)
Returns the value of attribute journal.
44 45 46 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 44 def journal @journal end |
#scopus_id ⇒ Object (readonly)
Returns the value of attribute scopus_id.
37 38 39 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 37 def scopus_id @scopus_id end |
#starting_page ⇒ Object (readonly)
Returns the value of attribute starting_page.
48 49 50 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 48 def starting_page @starting_page end |
#subject_areas ⇒ Object (readonly)
Returns the value of attribute subject_areas.
53 54 55 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 53 def subject_areas @subject_areas end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
39 40 41 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 39 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
42 43 44 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 42 def type @type end |
#type_code ⇒ Object (readonly)
Returns the value of attribute type_code.
41 42 43 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 41 def type_code @type_code end |
#volume ⇒ Object (readonly)
Returns the value of attribute volume.
46 47 48 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 46 def volume @volume end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
43 44 45 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 43 def year @year end |
Instance Method Details
#add_no_affiliation_case(auid) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 158 def add_no_affiliation_case(auid) id=NA_AFFILIATION+":"+Digest::MD5.hexdigest("#{@scopus_id}|#{auid}") @affiliations[id]={ :id => id, :name => "#{@scopus_id}|#{auid}", :city => "", :country => "NO_COUNTRY", :type=>:non_scopus } id end |
#add_unidentified_affilitations ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 142 def add_unidentified_affilitations xml.xpath("//bibrecord/head/author-group/affiliation").each do |aff| next if aff.attribute("afid") city, country, id, name = get_affiliation_data(aff) next if (name=="" and city=="" and country=="") @affiliations[id]={ :id => id, :name => name, :city => city, :country => country, :type=>:non_scopus } end end |
#get_affiliation_data(aff) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 169 def get_affiliation_data(aff) organization=aff.xpath("organization").map { |e| e.text }.join(";") address=aff.xpath("address-part").map { |e| e.text }.join(";") name= organization!="" ? organization : address city_only=aff.xpath("city").text city_part=aff.xpath("city-group").text city= city_only!="" ? city_only : city_part country=aff.xpath("country").text name="UNKOWN ORG FOR #{@scopus_id} ARTICLE" if name=="" country="NO_COUNTRY" if country=="" id=get_id_affiliation(name,city,country) return city, country, id, name end |
#get_affiliation_id(aff) ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 100 def get_affiliation_id(aff) if aff.nil? nil elsif id=aff.attribute('afid') id.value else city, country, id, name = get_affiliation_data(aff) id end end |
#get_id_affiliation(name, city, country) ⇒ Object
Some affiliations doesn’t have an id. We could create it hashing the name and the country on unidentified filliations on head tag The process only add the affiliation if name is not nil
139 140 141 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 139 def get_id_affiliation(name,city,country) "NS:"+Digest::MD5.hexdigest("#{name}|#{city}|#{country}") end |
#inspect ⇒ Object
57 58 59 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 57 def inspect "#<#{self.class}:#{self.object_id} @title=#{@title} @journal=#{@journal} @authors=[#{@authors.keys.join(",")}]>" end |
#process ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 60 def process ={} @affiliations={} =[] @subject_areas=[] =[] process_taxonomy process_affiliations end |
#process_affiliations ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 115 def process_affiliations xml.xpath("/xmlns:abstracts-retrieval-response/xmlns:affiliation").each do |x| id=x.attribute("id").nil? ? "" : x.attribute("id").value next if id=="" name=process_path(x, "xmlns:affilname") city=process_path(x, "xmlns:affiliation-city") country=process_path(x, "xmlns:affiliation-country") country=search_affiliation_country(id) if (country=="") @affiliations[id]={ :id => id, :name => name, :city => city, :country => country, :type=>:scopus } end add_unidentified_affilitations end |
#process_author_groups ⇒ Object
Author groups gives us information about the authors groups as appears on the head. Could be useful to retrieve information about missing affilitations Author-groups with authors duplicated are eliminated
190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 190 def =xml.xpath("//bibrecord/head/author-group").map do |ag| (ag) end #authors_list= [] = # @author_groups=[] # author_groups_temp.each do |ag| # @author_groups.push(ag) unless ag[:authors].any? {|author| authors_list.include? author} # authors_list=authors_list | ag[:authors] # end end |
#process_authors ⇒ Object
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 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 228 def xml.xpath("//xmlns:authors/xmlns:author").each do |x| auid=x.attribute("auid").value seq=x.attribute("seq").value initials =process_path(x, "xmlns:preferred-name/ce:initials") indexed_name = process_path(x, "xmlns:preferred-name/ce:indexed-name") given_name =process_path(x, "xmlns:preferred-name/ce:given-name") surname=process_path(x, "xmlns:preferred-name/ce:surname") affiliation=nil affiliation_node=x.xpath("xmlns:affiliation") if affiliation_node.length==1 affiliation=affiliation_node[0].attribute("id").text if !affiliation.nil? and @affiliations[affiliation].nil? @affiliations[affiliation]=search_affiliation(affiliation) end elsif affiliation_node.length>1 affiliation=affiliation_node.map{|af| af.attribute("id").text }.uniq affiliation.each do |af| if !af.nil? and @affiliations[af].nil? @affiliations[af]=search_affiliation(af) end end else # Must search in author-groups for affilitation res=.find{|ag| ag[:authors].include? auid } if res affiliation=res[:affiliation] end if affiliation.nil? # Affiliation shouldn't be nil. We create a custom affiliation for this cases affiliation=add_no_affiliation_case(auid) end # end #p "#{name} #{apellido}" [auid]={ :auid => auid, :seq => seq, :initials => initials, :indexed_name => indexed_name, :given_name => given_name, :surname => surname, :email => nil, :affiliation => affiliation } end # Searching for authors e-mails xml.xpath("//bibrecord//head//author-group/author//ce:e-address[@type='email']").each do |email| auid=email.parent.attribute("auid").value [auid][:email]=email.text end end |
#process_basic_metadata ⇒ Object
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 307 def @scopus_id = process_path(xml, "//dc:identifier") @title = process_path(xml, "//dc:title") @doi = process_path(xml, "//prism:doi") @doi||=search_doi @eid = process_path(xml, "//xmlns:eid") @type_code = process_path(xml, "//xmlns:srctype") @cited_by_count = process_path(xml,"//xmlns:citedby-count").to_i @type = process_path(xml, "//prism:aggregationType").downcase.to_sym if @type_code=="j" or @type_code=="p" @journal =process_path(xml, "//prism:publicationName") @volume =process_path(xml, "//prism:volume") @issue =process_path(xml, "//prism:issueIdentifier") elsif @type_code=="b" @book_title =process_path(xml, "//prism:publicationName") end @starting_page =process_path(xml, "//prism:startingPage") @ending_page =process_path(xml, "//prism:endingPage") @year =process_path(xml, "//year") @abstract =process_path(xml, "//dc:description/xmlns:abstract[@xml:lang='eng']/ce:para") @abstract ||=process_path(xml, "//abstract/ce:para") end |
#process_taxonomy ⇒ Object
293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 293 def process_taxonomy xml.xpath("//xmlns:authkeywords/xmlns:author-keyword").each do |x| .push(x.text) end xml.xpath("//xmlns:subject-areas/xmlns:subject-area").each do |x| @subject_areas.push( {:abbrev => x.attribute("abbrev").value, :code => x.attribute("code").value.to_i, :name => x.text } ) end end |
#search_affiliation(afid) ⇒ Object
We can’t find the affiliation the ussual way we have to improvise Given the afid, we search on every <affiliation> tag until we find the desired one
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 79 def search_affiliation(afid) x=xml.at_xpath("//affiliation[@afid=\"#{afid}\"]") if !x raise "I can't find affiliation #{afid}" else name=x.xpath("organization").map { |e| e.text }.join(";") city=process_path(xml, "//affiliation[@afid=\"#{afid}\"]/city-group") country=process_path(xml, "//affiliation[@afid=\"#{afid}\"]/country") country||=x.attribute("country").value end {:id => afid, :name => name, :city => city, :country => country,:type=>:scopus} end |
#search_affiliation_country(id) ⇒ Object
111 112 113 114 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 111 def search_affiliation_country(id) return nil if id.nil? process_path(xml, "//affiliation[@afid='#{id}']/country") end |
#search_doi ⇒ Object
We have to find doi on
93 94 95 96 97 98 |
# File 'lib/elsevier_api/xml_response/abstract_retrieval_response.rb', line 93 def search_doi if xml.at_xpath("//source").text=~/^\s*http:\/\/dx\.doi\.org\/([^\s]+)/ return $1 end end |