/** * Returns a list containing the tagged sentences according to the given tokenized sentence. * * @param tSentence the tokenized sentence to be tagged * @return a list of tagged sentences */ public Set<TaggedSentence> getTaggedSentences(TokenizedSentence tSentence) { Set<TaggedSentence> result = new HashSet<TaggedSentence>(); Pattern sentenceSeparator = Pattern.compile("\\p{Blank}+"); Matcher matcher = sentenceSeparator.matcher(tSentence.getActualSentence()); this.getTaggedSentences(tSentence, matcher, 0, result, new Stack<TaggedTerm>(), null); return result; }
/** * Returns a list containing the tagged sentences according to the given tokenized sentence. * * @param tSentence * @param matcher * @param start * @param taggedSentences * @param currentTerms * @param suggestions */ private void getTaggedSentences( TokenizedSentence tSentence, Matcher matcher, int start, Set<TaggedSentence> taggedSentences, Stack<TaggedTerm> currentTerms, Set<String> suggestions) { String sentence = tSentence.getActualSentence(); if (start >= sentence.length()) { taggedSentences.add(new TaggedSentence(new ArrayList<TaggedTerm>(currentTerms), tSentence)); } else { int numOfSentences = taggedSentences.size(); String str = ""; int pos = start; while (matcher.find(pos)) { str += " " + sentence.substring(pos, matcher.start()); pos = matcher.end(); if (this.getTaggedSentencesAuxiliar( tSentence, matcher, taggedSentences, currentTerms, str, start, matcher.start(), matcher.end(), suggestions)) { break; } } str += " " + sentence.substring(pos, sentence.length()); this.getTaggedSentencesAuxiliar( tSentence, matcher, taggedSentences, currentTerms, str, start, sentence.length(), sentence.length(), suggestions); if (suggestions != null) { if (numOfSentences == taggedSentences.size()) { int nextRead = 0; if (matcher.find(start)) { suggestions.add(this.processString(sentence.substring(start, matcher.start()))); nextRead = matcher.end(); } else { suggestions.add(this.processString(sentence.substring(start, sentence.length()))); nextRead = sentence.length(); } this.getTaggedSentences( tSentence, matcher, nextRead, taggedSentences, currentTerms, suggestions); } } } }