glossarist-new 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fca876eda8d9aaf1f9c931e93b47865f618f37991b317cf9a9b1aecaee4f60cf
4
- data.tar.gz: 9af3d0caefb3ecf7c1cc8958b4440641d279126bcc4a2888feb91ee4bb2ccf42
3
+ metadata.gz: 6c97457297f94e65b52da9de5fd9dc620f3722034e9a97dae80c81736333cf7d
4
+ data.tar.gz: e8716f64a5cb9d2e84f752540854219a6ffe406fc46140158274fc135a002da0
5
5
  SHA512:
6
- metadata.gz: 35fd58588549adf1b1978b6688b21257f8a9f094246daa69365f6e031a0c9e6de9ddbd57835692f80b4fbbe0a4f8cd40af8f60e2dd237cb397d8fb515824bd21
7
- data.tar.gz: 9f0843c03da02ffde2f6defad7f6d42732842ecb32cbbd560283d6e2ac5700073e7573ecf5d74e0764b781fedcb9fe48caae1d9a3de80c5e7d0a89976a603c8e
6
+ metadata.gz: 2f9db6e9f0f5e716c9810d44f06fd14d77140aa060b9004dbc900c2766be1bb08733789e0619d8cda633c18158ddf931b943cd9a5c4d6c025240f71453f351e4
7
+ data.tar.gz: 28c854fab76b67814180a2da7043ecb8072aea4828c9bcba92cf2b45ae57af5680733532837d46427a8bfd0d2834b965a04b51791010e50b214243ab27d7b7bc
@@ -17,8 +17,6 @@ jobs:
17
17
  - "3.0"
18
18
  - "2.7"
19
19
  - "2.6"
20
- - "2.5"
21
- - "2.4"
22
20
 
23
21
  steps:
24
22
  - name: Fetch source code
data/.gitignore CHANGED
@@ -16,3 +16,5 @@
16
16
  .rubocop-http---*
17
17
  .rubocop-https---*
18
18
 
19
+ # Relaton local cache directory
20
+ localcache
data/glossarist.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  "Concept models for terminology glossaries conforming ISO 10241-1."
17
17
  spec.homepage = "https://github.com/glossarist/glossarist-ruby"
18
18
  spec.license = "BSD-2-Clause"
19
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
19
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
20
20
 
21
21
  spec.metadata["homepage_uri"] = spec.homepage
22
22
  spec.metadata["source_code_uri"] = spec.homepage
@@ -30,6 +30,8 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
+ spec.add_dependency "relaton", "~>1.13.0"
34
+
33
35
  spec.add_development_dependency "pry", "~> 0.14.0"
34
36
  spec.add_development_dependency "rake", "~> 13.0"
35
37
  spec.add_development_dependency "rspec", "~> 3.10"
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # (c) Copyright 2021 Ribose Inc.
4
+ #
5
+
6
+ module Glossarist
7
+ class Asset
8
+ attr_accessor :path
9
+
10
+ def initialize(path)
11
+ @path = path
12
+ end
13
+
14
+ def eql?(asset)
15
+ path == asset.path
16
+ end
17
+
18
+ def hash
19
+ path.hash
20
+ end
21
+ end
22
+ end
@@ -67,9 +67,13 @@ module Glossarist
67
67
  end
68
68
 
69
69
  def ref=(ref)
70
- @source = ref["source"]
71
- @id = ref["id"]
72
- @version = ref["version"]
70
+ if ref.is_a?(Hash)
71
+ @source = ref["source"]
72
+ @id = ref["id"]
73
+ @version = ref["version"]
74
+ else
75
+ @text = ref
76
+ end
73
77
  end
74
78
 
75
79
  private
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module Collections
5
+ class AssetCollection < Set
6
+ def initialize(assets)
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "relaton"
4
+
5
+ module Glossarist
6
+ module Collections
7
+ class BibliographyCollection < Relaton::Db
8
+ def initialize(concepts, global_cache, local_cache)
9
+ super(global_cache, local_cache)
10
+ end
11
+
12
+ private
13
+
14
+ def populate_bibliographies(concepts)
15
+ concepts.each do |concept|
16
+ concept.default_lang.sources.each do |source|
17
+ next if source.origin.text.nil?
18
+
19
+ fetch(source.origin.text)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,2 @@
1
+ require_relative "collections/asset_collection"
2
+ require_relative "collections/bibliography_collection"
@@ -26,8 +26,6 @@ module Glossarist
26
26
  managed_concepts.each_value &method(:save_concept_to_file)
27
27
  end
28
28
 
29
- private
30
-
31
29
  def load_concept_from_file(filename)
32
30
  ManagedConcept.new(Psych.safe_load(File.read(filename)))
33
31
  end
@@ -37,6 +35,8 @@ module Glossarist
37
35
  File.write(filename, Psych.dump(concept.to_h))
38
36
  end
39
37
 
38
+ private
39
+
40
40
  def concepts_glob
41
41
  File.join(path, "concept-*.{yaml,yml}")
42
42
  end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ class ConceptSet
