diff options
author | jdschroeder <jdschroeder@1f5c12ca-751b-0410-a591-d2e778427230> | 2008-05-16 23:49:57 +0400 |
---|---|---|
committer | jdschroeder <jdschroeder@1f5c12ca-751b-0410-a591-d2e778427230> | 2008-05-16 23:49:57 +0400 |
commit | 004ad95da315a4f4d40b2c58bd0e88c59dbbf477 (patch) | |
tree | e6d956cb0dc52fe85258e758ce3d682d76e6403d /hypergraph-prototype | |
parent | a36c79a13c875791056f52e21f2f56331d91d6b8 (diff) |
generic coverage for PBCandidateGenerator
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@1759 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'hypergraph-prototype')
3 files changed, 71 insertions, 5 deletions
diff --git a/hypergraph-prototype/attempt1/org/statmt/hg4/Coverage.java b/hypergraph-prototype/attempt1/org/statmt/hg4/Coverage.java new file mode 100644 index 000000000..f8424c9ee --- /dev/null +++ b/hypergraph-prototype/attempt1/org/statmt/hg4/Coverage.java @@ -0,0 +1,51 @@ +package org.statmt.hg4; + +import java.util.BitSet; + +public class Coverage { + BitSet coverage; + + /** + * + * @param phraseSize + * @param coverageStart + * @param coverageEnd (exclusive) + */ + public Coverage(int phraseSize, int coverageStart, int coverageEnd) { + coverage = new BitSet(phraseSize); + coverage.set(coverageStart,coverageEnd,true); + } + + /** + * Takes 'or' of params, asserts compatibility. + * @param a + * @param b + */ + public Coverage(Coverage a, Coverage b) { + assert(a.isCompatible(b)); + this.coverage = (BitSet)a.coverage.clone(); + this.coverage.or(b.coverage); + } + + public int size() { + return coverage.size(); + } + + public int nextGap(int fromIndex) { + return coverage.nextClearBit(fromIndex); + } + + public int nextCover(int fromIndex) { + return coverage.nextSetBit(fromIndex); + } + + /** + * Checks if coverages don't overlap. + * @param other + * @return + */ + public boolean isCompatible(Coverage other) { + assert(this.coverage.size() == other.coverage.size()); + return !this.coverage.intersects(other.coverage); + } +} diff --git a/hypergraph-prototype/attempt1/org/statmt/hg4/Hypergraph.java b/hypergraph-prototype/attempt1/org/statmt/hg4/Hypergraph.java index f49ef34ae..0542fe72e 100644 --- a/hypergraph-prototype/attempt1/org/statmt/hg4/Hypergraph.java +++ b/hypergraph-prototype/attempt1/org/statmt/hg4/Hypergraph.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; public class Hypergraph { @@ -132,6 +133,7 @@ public class Hypergraph { pt.add(new Phrase("guten tag"), new Phrase("hello")); pt.add(new Phrase("guten tag"), new Phrase("good day")); Phrase sent = new Phrase("guten tag"); + HashMap<Hyperarc, Rule> rules = new HashMap<Hyperarc, Rule>(); ArrayList<ArrayList<ArrayList<Phrase>>> lattice = @@ -143,6 +145,7 @@ public class Hypergraph { stacks[0].add(source); Hypergraph hg = new Hypergraph(); hg.addNode(source); + for (int i = 0; i < sent.size(); i++) { ArrayList<Vertex> shs = stacks[i]; for (Vertex prevHyp : shs) { diff --git a/hypergraph-prototype/attempt1/org/statmt/hg4/PBCandidateGenerator.java b/hypergraph-prototype/attempt1/org/statmt/hg4/PBCandidateGenerator.java index 8f0a00ac5..628d0fedf 100644 --- a/hypergraph-prototype/attempt1/org/statmt/hg4/PBCandidateGenerator.java +++ b/hypergraph-prototype/attempt1/org/statmt/hg4/PBCandidateGenerator.java @@ -5,7 +5,9 @@ import java.util.Collection; import java.util.Map; import java.util.HashMap; -public class PBCandidateGenerator extends CandidateGenerator { +import org.statmt.hg4.Hypergraph.Rule; + +public class PBCandidateGenerator extends PassiveCandidateGenerator { ArrayList<ArrayList<Vertex>> lattice; @@ -55,14 +57,24 @@ public class PBCandidateGenerator extends CandidateGenerator { public Collection<Vertex> retrieveCominableNodesForActiveVertex( Vertex activeVertex, Map<String, Object> vertexState, Phrase sentence) { - int c = (Integer)vertexState.get("COVERAGE"); + Coverage c = (Coverage)vertexState.get("COVERAGE"); + ArrayList<Vertex> transOpts = new ArrayList<Vertex>(); - for (int e = c; e < sentence.size(); e++) { - Vertex opts = lattice.get(c).get(e-c); - transOpts.add(opts); + int gapStart = c.nextGap(0); + while (gapStart != -1) { + int gapEnd = c.nextCover(gapStart); + for (int e = gapStart; e < gapEnd && e < sentence.size(); e++) { + Vertex opts = lattice.get(gapStart).get(e-gapStart); + transOpts.add(opts); + } + gapStart = c.nextGap(gapEnd); } return transOpts; } + + public static void main(String[] args) { + + } } |