Class: LD4L::WorksRDF::WorkMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/ld4l/works_rdf/models/work_metadata.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(the_work = nil) ⇒ WorkMetadata

Returns a new instance of WorkMetadata.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 26

def initialize( the_work=nil )

  # displayable:
  #    line 1     @titla  @pubdate (year only)
  #    line 2     @author
  #    line 3     @format   @pub_info   @language   @edition
  #    line 4     @local_location   @local_callnumber
  # sortable:     @title, @author, @pub_date (year only)
  # facetable:    @format, @author, @pub_date (year_only), @language, @subject, @subject_region, @subject_era, @genre, @fiction_or_non, @local_location, @local_callnumber

  @work_type        = :UNKNOWN
  @rdf_types        = ""
  @uri              = ""    #             :displayable (used as URL for link)
  @model            = ""    #             :stored
  @title            = ""    #             :displayable, :searchable, :sortable
  @subtitle         = ""    #             :displayable, :searchable
  @author           = ""    # :facetable, :displayable, :searchable, :sortable
  @pub_date         = ""    # :facetable, :displayable,              :sortable   (year only)
  @pub_info         = ""    #             :displayable, :searchable
  @language         = ""    # :facetable, :displayable
  # @subject          = ""  # :facetable
  # @subject_region   = ""  # :facetable
  # @subject_era      = ""  # :facetable
  # @genre            = ""  # :facetable
  # @fiction_or_non   = ""  # :facetable
  @edition          = ""    #             :displayable
  @oclc_id          = ""    #             :displayable
  @source_id        = :UNKNOWN
  @source           = ""
  @local_id         = ""
  @local_location   = ""    # :facetable
  @local_callnumber = ""    # :facetable
  @format           = ""    # :facetable, :displayable
  @error            = false
  @error_message    = ""
  unless the_work.nil?
    @model = the_work
    @rdf_types = []
    the_work.type.each do |t|
      rdf_types << t.to_s
    end
  end
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



11
12
13
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 11

def author
  @author
end

#editionObject

Returns the value of attribute edition.



15
16
17
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 15

def edition
  @edition
end

#errorObject

attr_accessor :availability # TODO: for Cornell only???



23
24
25
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 23

def error
  @error
end

#error_messageObject

Returns the value of attribute error_message.



24
25
26
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 24

def error_message
  @error_message
end

#languageObject

Returns the value of attribute language.



14
15
16
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 14

def language
  @language
end

#local_callnumberObject

Returns the value of attribute local_callnumber.



21
22
23
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 21

def local_callnumber
  @local_callnumber
end

#local_idObject

Returns the value of attribute local_id.



19
20
21
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 19

def local_id
  @local_id
end

#local_locationObject

Returns the value of attribute local_location.



20
21
22
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 20

def local_location
  @local_location
end

#modelObject (readonly)

Returns the value of attribute model.



7
8
9
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 7

def model
  @model
end

#oclc_idObject

Returns the value of attribute oclc_id.



16
17
18
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 16

def oclc_id
  @oclc_id
end

#pub_dateObject

Returns the value of attribute pub_date.



12
13
14
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 12

def pub_date
  @pub_date
end

#pub_infoObject

Returns the value of attribute pub_info.



13
14
15
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 13

def pub_info
  @pub_info
end

#rdf_typesObject (readonly)

Returns the value of attribute rdf_types.



6
7
8
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 6

def rdf_types
  @rdf_types
end

#sourceObject

Returns the value of attribute source.



18
19
20
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 18

def source
  @source
end

#source_idObject (readonly)

valid values: :UNKNOWN, :OCLC, :CORNELL_VIVO, :CORNELL_LIBRARY, :STANFORD_LIBRARY



17
18
19
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 17

def source_id
  @source_id
end

#subtitleObject

Returns the value of attribute subtitle.



10
11
12
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 10

def subtitle
  @subtitle
end

#titleObject

Returns the value of attribute title.



9
10
11
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 9

def title
  @title
end

#uriObject

Returns the value of attribute uri.



8
9
10
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 8

def uri
  @uri
end

#work_typeObject (readonly)

valid values: :UNKNOWN, :BOOK, :VIDEO, :MUSIC



5
6
7
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 5

def work_type
  @work_type
end

Instance Method Details

#deserialize(serialization) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 116

def deserialize( serialization )
  attrs = JSON.parse serialization

  @title            = attrs["title"]
  @subtitle         = attrs["subtitle"]
  @author           = attrs["author"]
  @pub_date         = attrs["pub_date"]
  @pub_info         = attrs["pub_info"]
  @language         = attrs["language"]
  @edition          = attrs["edition"]
  @oclc_id          = attrs["oclc_id"]
  @source_id        = attrs["source_id"]
  @source           = attrs["source"]
  @local_id         = attrs["local_id"]
  @local_location   = attrs["local_location"]
  @local_callnumber = attrs["local_callnumber"]
  self
end

#generate_solr_docObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 70

