kinow commented on a change in pull request #109: TEXT-155: Add a generic 
IntersectionSimilarity measure
URL: https://github.com/apache/commons-text/pull/109#discussion_r263985299
 
 

 ##########
 File path: 
src/main/java/org/apache/commons/text/similarity/IntersectionSimilarity.java
 ##########
 @@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.text.similarity;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Stream;
+
+/**
+ * Measures the intersection of two sets created from a pair of character 
sequences.
+ *
+ * <p>It is assumed that the type {@code T} correctly conforms to the 
requirements for storage
+ * within a {@link Set} or {@link HashMap}. Ideally the type is immutable and 
implements
+ * {@link Object#equals(Object)} and {@link Object#hashCode()}.</p>
+ *
+ * @param <T> the type of the elements extracted from the character sequence
+ * @since 1.7
+ * @see Set
+ * @see HashMap
+ */
+public class IntersectionSimilarity<T> implements 
SimilarityScore<IntersectionResult> {
+    /** The converter used to create the elements from the characters. */
+    private final Function<CharSequence, Collection<T>> converter;
 
 Review comment:
   I wonder if we also need a `DEFAULT_CHARACTER_CONVERTER` in some 
class/interface? I needed one for characters, so just grabbed the one from the 
unit tests. I imagine other users with two `CharacterSequence` would probably 
use the default one too?
   
   Something like
   
   ```java
           public static final Function<CharSequence, Collection<Character>> 
DEFAULT_CHARACTER_CONVERTER = cs -> {
               final int length = cs.length();
               final Set<Character> set = new HashSet<>(length);
               for (int i = 0; i < length; i++) {
                   set.add(cs.charAt(i));
               }
               return set;
           };
   ```
   
   I think it is Commons CSV that provides some default parsers or readers.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to