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/20 03:12:43 UTC
incubator-joshua git commit: added removal of custom rules
Repository: incubator-joshua
Updated Branches:
refs/heads/master 6d2213a20 -> da124c200
added removal of custom rules
Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/da124c20
Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/da124c20
Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/da124c20
Branch: refs/heads/master
Commit: da124c2002d44b67485bd5eb138482b56bbc47ef
Parents: 6d2213a
Author: Matt Post <po...@cs.jhu.edu>
Authored: Sun Jun 19 23:12:41 2016 -0400
Committer: Matt Post <po...@cs.jhu.edu>
Committed: Sun Jun 19 23:12:41 2016 -0400
----------------------------------------------------------------------
.../org/apache/joshua/server/ServerThread.java | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/da124c20/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 b8bb111..fe0fdbd 100644
--- a/src/main/java/org/apache/joshua/server/ServerThread.java
+++ b/src/main/java/org/apache/joshua/server/ServerThread.java
@@ -263,23 +263,26 @@ public class ServerThread extends Thread implements HttpHandler {
}
} else if (type.equals("remove_rule")) {
+
// Remove a rule from a custom grammar, if present
String[] argTokens = args.split(" \\|\\|\\| ");
if (argTokens.length != 2) {
+ LOG.warn("didn't get two tokens");
return;
}
+
+ LOG.info("remove_rule source=" + argTokens[0] + " target=" + argTokens[1]);
- // Search for the rule in the trie
- int nt_i = Vocabulary.id(joshuaConfiguration.default_non_terminal);
- Trie trie = decoder.getCustomPhraseTable().getTrieRoot().match(nt_i);
-
+ Trie trie = decoder.getCustomPhraseTable().getTrieRoot();
for (String word: argTokens[0].split("\\s+")) {
int id = Vocabulary.id(word);
Trie nextTrie = trie.match(id);
- if (nextTrie != null)
- trie = nextTrie;
+ if (nextTrie == null)
+ return;
+
+ trie = nextTrie;
}
-
+
if (trie.hasRules()) {
Rule matched = null;
for (Rule rule: trie.getRuleCollection().getRules()) {