gpt-4-1106-preview· OpenAI
WildChat-4.8M (AI2)
improve this text private static List<SentenceInfo> collectSentences(Annotation…
- User
improve this text
private static List collectSentences(Annotation annotatedDoc, LanguageEnum language) throws Exception { List sentenceInfos = new ArrayList<>();
//Getting sentences... List<CoreMap> sentences = annotatedDoc.get(CoreAnnotations.SentencesAnnotation.class); //Get current language stop-words & POS Tags final CharArraySet stopWordSet = EnglishAnalyzer.getDefaultStopSet(); String word; for (CoreMap sentence : sentences) { List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class); if (tokens == null || tokens.size() >= 300) { continue; } List<String> sTokens = new ArrayList<>(); int isDigit = 0, startI = 0; for (int i = 0; i < tokens.size(); i++) { CoreLabel token = tokens.get(i); if (Thread.interrupted()) { // Allow interrupting throw new InterruptedException("Breaking KeyPhrase token loop due to thread is interrupted"); } // this is the text of the token word = token.word().toLowerCase(); word = CustomASCIIFoldingFilter.convertToASCII(word.toCharArray()); //Split sentence on "___________" or "--------" etc if (PUNCT_CHARS_MIN_5_PATTERN.matcher(word).matches()) { collectSentence(sentenceInfos, tokens.subList(startI, i), sTokens, isDigit); isDigit = 0; startI = i + 1; sTokens = new ArrayList<>(); continue; } String normalizeToken = word; boolean isValidWord = !stopWordSet.contains(normalizeToken); isValidWord = isValidWord && isValidKeyWord(normalizeToken);// isValidWord = isValidWord && validateByWordNet(splitedToken, language);
if (isValidWord) { sTokens.add(word); } if (DIGITS_PATTERN.matcher(word).matches()) { isDigit++; }// } } collectSentence(sentenceInfos, tokens.subList(startI, tokens.size()), sTokens, isDigit); } return sentenceInfos; }
- Assistant