You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by co...@apache.org on 2017/05/17 15:52:47 UTC
[21/50] opennlp git commit: OPENNLP-1026: Replace references and
usages of o.t.u.Heap with SortedSet
OPENNLP-1026: Replace references and usages of o.t.u.Heap with SortedSet
Closes #187
Project: http://git-wip-us.apache.org/repos/asf/opennlp/repo
Commit: http://git-wip-us.apache.org/repos/asf/opennlp/commit/3df659b9
Tree: http://git-wip-us.apache.org/repos/asf/opennlp/tree/3df659b9
Diff: http://git-wip-us.apache.org/repos/asf/opennlp/diff/3df659b9
Branch: refs/heads/LangDetect
Commit: 3df659b9bfb02084e782f1e8b6ec716f56e0611c
Parents: 9803662
Author: smarthi <sm...@apache.org>
Authored: Mon May 1 16:28:42 2017 -0400
Committer: Jörn Kottmann <jo...@apache.org>
Committed: Wed May 3 11:17:38 2017 +0200
----------------------------------------------------------------------
.../tools/parser/AbstractBottomUpParser.java | 23 ++++----
.../src/main/java/opennlp/tools/util/Heap.java | 3 ++
.../main/java/opennlp/tools/util/ListHeap.java | 3 ++
.../tools/eval/SourceForgeModelEval.java | 2 +-
.../java/opennlp/tools/util/ListHeapTest.java | 55 --------------------
5 files changed, 19 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/opennlp/blob/3df659b9/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractBottomUpParser.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractBottomUpParser.java b/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractBottomUpParser.java
index 7d7c1b0..1a414f1 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractBottomUpParser.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractBottomUpParser.java
@@ -22,14 +22,14 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
import opennlp.tools.chunker.Chunker;
import opennlp.tools.dictionary.Dictionary;
import opennlp.tools.ngram.NGramModel;
import opennlp.tools.parser.chunking.ParserEventStream;
import opennlp.tools.postag.POSTagger;
-import opennlp.tools.util.Heap;
-import opennlp.tools.util.ListHeap;
import opennlp.tools.util.ObjectStream;
import opennlp.tools.util.Sequence;
import opennlp.tools.util.Span;
@@ -77,17 +77,17 @@ public abstract class AbstractBottomUpParser implements Parser {
/**
* Completed parses.
*/
- protected Heap<Parse> completeParses;
+ private SortedSet<Parse> completeParses;
/**
* Incomplete parses which will be advanced.
*/
- protected Heap<Parse> odh;
+ private SortedSet<Parse> odh;
/**
* Incomplete parses which have been advanced.
*/
- protected Heap<Parse> ndh;
+ private SortedSet<Parse> ndh;
/**
* The head rules for the parser.
@@ -182,9 +182,9 @@ public abstract class AbstractBottomUpParser implements Parser {
reportFailedParse = true;
this.headRules = headRules;
this.punctSet = headRules.getPunctuationTags();
- odh = new ListHeap<>(K);
- ndh = new ListHeap<>(K);
- completeParses = new ListHeap<>(K);
+ odh = new TreeSet<>();
+ ndh = new TreeSet<>();
+ completeParses = new TreeSet<>();
}
/**
@@ -279,11 +279,11 @@ public abstract class AbstractBottomUpParser implements Parser {
double bestComplete = -100000; //approximating -infinity/0 in ln domain
while (odh.size() > 0 && (completeParses.size() < M || (odh.first()).getProb() < minComplete)
&& derivationStage < maxDerivationLength) {
- ndh = new ListHeap<>(K);
+ ndh = new TreeSet<>();
int derivationRank = 0;
for (Iterator<Parse> pi = odh.iterator(); pi.hasNext()
- && derivationRank < K; derivationRank++) { // forearch derivation
+ && derivationRank < K; derivationRank++) { // foreach derivation
Parse tp = pi.next();
//TODO: Need to look at this for K-best parsing cases
/*
@@ -359,7 +359,8 @@ public abstract class AbstractBottomUpParser implements Parser {
else {
List<Parse> topParses = new ArrayList<>(numParses);
while (!completeParses.isEmpty() && topParses.size() < numParses) {
- Parse tp = completeParses.extract();
+ Parse tp = completeParses.last();
+ completeParses.remove(tp);
topParses.add(tp);
//parses.remove(tp);
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/3df659b9/opennlp-tools/src/main/java/opennlp/tools/util/Heap.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/Heap.java b/opennlp-tools/src/main/java/opennlp/tools/util/Heap.java
index 00d79ba..83f3315 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/Heap.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/Heap.java
@@ -24,7 +24,10 @@ import java.util.Iterator;
* their natural ordering or the comparator provided to an implementation.
* While this is a typical of a heap it allows this objects natural ordering to
* match that of other sorted collections.
+ *
+ * This is now deprecated and will be removed in Release 1.8.1
* */
+@Deprecated
public interface Heap<E> {
/**
http://git-wip-us.apache.org/repos/asf/opennlp/blob/3df659b9/opennlp-tools/src/main/java/opennlp/tools/util/ListHeap.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/ListHeap.java b/opennlp-tools/src/main/java/opennlp/tools/util/ListHeap.java
index 303b729..92744e0 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/ListHeap.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/ListHeap.java
@@ -28,7 +28,10 @@ import java.util.List;
* return the top K values which have been added where K is specified by the size passed to
* the constructor. K+1 values are not gaurenteed to be kept in the heap or returned in a
* particular order.
+ *
+ * This is now deprecated and will be removed in Release 1.8.1
*/
+@Deprecated
public class ListHeap<E extends Comparable<E>> implements Heap<E> {
private List<E> list;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/3df659b9/opennlp-tools/src/test/java/opennlp/tools/eval/SourceForgeModelEval.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/eval/SourceForgeModelEval.java b/opennlp-tools/src/test/java/opennlp/tools/eval/SourceForgeModelEval.java
index c28fd7c..d3ea980 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/eval/SourceForgeModelEval.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/eval/SourceForgeModelEval.java
@@ -346,7 +346,7 @@ public class SourceForgeModelEval {
}
}
- Assert.assertEquals(new BigInteger("155722144104513046994135548456420803172"),
+ Assert.assertEquals(new BigInteger("13162568910062822351942983467905626940"),
new BigInteger(1, digest.digest()));
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/3df659b9/opennlp-tools/src/test/java/opennlp/tools/util/ListHeapTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/util/ListHeapTest.java b/opennlp-tools/src/test/java/opennlp/tools/util/ListHeapTest.java
deleted file mode 100644
index 09afca2..0000000
--- a/opennlp-tools/src/test/java/opennlp/tools/util/ListHeapTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package opennlp.tools.util;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class ListHeapTest {
-
- @Test
- public void testSimple() {
- int size = 5;
- Heap<Integer> heap = new ListHeap<>(size);
-
- for (int ai = 0; ai < 10; ai++) {
- if (ai < size) {
- Assert.assertEquals(ai, heap.size());
- } else {
- Assert.assertEquals(size, heap.size());
- }
- heap.add(ai);
- }
-
- Assert.assertEquals(Integer.valueOf(0), heap.extract());
- Assert.assertEquals(4, heap.size());
-
- Assert.assertEquals(Integer.valueOf(1), heap.extract());
- Assert.assertEquals(3, heap.size());
-
- Assert.assertEquals(Integer.valueOf(2), heap.extract());
- Assert.assertEquals(2, heap.size());
-
- Assert.assertEquals(Integer.valueOf(3), heap.extract());
- Assert.assertEquals(1, heap.size());
-
- Assert.assertEquals(Integer.valueOf(4), heap.extract());
- Assert.assertEquals(0, heap.size());
-
- }
-}