Class: RelatonCcsds::DataParser

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_ccsds/data_parser.rb

Constant Summary collapse

DOCTYPES =
{ B: "standard", M: "practice", G: "report", O: "specification", Y: "record" }.freeze
DOMAIN =
"https://public.ccsds.org".freeze
AREAS =
{
  "SEA" => "Systems Engineering Area",
  "MOIMS" => "Mission Operations and Information Management Services Area",
  "CSS" => "Cross Support Services Area",
  "SOIS" => "Spacecraft Onboard Interface Services Area",
  "SLS" => "Space Link Services Area",
  "SIS" => "Space Internetworking Services Area",
}.freeze
ATTRS =
%i[
  title docid abstract doctype date docstatus link edition relation editorialgroup technology_area
].freeze
ID_MAPPING =
{
  "CCSDS 320.0-B-1-S Corrigendum 1" => "CCSDS 320.0-B-1-S Cor. 1", # TODO relaton/relaton-data-ccsds#5
  "CCSDS 701.00-R-3" => "CCSDS 701.00-R-3-S", # TODO relaton/relaton-data-ccsds#8
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(doc, docs, successor = nil) ⇒ DataParser

Returns a new instance of DataParser.



24
25
26
27
28
# File 'lib/relaton_ccsds/data_parser.rb', line 24

def initialize(doc, docs, successor = nil)
  @doc = doc
  @docs = docs
  @successor = successor
end

Instance Method Details

#adoptedObject



92
93
94
95
96
97
98
# File 'lib/relaton_ccsds/data_parser.rb', line 92

def adopted
  return [] unless @doc["ISO_x0020_Number"]

  code = @doc["ISO_x0020_Number"]["Description"].match(/(?<=\s)\d+$/)
  id = "ISO #{code}"
  [create_relation("adoptedAs", id)]
end

#create_relation(type, rel_id) ⇒ Object



118
119
120
121
122
123
# File 'lib/relaton_ccsds/data_parser.rb', line 118

def create_relation(type, rel_id)
  id = RelatonBib::DocumentIdentifier.new id: rel_id, type: "CCSDS", primary: true
  fref = RelatonBib::FormattedRef.new content: rel_id
  bibitem = RelatonBib::BibliographicItem.new docid: [id], formattedref: fref
  RelatonBib::DocumentRelation.new type: type, bibitem: bibitem
end

#docidentifier(id = nil) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/relaton_ccsds/data_parser.rb', line 44

def docidentifier(id = nil)
  id ||= @doc["Document_x0020_Number"].strip
  docid = ID_MAPPING[id] || id
  return docid unless @successor

  docid.sub(/(-S|s)(?=\s|$)/, "")
end

#parseObject



30
31
32
33
# File 'lib/relaton_ccsds/data_parser.rb', line 30

def parse
  args = ATTRS.each_with_object({}) { |a, o| o[a] = send "parse_#{a}" }
  BibliographicItem.new(**args)
end

#parse_abstractObject



52
53
54
55
# File 'lib/relaton_ccsds/data_parser.rb', line 52

def parse_abstract
  a = @doc["Description0"]
  [RelatonBib::FormattedString.new(content: a, language: "en", script: "Latn")]
end

#parse_dateObject



62
63
64
65
# File 'lib/relaton_ccsds/data_parser.rb', line 62

def parse_date
  on = "#{@doc['calPublishedMonth']} #{@doc['calPublishedYear']}"
  [RelatonBib::BibliographicDate.new(type: "published", on: on)]
end

#parse_docidObject



40
41
42
# File 'lib/relaton_ccsds/data_parser.rb', line 40

def parse_docid
  [RelatonBib::DocumentIdentifier.new(id: docidentifier, type: "CCSDS", primary: true)]
end

#parse_docstatusObject



67
68
69
70
# File 'lib/relaton_ccsds/data_parser.rb', line 67

def parse_docstatus
  stage = @successor ? "withdrawn" : "published"
  RelatonBib::DocumentStatus.new stage: stage
end

#parse_doctypeObject



57
58
59
60
# File 'lib/relaton_ccsds/data_parser.rb', line 57

def parse_doctype
  /^CCSDS\s[\d.]+-(?<type>\w+)/ =~ @doc["Document_x0020_Number"]
  DocumentType.new type: DOCTYPES[type&.to_sym]
end

#parse_editionObject



78
79
80
# File 'lib/relaton_ccsds/data_parser.rb', line 78

def parse_edition
  @doc["Issue_x0020_Number"].match(/^\d+/)&.to_s
end

#parse_editorialgroupObject



125
126
127
128
129
130
131
132
# File 'lib/relaton_ccsds/data_parser.rb', line 125

def parse_editorialgroup
  name = @doc.dig("Working_x0020_Group", "Description")
  return unless name

  wg = RelatonBib::WorkGroup.new name: name
  tc = RelatonBib::TechnicalCommittee.new wg
  RelatonBib::EditorialGroup.new([tc])
end


72
73
74
75
76
# File 'lib/relaton_ccsds/data_parser.rb', line 72

def parse_link
  l = "#{DOMAIN}#{@doc['FileRef']}"
  t = File.extname(@doc["FileRef"])&.sub(/^\./, "")
  [RelatonBib::TypedUri.new(type: t, content: l)]
end

#parse_relationObject



82
83
84
85
86
87
88
89
90
# File 'lib/relaton_ccsds/data_parser.rb', line 82

def parse_relation
  @docs.each_with_object(successor + adopted) do |d, a|
    id = docidentifier d["Document_x0020_Number"].strip
    type = relation_type id
    next unless type

    a << create_relation(type, id)
  end
end

#parse_technology_areaObject



134
135
136
137
138
139
# File 'lib/relaton_ccsds/data_parser.rb', line 134

def parse_technology_area
  desc = @doc.dig("Working_x0020_Group", "Description")
  return unless desc

  AREAS[desc.match(/^[A-Z]+(?=-)/)&.to_s]
end

#parse_titleObject



35
36
37
38
# File 'lib/relaton_ccsds/data_parser.rb', line 35

def parse_title
  t = @doc["Dcoument_x0020_Title"]
  [RelatonBib::TypedTitleString.new(content: t, language: "en", script: "Latn")]
end

#relation_type(rel_id) ⇒ Object



107
108
109
110
111
112
113
114
115
116
# File 'lib/relaton_ccsds/data_parser.rb', line 107

def relation_type(rel_id)
  return if rel_id == docidentifier ||
    rel_id.match(DataFetcher::TRRGX).to_s != docidentifier.match(DataFetcher::TRRGX).to_s

  if rel_id.include?(docidentifier.sub(DataFetcher::TRRGX, ""))
    "updatedBy"
  elsif docidentifier.include?(rel_id.sub(DataFetcher::TRRGX, ""))
    "updates"
  end
end

#successorObject



100
101
102
103
104
105
# File 'lib/relaton_ccsds/data_parser.rb', line 100

def successor
  return [] unless @successor

  @successor.relation << create_relation("successorOf", docidentifier)
  [create_relation("hasSuccessor", @successor.docidentifier[0].id)]
end