5
+ # a `Glossarist::ManagedConceptCollection` object
6
+ attr_accessor :concepts
7
+
8
+ # a `BibliographyCollection` object
9
+ attr_accessor :bibliographies
10
+
11
+ # an `Collections::Asset` object
12
+ attr_accessor :assets
13
+
14
+ # @parameters
15
+ # concepts => a `Glossarist::ManagedConceptCollection` object or
16
+ # a string containing the path of the folder with concepts
17
+ # assets => a collection of Glossarist::Asset
18
+ def initialize(concepts, assets, options = {})
19
+ @concepts = read_concepts(concepts)
20
+ @assets = Glossarist::Collections::AssetCollection.new(assets)
21
+ @bibliographies = Glossarist::Collections::BibliographyCollection.new(
22
+ @concepts,
23
+ options.dig(:bibliography, :global_cache),
24
+ options.dig(:bibliography, :local_cache),
25
+ )
26
+ end
27
+
28
+ def to_latex(filename = nil)
29
+ return to_latex_from_file(filename) if filename
30
+
31
+ @concepts.map do |concept|
32
+ latex_template(concept)
33
+ end.join("\n")
34
+ end
35
+
36
+ private
37
+
38
+ def to_latex_from_file(entries_file)
39
+ File.readlines(entries_file).map do |concept_name|
40
+ concept = concept_map[concept_name.strip.downcase]
41
+
42
+ if concept.nil?
43
+ puts " [Not Found]: #{concept_name.strip}"
44
+ else
45
+ latex_template(concept)
46
+ end
47
+ end.compact.join("\n")
48
+ end
49
+
50
+ def read_concepts(concepts)
51
+ return concepts if concepts.is_a?(Glossarist::ManagedConceptCollection)
52
+
53
+ collection = Glossarist::ManagedConceptCollection.new
54
+ collection.load_from_files(concepts)
55
+ collection
56
+ end
57
+
58
+ def latex_template(concept)
59
+ <<~TEMPLATE
60
+ \\newglossaryentry{#{concept.default_designation.gsub('_', '-')}}
61
+ {
62
+ name={#{concept.default_designation.gsub('_', '\_')}}
63
+ description={#{normalize_definition(concept.default_definition)}}
64
+ }
65
+ TEMPLATE
66
+ end
67
+
68
+ def normalize_definition(definition)
69
+ definition.gsub(/{{([^}]*)}}/) do |match|
70
+ "\\textbf{\\gls{#{Regexp.last_match[1].gsub('_', '-')}}}"
71
+ end
72
+ end
73
+
74
+ def concept_map
75
+ @concept_map ||= concepts.managed_concepts.map do |concept|
76
+ [concept.default_designation.downcase, concept]
77
+ end.to_h
78
+ end
79
+ end
80
+ end
@@ -85,6 +85,15 @@ module Glossarist
85
85
  localized&.terms&.first&.designation
86
86
  end
87
87
 
88
+ def default_definition
89
+ localized = localization("eng") || localizations.values.first
90
+ localized&.definition&.first&.content
91
+ end
92
+
93
+ def default_lang
94
+ localization("eng") || localizations.values.first
95
+ end
96
+
88
97
  def managed_concept_attributes
89
98
  %i[
90
99
  id
@@ -4,5 +4,5 @@
4
4
  #
5
5
 
6
6
  module Glossarist
7
- VERSION = "1.0.0"
7
+ VERSION = "1.0.2"
8
8
  end
data/lib/glossarist.rb CHANGED
@@ -9,11 +9,13 @@ require_relative "glossarist/utilities"
9
9
  require_relative "glossarist/version"
10
10
  require_relative "glossarist/glossary_definition"
11
11
 
12
+ require_relative "glossarist/asset"
12
13
  require_relative "glossarist/model"
13
14
  require_relative "glossarist/concept_date"
14
15
  require_relative "glossarist/detailed_definition"
15
16
  require_relative "glossarist/related_concept"
16
17
  require_relative "glossarist/citation"
18
+ require_relative "glossarist/concept_set"
17
19
  require_relative "glossarist/concept_source"
18
20
  require_relative "glossarist/collection"
19
21
  require_relative "glossarist/designation"
@@ -24,6 +26,8 @@ require_relative "glossarist/concept_manager"
24
26
  require_relative "glossarist/managed_concept"
25
27
  require_relative "glossarist/non_verb_rep"
26
28
 
29
+ require_relative "glossarist/collections"
30
+
27
31
  module Glossarist
28
32
  class Error < StandardError; end
29
33
  class InvalidTypeError < StandardError; end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glossarist-new
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-27 00:00:00.000000000 Z
11
+ date: 2023-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: relaton
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.13.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.13.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: pry
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,11 +86,16 @@ files:
72
86
  - config.yml
73
87
  - glossarist.gemspec
74
88
  - lib/glossarist.rb
89
+ - lib/glossarist/asset.rb
75
90
  - lib/glossarist/citation.rb
76
91
  - lib/glossarist/collection.rb
92
+ - lib/glossarist/collections.rb
93
+ - lib/glossarist/collections/asset_collection.rb
94
+ - lib/glossarist/collections/bibliography_collection.rb
77
95
  - lib/glossarist/concept.rb
78
96
  - lib/glossarist/concept_date.rb
79
97
  - lib/glossarist/concept_manager.rb
98
+ - lib/glossarist/concept_set.rb
80
99
  - lib/glossarist/concept_source.rb
81
100
  - lib/glossarist/designation.rb
82
101
  - lib/glossarist/designation/abbreviation.rb
@@ -117,14 +136,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
136
  requirements:
118
137
  - - ">="
119
138
  - !ruby/object:Gem::Version
120
- version: 2.4.0
139
+ version: 2.6.0
121
140
  required_rubygems_version: !ruby/object:Gem::Requirement
122
141
  requirements:
123
142
  - - ">="
124
143
  - !ruby/object:Gem::Version
125
144
  version: '0'
126
145
  requirements: []
127
- rubygems_version: 3.1.2
146
+ rubygems_version: 3.3.25
128
147
  signing_key:
129
148
  specification_version: 4
130
149
  summary: Concept models for terminology glossaries conforming ISO 10241-1.