You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2021/02/12 16:22:04 UTC

[GitHub] [lucene-solr] donnerpeter opened a new pull request #2363: LUCENE-9766: Hunspell: add API for retrieving dictionary morphologica…

donnerpeter opened a new pull request #2363:
URL: https://github.com/apache/lucene-solr/pull/2363


   …l data and stemming
   
   <!--
   _(If you are a project committer then you may remove some/all of the following template.)_
   
   Before creating a pull request, please file an issue in the ASF Jira system for Lucene or Solr:
   
   * https://issues.apache.org/jira/projects/LUCENE
   * https://issues.apache.org/jira/projects/SOLR
   
   You will need to create an account in Jira in order to create an issue.
   
   The title of the PR should reference the Jira issue number in the form:
   
   * LUCENE-####: <short description of problem or changes>
   * SOLR-####: <short description of problem or changes>
   
   LUCENE and SOLR must be fully capitalized. A short description helps people scanning pull requests for items they can work on.
   
   Properly referencing the issue in the title ensures that Jira is correctly updated with code review comments and commits. -->
   
   
   # Description
   
   We need to rank suggestions based on metadata associated with corresponding dictionary entries. For that, we need a stemming API (to get the entries) and an API to get the morphological data (where we'd store the needed info)
   
   # Solution
   
   Add public `Hunspell.getRoots` and `Dictionary.lookupEntries`
   
   # Tests
   
   Yes, a test for each new introduced method
   
   # Checklist
   
   Please review the following and check all that apply:
   
   - [x] I have reviewed the guidelines for [How to Contribute](https://wiki.apache.org/solr/HowToContribute) and my code conforms to the standards described there to the best of my ability.
   - [x] I have created a Jira issue and added the issue ID to my pull request title.
   - [x] I have given Solr maintainers [access](https://help.github.com/en/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork) to contribute to my PR branch. (optional but recommended)
   - [x] I have developed this patch against the `master` branch.
   - [x] I have run `./gradlew check`.
   - [x] I have added tests for my changes.
   - [ ] I have added documentation for the [Ref Guide](https://github.com/apache/lucene-solr/tree/master/solr/solr-ref-guide) (for Solr changes only).
   


----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene-solr] dweiss commented on a change in pull request #2363: LUCENE-9766: Hunspell: add API for retrieving dictionary morphologica…

Posted by GitBox <gi...@apache.org>.
dweiss commented on a change in pull request #2363:
URL: https://github.com/apache/lucene-solr/pull/2363#discussion_r576383805



##########
File path: lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
##########
@@ -1224,10 +1259,29 @@ public int compare(BytesRef o1, BytesRef o2) {
     }
   }
 
-  private int addStemException(String stemException) {
-    stemExceptions = ArrayUtil.grow(stemExceptions, stemExceptionCount + 1);
-    stemExceptions[stemExceptionCount++] = stemException;
-    return stemExceptionCount; // we use '0' to indicate no exception for the form
+  private List<String> readMorphFields(String word, String unparsed) {
+    List<String> morphFields = null;
+    for (String datum : splitMorphData(unparsed)) {
+      if (datum.startsWith("ph:")) {
+        addPhoneticRepEntries(word, datum.substring(3));
+      } else {
+        if (morphFields == null) morphFields = new ArrayList<>(1);
+        morphFields.add(datum);
+      }
+    }
+    return morphFields == null ? Collections.emptyList() : morphFields;
+  }
+
+  private int addMorphFields(Map<String, Integer> indices, String morphFields) {
+    Integer alreadyCached = indices.get(morphFields);

Review comment:
       indices.computeIfAbsent?




----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene-solr] donnerpeter commented on a change in pull request #2363: LUCENE-9766: Hunspell: add API for retrieving dictionary morphologica…

Posted by GitBox <gi...@apache.org>.
donnerpeter commented on a change in pull request #2363:
URL: https://github.com/apache/lucene-solr/pull/2363#discussion_r576387876



##########
File path: lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
##########
@@ -1224,10 +1259,29 @@ public int compare(BytesRef o1, BytesRef o2) {
     }
   }
 
-  private int addStemException(String stemException) {
-    stemExceptions = ArrayUtil.grow(stemExceptions, stemExceptionCount + 1);
-    stemExceptions[stemExceptionCount++] = stemException;
-    return stemExceptionCount; // we use '0' to indicate no exception for the form
+  private List<String> readMorphFields(String word, String unparsed) {
+    List<String> morphFields = null;
+    for (String datum : splitMorphData(unparsed)) {
+      if (datum.startsWith("ph:")) {
+        addPhoneticRepEntries(word, datum.substring(3));
+      } else {
+        if (morphFields == null) morphFields = new ArrayList<>(1);
+        morphFields.add(datum);
+      }
+    }
+    return morphFields == null ? Collections.emptyList() : morphFields;
+  }
+
+  private int addMorphFields(Map<String, Integer> indices, String morphFields) {
+    Integer alreadyCached = indices.get(morphFields);

Review comment:
       Thanks, but my sense of beauty prefers `computeIfAbsent` lambdas to be side-effect free




----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene-solr] dweiss commented on a change in pull request #2363: LUCENE-9766: Hunspell: add API for retrieving dictionary morphologica…

Posted by GitBox <gi...@apache.org>.
dweiss commented on a change in pull request #2363:
URL: https://github.com/apache/lucene-solr/pull/2363#discussion_r576390025



##########
File path: lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
##########
@@ -1224,10 +1259,29 @@ public int compare(BytesRef o1, BytesRef o2) {
     }
   }
 
-  private int addStemException(String stemException) {
-    stemExceptions = ArrayUtil.grow(stemExceptions, stemExceptionCount + 1);
-    stemExceptions[stemExceptionCount++] = stemException;
-    return stemExceptionCount; // we use '0' to indicate no exception for the form
+  private List<String> readMorphFields(String word, String unparsed) {
+    List<String> morphFields = null;
+    for (String datum : splitMorphData(unparsed)) {
+      if (datum.startsWith("ph:")) {
+        addPhoneticRepEntries(word, datum.substring(3));
+      } else {
+        if (morphFields == null) morphFields = new ArrayList<>(1);
+        morphFields.add(datum);
+      }
+    }
+    return morphFields == null ? Collections.emptyList() : morphFields;
+  }
+
+  private int addMorphFields(Map<String, Integer> indices, String morphFields) {
+    Integer alreadyCached = indices.get(morphFields);

Review comment:
       There is absolutely nothing stating they have to be though?... it's just a contract on updating the map - how it computes the value and what it updates along the way is not part of the contract at all.
   
   I'll leave it to your sense of beauty though, of course.




----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene-solr] dweiss merged pull request #2363: LUCENE-9766: Hunspell: add API for retrieving dictionary morphologica…

Posted by GitBox <gi...@apache.org>.
dweiss merged pull request #2363:
URL: https://github.com/apache/lucene-solr/pull/2363


   


----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene-solr] donnerpeter commented on a change in pull request #2363: LUCENE-9766: Hunspell: add API for retrieving dictionary morphologica…

Posted by GitBox <gi...@apache.org>.
donnerpeter commented on a change in pull request #2363:
URL: https://github.com/apache/lucene-solr/pull/2363#discussion_r576395392



##########
File path: lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
##########
@@ -1224,10 +1259,29 @@ public int compare(BytesRef o1, BytesRef o2) {
     }
   }
 
-  private int addStemException(String stemException) {
-    stemExceptions = ArrayUtil.grow(stemExceptions, stemExceptionCount + 1);
-    stemExceptions[stemExceptionCount++] = stemException;
-    return stemExceptionCount; // we use '0' to indicate no exception for the form
+  private List<String> readMorphFields(String word, String unparsed) {
+    List<String> morphFields = null;
+    for (String datum : splitMorphData(unparsed)) {
+      if (datum.startsWith("ph:")) {
+        addPhoneticRepEntries(word, datum.substring(3));
+      } else {
+        if (morphFields == null) morphFields = new ArrayList<>(1);
+        morphFields.add(datum);
+      }
+    }
+    return morphFields == null ? Collections.emptyList() : morphFields;
+  }
+
+  private int addMorphFields(Map<String, Integer> indices, String morphFields) {
+    Integer alreadyCached = indices.get(morphFields);

Review comment:
       Yes, I've checked the javadoc and found nothing as well. But still, it aligns with other STM-like similar APIs (e.g. `AtomicInteger#getAndAccumulate`) and just feels better :)




----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene-solr] donnerpeter commented on a change in pull request #2363: LUCENE-9766: Hunspell: add API for retrieving dictionary morphologica…

Posted by GitBox <gi...@apache.org>.
donnerpeter commented on a change in pull request #2363:
URL: https://github.com/apache/lucene-solr/pull/2363#discussion_r575352045



##########
File path: lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/StemmerTestBase.java
##########
@@ -43,6 +43,11 @@ static void init(String affix, String dictionary) throws IOException, ParseExcep
 
   static void init(boolean ignoreCase, String affix, String... dictionaries)
       throws IOException, ParseException {
+    stemmer = new Stemmer(loadDictionary(ignoreCase, affix, dictionaries));
+  }
+
+  static Dictionary loadDictionary(boolean ignoreCase, String affix, String... dictionaries)

Review comment:
       extract a method to call from a test




----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene-solr] donnerpeter commented on a change in pull request #2363: LUCENE-9766: Hunspell: add API for retrieving dictionary morphologica…

Posted by GitBox <gi...@apache.org>.
donnerpeter commented on a change in pull request #2363:
URL: https://github.com/apache/lucene-solr/pull/2363#discussion_r575352984



##########
File path: lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries.java
##########
@@ -205,6 +205,7 @@ private static String memoryUsageSummary(Dictionary dic) {
         + ("strips=" + RamUsageTester.humanSizeOf(dic.stripData) + ", ")
         + ("conditions=" + RamUsageTester.humanSizeOf(dic.patterns) + ", ")
         + ("affixData=" + RamUsageTester.humanSizeOf(dic.affixData) + ", ")
+        + ("morphData=" + RamUsageTester.humanSizeOf(dic.morphData) + ", ")

Review comment:
       There's a slight memory usage increase, ~6% on average. I hope this is fine.




----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org