You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@joshua.apache.org by mj...@apache.org on 2016/08/22 21:47:38 UTC
[12/27] incubator-joshua git commit: converted from span -> separate
i, j
converted from span -> separate i, j
Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/eb002238
Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/eb002238
Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/eb002238
Branch: refs/heads/master
Commit: eb00223870c7683cf8e557ab689a1979fb36ec1d
Parents: 5719c8c
Author: Matt Post <po...@cs.jhu.edu>
Authored: Fri Aug 19 19:43:58 2016 -0500
Committer: Matt Post <po...@cs.jhu.edu>
Committed: Fri Aug 19 19:43:58 2016 -0500
----------------------------------------------------------------------
.../apache/joshua/decoder/phrase/Candidate.java | 33 +++++++++++---------
.../apache/joshua/decoder/phrase/Future.java | 6 ++--
.../joshua/decoder/phrase/Hypothesis.java | 6 +---
.../joshua/decoder/phrase/PhraseChart.java | 5 ++-
.../apache/joshua/decoder/phrase/Stacks.java | 4 ++-
.../joshua/decoder/phrase/TargetPhrases.java | 8 ++++-
6 files changed, 36 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/eb002238/src/main/java/org/apache/joshua/decoder/phrase/Candidate.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/phrase/Candidate.java b/src/main/java/org/apache/joshua/decoder/phrase/Candidate.java
index bd581e3..cb9cd6d 100644
--- a/src/main/java/org/apache/joshua/decoder/phrase/Candidate.java
+++ b/src/main/java/org/apache/joshua/decoder/phrase/Candidate.java
@@ -50,9 +50,6 @@ public class Candidate {
private List<FeatureFunction> featureFunctions;
private Sentence sentence;
- // source span of new phrase
- public Span span;
-
// the set of hypotheses that can be paired with phrases from this span
private List<Hypothesis> hypotheses;
@@ -92,7 +89,7 @@ public class Candidate {
public boolean equals(Object obj) {
if (obj instanceof Candidate) {
Candidate other = (Candidate) obj;
- if (hypotheses != other.hypotheses || phrases != other.phrases || span != other.span)
+ if (hypotheses != other.hypotheses || phrases != other.phrases)
return false;
if (ranks.length != other.ranks.length)
@@ -111,7 +108,6 @@ public class Candidate {
public int hashCode() {
return 17 * hypotheses.size()
+ 23 * phrases.size()
- + 57 * span.hashCode()
+ 117 * Arrays.hashCode(ranks);
// return hypotheses.hashCode() * phrases.hashCode() * span.hashCode() * Arrays.hashCode(ranks);
}
@@ -124,12 +120,11 @@ public class Candidate {
}
public Candidate(List<FeatureFunction> featureFunctions, Sentence sentence,
- List<Hypothesis> hypotheses, TargetPhrases phrases, Span span, float delta, int[] ranks) {
+ List<Hypothesis> hypotheses, TargetPhrases phrases, float delta, int[] ranks) {
this.featureFunctions = featureFunctions;
this.sentence = sentence;
this.hypotheses = hypotheses;
this.phrases = phrases;
- this.span = span;
this.future_delta = delta;
this.ranks = ranks;
this.rule = isMonotonic() ? Hypothesis.MONO_RULE : Hypothesis.SWAP_RULE;
@@ -148,7 +143,9 @@ public class Candidate {
* @return
*/
private boolean isMonotonic() {
- return getHypothesis().getLastSourceIndex() < span.start;
+// System.err.println(String.format("isMonotonic(); %d < %d -> %s",
+// getLastCovered(), getPhraseEnd(), getLastCovered() < getPhraseEnd()));
+ return getLastCovered() < getPhraseEnd();
}
/**
@@ -168,7 +165,7 @@ public class Candidate {
*/
public Candidate extendHypothesis() {
if (ranks[0] < hypotheses.size() - 1) {
- return new Candidate(featureFunctions, sentence, hypotheses, phrases, span, future_delta, new int[] { ranks[0] + 1, ranks[1] });
+ return new Candidate(featureFunctions, sentence, hypotheses, phrases, future_delta, new int[] { ranks[0] + 1, ranks[1] });
}
return null;
}
@@ -180,7 +177,7 @@ public class Candidate {
*/
public Candidate extendPhrase() {
if (ranks[1] < phrases.size() - 1) {
- return new Candidate(featureFunctions, sentence, hypotheses, phrases, span, future_delta, new int[] { ranks[0], ranks[1] + 1 });
+ return new Candidate(featureFunctions, sentence, hypotheses, phrases, future_delta, new int[] { ranks[0], ranks[1] + 1 });
}
return null;
@@ -192,7 +189,7 @@ public class Candidate {
* @return the span object
*/
public Span getSpan() {
- return this.span;
+ return new Span(this.phrases.i, this.phrases.j);
}
/**
@@ -236,13 +233,13 @@ public class Candidate {
public ComputeNodeResult computeResult() {
if (computedResult == null) {
// add the phrase node
- ComputeNodeResult phraseResult = new ComputeNodeResult(featureFunctions, getPhraseRule(), null, span.start, span.end, null, sentence);
+ ComputeNodeResult phraseResult = new ComputeNodeResult(featureFunctions, getPhraseRule(), null, phrases.i, phrases.j, null, sentence);
HyperEdge edge = new HyperEdge(getPhraseRule(), phraseResult.getViterbiCost(), phraseResult.getTransitionCost(), null, null);
- phraseNode = new HGNode(-1, span.end, rule.getLHS(), phraseResult.getDPStates(), edge, phraseResult.getPruningEstimate());
+ phraseNode = new HGNode(phrases.i, phrases.j, rule.getLHS(), phraseResult.getDPStates(), edge, phraseResult.getPruningEstimate());
// add the rule
// TODO: sourcepath
- computedResult = new ComputeNodeResult(featureFunctions, getRule(), getTailNodes(), -1, span.end, null, sentence);
+ computedResult = new ComputeNodeResult(featureFunctions, getRule(), getTailNodes(), getLastCovered(), getPhraseEnd(), null, sentence);
}
return computedResult;
@@ -315,4 +312,12 @@ public class Candidate {
public List<DPState> getStates() {
return computeResult().getDPStates();
}
+
+ public int getLastCovered() {
+ return getHypothesis().getLastSourceIndex();
+ }
+
+ public int getPhraseEnd() {
+ return phrases.j;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/eb002238/src/main/java/org/apache/joshua/decoder/phrase/Future.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/phrase/Future.java b/src/main/java/org/apache/joshua/decoder/phrase/Future.java
index 572aa64..c411ccb 100644
--- a/src/main/java/org/apache/joshua/decoder/phrase/Future.java
+++ b/src/main/java/org/apache/joshua/decoder/phrase/Future.java
@@ -99,8 +99,9 @@ public class Future {
public float Change(Coverage coverage, int begin, int end) {
int left = coverage.leftOpening(begin);
int right = coverage.rightOpening(end, sentlen);
- // System.err.println(String.format("Future::Change(%s, %d, %d) left %d right %d %.3f %.3f %.3f", coverage, begin, end, left, right,
- // Entry(left, begin), Entry(end, right), Entry(left, right)));
+// System.err.println(String.format("Future.Change(%s, %d, %d) left %d right %d %.3f %.3f %.3f",
+// coverage, begin, end, left, right,
+// getEntry(left, begin), getEntry(end, right), getEntry(left, right)));
return getEntry(left, begin) + getEntry(end, right) - getEntry(left, right);
}
@@ -113,6 +114,7 @@ public class Future {
private void setEntry(int begin, int end, float value) {
assert end >= begin;
assert end <= this.sentlen;
+// System.err.println(String.format("Future.setEntry(%d, %d) = %f", begin, end, value));
entries.set(begin, end, value);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/eb002238/src/main/java/org/apache/joshua/decoder/phrase/Hypothesis.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/phrase/Hypothesis.java b/src/main/java/org/apache/joshua/decoder/phrase/Hypothesis.java
index 132d62d..8ef5597 100644
--- a/src/main/java/org/apache/joshua/decoder/phrase/Hypothesis.java
+++ b/src/main/java/org/apache/joshua/decoder/phrase/Hypothesis.java
@@ -70,7 +70,7 @@ public class Hypothesis extends HGNode implements Comparable<Hypothesis> {
*/
public Hypothesis(Candidate cand) {
// TODO: sourcepath
- super(-1, cand.span.end, cand.getRule().getLHS(), cand.getStates(),
+ super(cand.getLastCovered(), cand.getPhraseEnd(), cand.getRule().getLHS(), cand.getStates(),
new HyperEdge(cand.getRule(), cand.computeResult().getViterbiCost(),
cand.computeResult().getTransitionCost(),
cand.getTailNodes(), null), cand.score());
@@ -84,10 +84,6 @@ public class Hypothesis extends HGNode implements Comparable<Hypothesis> {
this.coverage = previous.coverage;
}
- public Hypothesis(int lastSourceIndex, int lhs, List<DPState> states) {
- super(-1, lastSourceIndex, lhs, states, null, 0.0f);
- }
-
public Coverage getCoverage() {
return coverage;
}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/eb002238/src/main/java/org/apache/joshua/decoder/phrase/PhraseChart.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/phrase/PhraseChart.java b/src/main/java/org/apache/joshua/decoder/phrase/PhraseChart.java
index 9803d9b..dd5872f 100644
--- a/src/main/java/org/apache/joshua/decoder/phrase/PhraseChart.java
+++ b/src/main/java/org/apache/joshua/decoder/phrase/PhraseChart.java
@@ -185,9 +185,8 @@ public class PhraseChart {
try {
int offset = offset(begin, end);
if (entries.get(offset) == null)
- entries.set(offset, new TargetPhrases(rules));
- else
- entries.get(offset).addAll(rules);
+ entries.set(offset, new TargetPhrases(begin, end));
+ entries.get(offset).addAll(rules);
} catch (java.lang.IndexOutOfBoundsException e) {
LOG.error("Whoops! {} [{}-{}] too long ({})", to, begin, end, entries.size());
LOG.error(e.getMessage(), e);
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/eb002238/src/main/java/org/apache/joshua/decoder/phrase/Stacks.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/phrase/Stacks.java b/src/main/java/org/apache/joshua/decoder/phrase/Stacks.java
index dc1a692..c642226 100644
--- a/src/main/java/org/apache/joshua/decoder/phrase/Stacks.java
+++ b/src/main/java/org/apache/joshua/decoder/phrase/Stacks.java
@@ -193,7 +193,7 @@ public class Stacks {
* phrases from that span. The hypotheses are wrapped in HypoState objects, which
* augment the hypothesis score with a future cost.
*/
- Candidate cand = new Candidate(featureFunctions, sentence, hypotheses, phrases, span, future_delta, new int[] {0, 0});
+ Candidate cand = new Candidate(featureFunctions, sentence, hypotheses, phrases, future_delta, new int[] {0, 0});
targetStack.addCandidate(cand);
}
}
@@ -267,6 +267,8 @@ public class Stacks {
float finalTransitionScore = ComputeNodeResult.computeFinalCost(featureFunctions, tailNodes, 0, sentence.length(), null, sentence);
+ System.err.println(String.format("createGoalNode: final score: %f -> %f", score, finalTransitionScore));
+
if (null == this.end)
this.end = new Hypothesis(null, score + finalTransitionScore, hyp, sentence.length(), null);
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/eb002238/src/main/java/org/apache/joshua/decoder/phrase/TargetPhrases.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/phrase/TargetPhrases.java b/src/main/java/org/apache/joshua/decoder/phrase/TargetPhrases.java
index ed1d577..5692d1a 100644
--- a/src/main/java/org/apache/joshua/decoder/phrase/TargetPhrases.java
+++ b/src/main/java/org/apache/joshua/decoder/phrase/TargetPhrases.java
@@ -37,9 +37,15 @@ import org.apache.joshua.decoder.ff.tm.Rule;
public class TargetPhrases extends ArrayList<Rule> {
private static final long serialVersionUID = 1L;
+
+ public int i = -2;
+ public int j = -2;
- public TargetPhrases() {
+ public TargetPhrases(int i, int j) {
super();
+
+ this.i = i;
+ this.j = j;
}
/**