NehanPathan commented on code in PR #1154: URL: https://github.com/apache/lucenenet/pull/1154#discussion_r2051562721
########## 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: --- **[@NightOwl888]** Hi Shad, I've implemented the changes you suggested, including: - Setting up the temporary directory with `CreateTempDir()` - Naming the files correctly - Using `this.GetType().FindAndGetResourceStream()` - Adding the following to the `Lucene.Net.Tests.Analysis.SmartCn.csproj` file: ```xml <PackageReference Include="J2N" Version="$(J2NPackageVersion)" /> ``` However, I'm still encountering a build error: ``` CS1061: 'Type' does not contain a definition for 'FindAndGetResourceStream' and no accessible extension method 'FindAndGetResourceStream' accepting a first argument of type 'Type' could be found... ``` Could you please advise on why this extension method might not be recognized even with the J2N package referenced? Is there perhaps a specific `using` directive I'm missing, or a different way this extension is typically accessed in the project? --- **Code Snippet (Test Class):** ```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 J2N.IO; namespace Lucene.Net.Analysis.Cn.Smart.Hhmm { [TestFixture] [LuceneNetSpecific] public class DictionaryTests : LuceneTestCase { private const string BigramFileName = "bigramdict.dct"; private const string CoreFileName = "coredict.dct"; private DirectoryInfo tempDir; public override void OneTimeSetUp() { tempDir = CreateTempDir("smartcn-data"); AnalyzerProfile.ANALYSIS_DATA_DIR = tempDir.FullName; CopyResourceToFile(BigramFileName); CopyResourceToFile(CoreFileName); } private void CopyResourceToFile(string resourceName) { using var resourceStream = this.GetType().FindAndGetResourceStream(resourceName); Assert.NotNull(resourceStream, $"Resource '{resourceName}' not found!"); Assert.IsTrue(resourceStream.Length > 0, $"Resource Stream '{resourceName}' is empty"); string tempFilePath = Path.Combine(tempDir.FullName, resourceName); using var tempFileStream = File.Create(tempFilePath); resourceStream.CopyTo(tempFileStream); Assert.IsTrue(new FileInfo(tempFilePath).Length > 0, $"Temp file '{resourceName}' is empty."); } [Test] public void TestBigramDictionary() { BigramDictionary bigramDict = BigramDictionary.GetInstance(); 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 TestWordDictionaryGetInstance() { WordDictionary wordDict = WordDictionary.GetInstance(); var freq = wordDict.GetFrequency("尼".ToCharArray()); Assert.AreEqual(30, freq, "Frequency for '尼' is incorrect."); var freqMissing = wordDict.GetFrequency("missing".ToCharArray()); Assert.AreEqual(0, freqMissing, "Expected frequency 0 for unknown word."); } } } ``` --- **Relevant Section from `.csproj` File:** ```xml <ItemGroup> <ProjectReference Include="..\Lucene.Net\Lucene.Net.csproj"> <SetTargetFramework>$(SetTargetFramework)</SetTargetFramework> </ProjectReference> <ProjectReference Include="..\Lucene.Net.Analysis.Common\Lucene.Net.Analysis.Common.csproj"> <SetTargetFramework>$(SetTargetFramework)</SetTargetFramework> </ProjectReference> <ProjectReference Include="..\Lucene.Net.Analysis.SmartCn\Lucene.Net.Analysis.SmartCn.csproj"> <SetTargetFramework>$(SetTargetFramework)</SetTargetFramework> </ProjectReference> <ProjectReference Include="..\Lucene.Net.Codecs\Lucene.Net.Codecs.csproj"> <SetTargetFramework>$(SetTargetFramework)</SetTargetFramework> </ProjectReference> <ProjectReference Include="..\Lucene.Net.Highlighter\Lucene.Net.Highlighter.csproj"> <SetTargetFramework>$(SetTargetFramework)</SetTargetFramework> </ProjectReference> <ProjectReference Include="..\dotnet\Lucene.Net.ICU\Lucene.Net.ICU.csproj"> <SetTargetFramework>$(SetTargetFramework)</SetTargetFramework> </ProjectReference> <ProjectReference Include="..\Lucene.Net.Memory\Lucene.Net.Memory.csproj"> <SetTargetFramework>$(SetTargetFramework)</SetTargetFramework> </ProjectReference> <ProjectReference Include="..\Lucene.Net.Queries\Lucene.Net.Queries.csproj"> <SetTargetFramework>$(SetTargetFramework)</SetTargetFramework> </ProjectReference> <ProjectReference Include="..\Lucene.Net.TestFramework\Lucene.Net.TestFramework.csproj"> <SetTargetFramework>$(SetTargetFramework)</SetTargetFramework> </ProjectReference> <PackageReference Include="J2N" Version="$(J2NPackageVersion)" /> </ItemGroup> ``` Thanks again for your help! Let me know if there’s something I overlooked regarding the `FindAndGetResourceStream()` method. --- -- 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