Class: Semantic_Scholar_Paper

Inherits:
Sequel::Model
  • Object
show all
Defined in:
model/semantic_scholar_paper.rb

Overview

Class to store Semantic_Scholar_Paper

Class Method Summary collapse

Class Method Details

.add_from_json(json, doi = nil) ⇒ Object



47
48
49
50
51
52
53
54
# File 'model/semantic_scholar_paper.rb', line 47

def self.add_from_json(json,doi=nil)
  json_o=JSON.parse(json)
  ss=Semantic_Scholar_Paper[json_o["paperId"]]
  if !ss
    Semantic_Scholar_Paper.insert(:id => json_o["paperId"], :json => json , :doi => doi)
  end

end

.get(type, id) ⇒ Object

Obtain a tuple, using semantic_scholar_id or doi

Parameters:

  • typeor ('semantic_scholar_id''doi')

    ype ‘semantic_scholar_id’ or ‘doi’



35
36
37
38
39
40
41
42
43
44
# File 'model/semantic_scholar_paper.rb', line 35

def self.get(type, id)

  if type.to_s=='semantic_scholar_id'
    Semantic_Scholar_Paper[id]
  elsif type.to_s=='doi'
    Semantic_Scholar_Paper.where(:doi => id).first
  else
    raise Buhos::NoSemanticScholarMethodError, ::I18n.t("error.no_semantic_scholar_method", type:type)
  end
end

.get_abstract_cd(cd_id) ⇒ Object



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
99
100
101
102
103
104
105
# File 'model/semantic_scholar_paper.rb', line 56

def self.get_abstract_cd(cd_id)
  result=Result.new
  cd=CanonicalDocument[cd_id]
  doi=cd.doi
  #$log.info("Procesando scopus para CD:#{cd.id}")
  if cd.semantic_scholar_id
    type='semantic_scholar_id'
    id=cd.semantic_scholar_id
  elsif cd.doi
    type='doi'
    id=cd.doi
  else
    result.error(I18n::t("semantic_scholar_paper.cant_obtain_suitable_identificator", cd_title:cd[:title]))
    return result
  end


  sa=Semantic_Scholar_Paper.get(type, id)
  if !sa
    begin
      sr=SemanticScholar::Remote.new
      json=sr.json_by_id(id, type)
    rescue SocketError => e
      json=false
      sr=OpenStruct.new
      sr.error=e.message
    end

    if json
      add_from_json(json, doi)
      json_o=JSON.parse(json)
    else
      result.error(I18n::t("semantic_scholar_paper.cant_obtain_semantic_scholar_error", cd_title:cd[:title], sr_error: sr.error))
      return result
    end
  else
    json_o=JSON.parse(sa[:json])
  end



  if json_o["abstract"].to_s==""
    result.error(I18n::t("semantic_scholar_paper.no_semantic_scholar_abstract",cd_title:cd[:title]))
  elsif cd.abstract.to_s==""
    cd.update(:abstract => json_o["abstract"], :semantic_scholar_id=> json_o["paperId"])
    result.success(I18n::t("semantic_scholar_paper.updated_abstract",cd_title:cd[:title]))
  end

  result
end