MCPcopy Create free account
hub / github.com/LL4J/Filter4J / Tokenizer

Class Tokenizer

src/filter/Tokenizer.java:6–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4import java.util.Scanner;
5
6public 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected