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/06/13 15:16:00 UTC
[1/2] incubator-joshua git commit: bugfix: rule actually added
Repository: incubator-joshua
Updated Branches:
refs/heads/master 300f0bb40 -> 952a82d5a
bugfix: rule actually added
Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/e514d2f5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/e514d2f5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/e514d2f5
Branch: refs/heads/master
Commit: e514d2f533ba529d6a06861c3f2b8dcfaa2f7658
Parents: 300f0bb
Author: Matt Post <po...@cs.jhu.edu>
Authored: Mon Jun 13 08:15:38 2016 -0700
Committer: Matt Post <po...@cs.jhu.edu>
Committed: Mon Jun 13 08:15:38 2016 -0700
----------------------------------------------------------------------
.../java/org/apache/joshua/decoder/Decoder.java | 6 ++--
.../org/apache/joshua/decoder/ff/tm/Rule.java | 35 ++++++++++++--------
2 files changed, 25 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/e514d2f5/src/main/java/org/apache/joshua/decoder/Decoder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/Decoder.java b/src/main/java/org/apache/joshua/decoder/Decoder.java
index 7164134..097ce59 100644
--- a/src/main/java/org/apache/joshua/decoder/Decoder.java
+++ b/src/main/java/org/apache/joshua/decoder/Decoder.java
@@ -798,10 +798,12 @@ public class Decoder {
}
/**
- *
- * @param rule
+ * Adds a rule to the custom grammar.
+ *
+ * @param rule the rule to add
*/
public void addCustomRule(Rule rule) {
+ customPhraseTable.addRule(rule);
rule.estimateRuleCost(featureFunctions);
}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/e514d2f5/src/main/java/org/apache/joshua/decoder/ff/tm/Rule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/ff/tm/Rule.java b/src/main/java/org/apache/joshua/decoder/ff/tm/Rule.java
index c468e01..0e5a4bc 100644
--- a/src/main/java/org/apache/joshua/decoder/ff/tm/Rule.java
+++ b/src/main/java/org/apache/joshua/decoder/ff/tm/Rule.java
@@ -326,22 +326,18 @@ public class Rule implements Comparator<Rule>, Comparable<Rule> {
* features (such as a language model estimate). This getter and setter should also be cached, and
* is basically provided to allow the PhraseModel feature to cache its (expensive) computation for
* each rule.
- *
- * @return the precomputable cost of each rule
+ *
+ * The weights are passed in as dense weights and sparse weights. This allows the dense weight
+ * precomputation to be even faster (since we don't have to query a hash map.
+ *
+ * @param dense_weights the dense weights from the model
+ * @param weights the sparse weights from the model
*/
- public float getPrecomputableCost() {
- return precomputableCost;
- }
-
- public float getDenseFeature(int k) {
- return getFeatureVector().getDense(k);
- }
-
- public void setPrecomputableCost(float[] phrase_weights, FeatureVector weights) {
+ public void setPrecomputableCost(float[] dense_weights, FeatureVector weights) {
float cost = 0.0f;
FeatureVector features = getFeatureVector();
- for (int i = 0; i < features.getDenseFeatures().size() && i < phrase_weights.length; i++) {
- cost += phrase_weights[i] * features.getDense(i);
+ for (int i = 0; i < features.getDenseFeatures().size() && i < dense_weights.length; i++) {
+ cost += dense_weights[i] * features.getDense(i);
}
for (String key: features.getSparseFeatures().keySet()) {
@@ -350,7 +346,18 @@ public class Rule implements Comparator<Rule>, Comparable<Rule> {
this.precomputableCost = cost;
}
-
+
+ /**
+ * @return the precomputed model cost of each rule
+ */
+ public float getPrecomputableCost() {
+ return precomputableCost;
+ }
+
+ public float getDenseFeature(int k) {
+ return getFeatureVector().getDense(k);
+ }
+
/**
* This function estimates the cost of a rule, which is used for sorting the rules for cube
* pruning. The estimated cost is basically the set of precomputable features (features listed
[2/2] incubator-joshua git commit: bugfix: error in handling metadata
with no args
Posted by mj...@apache.org.
bugfix: error in handling metadata with no args
Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/952a82d5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/952a82d5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/952a82d5
Branch: refs/heads/master
Commit: 952a82d5a4f640532f4512b27d09a65f2ec19af1
Parents: e514d2f
Author: Matt Post <po...@cs.jhu.edu>
Authored: Mon Jun 13 08:15:56 2016 -0700
Committer: Matt Post <po...@cs.jhu.edu>
Committed: Mon Jun 13 08:15:56 2016 -0700
----------------------------------------------------------------------
src/main/java/org/apache/joshua/server/ServerThread.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/952a82d5/src/main/java/org/apache/joshua/server/ServerThread.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/server/ServerThread.java b/src/main/java/org/apache/joshua/server/ServerThread.java
index 0187ad1..ccadc2d 100644
--- a/src/main/java/org/apache/joshua/server/ServerThread.java
+++ b/src/main/java/org/apache/joshua/server/ServerThread.java
@@ -169,7 +169,7 @@ public class ServerThread extends Thread implements HttpHandler {
LOG.info("TRANSLATION: '{}' with {} k-best items", translation, translation.getStructuredTranslations().size());
message.addTranslation(translation);
}
-
+
OutputStream out = new HttpWriter(client);
out.write(message.toString().getBytes());
if (LOG.isDebugEnabled())
@@ -188,7 +188,7 @@ public class ServerThread extends Thread implements HttpHandler {
private String handleMetadata(String meta) {
String[] tokens = meta.split("\\s+", 2);
String type = tokens[0];
- String args = tokens[1];
+ String args = tokens.length > 1 ? tokens[1] : "";
String response = "";
if (type.equals("get_weight")) {