SimilarityMetricEditDistance implements IGenericSimilarityMetric { public int UTF8StringEditDistance(byte[] bytesLeft, int fsStart, byte[] bytesRight, int ssStart, int edThresh) throws HyracksDataException { int fsStrLen = UTF8StringUtil.getStringLength(bytesLeft, fsStart); int ssStrLen = UTF8StringUtil.getStringLength(bytesRight, ssStart); if (Math.abs(fsStrLen - ssStrLen) > edThresh) { return SIMILARITY_THRESHOLD_NOT_SATISFIED_VALUE; } int ed = getActualUTF8StringEditDistanceVal(bytesLeft, fsStart, bytesRight, ssStart, edThresh); if (ed > edThresh || ed < 0) { return SIMILARITY_THRESHOLD_NOT_SATISFIED_VALUE; } else { return ed; } } SimilarityMetricEditDistance(); @Override float computeSimilarity(ISequenceIterator firstList, ISequenceIterator secondList, float simThresh); int getSimilarityContains(ISequenceIterator exprList, ISequenceIterator patternList, int simThresh); int getActualUTF8StringEditDistanceVal(byte[] leftBytes, int fsStart, byte[] rightBytes, int ssStart,
            int edThresh); int UTF8StringEditDistance(byte[] bytesLeft, int fsStart, byte[] bytesRight, int ssStart, int edThresh); int UTF8StringEditDistanceContains(byte[] strBytes, int stringStart, byte[] patternBytes, int patternStart,
            int edThresh); @Override float computeSimilarity(ISequenceIterator firstSequence, ISequenceIterator secondSequence); static final int SIMILARITY_THRESHOLD_NOT_SATISFIED_VALUE; }
@Test public void test() throws Exception { UTF8StringPointable leftStrPointable1 = generateUTF8Pointable("coupon not available in store"); UTF8StringPointable rightStrPointable1 = generateUTF8Pointable("coupon is available in store"); UTF8StringPointable rightStrPointable2 = generateUTF8Pointable("coupon in store"); byte[] leftBytes1 = leftStrPointable1.getByteArray(); int leftStartOffset1 = leftStrPointable1.getStartOffset(); byte[] rightBytes1 = rightStrPointable1.getByteArray(); int rightStartOffset1 = rightStrPointable1.getStartOffset(); byte[] rightBytes2 = rightStrPointable2.getByteArray(); int rightStartOffset2 = rightStrPointable2.getStartOffset(); int edThresh = 3; int edVal = ed.UTF8StringEditDistance(leftBytes1, leftStartOffset1, rightBytes1, rightStartOffset1, edThresh); assertEquals(edThresh, edVal); edVal = ed.UTF8StringEditDistance(leftBytes1, leftStartOffset1, rightBytes2, rightStartOffset2, edThresh); assertEquals(SimilarityMetricEditDistance.SIMILARITY_THRESHOLD_NOT_SATISFIED_VALUE, edVal); edThresh = 1; edVal = ed.UTF8StringEditDistance(leftBytes1, leftStartOffset1, rightBytes2, rightStartOffset2, edThresh); assertEquals(SimilarityMetricEditDistance.SIMILARITY_THRESHOLD_NOT_SATISFIED_VALUE, edVal); edThresh = 13; edVal = ed.UTF8StringEditDistance(leftBytes1, leftStartOffset1, rightBytes2, rightStartOffset2, edThresh); assertEquals(SimilarityMetricEditDistance.SIMILARITY_THRESHOLD_NOT_SATISFIED_VALUE, edVal); }