diff --git a/src/BibleTaggingUtil/BibleTaggingForm.cs b/src/BibleTaggingUtil/BibleTaggingForm.cs
index c6ad5c7..088163c 100644
--- a/src/BibleTaggingUtil/BibleTaggingForm.cs
+++ b/src/BibleTaggingUtil/BibleTaggingForm.cs
@@ -22,6 +22,7 @@
using Microsoft.VisualBasic.Logging;
using System.Xml.Linq;
using System.Text;
+using System.Text.Json;
namespace BibleTaggingUtil
{
diff --git a/src/BibleTaggingUtil/BibleTaggingUtil.csproj b/src/BibleTaggingUtil/BibleTaggingUtil.csproj
index 2da49fd..0d0372b 100644
--- a/src/BibleTaggingUtil/BibleTaggingUtil.csproj
+++ b/src/BibleTaggingUtil/BibleTaggingUtil.csproj
@@ -8,7 +8,7 @@
Copyright © 2023 by Sami Abdel Malik
https://github.com/sabdelmalik/BibleTagging
git
- 5.2.0.0
+ 5.2.1.0
Bible Text Tagging with Strong's Numbers
diff --git a/src/BibleTaggingUtil/BibleVersions/BibleVersion.cs b/src/BibleTaggingUtil/BibleVersions/BibleVersion.cs
index ed0e05e..3c004b6 100644
--- a/src/BibleTaggingUtil/BibleVersions/BibleVersion.cs
+++ b/src/BibleTaggingUtil/BibleVersions/BibleVersion.cs
@@ -2,10 +2,13 @@
using System;
using System.CodeDom;
using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
+using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
+using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
@@ -424,8 +427,11 @@ private bool LoadOsisBibleFileInternal(string filePath, bool more)
string currentSID = string.Empty;
Verse verse = null;
+ //Stopwatch sw = new Stopwatch();
+ //sw.Start();
try
{
+ container.UpdateProgress("Loading " + bibleName,0);
string osisDoc = string.Empty;
using (StreamReader sr = new StreamReader(filePath))
{
@@ -580,6 +586,43 @@ private bool LoadOsisBibleFileInternal(string filePath, bool more)
}
}
+
+ //var bibleJson = JsonSerializer.Serialize(bible, new JsonSerializerOptions
+ //{
+ // Converters = { new JsonBibleConverter() },
+ // WriteIndented = true,
+ //});
+
+ //var bibleJson = JsonSerializer.Serialize(bible, new JsonSerializerOptions
+ //{
+ // WriteIndented = true,
+ //});
+
+ //sw.Stop();
+ //long leg1 = sw.ElapsedMilliseconds;
+ //sw.Restart();
+
+ //FileStream s = new FileStream(@"C:\temp\Bible.ser",FileMode.Create);
+ //BinaryFormatter b = new BinaryFormatter();
+ //b.Serialize(s, bible);
+ //s.Close();
+
+
+ //JsonBibleConverter conv = new JsonBibleConverter();
+ //string bibleJson = conv.Write(bible);
+ //File.WriteAllText(@"C:\temp\Bible.Json", bibleJson);
+ //sw.Stop();
+ //long leg2 = sw.ElapsedMilliseconds;
+ //sw.Restart();
+
+ //FileStream s1 = new FileStream(@"C:\temp\Bible.ser", FileMode.Open);
+ //BinaryFormatter b1 = new BinaryFormatter();
+ //bible = (Dictionary)b1.Deserialize(s1);
+
+ //conv.Read(@"C:\temp\Bible.Json", bible, bookNames, bookNamesList);
+ //sw.Stop();
+ //long leg3 = sw.ElapsedMilliseconds;
+
return result;
}
diff --git a/src/BibleTaggingUtil/BibleVersions/JsonBibleConverter.cs b/src/BibleTaggingUtil/BibleVersions/JsonBibleConverter.cs
new file mode 100644
index 0000000..d291450
--- /dev/null
+++ b/src/BibleTaggingUtil/BibleVersions/JsonBibleConverter.cs
@@ -0,0 +1,183 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Security.Cryptography.Xml;
+using System.Text;
+using System.Text.Json;
+using System.Text.Json.Nodes;
+using System.Text.Json.Serialization;
+using System.Threading.Tasks;
+using static System.Windows.Forms.Design.AxImporter;
+
+namespace BibleTaggingUtil.BibleVersions
+{
+ internal class JsonBibleConverter
+ {
+ public string Write(Dictionary bible)
+ {
+ string result = string.Empty;
+ try
+ {
+ var options = new JsonWriterOptions
+ {
+ Indented = true
+ };
+
+ using var stream = new MemoryStream();
+ using var writer = new Utf8JsonWriter(stream, options);
+ writer.WriteStartObject();
+ {
+ writer.WritePropertyName("Bible");
+ writer.WriteStartObject();
+ {
+ foreach (var (reference, verse) in bible)
+ {
+ writer.WritePropertyName(reference);
+ writer.WriteStartObject();
+ {
+ WriteVerse(writer, verse);
+ }
+ writer.WriteEndObject();
+ }
+ }
+ writer.WriteEndObject();
+ }
+ writer.WriteEndObject();
+ writer.Flush();
+
+ result = Encoding.UTF8.GetString(stream.ToArray());
+ }
+ catch (Exception ex)
+ {
+ var cm = System.Reflection.MethodBase.GetCurrentMethod();
+ var name = cm.DeclaringType.FullName + "." + cm.Name;
+ Tracing.TraceException(name, ex.Message);
+ }
+ return result;
+ }
+
+ public void Read(string jsonPath, Dictionary bible, Dictionary bookNames, List bookNamesList)
+ {
+ string jsonString = string.Empty;
+ using (StreamReader sr = new StreamReader(jsonPath))
+ {
+ jsonString = sr.ReadToEnd();
+ }
+ JsonNode root = JsonNode.Parse(jsonString);
+ JsonNode bibleNode = root["Bible"];
+ bible.Clear();
+ int wordIndex = 0;
+ var verses = bibleNode.AsObject();
+ foreach (var verse in verses)
+ {
+ string currentReference = verse.Key;
+ Verse theVerse = new Verse();
+ wordIndex = 0;
+ var value = verse.Value["Verse"];
+ var dirty = value["Dirty"];
+ var verseWords = value["VerseWords"].AsArray();
+ foreach (JsonObject verseWord in verseWords)
+ {
+ string? reference = (string)verseWord["Reference"];
+ string? morf = (string)verseWord["Morphology"];
+ string? word = (string)verseWord["Word"];
+ #region Strong's Numbers
+ string? s = (string)verseWord["StrongString"];
+ string[] strongs= new string[0];
+ bool isHebrew = Utils.GetTestament(reference)== BibleTestament.OT;
+ if(s != null)
+ {
+ strongs = s.Split(new char[] { ' ' });
+ for (int i = 0; i","").Replace("<","");
+ if(strongs[i].Length > 0)
+ strongs[i] = strongs[i].Substring(1);
+ }
+ }
+ #endregion Strong's Numbers
+ string? hebrew = (string)verseWord["Hebrew"];
+ string? greek = (string)verseWord["Greek"];
+ string? xlit = (string)verseWord["Transliteration"];
+ VerseWord theWord = new VerseWord(isHebrew ? hebrew : greek, word, strongs, xlit, reference, morf);
+ theVerse[wordIndex++] = theWord;
+ }
+ bible[currentReference] = theVerse;
+ }
+ }
+ private void WriteVerse(Utf8JsonWriter writer, Verse verse)
+ {
+ try
+ {
+ writer.WritePropertyName("Verse");
+
+ writer.WriteStartObject();
+
+ writer.WritePropertyName(nameof(verse.Count));
+ writer.WriteStringValue(verse.Count.ToString());
+
+ writer.WritePropertyName(nameof(verse.Dirty));
+ writer.WriteStringValue(verse.Dirty ? "true" : "false");
+
+ writer.WritePropertyName("VerseWords");
+ writer.WriteStartArray();
+ for (int i = 0; i < verse.Count; i++)
+ {
+ WriteVerseWord(writer, verse[i]);
+ }
+ writer.WriteEndArray();
+
+ writer.WriteEndObject();
+ }
+ catch (Exception ex)
+ {
+ var cm = System.Reflection.MethodBase.GetCurrentMethod();
+ var name = cm.DeclaringType.FullName + "." + cm.Name;
+ Tracing.TraceException(name, ex.Message);
+ }
+
+ }
+
+ private void WriteVerseWord(Utf8JsonWriter writer, VerseWord verseWord)
+ {
+ try
+ {
+ if (verseWord.Reference == "Gen 20:3")
+ {
+ int s = 0;
+ }
+ writer.WriteStartObject();
+
+ writer.WritePropertyName(nameof(verseWord.Reference));
+ writer.WriteStringValue(verseWord.Reference);
+
+ writer.WritePropertyName(nameof(verseWord.Morphology));
+ writer.WriteStringValue(verseWord.Morphology);
+
+ writer.WritePropertyName(nameof(verseWord.Word));
+ writer.WriteStringValue(verseWord.Word);
+
+ writer.WritePropertyName(nameof(verseWord.StrongString));
+ writer.WriteStringValue(verseWord.StrongString);
+
+ writer.WritePropertyName(nameof(verseWord.Hebrew));
+ writer.WriteStringValue(verseWord.Hebrew);
+
+ writer.WritePropertyName(nameof(verseWord.Greek));
+ writer.WriteStringValue(verseWord.Greek);
+
+ writer.WritePropertyName(nameof(verseWord.Transliteration));
+ writer.WriteStringValue(verseWord.Transliteration);
+
+ writer.WriteEndObject();
+ }
+ catch (Exception ex)
+ {
+ var cm = System.Reflection.MethodBase.GetCurrentMethod();
+ var name = cm.DeclaringType.FullName + "." + cm.Name;
+ Tracing.TraceException(name, ex.Message);
+ }
+ }
+ }
+}
diff --git a/src/BibleTaggingUtil/BibleVersions/TargetOsisVersion.cs b/src/BibleTaggingUtil/BibleVersions/TargetOsisVersion.cs
index 0a2941d..7aa4b2d 100644
--- a/src/BibleTaggingUtil/BibleVersions/TargetOsisVersion.cs
+++ b/src/BibleTaggingUtil/BibleVersions/TargetOsisVersion.cs
@@ -165,12 +165,13 @@ private void LoadT(string fileName)
osisDoc = sr.ReadToEnd();
}
+ container.UpdateProgress("Loading " + bibleName, (100 * bookCount) / 66);
+
// Build the book's offsets map
//BuildBookOffsets();
BuildOsisSegments();
bookCount = 0;
- container.UpdateProgress("Loading " + bibleName, (100 * bookCount) / 66);
// Create an OSIS Bible Map
//foreach (string book in bookOffsets.Keys)
//{
@@ -211,45 +212,6 @@ private void BookLoaded(string book, Dictionary localBible)
bookTemp[book] = localBible;
}
}
- //private void LoadBook(Object threadContext) //string book)
- //{
- // string book = (string)threadContext;
-
- // Dictionary localBible = new Dictionary();
- // try
- // {
- // Regex regex = new Regex(
- // string.Format(@"", book));
-
- // MatchCollection VerseMatches = regex.Matches(osisDoc, bookOffsets[book]);
- // if (VerseMatches.Count > 0)
- // {
- // foreach (Match VerseMatch in VerseMatches)
- // {
- // OsisVerse? osisVerse = GetVersesTags(book, VerseMatch);
- // if (osisVerse != null)
- // {
- // //lock (this)
- // {
- // localBible.Add(osisVerse.VerseRefX, osisVerse);
- // }
- // // Verse verseWords = osisVerse.GetVerseWords();
- // // bible.Add(osisVerse.VerseRefX, verseWords);
- // }
- // }
- // }
- // }
- // catch (Exception ex)
- // {
- // var cm = System.Reflection.MethodBase.GetCurrentMethod();
- // var name = cm.DeclaringType.FullName + "." + cm.Name;
- // Tracing.TraceException(name, ex.Message);
- // }
- // finally
- // {
- // BookLoaded(book, localBible);
- // }
- //}
private void LoadBookFromSegments(Object threadContext) //string book)
{
string book = (string)threadContext;
diff --git a/src/BibleTaggingUtil/Editor/EditorPanel.Designer.cs b/src/BibleTaggingUtil/Editor/EditorPanel.Designer.cs
index 184a284..b480343 100644
--- a/src/BibleTaggingUtil/Editor/EditorPanel.Designer.cs
+++ b/src/BibleTaggingUtil/Editor/EditorPanel.Designer.cs
@@ -307,7 +307,6 @@ private void InitializeComponent()
tbTopVersion.ReadOnly = true;
tbTopVersion.Size = new System.Drawing.Size(1299, 31);
tbTopVersion.TabIndex = 3;
- //tbTopVersion.Text = "KJV";
tbTopVersion.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// splitContainer1
diff --git a/src/BibleTaggingUtil/Editor/EditorPanel.resx b/src/BibleTaggingUtil/Editor/EditorPanel.resx
index 55f79fe..5cd9c1f 100644
--- a/src/BibleTaggingUtil/Editor/EditorPanel.resx
+++ b/src/BibleTaggingUtil/Editor/EditorPanel.resx
@@ -1,4 +1,64 @@
-
+
+
+
@@ -64,7 +124,7 @@
iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
- wgAADsIBFShKgAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAEKVSURBVHhe7d0L
+ wAAADsABataJCQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAEKVSURBVHhe7d0L
eBxXffD/XE24Q0hDA4Q0UFIKKaQESHhJQ/mnEOu+u/LWCUns2ZExFJ5waeS7La+1KynBeZ02kAR5Zuzc
2oL7QppQaAtvXi4tpAXbsiyttLuSrRAnxrZmRrYT5+KL9j9HPiHO+ljWZXc1O/v9PM/3gTbEls6Ozm9X
uzNzBgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
diff --git a/src/BibleTaggingUtil/Editor/TargetGridView.cs b/src/BibleTaggingUtil/Editor/TargetGridView.cs
index 48b87de..1fe4a4b 100644
--- a/src/BibleTaggingUtil/Editor/TargetGridView.cs
+++ b/src/BibleTaggingUtil/Editor/TargetGridView.cs
@@ -560,12 +560,55 @@ public void SaveVerse(string reference)
///
protected override void OnCellValueChanged(DataGridViewCellEventArgs e)
{
- if (e.RowIndex == 0)
+ int row = e.RowIndex;
+ int col = e.ColumnIndex;
+
+ if (row == 0)
{
string newWord = (string)this[e.ColumnIndex, e.RowIndex].Value;
CurrentVerse.UpdateWord(e.ColumnIndex, newWord);
-// FireVerseViewChanged();
+ // FireVerseViewChanged();
+ }
+ else if (row == this.RowCount - 1)
+ {
+ string newValue = (string)this[col, row].Value;
+ if (!string.IsNullOrEmpty(newValue))
+ {
+ Regex regex = new Regex(@"[<]{0,1}(\d\d\d\d)[>]{0,1}");
+ MatchCollection matches = regex.Matches(newValue);
+ if (matches.Count > 0)
+ {
+ string temp = string.Empty;
+ foreach (Match match in matches)
+ {
+ temp += string.Format("<{0}> ", match.Groups[1]);
+ }
+ newValue = temp.Trim();
+ }
+ else
+ {
+ // bad entry
+ this[e.ColumnIndex, e.RowIndex].Value = string.Empty;
+ return;
+ }
+ }
+ if (CurrentVerse[col].StrongString != newValue)
+ {
+ if (this.CurrentVerse != null)
+ undoStack.Push(new VerseEx(new Verse(this.CurrentVerse), col, row));
+
+ if (newValue == null) newValue = string.Empty;
+ this[e.ColumnIndex, e.RowIndex].Value = newValue;
+
+ CurrentVerse[col].StrongString = newValue;
+
+ FireRefernceHighlightRequest(newValue);
+
+ //SaveVerse(CurrentVerseReferece);
+ FireVerseViewChanged();
+ }
}
+
base.OnCellValueChanged(e);
}
@@ -635,8 +678,6 @@ protected override void OnDragEnter(DragEventArgs drgevent)
drgevent.Effect = DragDropEffects.Copy;
base.OnDragEnter(drgevent);
}
-
-
protected override void OnDragDrop(DragEventArgs drgevent)
{
DragData data = drgevent.Data.GetData(typeof(DragData)) as DragData;
diff --git a/src/BibleTaggingUtil/Verse.cs b/src/BibleTaggingUtil/Verse.cs
index c58212a..8d2e0e4 100644
--- a/src/BibleTaggingUtil/Verse.cs
+++ b/src/BibleTaggingUtil/Verse.cs
@@ -11,10 +11,18 @@ namespace BibleTaggingUtil
///
/// Represents a verse as a dictionary of verse words
///
+ [Serializable()]
public class Verse
{
private Dictionary verse = new Dictionary();
+ public Dictionary VerseWords
+ {
+ get
+ {
+ return verse;
+ }
+ }
public Verse() { Dirty = false; }
///
diff --git a/src/BibleTaggingUtil/VerseWord.cs b/src/BibleTaggingUtil/VerseWord.cs
index 7a9c13d..60f85e3 100644
--- a/src/BibleTaggingUtil/VerseWord.cs
+++ b/src/BibleTaggingUtil/VerseWord.cs
@@ -7,7 +7,7 @@
namespace BibleTaggingUtil
{
-
+ [Serializable()]
public class VerseWord : ICloneable
{
public VerseWord(string ancientWord, string english, string[] strong, string transliteration, string reference, string morphology)
@@ -69,8 +69,15 @@ public String StrongString
}
set
{
- string strong = value.Replace("<", "").Replace(">", "").Trim();
- Strong = strong.Split(' ');
+ if (string.IsNullOrEmpty(value))
+ {
+ Strong = new string[] {""};
+ }
+ else
+ {
+ string strong = value.Replace("<", "").Replace(">", "").Trim();
+ Strong = strong.Split(' ');
+ }
}
}
public string Transliteration { get; private set; }