@Test public void testNormalCase3() throws ParsingException { ParseTokens pTokens = new ParseTokens(Arrays.asList("functionalfoo",""), Arrays.asList('a', OpsinTools.END_OF_FUNCTIONALTERM)); List<ParseWord> parseWords = WordTools.splitIntoParseWords(Arrays.asList(pTokens), "functionalfoo"); assertEquals(1, parseWords.size()); assertEquals("functionalfoo", parseWords.get(0).getWord()); assertEquals(1, parseWords.get(0).getParseTokens().size()); assertEquals(pTokens, parseWords.get(0).getParseTokens().get(0)); }
static List<ParseWord> splitIntoParseWords(List<ParseTokens> parseTokensList, String chemicalName) { List<ParseTokens> wellFormedParseTokens = new ArrayList<ParseTokens>(); List<List<ParseTokens>> splitParseTokensForEachParseTokens = new ArrayList<List<ParseTokens>>(); int leastWordsInOmmittedSpaceParse = Integer.MAX_VALUE; int longestFunctionalTermEncountered = 0; for (ParseTokens parseTokens : parseTokensList) { List<Character> annotations = parseTokens.getAnnotations(); List<List<Character>> chunkedAnnotations = chunkAnnotations(annotations); if (containsOmittedSpace(chunkedAnnotations)){ List<ParseTokens> omittedWordParseTokens = new ArrayList<ParseTokens>(); List<String> tokens = parseTokens.getTokens(); List<Character> newAnnotations = new ArrayList<Character>(); List<String> newTokens = new ArrayList<String>(); int currentFunctionalTermLength = 0; int annotPos = 0; for (List<Character> annotationList : chunkedAnnotations) { Character finalAnnotationInList = annotationList.get(annotationList.size() - 1); if (finalAnnotationInList.equals(END_OF_FUNCTIONALTERM) && newAnnotations.size() > 0) { omittedWordParseTokens.add(new ParseTokens(newTokens, newAnnotations)); newAnnotations = new ArrayList<Character>(); newTokens = new ArrayList<String>(); } for (Character annotation : annotationList) { newAnnotations.add(annotation); newTokens.add(tokens.get(annotPos++)); } if (finalAnnotationInList.equals(END_OF_FUNCTIONALTERM) || finalAnnotationInList.equals(END_OF_MAINGROUP) || annotPos == tokens.size()) { omittedWordParseTokens.add(new ParseTokens(newTokens, newAnnotations)); if (finalAnnotationInList.equals(END_OF_FUNCTIONALTERM)){ currentFunctionalTermLength = StringTools.stringListToString(newTokens, "").length(); } newAnnotations = new ArrayList<Character>(); newTokens = new ArrayList<String>(); } } if (omittedWordParseTokens.size() <= leastWordsInOmmittedSpaceParse){ if (omittedWordParseTokens.size() < leastWordsInOmmittedSpaceParse){ splitParseTokensForEachParseTokens.clear(); leastWordsInOmmittedSpaceParse = omittedWordParseTokens.size(); longestFunctionalTermEncountered = 0; } if (currentFunctionalTermLength >=longestFunctionalTermEncountered){ if (currentFunctionalTermLength > longestFunctionalTermEncountered){ splitParseTokensForEachParseTokens.clear(); longestFunctionalTermEncountered =currentFunctionalTermLength; } splitParseTokensForEachParseTokens.add(omittedWordParseTokens); } } } else { wellFormedParseTokens.add(parseTokens); } } List<ParseWord> parseWords = new ArrayList<ParseWord>(); if (!wellFormedParseTokens.isEmpty()) { parseWords.add(new ParseWord(chemicalName, wellFormedParseTokens)); } else { for (int i = 0; i < leastWordsInOmmittedSpaceParse; i++) { List<ParseTokens> parseTokensForWord = new ArrayList<ParseTokens>(); for (List<ParseTokens> parseTokens : splitParseTokensForEachParseTokens) { if (!parseTokensForWord.contains(parseTokens.get(i))){ parseTokensForWord.add(parseTokens.get(i)); } } parseWords.add(new ParseWord(StringTools.stringListToString(parseTokensForWord.get(0).getTokens(), ""), parseTokensForWord)); } } return parseWords; }
WordTools { static List<ParseWord> splitIntoParseWords(List<ParseTokens> parseTokensList, String chemicalName) { List<ParseTokens> wellFormedParseTokens = new ArrayList<ParseTokens>(); List<List<ParseTokens>> splitParseTokensForEachParseTokens = new ArrayList<List<ParseTokens>>(); int leastWordsInOmmittedSpaceParse = Integer.MAX_VALUE; int longestFunctionalTermEncountered = 0; for (ParseTokens parseTokens : parseTokensList) { List<Character> annotations = parseTokens.getAnnotations(); List<List<Character>> chunkedAnnotations = chunkAnnotations(annotations); if (containsOmittedSpace(chunkedAnnotations)){ List<ParseTokens> omittedWordParseTokens = new ArrayList<ParseTokens>(); List<String> tokens = parseTokens.getTokens(); List<Character> newAnnotations = new ArrayList<Character>(); List<String> newTokens = new ArrayList<String>(); int currentFunctionalTermLength = 0; int annotPos = 0; for (List<Character> annotationList : chunkedAnnotations) { Character finalAnnotationInList = annotationList.get(annotationList.size() - 1); if (finalAnnotationInList.equals(END_OF_FUNCTIONALTERM) && newAnnotations.size() > 0) { omittedWordParseTokens.add(new ParseTokens(newTokens, newAnnotations)); newAnnotations = new ArrayList<Character>(); newTokens = new ArrayList<String>(); } for (Character annotation : annotationList) { newAnnotations.add(annotation); newTokens.add(tokens.get(annotPos++)); } if (finalAnnotationInList.equals(END_OF_FUNCTIONALTERM) || finalAnnotationInList.equals(END_OF_MAINGROUP) || annotPos == tokens.size()) { omittedWordParseTokens.add(new ParseTokens(newTokens, newAnnotations)); if (finalAnnotationInList.equals(END_OF_FUNCTIONALTERM)){ currentFunctionalTermLength = StringTools.stringListToString(newTokens, "").length(); } newAnnotations = new ArrayList<Character>(); newTokens = new ArrayList<String>(); } } if (omittedWordParseTokens.size() <= leastWordsInOmmittedSpaceParse){ if (omittedWordParseTokens.size() < leastWordsInOmmittedSpaceParse){ splitParseTokensForEachParseTokens.clear(); leastWordsInOmmittedSpaceParse = omittedWordParseTokens.size(); longestFunctionalTermEncountered = 0; } if (currentFunctionalTermLength >=longestFunctionalTermEncountered){ if (currentFunctionalTermLength > longestFunctionalTermEncountered){ splitParseTokensForEachParseTokens.clear(); longestFunctionalTermEncountered =currentFunctionalTermLength; } splitParseTokensForEachParseTokens.add(omittedWordParseTokens); } } } else { wellFormedParseTokens.add(parseTokens); } } List<ParseWord> parseWords = new ArrayList<ParseWord>(); if (!wellFormedParseTokens.isEmpty()) { parseWords.add(new ParseWord(chemicalName, wellFormedParseTokens)); } else { for (int i = 0; i < leastWordsInOmmittedSpaceParse; i++) { List<ParseTokens> parseTokensForWord = new ArrayList<ParseTokens>(); for (List<ParseTokens> parseTokens : splitParseTokensForEachParseTokens) { if (!parseTokensForWord.contains(parseTokens.get(i))){ parseTokensForWord.add(parseTokens.get(i)); } } parseWords.add(new ParseWord(StringTools.stringListToString(parseTokensForWord.get(0).getTokens(), ""), parseTokensForWord)); } } return parseWords; } }
WordTools { static List<ParseWord> splitIntoParseWords(List<ParseTokens> parseTokensList, String chemicalName) { List<ParseTokens> wellFormedParseTokens = new ArrayList<ParseTokens>(); List<List<ParseTokens>> splitParseTokensForEachParseTokens = new ArrayList<List<ParseTokens>>(); int leastWordsInOmmittedSpaceParse = Integer.MAX_VALUE; int longestFunctionalTermEncountered = 0; for (ParseTokens parseTokens : parseTokensList) { List<Character> annotations = parseTokens.getAnnotations(); List<List<Character>> chunkedAnnotations = chunkAnnotations(annotations); if (containsOmittedSpace(chunkedAnnotations)){ List<ParseTokens> omittedWordParseTokens = new ArrayList<ParseTokens>(); List<String> tokens = parseTokens.getTokens(); List<Character> newAnnotations = new ArrayList<Character>(); List<String> newTokens = new ArrayList<String>(); int currentFunctionalTermLength = 0; int annotPos = 0; for (List<Character> annotationList : chunkedAnnotations) { Character finalAnnotationInList = annotationList.get(annotationList.size() - 1); if (finalAnnotationInList.equals(END_OF_FUNCTIONALTERM) && newAnnotations.size() > 0) { omittedWordParseTokens.add(new ParseTokens(newTokens, newAnnotations)); newAnnotations = new ArrayList<Character>(); newTokens = new ArrayList<String>(); } for (Character annotation : annotationList) { newAnnotations.add(annotation); newTokens.add(tokens.get(annotPos++)); } if (finalAnnotationInList.equals(END_OF_FUNCTIONALTERM) || finalAnnotationInList.equals(END_OF_MAINGROUP) || annotPos == tokens.size()) { omittedWordParseTokens.add(new ParseTokens(newTokens, newAnnotations)); if (finalAnnotationInList.equals(END_OF_FUNCTIONALTERM)){ currentFunctionalTermLength = StringTools.stringListToString(newTokens, "").length(); } newAnnotations = new ArrayList<Character>(); newTokens = new ArrayList<String>(); } } if (omittedWordParseTokens.size() <= leastWordsInOmmittedSpaceParse){ if (omittedWordParseTokens.size() < leastWordsInOmmittedSpaceParse){ splitParseTokensForEachParseTokens.clear(); leastWordsInOmmittedSpaceParse = omittedWordParseTokens.size(); longestFunctionalTermEncountered = 0; } if (currentFunctionalTermLength >=longestFunctionalTermEncountered){ if (currentFunctionalTermLength > longestFunctionalTermEncountered){ splitParseTokensForEachParseTokens.clear(); longestFunctionalTermEncountered =currentFunctionalTermLength; } splitParseTokensForEachParseTokens.add(omittedWordParseTokens); } } } else { wellFormedParseTokens.add(parseTokens); } } List<ParseWord> parseWords = new ArrayList<ParseWord>(); if (!wellFormedParseTokens.isEmpty()) { parseWords.add(new ParseWord(chemicalName, wellFormedParseTokens)); } else { for (int i = 0; i < leastWordsInOmmittedSpaceParse; i++) { List<ParseTokens> parseTokensForWord = new ArrayList<ParseTokens>(); for (List<ParseTokens> parseTokens : splitParseTokensForEachParseTokens) { if (!parseTokensForWord.contains(parseTokens.get(i))){ parseTokensForWord.add(parseTokens.get(i)); } } parseWords.add(new ParseWord(StringTools.stringListToString(parseTokensForWord.get(0).getTokens(), ""), parseTokensForWord)); } } return parseWords; }  }
WordTools { static List<ParseWord> splitIntoParseWords(List<ParseTokens> parseTokensList, String chemicalName) { List<ParseTokens> wellFormedParseTokens = new ArrayList<ParseTokens>(); List<List<ParseTokens>> splitParseTokensForEachParseTokens = new ArrayList<List<ParseTokens>>(); int leastWordsInOmmittedSpaceParse = Integer.MAX_VALUE; int longestFunctionalTermEncountered = 0; for (ParseTokens parseTokens : parseTokensList) { List<Character> annotations = parseTokens.getAnnotations(); List<List<Character>> chunkedAnnotations = chunkAnnotations(annotations); if (containsOmittedSpace(chunkedAnnotations)){ List<ParseTokens> omittedWordParseTokens = new ArrayList<ParseTokens>(); List<String> tokens = parseTokens.getTokens(); List<Character> newAnnotations = new ArrayList<Character>(); List<String> newTokens = new ArrayList<String>(); int currentFunctionalTermLength = 0; int annotPos = 0; for (List<Character> annotationList : chunkedAnnotations) { Character finalAnnotationInList = annotationList.get(annotationList.size() - 1); if (finalAnnotationInList.equals(END_OF_FUNCTIONALTERM) && newAnnotations.size() > 0) { omittedWordParseTokens.add(new ParseTokens(newTokens, newAnnotations)); newAnnotations = new ArrayList<Character>(); newTokens = new ArrayList<String>(); } for (Character annotation : annotationList) { newAnnotations.add(annotation); newTokens.add(tokens.get(annotPos++)); } if (finalAnnotationInList.equals(END_OF_FUNCTIONALTERM) || finalAnnotationInList.equals(END_OF_MAINGROUP) || annotPos == tokens.size()) { omittedWordParseTokens.add(new ParseTokens(newTokens, newAnnotations)); if (finalAnnotationInList.equals(END_OF_FUNCTIONALTERM)){ currentFunctionalTermLength = StringTools.stringListToString(newTokens, "").length(); } newAnnotations = new ArrayList<Character>(); newTokens = new ArrayList<String>(); } } if (omittedWordParseTokens.size() <= leastWordsInOmmittedSpaceParse){ if (omittedWordParseTokens.size() < leastWordsInOmmittedSpaceParse){ splitParseTokensForEachParseTokens.clear(); leastWordsInOmmittedSpaceParse = omittedWordParseTokens.size(); longestFunctionalTermEncountered = 0; } if (currentFunctionalTermLength >=longestFunctionalTermEncountered){ if (currentFunctionalTermLength > longestFunctionalTermEncountered){ splitParseTokensForEachParseTokens.clear(); longestFunctionalTermEncountered =currentFunctionalTermLength; } splitParseTokensForEachParseTokens.add(omittedWordParseTokens); } } } else { wellFormedParseTokens.add(parseTokens); } } List<ParseWord> parseWords = new ArrayList<ParseWord>(); if (!wellFormedParseTokens.isEmpty()) { parseWords.add(new ParseWord(chemicalName, wellFormedParseTokens)); } else { for (int i = 0; i < leastWordsInOmmittedSpaceParse; i++) { List<ParseTokens> parseTokensForWord = new ArrayList<ParseTokens>(); for (List<ParseTokens> parseTokens : splitParseTokensForEachParseTokens) { if (!parseTokensForWord.contains(parseTokens.get(i))){ parseTokensForWord.add(parseTokens.get(i)); } } parseWords.add(new ParseWord(StringTools.stringListToString(parseTokensForWord.get(0).getTokens(), ""), parseTokensForWord)); } } return parseWords; }   }
WordTools { static List<ParseWord> splitIntoParseWords(List<ParseTokens> parseTokensList, String chemicalName) { List<ParseTokens> wellFormedParseTokens = new ArrayList<ParseTokens>(); List<List<ParseTokens>> splitParseTokensForEachParseTokens = new ArrayList<List<ParseTokens>>(); int leastWordsInOmmittedSpaceParse = Integer.MAX_VALUE; int longestFunctionalTermEncountered = 0; for (ParseTokens parseTokens : parseTokensList) { List<Character> annotations = parseTokens.getAnnotations(); List<List<Character>> chunkedAnnotations = chunkAnnotations(annotations); if (containsOmittedSpace(chunkedAnnotations)){ List<ParseTokens> omittedWordParseTokens = new ArrayList<ParseTokens>(); List<String> tokens = parseTokens.getTokens(); List<Character> newAnnotations = new ArrayList<Character>(); List<String> newTokens = new ArrayList<String>(); int currentFunctionalTermLength = 0; int annotPos = 0; for (List<Character> annotationList : chunkedAnnotations) { Character finalAnnotationInList = annotationList.get(annotationList.size() - 1); if (finalAnnotationInList.equals(END_OF_FUNCTIONALTERM) && newAnnotations.size() > 0) { omittedWordParseTokens.add(new ParseTokens(newTokens, newAnnotations)); newAnnotations = new ArrayList<Character>(); newTokens = new ArrayList<String>(); } for (Character annotation : annotationList) { newAnnotations.add(annotation); newTokens.add(tokens.get(annotPos++)); } if (finalAnnotationInList.equals(END_OF_FUNCTIONALTERM) || finalAnnotationInList.equals(END_OF_MAINGROUP) || annotPos == tokens.size()) { omittedWordParseTokens.add(new ParseTokens(newTokens, newAnnotations)); if (finalAnnotationInList.equals(END_OF_FUNCTIONALTERM)){ currentFunctionalTermLength = StringTools.stringListToString(newTokens, "").length(); } newAnnotations = new ArrayList<Character>(); newTokens = new ArrayList<String>(); } } if (omittedWordParseTokens.size() <= leastWordsInOmmittedSpaceParse){ if (omittedWordParseTokens.size() < leastWordsInOmmittedSpaceParse){ splitParseTokensForEachParseTokens.clear(); leastWordsInOmmittedSpaceParse = omittedWordParseTokens.size(); longestFunctionalTermEncountered = 0; } if (currentFunctionalTermLength >=longestFunctionalTermEncountered){ if (currentFunctionalTermLength > longestFunctionalTermEncountered){ splitParseTokensForEachParseTokens.clear(); longestFunctionalTermEncountered =currentFunctionalTermLength; } splitParseTokensForEachParseTokens.add(omittedWordParseTokens); } } } else { wellFormedParseTokens.add(parseTokens); } } List<ParseWord> parseWords = new ArrayList<ParseWord>(); if (!wellFormedParseTokens.isEmpty()) { parseWords.add(new ParseWord(chemicalName, wellFormedParseTokens)); } else { for (int i = 0; i < leastWordsInOmmittedSpaceParse; i++) { List<ParseTokens> parseTokensForWord = new ArrayList<ParseTokens>(); for (List<ParseTokens> parseTokens : splitParseTokensForEachParseTokens) { if (!parseTokensForWord.contains(parseTokens.get(i))){ parseTokensForWord.add(parseTokens.get(i)); } } parseWords.add(new ParseWord(StringTools.stringListToString(parseTokensForWord.get(0).getTokens(), ""), parseTokensForWord)); } } return parseWords; }    }