public Locale getLocale(String text) { if (Strings.isBlank(text)) { return null; } LanguageIdentifier id = new LanguageIdentifier(text); String language = id.getLanguage(); if (Strings.isBlank(language)) { return null; } return new Locale(language); }
public static String simplifyURL(String url) { if (Strings.isBlank(url)) { return ""; } if (url.indexOf("?") != -1) { url = url.substring(0, url.indexOf("?")); } if (url.indexOf("#") != -1) { url = url.substring(0, url.indexOf("#")); } url = url.trim(); url = url.replaceFirst("^[a-z]+://", ""); url = url.replaceFirst("^www\\.", ""); String[] parts = url.split("/"); StringBuilder simplified = new StringBuilder(); for (int i = 0; i < parts.length; i++) { if (i == 0) { simplified.append(parts[i]); } else if (i == parts.length - 1) { simplified.append(" : "); String part = parts[i]; simplified.append(Strings.decodeURL(part).trim()); } } return simplified.toString(); }
public Language getLanguageForCode(String code) { if (Strings.isBlank(code)) { return null; } Query<Language> query = Query.of(Language.class).withField(Language.CODE, code); return modelService.search(query).getFirst(); }
public LexicalCategory getLexcialCategoryForCode(String code) { if (Strings.isBlank(code)) { return null; } Query<LexicalCategory> query = Query.of(LexicalCategory.class).withField(LexicalCategory.CODE, code); return modelService.search(query).getFirst(); }
public static String[] getWords(String query) { if (Strings.isBlank(query)) { return new String[] {}; } return query.trim().split("\\s+"); }
public static String fallback(String str, String defaultValue) { if (Strings.isBlank(str)) { return defaultValue; } return str; }