本文整理汇总了Java中org.apache.commons.codec.language.bm.Languages.LanguageSet.from方法的典型用法代码示例。如果您正苦于以下问题:Java LanguageSet.from方法的具体用法?Java LanguageSet.from怎么用?Java LanguageSet.from使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.codec.language.bm.Languages.LanguageSet
的用法示例。
在下文中一共展示了LanguageSet.from方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.apache.commons.codec.language.bm.Languages.LanguageSet; //导入方法依赖的package包/类
@Override
public TokenStream create(TokenStream tokenStream) {
if (encoder == null) {
if (ruletype != null && nametype != null) {
if (languageset != null) {
final LanguageSet languages = LanguageSet.from(new HashSet<>(Arrays.asList(languageset)));
return new BeiderMorseFilter(tokenStream, new PhoneticEngine(nametype, ruletype, true), languages);
}
return new BeiderMorseFilter(tokenStream, new PhoneticEngine(nametype, ruletype, true));
}
if (maxcodelength > 0) {
return new DoubleMetaphoneFilter(tokenStream, maxcodelength, !replace);
}
} else {
return new PhoneticFilter(tokenStream, encoder, !replace);
}
throw new IllegalArgumentException("encoder error");
}
示例2: BeiderMorseFilterFactory
import org.apache.commons.codec.language.bm.Languages.LanguageSet; //导入方法依赖的package包/类
/** Creates a new BeiderMorseFilterFactory */
public BeiderMorseFilterFactory(Map<String,String> args) {
super(args);
// PhoneticEngine = NameType + RuleType + concat
// we use common-codec's defaults: GENERIC + APPROX + true
NameType nameType = NameType.valueOf(get(args, "nameType", NameType.GENERIC.toString()));
RuleType ruleType = RuleType.valueOf(get(args, "ruleType", RuleType.APPROX.toString()));
boolean concat = getBoolean(args, "concat", true);
engine = new PhoneticEngine(nameType, ruleType, concat);
// LanguageSet: defaults to automagic, otherwise a comma-separated list.
Set<String> langs = getSet(args, "languageSet");
languageSet = (null == langs || (1 == langs.size() && langs.contains("auto"))) ? null : LanguageSet.from(langs);
if (!args.isEmpty()) {
throw new IllegalArgumentException("Unknown parameters: " + args);
}
}
示例3: testLanguageSet
import org.apache.commons.codec.language.bm.Languages.LanguageSet; //导入方法依赖的package包/类
/** restrict the output to a set of possible origin languages */
public void testLanguageSet() throws Exception {
final LanguageSet languages = LanguageSet.from(new HashSet<String>() {{
add("italian"); add("greek"); add("spanish");
}});
Analyzer analyzer = new Analyzer() {
@Override
protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
Tokenizer tokenizer = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
return new TokenStreamComponents(tokenizer,
new BeiderMorseFilter(tokenizer,
new PhoneticEngine(NameType.GENERIC, RuleType.EXACT, true), languages));
}
};
assertAnalyzesTo(analyzer, "Angelo",
new String[] { "andZelo", "angelo", "anxelo" },
new int[] { 0, 0, 0, },
new int[] { 6, 6, 6, },
new int[] { 1, 0, 0, });
}
示例4: init
import org.apache.commons.codec.language.bm.Languages.LanguageSet; //导入方法依赖的package包/类
@Override
public void init(Map<String,String> args) {
super.init(args);
// PhoneticEngine = NameType + RuleType + concat
// we use common-codec's defaults: GENERIC + APPROX + true
String nameTypeArg = args.get("nameType");
NameType nameType = (nameTypeArg == null) ? NameType.GENERIC : NameType.valueOf(nameTypeArg);
String ruleTypeArg = args.get("ruleType");
RuleType ruleType = (ruleTypeArg == null) ? RuleType.APPROX : RuleType.valueOf(ruleTypeArg);
boolean concat = getBoolean("concat", true);
engine = new PhoneticEngine(nameType, ruleType, concat);
// LanguageSet: defaults to automagic, otherwise a comma-separated list.
String languageSetArg = args.get("languageSet");
if (languageSetArg == null || languageSetArg.equals("auto")) {
languageSet = null;
} else {
languageSet = LanguageSet.from(new HashSet<String>(Arrays.asList(languageSetArg.split(","))));
}
}
示例5: guessLanguages
import org.apache.commons.codec.language.bm.Languages.LanguageSet; //导入方法依赖的package包/类
public LanguageSet guessLanguages(String input) {
String text = input.toLowerCase(Locale.ENGLISH);
Set<String> langs = new HashSet(this.languages.getLanguages());
for (LangRule rule : this.rules) {
if (rule.matches(text)) {
if (rule.acceptOnMatch) {
langs.retainAll(rule.languages);
} else {
langs.removeAll(rule.languages);
}
}
}
LanguageSet ls = LanguageSet.from(langs);
return ls.equals(Languages.NO_LANGUAGES) ? Languages.ANY_LANGUAGE : ls;
}
示例6: parsePhoneme
import org.apache.commons.codec.language.bm.Languages.LanguageSet; //导入方法依赖的package包/类
private static Phoneme parsePhoneme(String ph) {
int open = ph.indexOf("[");
if (open < 0) {
return new Phoneme((CharSequence) ph, Languages.ANY_LANGUAGE);
}
if (ph.endsWith("]")) {
return new Phoneme(ph.substring(0, open), LanguageSet.from(new HashSet(Arrays.asList(ph.substring(open + 1, ph.length() - 1).split("[+]")))));
}
throw new IllegalArgumentException("Phoneme expression contains a '[' but does not end in ']'");
}