diff options
author | redpony <redpony@1f5c12ca-751b-0410-a591-d2e778427230> | 2008-05-16 17:16:19 +0400 |
---|---|---|
committer | redpony <redpony@1f5c12ca-751b-0410-a591-d2e778427230> | 2008-05-16 17:16:19 +0400 |
commit | e7934202787de3d3374c30eca74ca09521999df3 (patch) | |
tree | e4d37012a3e82f5c3f11330032d7694a7d7539fa /hypergraph-prototype | |
parent | 044a43b5121742c4f372a71e83f6f9632f5752c4 (diff) |
beginning of agenda
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@1734 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'hypergraph-prototype')
3 files changed, 124 insertions, 0 deletions
diff --git a/hypergraph-prototype/attempt1/org/statmt/hg4/Decoder.java b/hypergraph-prototype/attempt1/org/statmt/hg4/Decoder.java new file mode 100644 index 000000000..d40ddf467 --- /dev/null +++ b/hypergraph-prototype/attempt1/org/statmt/hg4/Decoder.java @@ -0,0 +1,81 @@ +package org.statmt.hg4; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Dictionary; +import java.util.HashMap; +import java.util.Map; + +public class Decoder { + + static class GNode { + HashMap<String, GNode> edges = + new HashMap<String, GNode>(); + HashMap<String, ArrayList<Object>> data = + new HashMap<String,ArrayList<Object>>(); + public void addEdge(String word, GNode node) { + edges.put(word, node); + } + public GNode getOrAddNode(String edgeName) { + GNode x = edges.get(edgeName); + if (x == null) { + x = new GNode(); + edges.put(edgeName, x); + } + return x; + } + public void addData(String lhs, Object o) { + ArrayList<Object> d = data.get(lhs); + if (d == null) { + d = new ArrayList<Object>(); + data.put(lhs, d); + } + d.add(o); + } + public GNode followEdge(String word) { + return edges.get(word); + } + } + static class SGrammar { + GNode root = new GNode(); + public void addRule(String lhs, String rhs, Object data) { + String[] its = rhs.split("\\s+"); + GNode cur = root; + for (String word: its) { + cur = cur.getOrAddNode(word); + } + cur.addData(lhs, data); + } + + public GNode getRoot() { return root; } + } + + static class PBCandidateGenerator extends PassiveCandidateGenerator { + ArrayList<ArrayList<Vertex>> lattice; + public PBCandidateGenerator(ArrayList<ArrayList<ArrayList<Phrase>>> l, Hypergraph derivation) { + assert(derivation.sourceVertices.size() == 1); + Vertex v = derivation.sourceVertices.iterator().next(); + lattice = new ArrayList<ArrayList<ArrayList<Vertex>>>(); + for (ArrayList<ArrayList<Phrase>> cols : l) { + lattice.add(new ArrayList<ArrayList<Vertex>>())); + } + } + public Collection<Vertex> retrieveCominableNodesForActiveVertex(Vertex activeVertex, + Map<String, Object> state, Phrase sentence) { + int c = (Integer)state.get("COVERAGE"); + ArrayList<Vertex> transOpts = new ArrayList<Vertex>(); + for (int e = c; e < sentence.size(); e++) { + lattice.get(c); + ArrayList<Vertex> opts = lattice.get(c).get(e-c); + transOpts.addAll(opts); + } + return transOpts; + } + } + + public static void main(String[] args) { + SGrammar g = new SGrammar(); + g.addRule("[X]", "der [X1] man", "the [X1] man"); + g.addRule("[X]", "der", "the"); + } +} diff --git a/hypergraph-prototype/attempt1/org/statmt/hg4/PBCandidateGenerator.java b/hypergraph-prototype/attempt1/org/statmt/hg4/PBCandidateGenerator.java new file mode 100644 index 000000000..3803c92d7 --- /dev/null +++ b/hypergraph-prototype/attempt1/org/statmt/hg4/PBCandidateGenerator.java @@ -0,0 +1,33 @@ +package org.statmt.hg4; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +public class PBCandidateGenerator extends PassiveCandidateGenerator { + + ArrayList<ArrayList<Vertex>> lattice; + public PBCandidateGenerator(ArrayList<ArrayList<ArrayList<Phrase>>> l, Hypergraph derivation) { + assert(derivation.sourceVertices.size() == 1); + Vertex v = derivation.sourceVertices.iterator().next(); + lattice = new ArrayList<ArrayList<ArrayList<Vertex>>>(); + for (ArrayList<ArrayList<Phrase>> cols : l) { + lattice.add(new ArrayList<ArrayList<Vertex>>())); + } + } + + @Override + public Collection<Vertex> retrieveCominableNodesForActiveVertex( + Vertex activeVertex, Map<String, Object> vertexState, + Phrase sentence) { + int c = (Integer)state.get("COVERAGE"); + ArrayList<Vertex> transOpts = new ArrayList<Vertex>(); + for (int e = c; e < sentence.size(); e++) { + lattice.get(c); + ArrayList<Vertex> opts = lattice.get(c).get(e-c); + transOpts.addAll(opts); + } + return transOpts; + } + +} diff --git a/hypergraph-prototype/attempt1/org/statmt/hg4/PassiveCandidateGenerator.java b/hypergraph-prototype/attempt1/org/statmt/hg4/PassiveCandidateGenerator.java new file mode 100644 index 000000000..6d38b7b4a --- /dev/null +++ b/hypergraph-prototype/attempt1/org/statmt/hg4/PassiveCandidateGenerator.java @@ -0,0 +1,10 @@ +package org.statmt.hg4; + +import java.util.Collection; +import java.util.Map; + +public abstract class PassiveCandidateGenerator { + public abstract Collection<Vertex> retrieveCominableNodesForActiveVertex(Vertex activeVertex, + Map<String, Object> vertexState, Phrase sentence); + +} |