@Signature public Double cosineDistance(Environment env, Memory other) { CosineDistance cosineDistance = new CosineDistance(); return cosineDistance.apply(text, other.toString()); }
@Override public void eval() { String input1 = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput1.start, rawInput1.end, rawInput1.buffer); String input2 = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput2.start, rawInput2.end, rawInput2.buffer); out.value = d.apply(input1, input2); } }
@Override public void setup() { d = new org.apache.commons.text.similarity.CosineDistance(); }
/** * Tests the cosine distance with several inputs. */ @Test public void testCosineDistance() { assertThat(roundValue(cosineDistance.apply("the house", "da house"))).isEqualTo(Double.valueOf(0.5d)); assertThat(roundValue(cosineDistance.apply("AB", "AB"))).isEqualTo(Double.valueOf(0.0d)); assertThat(roundValue(cosineDistance.apply("AB", "BA"))).isEqualTo(Double.valueOf(1.0d)); assertThat(roundValue(cosineDistance.apply( "the boy was from tamana shi, kumamoto ken, and the girl was from rio de janeiro, rio", "the boy was from tamana shi, kumamoto, and the boy was from rio de janeiro, rio de janeiro"))) .isEqualTo(Double.valueOf(0.08d)); }
/** * Creates the cosine distance object used throughout the tests. */ @BeforeAll public static void setUp() { cosineDistance = new CosineDistance(); }
@Override public double calculate(CharSequence s, CharSequence t) { org.apache.commons.text.similarity.CosineDistance distance = new org.apache.commons.text.similarity.CosineDistance(); return distance.apply(s, t); }