def generate_solr_doc
  solr_doc = {}

  solr_doc[:resource_title_ti]         = @title
  solr_doc[:resource_title_sort_ss]    = @title
  solr_doc[:resource_subtitle_ti]      = @subtitle
  solr_doc[:resource_author_ti]        = @author
  solr_doc[:resource_author_facet_sim] = @author
  solr_doc[:resource_author_sort_ss]   = @author
  # solr_doc[:resource_subject_tim]     = @subject
  solr_doc[:resource_pub_date_iti]     = @pub_date      # year only, e.g.:  2005
  solr_doc[:resource_pub_info]         = @pub_info      # format: "Champaign, IL :Human Kinetics, c2005."
  solr_doc[:resource_language]         = @language
  solr_doc[:resource_edition]          = @edition
  solr_doc[:resource_oclc_id]          = @oclc_id
  solr_doc[:resource_source_id]        = @source_id
  solr_doc[:resource_source]           = @source
  solr_doc[:resource_local_id]         = @local_id
  solr_doc[:resource_local_location]   = @local_location
  solr_doc[:resource_local_callnumber] = @local_callnumber
  solr_doc[:resource_profile_ss]       = serialize
  solr_doc
end

#is_book?Boolean

Returns:

  • (Boolean)


142
143
144
145
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 142

def is_book?
  return true if @work_type == :BOOK
  false
end

#is_cornell_library?Boolean

Returns:

  • (Boolean)


190
191
192
193
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 190

def is_cornell_library?
  return true if @source_id == :CORNELL_LIBRARY
  false
end

#is_cornell_vivo?Boolean

Returns:

  • (Boolean)


174
175
176
177
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 174

def is_cornell_vivo?
  return true if @source_id == :CORNELL_VIVO
  false
end

#is_harvard_library?Boolean

Returns:

  • (Boolean)


206
207
208
209
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 206

def is_harvard_library?
  return true if @source_id == :HARVARD_LIBRARY
  false
end

#is_music?Boolean

Returns:

  • (Boolean)


158
159
160
161
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 158

def is_music?
  return true if @work_type == :MUSIC
  false
end

#is_oclc?Boolean

Returns:

  • (Boolean)


182
183
184
185
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 182

def is_oclc?
  return true if @source_id == :OCLC
  false
end

#is_source_unknown?Boolean

Returns:

  • (Boolean)


166
167
168
169
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 166

def is_source_unknown?
  return true if @source_id == :UNKNOWN
  false
end

#is_stanford_library?Boolean

Returns:

  • (Boolean)


198
199
200
201
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 198

def is_stanford_library?
  return true if @source_id == :STANFORD_LIBRARY
  false
end

#is_video?Boolean

Returns:

  • (Boolean)


150
151
152
153
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 150

def is_video?
  return true if @work_type == :VIDEO
  false
end

#load_from_solr_doc(solr_doc) ⇒ Object



94
95
96
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 94

def load_from_solr_doc( solr_doc )
  deserialize solr_doc[:resource_profile_ss]  if solr_doc.has_key? :resource_profile_ss
end

#serializeObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 98

def serialize
  attrs = {}
  attrs[:title]            = @title
  attrs[:subtitle]         = @subtitle
  attrs[:author]           = @author
  attrs[:pub_date]         = @pub_date
  attrs[:pub_info]         = @pub_info
  attrs[:language]         = @language
  attrs[:edition]          = @edition
  attrs[:oclc_id]          = @oclc_id
  attrs[:source_id]        = @source_id
  attrs[:source]           = @source
  attrs[:local_id]         = @local_id
  attrs[:local_location]   = @local_location
  attrs[:local_callnumber] = @local_callnumber
  attrs.to_json
end

#set_source_to_cornell_libraryObject



187
188
189
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 187

def set_source_to_cornell_library
  @source_id = :CORNELL_LIBRARY
end

#set_source_to_cornell_vivoObject



171
172
173
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 171

def set_source_to_cornell_vivo
  @source_id = :CORNELL_VIVO
end

#set_source_to_harvard_libraryObject



203
204
205
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 203

def set_source_to_harvard_library
  @source_id = :HARVARD_LIBRARY
end

#set_source_to_oclcObject



179
180
181
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 179

def set_source_to_oclc
  @source_id = :OCLC
end

#set_source_to_stanford_libraryObject



195
196
197
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 195

def set_source_to_stanford_library
  @source_id = :STANFORD_LIBRARY
end

#set_source_to_unknownObject



163
164
165
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 163

def set_source_to_unknown
  @source_id = :UNKNOWN
end

#set_type(format) ⇒ Object

TODO validate format, don’t just use it



135
136
137
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 135

def set_type(format)       # TODO validate format, don't just use it
  @work_type = format.upcase.to_sym if format.is_a? String  # TODO sometimes format is an array (e.g. ["Thesis","Book"])
end

#set_type_to_bookObject



139
140
141
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 139

def set_type_to_book
  @work_type = :BOOK
end

#set_type_to_musicObject



155
156
157
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 155

def set_type_to_music
  @work_type = :MUSIC
end

#set_type_to_videoObject



147
148
149
# File 'lib/ld4l/works_rdf/models/work_metadata.rb', line 147

def set_type_to_video
  @work_type = :VIDEO
end