@Test public void shouldAvoidOpeningParenthesisAsTheBeginningCharacter() { String string = "Ismail (Emre Kartoglu. Ismai Emre. Ismal. My name is Is mail."; String result = StringTools.getCompletingString(string, 6, 11); assertThat(result, equalTo("Emre")); }
public static String getCompletingString(String string, int begin, int end) { while ( begin > 0 && StringUtils.isAlphanumeric(string.substring(begin, begin+1)) ){ begin -= 1; } if (begin != 0) begin += 1; while ( end < string.length() - 1 && StringUtils.isAlphanumeric(string.substring(end, end + 1)) ){ end += 1; } String regex = "\\w+(\\(?\\)?\\s+\\w+)*"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(string.substring(begin, end)); if (matcher.find()) { return matcher.group(); } return StringUtils.EMPTY; }
StringTools { public static String getCompletingString(String string, int begin, int end) { while ( begin > 0 && StringUtils.isAlphanumeric(string.substring(begin, begin+1)) ){ begin -= 1; } if (begin != 0) begin += 1; while ( end < string.length() - 1 && StringUtils.isAlphanumeric(string.substring(end, end + 1)) ){ end += 1; } String regex = "\\w+(\\(?\\)?\\s+\\w+)*"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(string.substring(begin, end)); if (matcher.find()) { return matcher.group(); } return StringUtils.EMPTY; } }
StringTools { public static String getCompletingString(String string, int begin, int end) { while ( begin > 0 && StringUtils.isAlphanumeric(string.substring(begin, begin+1)) ){ begin -= 1; } if (begin != 0) begin += 1; while ( end < string.length() - 1 && StringUtils.isAlphanumeric(string.substring(end, end + 1)) ){ end += 1; } String regex = "\\w+(\\(?\\)?\\s+\\w+)*"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(string.substring(begin, end)); if (matcher.find()) { return matcher.group(); } return StringUtils.EMPTY; }  }
StringTools { public static String getCompletingString(String string, int begin, int end) { while ( begin > 0 && StringUtils.isAlphanumeric(string.substring(begin, begin+1)) ){ begin -= 1; } if (begin != 0) begin += 1; while ( end < string.length() - 1 && StringUtils.isAlphanumeric(string.substring(end, end + 1)) ){ end += 1; } String regex = "\\w+(\\(?\\)?\\s+\\w+)*"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(string.substring(begin, end)); if (matcher.find()) { return matcher.group(); } return StringUtils.EMPTY; }  static int getLevenshteinDistance(String str1, String str2); static Set<String> getApproximatelyMatchingStringList(String sourceString, String search); boolean isNotTooShort(String string); static Set<String> getApproximatelyMatchingStringList(String sourceString, String search, int maxDistance); static String getCompletingString(String string, int begin, int end); static List<MatchingWindow> getMatchingWindowsAboveThreshold(String text, String search, double threshold); static Set<String> splitIntoWordsWithLengthHigherThan(String string, int minLength); static Set<String> splitIntoWordsWithLengthHigherThan(String string, int minLength, String... ignoreWords); static boolean noContentInHtml(String text); static List<String> getRegexMatchesWithMinLength(String text, String regex, int minLength); static String getRandomForeName(); static String getRandomSurname(); static String getFirstHtmlWithContent(String html); static String getMetaDataFromHTML(String html); static String addMetaDataToHtml(String htmlText, String metaData); }
StringTools { public static String getCompletingString(String string, int begin, int end) { while ( begin > 0 && StringUtils.isAlphanumeric(string.substring(begin, begin+1)) ){ begin -= 1; } if (begin != 0) begin += 1; while ( end < string.length() - 1 && StringUtils.isAlphanumeric(string.substring(end, end + 1)) ){ end += 1; } String regex = "\\w+(\\(?\\)?\\s+\\w+)*"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(string.substring(begin, end)); if (matcher.find()) { return matcher.group(); } return StringUtils.EMPTY; }  static int getLevenshteinDistance(String str1, String str2); static Set<String> getApproximatelyMatchingStringList(String sourceString, String search); boolean isNotTooShort(String string); static Set<String> getApproximatelyMatchingStringList(String sourceString, String search, int maxDistance); static String getCompletingString(String string, int begin, int end); static List<MatchingWindow> getMatchingWindowsAboveThreshold(String text, String search, double threshold); static Set<String> splitIntoWordsWithLengthHigherThan(String string, int minLength); static Set<String> splitIntoWordsWithLengthHigherThan(String string, int minLength, String... ignoreWords); static boolean noContentInHtml(String text); static List<String> getRegexMatchesWithMinLength(String text, String regex, int minLength); static String getRandomForeName(); static String getRandomSurname(); static String getFirstHtmlWithContent(String html); static String getMetaDataFromHTML(String html); static String addMetaDataToHtml(String htmlText, String metaData);  }