You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@opennlp.apache.org by GitBox <gi...@apache.org> on 2022/12/15 14:35:03 UTC

[GitHub] [opennlp] rzo1 commented on a diff in pull request #458: OPENNLP-1412 Provide equals and hashCode for ParserModel and TokenizerModel

rzo1 commented on code in PR #458:
URL: https://github.com/apache/opennlp/pull/458#discussion_r1049705186


##########
opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java:
##########
@@ -367,4 +367,27 @@ else if (ParserType.TREEINSERT.equals(modelType)) {
       throw new InvalidFormatException("Missing the head rules!");
     }
   }
+
+  @Override
+  public int hashCode() {
+    return Objects.hash(artifactMap.get("manifest.properties"),
+            artifactMap.get(PARSER_TAGGER_MODEL_ENTRY_NAME));
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (obj == this) {
+      return true;
+    }
+
+    if (obj instanceof ParserModel) {
+      ParserModel model = (ParserModel) obj;
+      Map<String, Object> artifactMapToCheck = model.artifactMap;
+      AbstractModel abstractModel = (AbstractModel) artifactMapToCheck.get(BUILD_MODEL_ENTRY_NAME);
+
+      return artifactMap.get("manifest.properties").equals(artifactMapToCheck.get("manifest.properties")) &&

Review Comment:
   see above



##########
opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerModel.java:
##########
@@ -162,4 +163,26 @@ public Dictionary getAbbreviations() {
   public boolean useAlphaNumericOptimization() {
     return getFactory() != null && getFactory().isUseAlphaNumericOptmization();
   }
+
+  @Override
+  public int hashCode() {
+    return Objects.hash(artifactMap.get("manifest.properties"), artifactMap.get(TOKENIZER_MODEL_ENTRY));
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (obj == this) {
+      return true;
+    }
+
+    if (obj instanceof TokenizerModel) {
+      TokenizerModel model = (TokenizerModel) obj;
+      Map<String, Object> artifactMapToCheck = model.artifactMap;
+      AbstractModel abstractModel = (AbstractModel) artifactMapToCheck.get(TOKENIZER_MODEL_ENTRY);
+
+      return artifactMap.get("manifest.properties").equals(artifactMapToCheck.get("manifest.properties")) &&

Review Comment:
   see above



##########
opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java:
##########
@@ -367,4 +367,27 @@ else if (ParserType.TREEINSERT.equals(modelType)) {
       throw new InvalidFormatException("Missing the head rules!");
     }
   }
+
+  @Override
+  public int hashCode() {
+    return Objects.hash(artifactMap.get("manifest.properties"),

Review Comment:
   Can we use ` MANIFEST_ENTRY` from `BaseModel`  ?



##########
opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerModel.java:
##########
@@ -162,4 +163,26 @@ public Dictionary getAbbreviations() {
   public boolean useAlphaNumericOptimization() {
     return getFactory() != null && getFactory().isUseAlphaNumericOptmization();
   }
+
+  @Override
+  public int hashCode() {
+    return Objects.hash(artifactMap.get("manifest.properties"), artifactMap.get(TOKENIZER_MODEL_ENTRY));

Review Comment:
   see above



-- 
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-unsubscribe@opennlp.apache.org

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