mawiesne commented on code in PR #158:
URL: https://github.com/apache/opennlp-sandbox/pull/158#discussion_r1677366259
##########
summarizer/src/main/java/opennlp/summarization/lexicalchaining/LexChainingKeywordExtractor.java:
##########
@@ -22,20 +22,45 @@
import java.util.List;
/**
- * Uses the lexical chaining algorithm to extract keywords.
+ * Uses the {@link LexicalChain lexical chaining} algorithm to extract
keywords.
+ *
+ * @see LexicalChain
*/
public class LexChainingKeywordExtractor {
- // Simple logic to pull out the keyword based on longest lexical chains..
- public List<String> getKeywords(List<LexicalChain> lexicalChains, int
noOfKeywords) {
- Collections.sort(lexicalChains);
- List<String> ret = new ArrayList<>();
- for (int i = 0; i < Math.min(lexicalChains.size(), noOfKeywords); i++) {
- List<Word> words = lexicalChains.get(i).getWord();
- if (!words.isEmpty() && !ret.contains(words.get(0).getLexicon())) {
- ret.add(words.get(0).getLexicon());
+ /**
+ * Extracts keywords from a list of {@link LexicalChain lexical chains},
limited by {@code noOfKeywords}.
+ *
+ * @param lexicalChains The {@link LexicalChain lexical chains} to process.
Must not be {@code null}.
+ * @param noOfKeywords The upper limit of keywords. Must be greater than
{@code zero}.
+ *
+ * @return The extracted keywords as a list. Guaranteed to be not {@code
null}.
+ *
+ * @throws IllegalArgumentException Thrown if parameters are invalid.
+ * @implNote This operation is based on longest lexical chains.
Review Comment:
That's cool! :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]