NehanPathan commented on code in PR #1154:
URL: https://github.com/apache/lucenenet/pull/1154#discussion_r2052328325


##########
src/Lucene.Net.Tests.Analysis.SmartCn/DictionaryTests.cs:
##########
@@ -0,0 +1,72 @@
+using Lucene.Net.Util;
+using Lucene.Net.Analysis.Cn.Smart.Hhmm;
+using Lucene.Net.Attributes;
+using NUnit.Framework;
+using System;
+using System.IO;
+using System.Reflection;
+
+
+[TestFixture]
+[LuceneNetSpecific]
+public class DictionaryTests : LuceneTestCase

Review Comment:
   
   ---
   
   **Subject: SmartCN Dictionary Issue – New Structure Failing, Old Approach 
with Tweaks Works**
   
   Hi Shad,
   
   I wanted to follow up on the SmartCN dictionary test. I tried to add all as 
you suggested— ( in which main include ->moving both the `.dct` files and test 
file into a new `Hhmm` folder under `Lucene.Net.Tests.Analysis.SmartCn`. 
However, I’m running continuosly into this error when trying to load the 
dictionary,
   even when we comment out wordDictionary related test code then also show the 
same error after referesh and clean code :
   
   ```
   DirectoryNotFoundException at WordDictionary.LoadMainDataFromFile(String 
dctFilePath)
   ```
   
   But, when I use the very **old test structure with a few tweaks**, 
everything works fine. Here's the working test code I used:
   
   ```csharp
   using Lucene.Net.Util;
   using Lucene.Net.Analysis.Cn.Smart.Hhmm;
   using Lucene.Net.Attributes;
   using NUnit.Framework;
   using Assert = Lucene.Net.TestFramework.Assert;
   using System;
   using System.IO;
   using J2N;
   using System.Reflection;
   
   namespace Lucene.Net.Analysis.Cn.Smart.Hhmm
   {
       [TestFixture]
       [LuceneNetSpecific]
       public class TestBuildDictionary : LuceneTestCase
       {
           [Test]
           public void TestBigramDictionary()
           {
               using var resourceStream = 
typeof(TestBuildDictionary).FindAndGetManifestResourceStream("bigramdict.dct");
   
               FileInfo _tempFile = CreateTempFile("bigramdict", ".dct");
               CopyStreamToFile(resourceStream, _tempFile);
   
               Assert.IsTrue(_tempFile.Length > 0, "Temp file is empty.");
   
               BigramDictionary bigramDict = BigramDictionary.GetInstance();
               bigramDict.LoadFromFile(_tempFile.FullName);
   
               Assert.AreEqual(10, bigramDict.GetFrequency("啊hello".AsSpan()), 
"Frequency for '啊hello' is incorrect.");
               Assert.AreEqual(20, bigramDict.GetFrequency("阿world".AsSpan()), 
"Frequency for '阿world' is incorrect.");
           }
   
           [Test]
           public void TestWordDictionary()
           {
               using var resourceStream = 
typeof(TestBuildDictionary).FindAndGetManifestResourceStream("coredict.dct");
   
               FileInfo _tempFile = CreateTempFile("coredict", ".dct");
               CopyStreamToFile(resourceStream, _tempFile);
   
               Assert.IsTrue(_tempFile.Length > 0, "Temp file is empty.");
   
               WordDictionary wordDict = WordDictionary.GetInstance();
               Assert.AreEqual(30, wordDict.GetFrequency("尼".ToCharArray()), 
"Frequency for '尼' is incorrect.");
               Assert.AreEqual(0, 
wordDict.GetFrequency("missing".ToCharArray()), "Expected frequency 0 for 
unknown word.");
           }
   
           private void CopyStreamToFile(Stream stream, FileInfo file)
           {
               try
               {
                   stream.Position = 0;
                   using var outputStream = File.Create(file.FullName);
                   stream.CopyTo(outputStream);
               }
               catch (Exception ex)
               {
                   Assert.Fail($"Failed to copy stream to file: {ex.Message}");
               }
           }
   
           private new FileInfo CreateTempFile(string prefix, string extension)
           {
               string tempFileName = System.IO.Path.Combine(
                   System.IO.Path.GetTempPath(),
                   $"{prefix}_{Guid.NewGuid():N}{extension}"
               );
               return new FileInfo(tempFileName);
           }
       }
   }
   ```
   
   This version loads the embedded `.dct` files via `ManifestResourceStream`, 
writes them to a temporary file, and then uses that path for loading — and it 
works great.And the interesting part is  here our both the `.dct` files and 
test file still presnt into a new `Hhmm` folder under 
`Lucene.Net.Tests.Analysis.SmartCn`.  
   And all works Great with old structure.
   
   Would love your advice on why the newer structure fails. Is there something 
else I need to tweak in the dictionary loading or resource embedding to make it 
work with the new path?
   
   Thanks again for your time and help!
   
   ---



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to