[ 
https://issues.apache.org/jira/browse/OPENNLP-1340?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17653992#comment-17653992
 ] 

ASF GitHub Bot commented on OPENNLP-1340:
-----------------------------------------

mawiesne commented on code in PR #481:
URL: https://github.com/apache/opennlp/pull/481#discussion_r1060558324


##########
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 or equal to zero and must not exceed 
{@link Sequence#getSize()}.

Review Comment:
   Should read: ".. must be less than {@link Sequence#getSize()}"



##########
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 or equal to 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 or equal to zero and must not exceed 
{@link Sequence#getSize()}.

Review Comment:
   Should read: ".. must be less than {@link Sequence#getSize()}"





> 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)

Reply via email to