You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@opennlp.apache.org by "Daniel Russ (JIRA)" <ji...@apache.org> on 2016/10/21 14:09:58 UTC
[jira] [Commented] (OPENNLP-870) Please Make ContextGenerator a
Generic Type
[ https://issues.apache.org/jira/browse/OPENNLP-870?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15595197#comment-15595197 ]
Daniel Russ commented on OPENNLP-870:
-------------------------------------
/** Here is a Patch.... **/
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/BasicContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/BasicContextGenerator.java
index 1175ecc..ec90d60 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/BasicContextGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/BasicContextGenerator.java
@@ -29,7 +29,7 @@ package opennlp.tools.ml.maxent;
* cp_1 cp_2 ... cp_n
* </p>
*/
-public class BasicContextGenerator implements ContextGenerator {
+public class BasicContextGenerator implements ContextGenerator<String> {
private String separator = " ";
@@ -42,8 +42,7 @@ public class BasicContextGenerator implements ContextGenerator {
/**
* Builds up the list of contextual predicates given a String.
*/
- public String[] getContext(Object o) {
- String s = (String) o;
+ public String[] getContext(String s) {
return (String[]) s.split(separator);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/ContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/ContextGenerator.java
index 0582323..fa92846 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/ContextGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/ContextGenerator.java
@@ -22,11 +22,11 @@ package opennlp.tools.ml.maxent;
/**
* Generate contexts for maxent decisions.
*/
-public interface ContextGenerator {
+public interface ContextGenerator<T> {
/**
* Builds up the list of contextual predicates given an Object.
*/
- public String[] getContext(Object o);
+ public String[] getContext(T o);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/RealBasicEventStream.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/RealBasicEventStream.java
index 97ff167..682185a 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/RealBasicEventStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/RealBasicEventStream.java
@@ -26,7 +26,7 @@ import opennlp.tools.ml.model.RealValueFileEventStream;
import opennlp.tools.util.ObjectStream;
public class RealBasicEventStream implements ObjectStream<Event> {
- ContextGenerator cg = new BasicContextGenerator();
+ ContextGenerator<String> cg = new BasicContextGenerator();
ObjectStream<String> ds;
public RealBasicEventStream(ObjectStream<String> ds) {
> Please Make ContextGenerator a Generic Type
> -------------------------------------------
>
> Key: OPENNLP-870
> URL: https://issues.apache.org/jira/browse/OPENNLP-870
> Project: OpenNLP
> Issue Type: Improvement
> Components: Machine Learning
> Reporter: Daniel Russ
> Priority: Minor
> Original Estimate: 24h
> Remaining Estimate: 24h
>
> public interface ContextGenerator<T> {
> /**
> * Builds up the list of contextual predicates given an Object.
> */
> public String[] getContext(T o);
> }
> If this is a generic method, it makes writing ContextGenerators easier to debug at compile time.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)