NightOwl888 opened a new issue, #694:
URL: https://github.com/apache/lucenenet/issues/694

   In several code files in `Lucene.Net.Search.Similarities` the `Log2` method 
is imported directly in Java so it doesn't have to be qualified.
   
   ```java
   import static org.apache.lucene.search.similarities.SimilarityBase.log2;
   
   public class BasicModelG extends BasicModel {
     
     /** Sole constructor: parameter-free */
     public BasicModelG() {}
   
     @Override
     public final float score(BasicStats stats, float tfn) {
       // just like in BE, approximation only holds true when F << N, so we use 
lambda = F / (N + F)
       double F = stats.getTotalTermFreq() + 1;
       double N = stats.getNumberOfDocuments();
       double lambda = F / (N + F);
       // -log(1 / (lambda + 1)) -> log(lambda + 1)
       return (float)(log2(lambda + 1) + tfn * log2((1 + lambda) / lambda));
     }
   
     @Override
     public String toString() {
       return "G";
     }
   }
   ```
   
   However, in .NET we are fully qualifying as `SimilarityBase.Log2()`, which 
reduces readability and doesn't align well with the original code.
   
   ```c#
       public class BasicModelG : BasicModel
       {
           /// <summary>
           /// Sole constructor: parameter-free </summary>
           public BasicModelG()
           {
           }
   
           public override sealed float Score(BasicStats stats, float tfn)
           {
               // just like in BE, approximation only holds true when F << N, 
so we use lambda = F / (N + F)
               double F = stats.TotalTermFreq + 1;
               double N = stats.NumberOfDocuments;
               double lambda = F / (N + F);
               // -log(1 / (lambda + 1)) -> log(lambda + 1)
               return (float)(SimilarityBase.Log2(lambda + 1) + tfn * 
SimilarityBase.Log2((1 + lambda) / lambda));
           }
   
           public override string ToString()
           {
               return "G";
           }
       }
   ```
   
   
   To fix this, we should import the static members of `SimilarityBase` in 
every class where it is used. Add the following line at the top of the file 
above the namespace declaration.
   
   ```c#
   using static Lucene.Net.Search.Similarities.SimilarityBase;
   ```
   
   Then we can remove the qualifying statements for `Log2()`.
   
   ```c#
       public class BasicModelG : BasicModel
       {
           /// <summary>
           /// Sole constructor: parameter-free </summary>
           public BasicModelG()
           {
           }
   
           public override sealed float Score(BasicStats stats, float tfn)
           {
               // just like in BE, approximation only holds true when F << N, 
so we use lambda = F / (N + F)
               double F = stats.TotalTermFreq + 1;
               double N = stats.NumberOfDocuments;
               double lambda = F / (N + F);
               // -log(1 / (lambda + 1)) -> log(lambda + 1)
               return (float)(Log2(lambda + 1) + tfn * Log2((1 + lambda) / 
lambda));
           }
   
           public override string ToString()
           {
               return "G";
           }
       }
   ```
   
   We should do this in all classes in `Lucene.Net.Search.Similarities` 
namespace that use the `SimilarityBase.Log2()` 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to