-
Notifications
You must be signed in to change notification settings - Fork 0
Support Checks for Missing Chapters #1
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
Open
BryanHo10
wants to merge
4
commits into
develop
Choose a base branch
from
bh-Missingchapters
base: develop
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.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text; | ||
| using Newtonsoft.Json; | ||
| using System.Text.RegularExpressions; | ||
| using USFMToolsSharp.Linter.Models; | ||
| using USFMToolsSharp.Models.Markers; | ||
| using System.IO; | ||
| using Newtonsoft.Json.Linq; | ||
| using System.Linq; | ||
| using static USFMToolsSharp.Linter.Models.Versisification; | ||
|
|
||
| namespace USFMToolsSharp.Linter.LinterModules | ||
| { | ||
| /// <summary> | ||
| /// Identifies Missing Chapters in a Book. | ||
| /// <remark> A new book is defined on ID Markers </remark> | ||
| /// </summary> | ||
| public class MissingChapters : ILinterModule | ||
| { | ||
| public Versisification ScriptureConfig; | ||
| public MissingChapters(Versisification input) | ||
| { | ||
| ScriptureConfig = input; | ||
| } | ||
| public List<LinterResult> Lint(USFMDocument input) | ||
| { | ||
| List<LinterResult> results = new List<LinterResult>(); | ||
| Dictionary<string, List<int>> chapterCounts = populateBookData(); | ||
| List<Marker> chapters = new List<Marker>(); | ||
| List<string> bookIDs = new List<string>(); | ||
|
|
||
| string currentID =""; | ||
|
|
||
|
|
||
| foreach (Marker marker in input.Contents) | ||
| { | ||
| if(marker is IDMarker) | ||
| { | ||
| currentID = ((IDMarker)marker).TextIdentifier.Split(' ')[0].ToUpper(); | ||
| bookIDs.Add(currentID); | ||
| } | ||
| if(marker is CMarker) | ||
| { | ||
| chapters.Add(marker); | ||
| if (chapterCounts.ContainsKey(currentID)) | ||
| { | ||
| chapterCounts[currentID].Remove(((CMarker)marker).Number); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| foreach(KeyValuePair<string, List<int>> entry in chapterCounts) | ||
| { | ||
| if (bookIDs.Contains(entry.Key)) | ||
| { | ||
| foreach (int missingChapter in entry.Value) | ||
| { | ||
| results.Add(new LinterResult | ||
| { | ||
| Position = chapters[chapters.Count - 1].Position, | ||
| Level = LinterLevel.Warning, | ||
| Message = $"Missing Chapter {missingChapter} in the book of {entry.Key}." | ||
| }); | ||
|
|
||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| return results; | ||
| } | ||
| /// <summary> | ||
| /// Extracts the Book ID (Abbreviation) and Total Number of Chapters into a Dictionary | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| private Dictionary<string,List<int>> populateBookData() | ||
| { | ||
| Dictionary<string, List<int>> output = new Dictionary<string, List<int>>(); | ||
| foreach (KeyValuePair<string,Book> book in ScriptureConfig.metadata) | ||
| { | ||
| output[book.Key] = Enumerable.Range(1, book.Value.TotalChapters).ToList(); | ||
| } | ||
| return output; | ||
| } | ||
|
|
||
| } | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Text; | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace USFMToolsSharp.Linter.Models | ||
| { | ||
| public class Versisification | ||
| { | ||
|
|
||
| public Dictionary<string, Book> metadata { get; set; } | ||
|
|
||
| public class Chapter | ||
| { | ||
| public int ChapterNum { get; set; } | ||
| public int TotalVerses { get; set; } | ||
|
|
||
| } | ||
| public class Book | ||
| { | ||
| public List<Chapter> Chapters { get; set; } | ||
| public int BookID { get; set; } | ||
| public string BookName { get; set; } | ||
| public int TotalChapters { get; set; } | ||
|
|
||
| } | ||
| public Versisification(string filename) | ||
| { | ||
| string jsonData = File.ReadAllText(filename); | ||
| metadata = JsonConvert.DeserializeObject<Dictionary<string, Book>>(jsonData); | ||
|
|
||
| } | ||
| } | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
metadata is metadata and not MetaData