glossarist-new 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +0 -2
- data/.gitignore +2 -0
- data/glossarist.gemspec +3 -1
- data/lib/glossarist/asset.rb +22 -0
- data/lib/glossarist/collections/asset_collection.rb +11 -0
- data/lib/glossarist/collections/bibliography_collection.rb +25 -0
- data/lib/glossarist/collections.rb +2 -0
- data/lib/glossarist/concept.rb +1 -1
- data/lib/glossarist/concept_manager.rb +2 -2
- data/lib/glossarist/concept_set.rb +80 -0
- data/lib/glossarist/config.rb +37 -0
- data/lib/glossarist/managed_concept.rb +10 -1
- data/lib/glossarist/version.rb +1 -1
- data/lib/glossarist.rb +12 -0
- metadata +24 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0b88c582178e67916b7058bba75f92a14b5862926188092fa6e539c0eb05ad5
|
4
|
+
data.tar.gz: c7d3c4e294f2f77279e712d865239a824ea84ee8fb2a884e23f935c9ca5b871e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ed31f71ae7f554ed6e4f32f27f2203d78c66ce95e6f1e33502cc610142d9cef534ba21fe6a01aee37bf75f6d889b61f99780448e12aa591e4454cf73986d891
|
7
|
+
data.tar.gz: aa4f3b7c9882afde4d1bbf541ccf509150e434a63fa0f68314d6f72e48d344a22d73524eed91524b5b81c83105cc9917c5c469a24560c181619fe0c10c827f01
|
data/.github/workflows/test.yml
CHANGED
data/.gitignore
CHANGED
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.
|
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
|
@@ -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
|
data/lib/glossarist/concept.rb
CHANGED
@@ -122,7 +122,7 @@ module Glossarist
|
|
122
122
|
|
123
123
|
hash.values
|
124
124
|
.grep(Hash)
|
125
|
-
.map { |subhash|
|
125
|
+
.map { |subhash| Config.class_for(:localized_concept).from_h(subhash) rescue nil }
|
126
126
|
.compact
|
127
127
|
|
128
128
|
concept.related = hash.dig("related") || []
|
@@ -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
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "singleton"
|
4
|
+
|
5
|
+
module Glossarist
|
6
|
+
class Config
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
DEFAULT_CLASSES = {
|
10
|
+
localized_concept: Glossarist::LocalizedConcept,
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
attr_reader :registered_classes
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@registered_classes = DEFAULT_CLASSES.dup
|
17
|
+
end
|
18
|
+
|
19
|
+
def class_for(name)
|
20
|
+
@registered_classes[name.to_sym]
|
21
|
+
end
|
22
|
+
|
23
|
+
def register_class(class_name, klass)
|
24
|
+
@registered_classes[class_name] = klass
|
25
|
+
end
|
26
|
+
|
27
|
+
class << self
|
28
|
+
def class_for(name)
|
29
|
+
self.instance.class_for(name)
|
30
|
+
end
|
31
|
+
|
32
|
+
def register_class(class_name, klass)
|
33
|
+
self.instance.register_class(class_name, klass)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -36,7 +36,7 @@ module Glossarist
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def localized_concepts=(localized_concepts_hash)
|
39
|
-
@localized_concepts = localized_concepts_hash.map { |l|
|
39
|
+
@localized_concepts = localized_concepts_hash.map { |l| Config.class_for(:localized_concept).new(l) }.compact
|
40
40
|
|
41
41
|
@localized_concepts.each do |l|
|
42
42
|
add_l10n(l)
|
@@ -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
|
data/lib/glossarist/version.rb
CHANGED
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,8 +26,18 @@ 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
|
+
|
31
|
+
require_relative "glossarist/config"
|
32
|
+
|
27
33
|
module Glossarist
|
28
34
|
class Error < StandardError; end
|
29
35
|
class InvalidTypeError < StandardError; end
|
30
36
|
# Your code goes here...
|
37
|
+
|
38
|
+
def self.configure
|
39
|
+
config = Glossarist::Config.instance
|
40
|
+
|
41
|
+
yield(config) if block_given?
|
42
|
+
end
|
31
43
|
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.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-10 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,12 +86,18 @@ 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
|
100
|
+
- lib/glossarist/config.rb
|
81
101
|
- lib/glossarist/designation.rb
|
82
102
|
- lib/glossarist/designation/abbreviation.rb
|
83
103
|
- lib/glossarist/designation/base.rb
|
@@ -117,14 +137,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
137
|
requirements:
|
118
138
|
- - ">="
|
119
139
|
- !ruby/object:Gem::Version
|
120
|
-
version: 2.
|
140
|
+
version: 2.6.0
|
121
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
142
|
requirements:
|
123
143
|
- - ">="
|
124
144
|
- !ruby/object:Gem::Version
|
125
145
|
version: '0'
|
126
146
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
147
|
+
rubygems_version: 3.3.25
|
128
148
|
signing_key:
|
129
149
|
specification_version: 4
|
130
150
|
summary: Concept models for terminology glossaries conforming ISO 10241-1.
|