Skip to content

[ML] remove use of hppc collections from NLP tokenization #84815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package org.elasticsearch.xpack.ml.inference.nlp.tokenizers;

import com.carrotsearch.hppc.IntArrayList;
import com.ibm.icu.text.Normalizer;
import com.ibm.icu.text.Normalizer2;

Expand Down Expand Up @@ -146,8 +145,8 @@ void stripAccent() {
if (normalizer.quickCheck(termAtt) != Normalizer.YES) {
normalizer.normalize(termAtt, accentBuffer);
}
IntArrayList badIndices = new IntArrayList();
IntArrayList charCount = new IntArrayList();
List<Integer> badIndices = new ArrayList<>();
List<Integer> charCount = new ArrayList<>();
int index = 0;
for (PrimitiveIterator.OfInt it = accentBuffer.codePoints().iterator(); it.hasNext();) {
int cp = it.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

package org.elasticsearch.xpack.ml.inference.nlp.tokenizers;

import com.carrotsearch.hppc.CharArrayList;

import org.apache.lucene.analysis.charfilter.BaseCharFilter;

import java.io.CharArrayReader;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* Char filter for removing control chars from a stream
Expand Down Expand Up @@ -47,7 +48,7 @@ public int read() throws IOException {
}

private void fill() throws IOException {
CharArrayList charArrayList = new CharArrayList(1024);
List<char[]> charArrays = new ArrayList<>();
char[] temp = new char[1024];
int totalRead = 0;
int diff = 0;
Expand All @@ -74,12 +75,18 @@ private void fill() throws IOException {
break;
}
}
charArrayList.add(temp, start, size);
charArrays.add(Arrays.copyOfRange(temp, start, start + size));
pos = start + size;
}
totalRead += cnt;
}
transformedInput = new CharArrayReader(charArrayList.toArray());
char[] wholeArray = new char[charArrays.stream().mapToInt(cs -> cs.length).sum()];
int currIndex = 0;
for (char[] elements : charArrays) {
System.arraycopy(elements, 0, wholeArray, currIndex, elements.length);
currIndex += elements.length;
}
transformedInput = new CharArrayReader(wholeArray);
}

private static boolean isControlChar(char c) {
Expand Down