@Test public void extractContext() throws Exception { String doc = "abcde fghijk"; LanguageDetectorContextGenerator cg = new DefaultLanguageDetectorContextGenerator(1, 3); Collection<String> features = Arrays.asList(cg.getContext(doc)); Assert.assertEquals(33, features.size()); Assert.assertTrue(features.contains("ab")); Assert.assertTrue(features.contains("abc")); Assert.assertTrue(features.contains("e f")); Assert.assertTrue(features.contains(" fg")); }
@Override public String[] getContext(CharSequence document) { Collection<String> context = new ArrayList<>(); NGramCharModel model = new NGramCharModel(); model.add(normalizer.normalize(document), minLength, maxLength); for (String token : model) { context.add(token); } return context.toArray(new String[context.size()]); }
DefaultLanguageDetectorContextGenerator implements LanguageDetectorContextGenerator { @Override public String[] getContext(CharSequence document) { Collection<String> context = new ArrayList<>(); NGramCharModel model = new NGramCharModel(); model.add(normalizer.normalize(document), minLength, maxLength); for (String token : model) { context.add(token); } return context.toArray(new String[context.size()]); } }
DefaultLanguageDetectorContextGenerator implements LanguageDetectorContextGenerator { @Override public String[] getContext(CharSequence document) { Collection<String> context = new ArrayList<>(); NGramCharModel model = new NGramCharModel(); model.add(normalizer.normalize(document), minLength, maxLength); for (String token : model) { context.add(token); } return context.toArray(new String[context.size()]); } DefaultLanguageDetectorContextGenerator(int minLength, int maxLength,
                                                 CharSequenceNormalizer... normalizers); }
DefaultLanguageDetectorContextGenerator implements LanguageDetectorContextGenerator { @Override public String[] getContext(CharSequence document) { Collection<String> context = new ArrayList<>(); NGramCharModel model = new NGramCharModel(); model.add(normalizer.normalize(document), minLength, maxLength); for (String token : model) { context.add(token); } return context.toArray(new String[context.size()]); } DefaultLanguageDetectorContextGenerator(int minLength, int maxLength,
                                                 CharSequenceNormalizer... normalizers); @Override String[] getContext(CharSequence document); }
DefaultLanguageDetectorContextGenerator implements LanguageDetectorContextGenerator { @Override public String[] getContext(CharSequence document) { Collection<String> context = new ArrayList<>(); NGramCharModel model = new NGramCharModel(); model.add(normalizer.normalize(document), minLength, maxLength); for (String token : model) { context.add(token); } return context.toArray(new String[context.size()]); } DefaultLanguageDetectorContextGenerator(int minLength, int maxLength,
                                                 CharSequenceNormalizer... normalizers); @Override String[] getContext(CharSequence document);  }