[
https://issues.apache.org/jira/browse/OPENNLP-1340?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17653830#comment-17653830
]
ASF GitHub Bot commented on OPENNLP-1340:
-----------------------------------------
rzo1 commented on code in PR #481:
URL: https://github.com/apache/opennlp/pull/481#discussion_r1060319598
##########
opennlp-tools/src/main/java/opennlp/tools/util/Sequence.java:
##########
@@ -122,7 +122,32 @@ public void add(String outcome, double p) {
* @return Retrieves a list of outcomes for this {@link Sequence}.
*/
public List<String> getOutcomes() {
- return outcomes;
+ return List.copyOf(outcomes);
+ }
+
+ /**
+ * @return Retrieves the size of the outcomes for this {@link Sequence}.
+ */
+ public int getSize() {
+ return outcomes.size();
+ }
+
+ /**
+ * @param index must be greater than zero and must not exceed {@link
Sequence#getSize()}.
Review Comment:
Reading it after the night, it should better read: "must be greater or equal
to zero". 0 is an allowed value here. Will fix later.
##########
opennlp-tools/src/main/java/opennlp/tools/util/Sequence.java:
##########
@@ -122,7 +122,32 @@ public void add(String outcome, double p) {
* @return Retrieves a list of outcomes for this {@link Sequence}.
*/
public List<String> getOutcomes() {
- return outcomes;
+ return List.copyOf(outcomes);
+ }
+
+ /**
+ * @return Retrieves the size of the outcomes for this {@link Sequence}.
+ */
+ public int getSize() {
+ return outcomes.size();
+ }
+
+ /**
+ * @param index must be greater than zero and must not exceed {@link
Sequence#getSize()}.
+ * @return the outcome at the specified index.
+ * @throws IndexOutOfBoundsException thrown if the given index is out of
range.
+ */
+ public String getOutcome(int index) {
+ return outcomes.get(index);
+ }
+
+ /**
+ * @param index must be greater than zero and must not exceed {@link
Sequence#getSize()}.
Review Comment:
Dito
> Get the probability for a sequence without copying the probabilities
> --------------------------------------------------------------------
>
> Key: OPENNLP-1340
> URL: https://issues.apache.org/jira/browse/OPENNLP-1340
> Project: OpenNLP
> Issue Type: Wish
> Components: POS Tagger
> Affects Versions: 1.9.3
> Reporter: Reece H. Dunn
> Assignee: Richard Zowalla
> Priority: Trivial
> Labels: easyfix
> Fix For: 2.1.1
>
>
> The "opennlp.tools.util.Sequence" class has a "getOutcomes" method that
> returns the outcomes as the underlying list without copying the data.
> However, the "getProbs" method returns the probabilities as an array copy of
> the underlying probabilities list.
> It would be useful to have the following accessor methods to avoid the copy
> (and an accessor for the outcomes for API consistency):
> {code:java}
> public int getSize() {
> return outcomes.size();
> }
> public String getOutcome(int index) {
> return outcomes.get(index);
> }
> public double getProb(int index) {
> return probs.get(index);
> }
> {code}
> The motivation is that I want to convert the "POSTagger.topKSequences" to a
> "Map<String, Double>", in addition to locating the highest probability tag in
> the result.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)