termium 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9f242a07fdedab976941acc1580ca44d301ab96e3b3c5f70bf17704fabf39f0e
4
+ data.tar.gz: 9b650e4b6d9786014c09ada236f5d369c5a9138616d77083b14f121b881cb2eb
5
+ SHA512:
6
+ metadata.gz: 98d930ad1aab03405b14561d17cd14b76531d3a65381362b3a2822e1c8f4244bb49a9f4074a3d189fc8049a6bccbd43d40d02f9766ec00bfe78070c1950c0c5c
7
+ data.tar.gz: 904748c40e59b69efeb8d2c9355ac9523b005f39b89ca03f2fac18384780e2bba4e87d2b5a441b9c725ed2c9aff426a4c588ef4cb72956199fa92aa371e099c0
@@ -0,0 +1,27 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ pull_request:
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ name: Ruby ${{ matrix.ruby }}
14
+ strategy:
15
+ matrix:
16
+ ruby:
17
+ - '3.1.2'
18
+
19
+ steps:
20
+ - uses: actions/checkout@v3
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+ - name: Run the default task
27
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at ronald.tse@ribose.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
data/README.adoc ADDED
@@ -0,0 +1,66 @@
1
+ = Termium Ruby gem
2
+
3
+ == Purpose
4
+
5
+ The Termium Ruby gem parses export data formats from the
6
+ https://www.btb.termiumplus.gc.ca[TERMIUM Plus]
7
+ terminology database service from the Government of Canada.
8
+
9
+
10
+ == Commands
11
+
12
+ `termium convert`:: Convert a TERMIUM Plus export XML file to a Glossarist dataset
13
+
14
+
15
+ === Usage
16
+
17
+ [source,sh]
18
+ ----
19
+ $ termium convert -i INPUT_XML_FILE [-o OUTPUT_PATH]
20
+ ----
21
+
22
+ === Options
23
+
24
+ [cols="a,a",options="header"]
25
+ |===
26
+ | Flag | Description
27
+
28
+ |`-i`, `--input-path`
29
+ |
30
+ Source path to TERMIUM Plus XML export file.
31
+ The file needs to start with the `<extract>` tag.
32
+
33
+ |`-o`, `--output-path`
34
+ |
35
+ Destination path to Glossarist dataset directory.
36
+ If the directory doesn't exist it will be created.
37
+ If not provided, defaults to the basename of the input file, e.g. `foo/bar.xml` will export to `foo/bar/`.
38
+
39
+ |===
40
+
41
+
42
+ == Library
43
+
44
+ === Usage
45
+
46
+ This gem makes heavy use of the `Shale` classes for XML serialization.
47
+
48
+ The following code converts the Termium extract into a Glossarist dataset.
49
+
50
+ [source,ruby]
51
+ ----
52
+ termium_extract = Termium::Extract.from_xml(IO.read(termium_extract_file))
53
+ glossarist_col = termium_extract.to_concept
54
+ FileUtils.mkdir_p(glossarist_output_file)
55
+ glossarist_col.save_to_files(glossarist_output_file)
56
+ ----
57
+
58
+ == Credits
59
+
60
+ This gem is developed, maintained and funded by
61
+ https://www.ribose.com[Ribose Inc.]
62
+
63
+ == License
64
+
65
+ The gem is available as open source under the terms of the
66
+ https://opensource.org/licenses/BSD-2-Clause[2-Clause BSD License].
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ # require "rubocop/rake_task"
9
+ # RuboCop::RakeTask.new
10
+
11
+ task default: %i[spec] #rubocop
data/exe/termium ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/termium/cli"
5
+
6
+ Termium::Cli.start(ARGV)
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "source_ref"
4
+ require_relative "parameter"
5
+ require_relative "designation_operations"
6
+
7
+ module Termium
8
+ # For <abbreviation>
9
+ class Abbreviation < Shale::Mapper
10
+ attribute :order, Shale::Type::Integer
11
+ attribute :value, Shale::Type::String
12
+ attribute :source_ref, SourceRef
13
+ attribute :parameter, Parameter, collection: true
14
+ include DesignationOperations
15
+
16
+ # <abbreviation order="1" value="PCI">
17
+ # <sourceRef order="1" />
18
+ # <parameter abbreviation="COR" />
19
+ # <parameter abbreviation="F" />
20
+ # <parameter abbreviation="NORM" />
21
+
22
+ xml do
23
+ root "abbreviation"
24
+ map_attribute "order", to: :order
25
+ map_attribute "value", to: :value
26
+ map_element "sourceRef", to: :source_ref
27
+ map_element "parameter", to: :parameter
28
+ end
29
+
30
+ def deprecated
31
+ parameter.map(&:abbreviation).include?("AE")
32
+ end
33
+
34
+ def to_h
35
+ set = {
36
+ "designation" => value,
37
+ "type" => "abbreviation",
38
+ "normative_status" => deprecated ? "deprecated" : "preferred"
39
+ }
40
+
41
+ # if geographical_area
42
+ # set["geographical_area"] = geographical_area
43
+ # end
44
+
45
+ # if plurality
46
+ # set["plurality"] = plurality
47
+ # end
48
+
49
+ set["gender"] = gender if gender
50
+
51
+ set["part_of_speech"] = part_of_speech if part_of_speech
52
+
53
+ set
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../termium"
4
+
5
+ module Termium
6
+ # Command-line interface
7
+ class Cli < Thor
8
+ desc "convert", "Convert Termium entries into a Glossarist dataset"
9
+
10
+ option :input_file, aliases: :i, required: true, desc: "Path to TERMIUM Plus XML extract"
11
+ option :output_file, aliases: :o, desc: "Output file path"
12
+
13
+ def input_file_as_path
14
+ input_path = Pathname.new(Dir.pwd).join(Pathname.new(options[:input_file]))
15
+
16
+ unless input_path.exist?
17
+ error "Input file `#{options[:input_file]}` does not exist."
18
+ exit 1
19
+ end
20
+
21
+ input_path
22
+ end
23
+
24
+ def output_path_ready
25
+ output_path = options[:output_file]
26
+ output_path ||= input_path.dirname.join(input_path.basename(input_path.extname))
27
+
28
+ output_path = Pathname.new(Dir.pwd).join(Pathname.new(output_path))
29
+
30
+ if output_path.exist?
31
+ puts "Using existing directory: #{output_path.relative_path_from(Dir.pwd)}"
32
+ else # and is directory
33
+ puts "Created directory: #{output_path.relative_path_from(Dir.pwd)}"
34
+ output_path.mkdir
35
+ end
36
+
37
+ output_path
38
+ end
39
+
40
+ def convert
41
+ input_path = input_file_as_path
42
+ puts "Reading input file: #{input_path.relative_path_from(Dir.pwd)}"
43
+ termium_extract = Termium::Extract.from_xml(IO.read(input_path.expand_path))
44
+
45
+ puts "Size of dataset: #{termium_extract.core.size}"
46
+
47
+ puts "Converting to Glossarist..."
48
+ glossarist_col = termium_extract.to_concept
49
+ # pp glossarist_col.first
50
+
51
+ output_path = output_path_ready
52
+ puts "Writing Glossarist dataset..."
53
+ glossarist_col.save_to_files(output_path.expand_path)
54
+ puts "Written Glossarist dataset to: #{output_path.relative_path_from(Dir.pwd)}"
55
+ end
56
+
57
+ def method_missing(*args)
58
+ warn "No method found named: #{args[0]}"
59
+ warn "Run with `--help` or `-h` to see available options"
60
+ exit 1
61
+ end
62
+
63
+ def respond_to_missing?
64
+ true
65
+ end
66
+
67
+ def self.exit_on_failure?
68
+ true
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "language_module"
4
+ require_relative "subject"
5
+ require_relative "universal_entry"
6
+ require_relative "source"
7
+
8
+ module Termium
9
+ # For <core>
10
+ class Core < Shale::Mapper
11
+ attribute :identification_number, Shale::Type::String
12
+ attribute :dissemination_level, Shale::Type::String
13
+
14
+ attribute :language_module, LanguageModule, collection: true
15
+ attribute :subject, Subject
16
+ attribute :universal_entry, UniversalEntry
17
+ attribute :source, Source, collection: true
18
+
19
+ xml do
20
+ root "core"
21
+ map_attribute "disseminationLevel", to: :dissemination_level
22
+ map_attribute "identificationNumber", to: :identification_number
23
+ map_element "languageModule", to: :language_module
24
+ map_element "subject", to: :subject
25
+ map_element "universalEntry", to: :universal_entry
26
+ map_element "source", to: :source
27
+ end
28
+
29
+ # TODO: In Termium XML, each definition per lang or note can be linked to a
30
+ # particular source via the sourceRef number.
31
+ def concept_sources
32
+ source.map(&:to_concept_source)
33
+ end
34
+
35
+ def to_concept
36
+ concept = Glossarist::ManagedConcept.new(id: identification_number)
37
+
38
+ language_module.map(&:to_concept).each do |localized_concept|
39
+ # TODO: This is needed to skip the empty french entries of 10031781 and 10031778
40
+ next if localized_concept.nil?
41
+
42
+ localized_concept.id = identification_number
43
+ # TODO: this should just be localized_concept.notes << universal_entry.value
44
+ # TODO: Depends on https://github.com/glossarist/glossarist-ruby/issues/82
45
+ localized_concept.notes << Glossarist::DetailedDefinition.new(universal_entry.value)
46
+ localized_concept.sources = concept_sources
47
+ concept.add_localization(localized_concept)
48
+ end
49
+
50
+ concept
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Termium
4
+ # Mixin for designation operations
5
+ module DesignationOperations
6
+ PART_OF_SPEECH_CODE_MAPPING = {
7
+ "ADJ" => "adj",
8
+ "N" => "noun",
9
+ "V" => "verb"
10
+ }.freeze
11
+ def part_of_speech
12
+ value = parameter.detect do |x|
13
+ PART_OF_SPEECH_CODE_MAPPING[x.abbreviation]
14
+ end
15
+
16
+ value ? PART_OF_SPEECH_CODE_MAPPING[value.abbreviation] : nil
17
+ end
18
+
19
+ GENDER_CODE_MAPPING = {
20
+ "F" => "f",
21
+ "M" => "m",
22
+ "EPI" => "c" # this means "Epicine"
23
+ }.freeze
24
+ def gender
25
+ value = parameter.detect do |x|
26
+ GENDER_CODE_MAPPING[x.abbreviation]
27
+ end
28
+
29
+ value ? GENDER_CODE_MAPPING[value.abbreviation] : nil
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "source_ref"
4
+ require_relative "abbreviation"
5
+ require_relative "parameter"
6
+ require_relative "designation_operations"
7
+
8
+ module Termium
9
+ # For <entryTerm>
10
+ class EntryTerm < Shale::Mapper
11
+ attribute :order, Shale::Type::Integer
12
+ attribute :value, Shale::Type::String
13
+ attribute :source_ref, SourceRef
14
+ attribute :abbreviation, Abbreviation, collection: true
15
+ attribute :parameter, Parameter, collection: true
16
+ include DesignationOperations
17
+
18
+ xml do
19
+ root "entryTerm"
20
+ map_attribute "order", to: :order
21
+ map_attribute "value", to: :value
22
+ map_element "abbreviation", to: :abbreviation
23
+ map_element "sourceRef", to: :source_ref
24
+ map_element "parameter", to: :parameter
25
+ end
26
+
27
+ # attr_accessor :geographical_area,
28
+ # :deprecated,
29
+ # :plurality,
30
+ # :part_of_speech,
31
+ # :gender
32
+
33
+ GEOGRAPHICAL_CODE_MAPPING = {
34
+ "USA" => "US",
35
+ "CAN" => "CA",
36
+ "GB" => "GB",
37
+ "AUS" => "AU",
38
+ "EUR" => "EU"
39
+ }.freeze
40
+ def geographical_area
41
+ keys = GEOGRAPHICAL_CODE_MAPPING.keys
42
+ usage = parameter.select do |x|
43
+ keys.include?(x.abbreviation)
44
+ end
45
+
46
+ return nil if usage.empty?
47
+
48
+ usage.map do |x|
49
+ GEOGRAPHICAL_CODE_MAPPING[x.abbreviation]
50
+ end.join("; ")
51
+ end
52
+
53
+ def deprecated
54
+ parameter.map(&:abbreviation).include?("AE")
55
+ end
56
+
57
+ def plurality
58
+ if parameter.map(&:abbreviation).include?("PL")
59
+ "plural"
60
+ else
61
+ "singular"
62
+ end
63
+ end
64
+
65
+ def to_h
66
+ set = {
67
+ "designation" => value,
68
+ "type" => "expression",
69
+ "normative_status" => deprecated ? "deprecated" : "preferred"
70
+ }
71
+
72
+ set["geographical_area"] = geographical_area if geographical_area
73
+
74
+ set["plurality"] = plurality if plurality
75
+
76
+ set["gender"] = gender if gender
77
+
78
+ set["part_of_speech"] = part_of_speech if part_of_speech
79
+
80
+ set
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "extract_language"
4
+ require_relative "core"
5
+
6
+ module Termium
7
+ # For <extract>
8
+ class Extract < Shale::Mapper
9
+ attribute :language, Shale::Type::String
10
+ attribute :extract_language, ExtractLanguage, collection: true
11
+ attribute :core, Core, collection: true
12
+
13
+ xml do
14
+ root "termium_extract"
15
+ # namespace 'http://termium.tpsgc-pwgsc.gc.ca/schemas/2012/06/Termium', 'ns2'
16
+
17
+ map_attribute "language", to: :language
18
+ map_element "extractLanguage", to: :extract_language
19
+ map_element "core", to: :core
20
+ end
21
+
22
+ def to_concept
23
+ coll = Glossarist::ManagedConceptCollection.new
24
+ coll.managed_concepts = core.map(&:to_concept)
25
+ coll
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Termium
4
+ # For <extractLanguage>
5
+ class ExtractLanguage < Shale::Mapper
6
+ attribute :language, Shale::Type::String
7
+ attribute :order, Shale::Type::Integer
8
+ xml do
9
+ root "extractLanguage"
10
+ map_attribute "language", to: :language
11
+ map_attribute "order", to: :order
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "entry_term"
4
+ require_relative "textual_support"
5
+
6
+ module Termium
7
+ # For <languageModule>
8
+ class LanguageModule < Shale::Mapper
9
+ attribute :language, Shale::Type::String
10
+ attribute :entry_term, EntryTerm, collection: true
11
+ attribute :textual_support, TextualSupport, collection: true
12
+ xml do
13
+ root "languageModule"
14
+ map_attribute "language", to: :language
15
+ map_element "entryTerm", to: :entry_term
16
+ map_element "textualSupport", to: :textual_support
17
+ end
18
+
19
+ def definition_raw
20
+ textual_support.detect(&:is_definition?)
21
+ end
22
+
23
+ def definition
24
+ definition_raw&.value_typed
25
+ end
26
+
27
+ def domain
28
+ definition_raw&.domain
29
+ end
30
+
31
+ def notes
32
+ textual_support.select(&:is_note?).map(&:value_typed)
33
+ end
34
+
35
+ def examples
36
+ textual_support.select(&:is_example?).map(&:value_typed)
37
+ end
38
+
39
+ def abbreviations
40
+ entry_term.map(&:abbreviation).flatten
41
+ end
42
+
43
+ LANGUAGE_CODE_MAPPING = {
44
+ "en" => "eng",
45
+ "fr" => "fre"
46
+ }.freeze
47
+
48
+ def designations
49
+ # NOTE: entry_term is a collection
50
+ entry_term + abbreviations
51
+ end
52
+
53
+ def to_h
54
+ # TODO: This is needed to skip the empty french entries of 10031781 and 10031778
55
+ return nil unless definition
56
+
57
+ src = {
58
+ "language_code" => LANGUAGE_CODE_MAPPING[language.downcase],
59
+ "terms" => designations.map(&:to_h),
60
+ "definition" => [{ content: definition }],
61
+ "notes" => notes,
62
+ "examples" => examples
63
+ }
64
+
65
+ src["domain"] = domain if domain
66
+
67
+ src
68
+ end
69
+
70
+ def to_concept
71
+ x = to_h
72
+ return nil unless x
73
+
74
+ Glossarist::LocalizedConcept.new(x)
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Termium
4
+ # For <parameter>
5
+ class Parameter < Shale::Mapper
6
+ # <parameter abbreviation="NORM"/>
7
+ attribute :abbreviation, Shale::Type::String
8
+ xml do
9
+ root "parameter"
10
+ map_attribute "abbreviation", to: :abbreviation
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Termium
4
+ # For <source>
5
+ class Source < Shale::Mapper
6
+ ISO_BIB_REGEX = /\AISO-([\d-]+)\s+\*\s+(\d{4})\s+.*/.freeze
7
+ ISOIEC_BIB_REGEX = /\AISO-IEC-([\d-]+)\s+\*\s+(\d{4})\s+.*/.freeze
8
+
9
+ attribute :order, Shale::Type::Integer
10
+ attribute :details, Shale::Type::String
11
+ xml do
12
+ root "source"
13
+ map_attribute "order", to: :order
14
+ map_attribute "details", to: :details
15
+ end
16
+
17
+ def content
18
+ if (matches = details.match(ISOIEC_BIB_REGEX))
19
+ "ISO/IEC #{matches[1]}:#{matches[2]}"
20
+ elsif (matches = details.match(ISO_BIB_REGEX))
21
+ "ISO #{matches[1]}:#{matches[2]}"
22
+ else
23
+ details
24
+ end
25
+ end
26
+
27
+ def to_concept_source
28
+ Glossarist::ConceptSource.new({
29
+ "type" => "lineage",
30
+ "ref" => content,
31
+ "status" => "identical"
32
+ })
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Termium
4
+ # For <sourceRef>
5
+ class SourceRef < Shale::Mapper
6
+ attribute :order, Shale::Type::Integer
7
+ xml do
8
+ root "sourceRef"
9
+ map_attribute "order", to: :order
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Termium
4
+ # For <subject>
5
+ class Subject < Shale::Mapper
6
+ attribute :abbreviation, Shale::Type::String
7
+ attribute :details, Shale::Type::String
8
+
9
+ # <subject abbreviation="YBB" details="Compartment - ISO/IEC JTC 1 Information Technology Vocabulary"/>
10
+ xml do
11
+ root "subject"
12
+ map_attribute "abbreviation", to: :abbreviation
13
+ map_attribute "details", to: :details
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "source_ref"
4
+
5
+ module Termium
6
+ # For <textualSupport>
7
+ class TextualSupport < Shale::Mapper
8
+ attribute :order, Shale::Type::Integer
9
+ attribute :type, Shale::Type::String
10
+ attribute :value, Shale::Type::String
11
+ attribute :source_ref, SourceRef
12
+ xml do
13
+ root "textualSupport"
14
+ map_attribute "order", to: :order
15
+ map_attribute "type", to: :type
16
+ map_element "value", to: :value
17
+ map_element "sourceRef", to: :source_ref
18
+ end
19
+
20
+ def value_cleaned
21
+ value.gsub(/\n\s+/, " ")
22
+ end
23
+
24
+ def value_typed
25
+ if is_example?
26
+ value_example
27
+ elsif is_definition?
28
+ value_definition
29
+ else
30
+ value_cleaned
31
+ end
32
+ end
33
+
34
+ EXAMPLE_REGEX = /\AEx[ea]mples?\s*:\s*/.freeze
35
+ def is_example?
36
+ value_cleaned.match(EXAMPLE_REGEX)
37
+ end
38
+
39
+ def is_definition?
40
+ type == "DEF"
41
+ end
42
+
43
+ def is_note?
44
+ !is_definition? && !is_example?
45
+ end
46
+
47
+ def is_observation?
48
+ type == "OBS"
49
+ end
50
+
51
+ def value_example
52
+ value_cleaned.gsub(EXAMPLE_REGEX, "")
53
+ end
54
+
55
+ DEFINITION_REGEX = /\A<(.+?)>\s*/.freeze
56
+ def value_definition
57
+ value_cleaned.gsub(DEFINITION_REGEX, "")
58
+ end
59
+
60
+ def has_domain?
61
+ !value_cleaned.match(DEFINITION_REGEX).nil?
62
+ end
63
+
64
+ def domain
65
+ return unless has_domain?
66
+
67
+ value_cleaned.match(DEFINITION_REGEX)[1]
68
+ end
69
+
70
+ # This is an attempt to extract the textual reference within the note.
71
+ # TODO: Use this to correlate the actual term with the source reference, i.e
72
+ # from the following note, the terms "abduction; inférence abductive" come from
73
+ # "ISO-IEC-2382-28-1995".
74
+ # NOTE: abduction; inférence abductive : termes et définition normalisés par l'ISO/CEI [<<ISO-IEC-2382-28-1995>>].
75
+ def source_from_note
76
+ x = note.match(/\[.*\]/)
77
+ return nil if x.nil?
78
+
79
+ ref = x.match(/\[.*\]/).to_s.gsub(/[\[\]]/, "")
80
+
81
+ # "[ISO/IEC 2382-13:1996; ISO/IEC 2382-24:1995]"
82
+ if ref.include?(";")
83
+ ref.split("; ")
84
+ else
85
+ [ref]
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "source_ref"
4
+ require_relative "parameter"
5
+
6
+ module Termium
7
+ # For <universalEntry>
8
+ class UniversalEntry < Shale::Mapper
9
+ attribute :order, Shale::Type::Integer
10
+ attribute :value, Shale::Type::String
11
+ attribute :source_ref, SourceRef
12
+ attribute :parameter, Parameter
13
+
14
+ # <universalEntry order="1">
15
+ # <value>09.08.09 (2382)</value>
16
+ # <sourceRef order="1"/>
17
+ # <parameter abbreviation="CONUM"/>
18
+ # </universalEntry>
19
+
20
+ xml do
21
+ root "universalEntry"
22
+ map_attribute "order", to: :order
23
+ map_element "value", to: :value
24
+ map_element "sourceRef", to: :source_ref
25
+ map_element "parameter", to: :parameter
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Termium
4
+ VERSION = "0.1.0"
5
+ end
data/lib/termium.rb ADDED
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "glossarist"
4
+ require "shale"
5
+ require "shale/adapter/nokogiri"
6
+ Shale.xml_adapter = Shale::Adapter::Nokogiri
7
+
8
+ module Termium
9
+ class Error < StandardError; end
10
+ end
11
+
12
+ require_relative "termium/version"
13
+ require_relative "termium/extract"
14
+ require_relative "termium/extract_language"
15
+ require_relative "termium/core"
16
+ require_relative "termium/abbreviation"
17
+ require_relative "termium/designation_operations"
18
+ require_relative "termium/entry_term"
19
+ require_relative "termium/language_module"
20
+ require_relative "termium/parameter"
21
+ require_relative "termium/source"
22
+ require_relative "termium/source_ref"
23
+ require_relative "termium/subject"
24
+ require_relative "termium/textual_support"
25
+ require_relative "termium/universal_entry"
data/sig/termium.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Termium
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/termium.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/termium/version"
4
+
5
+ all_files_in_git = Dir.chdir(File.expand_path(__dir__)) do
6
+ `git ls-files -z`.split("\x0")
7
+ end
8
+
9
+ Gem::Specification.new do |spec|
10
+ spec.name = "termium"
11
+ spec.version = Termium::VERSION
12
+ spec.authors = ["Ribose"]
13
+ spec.email = ["open.source@ribose.com"]
14
+
15
+ spec.summary =
16
+ "Parser for the TERMIUM Plus terminology database of the Government of Canada"
17
+ spec.homepage = "https://github.com/glossarist/termium"
18
+ spec.license = "BSD-2-Clause"
19
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = spec.homepage
23
+ spec.metadata["bug_tracker_uri"] = "#{spec.homepage}/issues"
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ spec.files = all_files_in_git
27
+ .reject { |f| f.match(%r{\A(?:test|spec|features|bin|\.)/}) }
28
+
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "glossarist", "~> 1.0"
34
+ spec.add_dependency "shale"
35
+ spec.add_dependency "thor"
36
+
37
+ spec.add_development_dependency "pry", "~> 0.14.0"
38
+ spec.add_development_dependency "rake", "~> 13.0"
39
+ spec.add_development_dependency "rspec", "~> 3.10"
40
+ spec.add_development_dependency "rubocop"
41
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: termium
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ribose
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-11-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: glossarist
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.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.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: shale
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.14.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.14.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '13.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '13.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - open.source@ribose.com
114
+ executables:
115
+ - termium
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".github/workflows/main.yml"
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - CODE_OF_CONDUCT.md
123
+ - Gemfile
124
+ - README.adoc
125
+ - Rakefile
126
+ - exe/termium
127
+ - lib/termium.rb
128
+ - lib/termium/abbreviation.rb
129
+ - lib/termium/cli.rb
130
+ - lib/termium/core.rb
131
+ - lib/termium/designation_operations.rb
132
+ - lib/termium/entry_term.rb
133
+ - lib/termium/extract.rb
134
+ - lib/termium/extract_language.rb
135
+ - lib/termium/language_module.rb
136
+ - lib/termium/parameter.rb
137
+ - lib/termium/source.rb
138
+ - lib/termium/source_ref.rb
139
+ - lib/termium/subject.rb
140
+ - lib/termium/textual_support.rb
141
+ - lib/termium/universal_entry.rb
142
+ - lib/termium/version.rb
143
+ - sig/termium.rbs
144
+ - termium.gemspec
145
+ homepage: https://github.com/glossarist/termium
146
+ licenses:
147
+ - BSD-2-Clause
148
+ metadata:
149
+ homepage_uri: https://github.com/glossarist/termium
150
+ source_code_uri: https://github.com/glossarist/termium
151
+ bug_tracker_uri: https://github.com/glossarist/termium/issues
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: 2.6.0
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubygems_version: 3.3.7
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Parser for the TERMIUM Plus terminology database of the Government of Canada
171
+ test_files: []