-
Notifications
You must be signed in to change notification settings - Fork 0
Changed models to use glossarist v2 format #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
HassanAkbar
wants to merge
3
commits into
main
Choose a base branch
from
glossarist-v2-data-format
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,87 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "yaml" | ||
|
|
||
| RSpec.describe Termium do | ||
| let(:termium_extract_file) { fixtures_path("Characters.xml") } | ||
| let(:glossarist_output_dir) { fixtures_path("Characters-Glossarist") } | ||
|
|
||
| # let(:concept_folder) { "concept_collection_v2" } | ||
| # let(:concept_files) { Dir.glob(File.join(fixtures_path(concept_folder), "concept", "*.{yaml,yml}")) } | ||
| # let(:localized_concepts_folder) { File.join(fixtures_path(concept_folder), "localized_concept") } | ||
| before do | ||
| FileUtils.mkdir_p(glossarist_output_dir) | ||
| end | ||
|
|
||
| let(:termium_extract_file) { fixtures_path("Characters.xml") } | ||
| let(:glossarist_output_file) { fixtures_path("Characters-Glossarist") } | ||
| it "does something useful" do | ||
| termium_extract = Termium::Extract.from_xml(IO.read(termium_extract_file)) | ||
| glossarist_col = termium_extract.to_concept | ||
| FileUtils.mkdir_p(glossarist_output_file) | ||
| glossarist_col.save_to_files(glossarist_output_file) | ||
| after do | ||
| FileUtils.rm_rf(glossarist_output_dir) | ||
| end | ||
|
|
||
| describe "V2 format conversion" do | ||
| let(:termium_extract) { Termium::Extract.from_xml(IO.read(termium_extract_file)) } | ||
| let(:glossarist_col) { termium_extract.to_concept } | ||
|
|
||
| before do | ||
| glossarist_col.save_to_files(glossarist_output_dir) | ||
| end | ||
|
|
||
| it "creates concept and localized_concept directories" do | ||
| expect(Dir.exist?(File.join(glossarist_output_dir, "concept"))).to be true | ||
| expect(Dir.exist?(File.join(glossarist_output_dir, "localized_concept"))).to be true | ||
| end | ||
|
|
||
| it "creates concept files with V2 structure" do | ||
| concept_files = Dir.glob(File.join(glossarist_output_dir, "concept", "*.yaml")) | ||
| expect(concept_files).not_to be_empty | ||
|
|
||
| concept_files.each do |file| | ||
| concept = YAML.safe_load(File.read(file), permitted_classes: [Date, Time]) | ||
|
|
||
| # V2: concept must have id (UUID) at root level | ||
| expect(concept).to have_key("id") | ||
| expect(concept["id"]).to match(/^[0-9a-f-]{36}$/) | ||
|
|
||
| # V2: concept must have data with identifier and localized_concepts | ||
| expect(concept).to have_key("data") | ||
| expect(concept["data"]).to have_key("identifier") | ||
| expect(concept["data"]).to have_key("localized_concepts") | ||
| expect(concept["data"]["localized_concepts"]).to be_a(Hash) | ||
| end | ||
| end | ||
|
|
||
| it "creates localized_concept files with V2 structure" do | ||
| localized_files = Dir.glob(File.join(glossarist_output_dir, "localized_concept", "*.yaml")) | ||
| expect(localized_files).not_to be_empty | ||
|
|
||
| localized_files.each do |file| | ||
| localized = YAML.safe_load(File.read(file), permitted_classes: [Date, Time]) | ||
|
|
||
| # V2: localized concept must have id (UUID) at root level | ||
| expect(localized).to have_key("id") | ||
| expect(localized["id"]).to match(/^[0-9a-f-]{36}$/) | ||
|
|
||
| # V2: localized concept must have data with language_code and terms | ||
| expect(localized).to have_key("data") | ||
| expect(localized["data"]).to have_key("language_code") | ||
| expect(localized["data"]["language_code"]).to match(/^[a-z]{3}$/) | ||
| expect(localized["data"]).to have_key("terms") | ||
| expect(localized["data"]["terms"]).to be_an(Array) | ||
| end | ||
| end | ||
|
|
||
| it "links concepts to localized concepts via UUID" do | ||
| concept_files = Dir.glob(File.join(glossarist_output_dir, "concept", "*.yaml")) | ||
| localized_files = Dir.glob(File.join(glossarist_output_dir, "localized_concept", "*.yaml")) | ||
|
|
||
| localized_uuids = localized_files.map do |file| | ||
| YAML.safe_load(File.read(file), permitted_classes: [Date, Time])["id"] | ||
| end | ||
|
|
||
| concept_files.each do |file| | ||
| concept = YAML.safe_load(File.read(file), permitted_classes: [Date, Time]) | ||
| referenced_uuids = concept["data"]["localized_concepts"].values | ||
|
|
||
| referenced_uuids.each do |uuid| | ||
| expect(localized_uuids).to include(uuid) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.