| 4 | import java.util.Scanner; |
| 5 | |
| 6 | public class Tokenizer { |
| 7 | private final String[] vocab; |
| 8 | |
| 9 | public Tokenizer(String[] vocab) { |
| 10 | this.vocab = vocab; |
| 11 | } |
| 12 | |
| 13 | public static Tokenizer loadFromFile(String filename) { |
| 14 | try { |
| 15 | Scanner scanner = new Scanner(new File(filename)); |
| 16 | int size = Integer.parseInt(scanner.nextLine()); |
| 17 | String[] vocab = new String[size]; |
| 18 | for (int i = 0; i < size; i++) { |
| 19 | vocab[i] = scanner.nextLine(); |
| 20 | } |
| 21 | return new Tokenizer(vocab); |
| 22 | } catch (Exception ignored) { |
| 23 | } |
| 24 | return null; |
| 25 | } |
| 26 | |
| 27 | public double[] tokenize(String text) { |
| 28 | double[] values = new double[vocab.length]; |
| 29 | for (int i = 0; i < values.length; i++) { |
| 30 | if (text.contains(vocab[i])) { |
| 31 | values[i] = 1; |
| 32 | } |
| 33 | } |
| 34 | return values; |
| 35 | } |
| 36 | } |
nothing calls this directly
no outgoing calls
no test coverage detected