You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@joshua.apache.org by le...@apache.org on 2016/05/25 20:17:15 UTC
incubator-joshua git commit: JOSHUA-252 Make it possible to use Maven
to build Joshua
Repository: incubator-joshua
Updated Branches:
refs/heads/JOSHUA-252 aead62094 -> d8a68df39
JOSHUA-252 Make it possible to use Maven to build Joshua
Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/d8a68df3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/d8a68df3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/d8a68df3
Branch: refs/heads/JOSHUA-252
Commit: d8a68df396d086c75a26133ea3011e4de6bd54b9
Parents: aead620
Author: Lewis John McGibbney <le...@gmail.com>
Authored: Wed May 25 12:42:27 2016 -0700
Committer: Lewis John McGibbney <le...@gmail.com>
Committed: Wed May 25 12:42:27 2016 -0700
----------------------------------------------------------------------
.../org/apache/joshua/tools/GrammarPacker.java | 2 +-
.../org/apache/joshua/tools/LabelPhrases.java | 5 +-
.../org/apache/joshua/tools/TestSetFilter.java | 2 +
.../ui/tree_visualizer/browser/Browser.java | 1 +
.../joshua/ui/tree_visualizer/tree/Tree.java | 408 ++++++++++---------
.../java/org/apache/joshua/util/Algorithms.java | 4 +-
src/main/java/org/apache/joshua/util/Bits.java | 12 +-
.../java/org/apache/joshua/util/ChartSpan.java | 9 +-
.../org/apache/joshua/util/CompareGrammars.java | 4 +-
.../java/org/apache/joshua/util/Counted.java | 3 +-
.../java/org/apache/joshua/util/Counts.java | 18 +-
.../org/apache/joshua/util/ExtractTopCand.java | 6 +
.../org/apache/joshua/util/FileUtility.java | 32 +-
.../org/apache/joshua/util/FormatUtils.java | 12 +-
.../java/org/apache/joshua/util/ListUtil.java | 2 +-
src/main/java/org/apache/joshua/util/Ngram.java | 16 +-
src/main/java/org/apache/joshua/util/Regex.java | 13 +
.../util/encoding/EncoderConfiguration.java | 2 +-
.../org/apache/joshua/util/io/BinaryOut.java | 4 +-
.../apache/joshua/util/io/IndexedReader.java | 19 +-
.../org/apache/joshua/util/io/LineReader.java | 13 +-
.../java/org/apache/joshua/util/io/Reader.java | 17 +-
22 files changed, 337 insertions(+), 267 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/tools/GrammarPacker.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/tools/GrammarPacker.java b/src/main/java/org/apache/joshua/tools/GrammarPacker.java
index 0b5985d..08f162f 100644
--- a/src/main/java/org/apache/joshua/tools/GrammarPacker.java
+++ b/src/main/java/org/apache/joshua/tools/GrammarPacker.java
@@ -150,7 +150,7 @@ public class GrammarPacker {
/**
* Executes the packing.
*
- * @throws IOException
+ * @throws IOException if there is an error reading the grammar
*/
public void pack() throws IOException {
logger.info("Beginning exploration pass.");
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/tools/LabelPhrases.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/tools/LabelPhrases.java b/src/main/java/org/apache/joshua/tools/LabelPhrases.java
index b4a31c7..9dbf249 100644
--- a/src/main/java/org/apache/joshua/tools/LabelPhrases.java
+++ b/src/main/java/org/apache/joshua/tools/LabelPhrases.java
@@ -39,10 +39,9 @@ public class LabelPhrases {
* Main method.
*
* @param args names of the two grammars to be compared
- * @throws IOException
- * @throws NumberFormatException
+ * @throws IOException if there is an error reading the input grammars
*/
- public static void main(String[] args) throws NumberFormatException, IOException {
+ public static void main(String[] args) throws IOException {
if (args.length < 1 || args[0].equals("-h")) {
System.err.println("Usage: " + LabelPhrases.class.toString());
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/tools/TestSetFilter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/tools/TestSetFilter.java b/src/main/java/org/apache/joshua/tools/TestSetFilter.java
index 6312266..1b3cf74 100644
--- a/src/main/java/org/apache/joshua/tools/TestSetFilter.java
+++ b/src/main/java/org/apache/joshua/tools/TestSetFilter.java
@@ -106,6 +106,8 @@ public class TestSetFilter {
/**
* Top-level filter, responsible for calling the fast or exact version. Takes the source side
* of a rule and determines whether there is any sentence in the test set that can match it.
+ * @param sourceSide an input source sentence
+ * @return true if is any sentence in the test set can match the source input
*/
public boolean inTestSet(String sourceSide) {
if (!sourceSide.equals(lastSourceSide)) {
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/ui/tree_visualizer/browser/Browser.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/ui/tree_visualizer/browser/Browser.java b/src/main/java/org/apache/joshua/ui/tree_visualizer/browser/Browser.java
index 1e54920..ee22b94 100644
--- a/src/main/java/org/apache/joshua/ui/tree_visualizer/browser/Browser.java
+++ b/src/main/java/org/apache/joshua/ui/tree_visualizer/browser/Browser.java
@@ -75,6 +75,7 @@ public class Browser {
/**
* @param argv the paths to the source, reference, and n-best files
+ * @throws IOException if there is an error reading from standard input
*/
public static void main(String[] argv) throws IOException {
String sourcePath = argv.length > 0 ? argv[0] : null;
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/ui/tree_visualizer/tree/Tree.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/ui/tree_visualizer/tree/Tree.java b/src/main/java/org/apache/joshua/ui/tree_visualizer/tree/Tree.java
index 48f4c74..662544b 100644
--- a/src/main/java/org/apache/joshua/ui/tree_visualizer/tree/Tree.java
+++ b/src/main/java/org/apache/joshua/ui/tree_visualizer/tree/Tree.java
@@ -52,228 +52,232 @@ import java.util.Comparator;
*/
public class Tree {
- /**
- * An array holding the label of each node of the tree, in depth-first order.
- * The label of a node means the NT label assigned to an internal node, or
- * the terminal symbol (English word) at a leaf.
- */
- private final String [] labels;
+ /**
+ * An array holding the label of each node of the tree, in depth-first order.
+ * The label of a node means the NT label assigned to an internal node, or
+ * the terminal symbol (English word) at a leaf.
+ */
+ private final String [] labels;
- /**
- * The number of children of each node of the tree, in depth-first order.
- */
- private final int [] numChildren;
+ /**
+ * The number of children of each node of the tree, in depth-first order.
+ */
+ private final int [] numChildren;
- /**
- * The smallest source-side index that each node covers, in depth-first order.
- * Note that we only have this information for internal nodes. For leaves,
- * this value will always be -1.
- */
- private final int [] sourceStartIndices;
+ /**
+ * The smallest source-side index that each node covers, in depth-first order.
+ * Note that we only have this information for internal nodes. For leaves,
+ * this value will always be -1.
+ */
+ private final int [] sourceStartIndices;
- /**
- * 1 + the largest source-side index that each node covers, in depth-first
- * order. Note that we only have this informaion for internal nodes. For
- * leaves, this value will always be -1.
- */
- private final int [] sourceEndIndices;
+ /**
+ * 1 + the largest source-side index that each node covers, in depth-first
+ * order. Note that we only have this informaion for internal nodes. For
+ * leaves, this value will always be -1.
+ */
+ private final int [] sourceEndIndices;
- /**
- * A pattern to match an aligned internal node and pull out its information.
- * This pattern matches:
- *
- * 1) start-of-string
- * 2) (
- * 3) an arbitrary sequence of non-whitespace characters (at least 1)
- * 4) {
- * 5) a decimal number
- * 6) -
- * 7) a decimal number
- * 8) }
- * 9) end-of-string
- *
- * That is, it matches something like "(FOO{32-55}". The string and two
- * decimal numbers (parts 3, 5, and 7) are captured in groups.
- */
- private static final Pattern NONTERMINAL_PATTERN =
- Pattern.compile("^\\((\\S+)\\{(\\d+)-(\\d+)\\}$");
+ /**
+ * A pattern to match an aligned internal node and pull out its information.
+ * This pattern matches:
+ *
+ * 1) start-of-string
+ * 2) (
+ * 3) an arbitrary sequence of non-whitespace characters (at least 1)
+ * 4) {
+ * 5) a decimal number
+ * 6) -
+ * 7) a decimal number
+ * 8) }
+ * 9) end-of-string
+ *
+ * That is, it matches something like "(FOO{32-55}". The string and two
+ * decimal numbers (parts 3, 5, and 7) are captured in groups.
+ */
+ private static final Pattern NONTERMINAL_PATTERN =
+ Pattern.compile("^\\((\\S+)\\{(\\d+)-(\\d+)\\}$");
- /**
- * Creates a Tree object from an input string in Penn treebank format with
- * source alignment annotations.
- */
- public Tree(String s) {
- final String [] tokens = s.replaceAll("\\)", " )").split("\\s+");
- int numNodes = 0;
- for (String t : tokens) {
- if (!t.equals(")")) {
- numNodes++;
- }
- }
- labels = new String[numNodes];
- numChildren = new int[numNodes];
- sourceStartIndices = new int[numNodes];
- sourceEndIndices = new int[numNodes];
- try {
- initialize(tokens);
- } catch (Exception e) {
- // This will catch most formatting errors.
- throw new IllegalArgumentException(
- String.format("couldn't create tree from string: \"%s\"", s),
- e);
- }
- }
+ /**
+ * Creates a Tree object from an input string in Penn treebank format with
+ * source alignment annotations.
+ * @param s an input string in Penn treebank format with source alignment annotations
+ */
+ public Tree(String s) {
+ final String [] tokens = s.replaceAll("\\)", " )").split("\\s+");
+ int numNodes = 0;
+ for (String t : tokens) {
+ if (!t.equals(")")) {
+ numNodes++;
+ }
+ }
+ labels = new String[numNodes];
+ numChildren = new int[numNodes];
+ sourceStartIndices = new int[numNodes];
+ sourceEndIndices = new int[numNodes];
+ try {
+ initialize(tokens);
+ } catch (Exception e) {
+ // This will catch most formatting errors.
+ throw new IllegalArgumentException(
+ String.format("couldn't create tree from string: \"%s\"", s),
+ e);
+ }
+ }
- private void initialize(String [] tokens) {
- final Stack<Integer> stack = new Stack<Integer>();
- int nodeIndex = 0;
- for (String token : tokens) {
- final Matcher matcher = NONTERMINAL_PATTERN.matcher(token);
- if (matcher.matches()) {
- // new non-terminal node
- labels[nodeIndex] = matcher.group(1);
- sourceStartIndices[nodeIndex] = Integer.parseInt(matcher.group(2));
- sourceEndIndices[nodeIndex] = Integer.parseInt(matcher.group(3));
- stack.push(nodeIndex);
- nodeIndex++;
- } else if (token.equals(")")) {
- // finished a subtree
- stack.pop();
- if (stack.empty()) {
- break;
- } else {
- numChildren[stack.peek()]++;
- }
- } else {
- // otherwise, it's a new leaf node
- labels[nodeIndex] = token;
- sourceStartIndices[nodeIndex] = -1;
- sourceEndIndices[nodeIndex] = -1;
- numChildren[stack.peek()]++;
- nodeIndex++;
- }
- }
- if (!stack.empty()) {
- // Not enough close-parentheses at the end of the tree.
- throw new IllegalArgumentException();
- }
- }
+ private void initialize(String [] tokens) {
+ final Stack<Integer> stack = new Stack<Integer>();
+ int nodeIndex = 0;
+ for (String token : tokens) {
+ final Matcher matcher = NONTERMINAL_PATTERN.matcher(token);
+ if (matcher.matches()) {
+ // new non-terminal node
+ labels[nodeIndex] = matcher.group(1);
+ sourceStartIndices[nodeIndex] = Integer.parseInt(matcher.group(2));
+ sourceEndIndices[nodeIndex] = Integer.parseInt(matcher.group(3));
+ stack.push(nodeIndex);
+ nodeIndex++;
+ } else if (token.equals(")")) {
+ // finished a subtree
+ stack.pop();
+ if (stack.empty()) {
+ break;
+ } else {
+ numChildren[stack.peek()]++;
+ }
+ } else {
+ // otherwise, it's a new leaf node
+ labels[nodeIndex] = token;
+ sourceStartIndices[nodeIndex] = -1;
+ sourceEndIndices[nodeIndex] = -1;
+ numChildren[stack.peek()]++;
+ nodeIndex++;
+ }
+ }
+ if (!stack.empty()) {
+ // Not enough close-parentheses at the end of the tree.
+ throw new IllegalArgumentException();
+ }
+ }
- /**
- * Return the number of nodes in this Tree.
- */
- public int size() {
- return labels.length;
- }
+ /**
+ * Return the number of nodes in this Tree.
+ * @return the number of nodes in this Tree
+ */
+ public int size() {
+ return labels.length;
+ }
- /**
- * Get the root Node of this Tree.
- */
- public Node root() {
- return new Node(0);
- }
+ /**
+ * Get the root Node of this Tree.
+ * @return the Node present at the toom the this Tree
+ */
+ public Node root() {
+ return new Node(0);
+ }
- private List<Integer> childIndices(int index) {
- List<Integer> result = new ArrayList<Integer>();
- int remainingChildren = numChildren[index];
- int childIndex = index + 1;
- while (remainingChildren > 0) {
- result.add(childIndex);
- childIndex = nextSiblingIndex(childIndex);
- remainingChildren--;
- }
- return result;
- }
+ private List<Integer> childIndices(int index) {
+ List<Integer> result = new ArrayList<Integer>();
+ int remainingChildren = numChildren[index];
+ int childIndex = index + 1;
+ while (remainingChildren > 0) {
+ result.add(childIndex);
+ childIndex = nextSiblingIndex(childIndex);
+ remainingChildren--;
+ }
+ return result;
+ }
- private int nextSiblingIndex(int index) {
- int result = index + 1;
- int remainingChildren = numChildren[index];
- for (int i = 0; i < remainingChildren; i++) {
- result = nextSiblingIndex(result);
- }
- return result;
- }
+ private int nextSiblingIndex(int index) {
+ int result = index + 1;
+ int remainingChildren = numChildren[index];
+ for (int i = 0; i < remainingChildren; i++) {
+ result = nextSiblingIndex(result);
+ }
+ return result;
+ }
- public String yield() {
- String result = "";
- for (int i = 0; i < labels.length; i++) {
- if (numChildren[i] == 0) {
- if (!result.equals("")) {
- result += " ";
- }
- result += labels[i];
- }
- }
- return result;
- }
+ public String yield() {
+ String result = "";
+ for (int i = 0; i < labels.length; i++) {
+ if (numChildren[i] == 0) {
+ if (!result.equals("")) {
+ result += " ";
+ }
+ result += labels[i];
+ }
+ }
+ return result;
+ }
- @Override
- public String toString() {
- return root().toString();
- }
+ @Override
+ public String toString() {
+ return root().toString();
+ }
- /**
- * A class representing the Nodes of a tree.
- */
- public class Node {
+ /**
+ * A class representing the Nodes of a tree.
+ */
+ public class Node {
- /**
- * The index into the Tree class's internal arrays.
- */
- private final int index;
+ /**
+ * The index into the Tree class's internal arrays.
+ */
+ private final int index;
- private Node(int i) {
- index = i;
- }
+ private Node(int i) {
+ index = i;
+ }
- /**
- * Get the label for this node. If the node is internal to the tree, its
- * label is the non-terminal label assigned to it. If it is a leaf node,
- * the label is the English word at the leaf.
- */
- public String label() {
- return labels[index];
- }
+ /**
+ * Get the label for this node. If the node is internal to the tree, its
+ * label is the non-terminal label assigned to it. If it is a leaf node,
+ * the label is the English word at the leaf.
+ * @return a string representing the label for this node
+ */
+ public String label() {
+ return labels[index];
+ }
- public boolean isLeaf() {
- return numChildren[index] == 0;
- }
+ public boolean isLeaf() {
+ return numChildren[index] == 0;
+ }
- public int sourceStartIndex() {
- return sourceStartIndices[index];
- }
+ public int sourceStartIndex() {
+ return sourceStartIndices[index];
+ }
- public int sourceEndIndex() {
- return sourceEndIndices[index];
- }
+ public int sourceEndIndex() {
+ return sourceEndIndices[index];
+ }
- public List<Node> children() {
- List<Node> result = new ArrayList<Node>();
- for (int j : childIndices(index)) {
- result.add(new Node(j));
- }
- return result;
- }
+ public List<Node> children() {
+ List<Node> result = new ArrayList<Node>();
+ for (int j : childIndices(index)) {
+ result.add(new Node(j));
+ }
+ return result;
+ }
- @Override
- public String toString() {
- if (isLeaf()) {
- return label();
- }
- String result = String.format("(%s{%d-%d}",
- label(),
- sourceStartIndex(),
- sourceEndIndex());
- for (Node c : children()) {
- result += String.format(" %s", c);
- }
- return result + ")";
- }
- }
+ @Override
+ public String toString() {
+ if (isLeaf()) {
+ return label();
+ }
+ String result = String.format("(%s{%d-%d}",
+ label(),
+ sourceStartIndex(),
+ sourceEndIndex());
+ for (Node c : children()) {
+ result += String.format(" %s", c);
+ }
+ return result + ")";
+ }
+ }
- public static class NodeSourceStartComparator implements Comparator<Node> {
- public int compare(Node a, Node b) {
- return a.sourceStartIndex() - b.sourceStartIndex();
- }
- }
+ public static class NodeSourceStartComparator implements Comparator<Node> {
+ public int compare(Node a, Node b) {
+ return a.sourceStartIndex() - b.sourceStartIndex();
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/util/Algorithms.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/Algorithms.java b/src/main/java/org/apache/joshua/util/Algorithms.java
index 93e8e55..327c882 100644
--- a/src/main/java/org/apache/joshua/util/Algorithms.java
+++ b/src/main/java/org/apache/joshua/util/Algorithms.java
@@ -25,7 +25,9 @@ public final class Algorithms {
*
* The code is based on the example by Michael Gilleland found at
* http://www.merriampark.com/ld.htm.
- *
+ * @param candidate todo
+ * @param source todo
+ * @return the minimum edit distance.
*/
public static final int levenshtein(String[] candidate, String[] source) {
// First check to see whether either of the arrays
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/util/Bits.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/Bits.java b/src/main/java/org/apache/joshua/util/Bits.java
index d98415e..b5294f6 100644
--- a/src/main/java/org/apache/joshua/util/Bits.java
+++ b/src/main/java/org/apache/joshua/util/Bits.java
@@ -28,9 +28,9 @@ public class Bits {
/**
* Encodes two shorts in an int.
*
- * @param high
- * @param low
- * @return
+ * @param high input high short to encode
+ * @param low input low short to encode
+ * @return encoded int
*/
public static int encodeAsInt(short high, short low) {
@@ -79,9 +79,9 @@ public class Bits {
/**
* Encodes two integers in a long.
*
- * @param high
- * @param low
- * @return
+ * @param high input high int to encode
+ * @param low input low int to encode
+ * @return encoded long
*/
public static long encodeAsLong(int high, int low) {
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/util/ChartSpan.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/ChartSpan.java b/src/main/java/org/apache/joshua/util/ChartSpan.java
index 3e9a1c9..b22d2aa 100644
--- a/src/main/java/org/apache/joshua/util/ChartSpan.java
+++ b/src/main/java/org/apache/joshua/util/ChartSpan.java
@@ -64,17 +64,14 @@ public class ChartSpan<Type> {
/**
* This computes the offset into the one-dimensional array for a given span.
*
- * @param i
- * @param j
+ * @param i source node in span
+ * @param j target node in span
* @return the offset
- * @throws InvalidSpanException
*/
private int offset(int i, int j) {
if (i < 0 || j > max || i > j) {
throw new RuntimeException(String.format("Invalid span (%d,%d | %d)", i, j, max));
}
-
- // System.err.println(String.format("ChartSpan::offset(%d,%d) = %d / %d", i, j, i * (max + 1) - i * (i + 1) / 2 + j, max * (max + 1) - max * (max + 1) / 2 + max));
return i * (max + 1) - i * (i + 1) / 2 + j;
}
@@ -82,7 +79,7 @@ public class ChartSpan<Type> {
/**
* Convenience function for setting the values along the diagonal.
*
- * @param value
+ * @param value input Type for which to set values
*/
public void setDiagonal(Type value) {
for (int i = 0; i <= max; i++)
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/util/CompareGrammars.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/CompareGrammars.java b/src/main/java/org/apache/joshua/util/CompareGrammars.java
index c20e962..7c4e263 100644
--- a/src/main/java/org/apache/joshua/util/CompareGrammars.java
+++ b/src/main/java/org/apache/joshua/util/CompareGrammars.java
@@ -45,7 +45,7 @@ public class CompareGrammars {
* @param fieldDelimiter Regular expression to split each line
* @param fieldNumber Field from each rule to extract
* @return set containing all unique instances of the specified field
- * @throws FileNotFoundException
+ * @throws FileNotFoundException if the input grammer file cannot be found
*/
public static Set<String> getFields(File grammarFile, String fieldDelimiter, int fieldNumber)
throws FileNotFoundException {
@@ -129,7 +129,7 @@ public class CompareGrammars {
* Main method.
*
* @param args names of the two grammars to be compared
- * @throws FileNotFoundException
+ * @throws FileNotFoundException if any of the input grammer file cannot be found
*/
public static void main(String[] args) throws FileNotFoundException {
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/util/Counted.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/Counted.java b/src/main/java/org/apache/joshua/util/Counted.java
index eeb77c8..9f719b3 100644
--- a/src/main/java/org/apache/joshua/util/Counted.java
+++ b/src/main/java/org/apache/joshua/util/Counted.java
@@ -78,8 +78,7 @@ public class Counted<E> implements Comparable<Counted<E>> {
/**
* Gets a comparator that compares two counted objects based on the reverse of the natural order
* of the counts associated with each object.
- *
- * @param <E>
+ * @param <E> todo
* @return A comparator that compares two counted objects based on the reverse of the natural
* order of the counts associated with each object
*/
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/util/Counts.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/Counts.java b/src/main/java/org/apache/joshua/util/Counts.java
index 3c44f02..89a9f38 100644
--- a/src/main/java/org/apache/joshua/util/Counts.java
+++ b/src/main/java/org/apache/joshua/util/Counts.java
@@ -31,8 +31,6 @@ import java.util.Map.Entry;
*
* @author Lane Schwartz
* @author Chris Callison-Burch
- * @param <A>
- * @param <B>
*/
public class Counts<A, B> implements Iterable<Pair<A, B>> {
@@ -78,8 +76,8 @@ public class Counts<A, B> implements Iterable<Pair<A, B>> {
/**
* Increments the co-occurrence count of the provided objects.
*
- * @param a
- * @param b
+ * @param a input object A
+ * @param b input object B
*/
public void incrementCount(A a, B b) {
// increment the count and handle the adding of objects to the map if they aren't already there
@@ -127,8 +125,8 @@ public class Counts<A, B> implements Iterable<Pair<A, B>> {
/**
* Gets the co-occurrence count for the two elements.
*
- * @param a
- * @param b
+ * @param a input object A
+ * @param b input object B
* @return the co-occurrence count for the two elements
*/
public int getCount(A a, B b) {
@@ -161,8 +159,8 @@ public class Counts<A, B> implements Iterable<Pair<A, B>> {
* <p>
* This value is the relative frequency estimate.
*
- * @param a
- * @param b
+ * @param a object A
+ * @param b object B
* @return the probability of a given b.
*/
public float getProbability(A a, B b) {
@@ -202,8 +200,8 @@ public class Counts<A, B> implements Iterable<Pair<A, B>> {
* <p>
* This value is the relative frequency estimate in the reverse direction.
*
- * @param b
- * @param a
+ * @param b object B
+ * @param a object A
* @return the probability of b given a.
*/
public float getReverseProbability(B b, A a) {
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/util/ExtractTopCand.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/ExtractTopCand.java b/src/main/java/org/apache/joshua/util/ExtractTopCand.java
index 91186ce..25fc00e 100644
--- a/src/main/java/org/apache/joshua/util/ExtractTopCand.java
+++ b/src/main/java/org/apache/joshua/util/ExtractTopCand.java
@@ -49,6 +49,7 @@ public class ExtractTopCand {
* file name is "-" then output is directed to <code>System.out</code>. If a file already exists
* with the output file name, it is truncated before writing. The bulk of this program is
* implemented by {@link org.apache.joshua.util.ExtractTopCand#extractOneBest(IndexedReader, BufferedWriter, int)}.
+ * @param args input arguments for the tool
*/
public static void main(String[] args) {
String inFile = "-";
@@ -121,6 +122,11 @@ public class ExtractTopCand {
* ensure future compatibility with being able to configure the output format of the decoder. The
* MERT code needs such a SegmentFileParser anyways, so that will reduce the code duplication
* between these two classes.
+ *
+ * @param nbestReader todo
+ * @param onebestWriter todo
+ * @param field todo
+ * @throws IOException if there is an issue reading or writing input/output data
*/
protected static void extractOneBest(IndexedReader<String> nbestReader,
BufferedWriter onebestWriter, int field) throws IOException {
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/util/FileUtility.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/FileUtility.java b/src/main/java/org/apache/joshua/util/FileUtility.java
index 19b26ab..0fe2c63 100644
--- a/src/main/java/org/apache/joshua/util/FileUtility.java
+++ b/src/main/java/org/apache/joshua/util/FileUtility.java
@@ -52,7 +52,12 @@ public class FileUtility {
*/
private static final Charset FILE_ENCODING = Charset.forName(DEFAULT_ENCODING);
- /** Warning, will truncate/overwrite existing files */
+ /**
+ * Warning, will truncate/overwrite existing files
+ * @param filename a file for which to obtain a writer
+ * @return the buffered writer object
+ * @throws IOException if there is a problem reading the inout file
+ */
public static BufferedWriter getWriteFileStream(String filename) throws IOException {
return new BufferedWriter(new OutputStreamWriter(
// TODO: add GZIP
@@ -83,7 +88,7 @@ public class FileUtility {
*
* @param data The integer array to write to disk.
* @param filename The filename where the data should be written.
- * @throws IOException
+ * @throws IOException if there is a problem writing to the output file
* @return the FileOutputStream on which the bytes were written
*/
public static FileOutputStream writeBytes(int[] data, String filename) throws IOException {
@@ -97,7 +102,7 @@ public class FileUtility {
*
* @param data The integer array to write to disk.
* @param out The output stream where the data should be written.
- * @throws IOException
+ * @throws IOException if there is a problem writing bytes
*/
public static void writeBytes(int[] data, OutputStream out) throws IOException {
@@ -184,6 +189,8 @@ public class FileUtility {
/**
* Returns the base directory of the file. For example, dirname('/usr/local/bin/emacs') ->
* '/usr/local/bin'
+ * @param fileName the input path
+ * @return the parent path
*/
static public String dirname(String fileName) {
if (fileName.indexOf(File.separator) != -1)
@@ -217,14 +224,15 @@ public class FileUtility {
* Returns the directory were the program has been started,
* the base directory you will implicitly get when specifying no
* full path when e.g. opening a file
- * @return
+ * @return the current 'user.dir'
*/
public static String getWorkingDirectory() {
return System.getProperty("user.dir");
}
/**
- * Method to handle standard IO xceptions. catch (Exception e) {Utility.handleIO_exception(e);}
+ * Method to handle standard IO exceptions. catch (Exception e) {Utility.handleIO_exception(e);}
+ * @param e an input {@link java.lang.Exception}
*/
public static void handleExceptions(Exception e) {
e.printStackTrace();
@@ -233,7 +241,7 @@ public class FileUtility {
/**
* Convenience method to get a full file as a String
- * @param file
+ * @param file the input {@link java.io.File}
* @return The file as a String. Lines are separated by newline character.
*/
public static String getFileAsString(File file) {
@@ -252,6 +260,9 @@ public class FileUtility {
* This method returns a List of String. Each element of the list corresponds to a line from the
* input file. The boolean keepDuplicates in the input determines if duplicate lines are allowed
* in the output LinkedList or not.
+ * @param file the input file
+ * @param keepDuplicates whether to retain duplicate lines
+ * @return a {@link java.util.List} of lines
*/
static public List<String> getLines(File file, boolean keepDuplicates) {
LinkedList<String> list = new LinkedList<String>();
@@ -280,8 +291,9 @@ public class FileUtility {
/**
* Returns a Scanner of the inputFile using a specific encoding
*
- * @param inputFile
- * @return : Scanner
+ * @param inputFile the file for which to get a {@link java.util.Scanner} object
+ * @param encoding the encoding to use within the Scanner
+ * @return a {@link java.util.Scanner} object for a given file
*/
public static Scanner getScanner(File inputFile, String encoding) {
Scanner scan = null;
@@ -296,8 +308,8 @@ public class FileUtility {
/**
* Returns a Scanner of the inputFile using default encoding
*
- * @param inputFile
- * @return : Scanner
+ * @param inputFile the file for which to get a {@link java.util.Scanner} object
+ * @return a {@link java.util.Scanner} object for a given file
*/
public static Scanner getScanner(File inputFile) {
return getScanner(inputFile, DEFAULT_ENCODING);
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/util/FormatUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/FormatUtils.java b/src/main/java/org/apache/joshua/util/FormatUtils.java
index f4854c5..78e19fe 100644
--- a/src/main/java/org/apache/joshua/util/FormatUtils.java
+++ b/src/main/java/org/apache/joshua/util/FormatUtils.java
@@ -38,7 +38,7 @@ public class FormatUtils {
* Determines whether the string is a nonterminal by checking that the first character is [
* and the last character is ].
*
- * @param token
+ * @param token input string
* @return true if it's a nonterminal symbol, false otherwise
*/
public static boolean isNonterminal(String token) {
@@ -73,6 +73,8 @@ public class FormatUtils {
/**
* Removes the index from a nonTerminal: [X,1] -> [X].
+ * @param nt an input non-terminal string
+ * @return the stripped non terminal string
*/
public static String stripNonTerminalIndex(String nt) {
return markup(cleanNonTerminal(nt));
@@ -117,6 +119,8 @@ public class FormatUtils {
/**
* wrap sentence with sentence start/stop markers
* as defined by Vocabulary; separated by a single whitespace.
+ * @param s an input sentence
+ * @return the wrapped sentence
*/
public static String addSentenceMarkers(String s) {
return Vocabulary.START_SYM + " " + s + " " + Vocabulary.STOP_SYM;
@@ -124,6 +128,8 @@ public class FormatUtils {
/**
* strip sentence markers (and whitespaces) from string
+ * @param s the sentence to strip of markers (and whitespaces)
+ * @return the stripped string
*/
public static String removeSentenceMarkers(String s) {
return s.replaceAll("<s> ", "").replace(" </s>", "");
@@ -134,7 +140,7 @@ public class FormatUtils {
* <p>
* The body of this method is taken from the Javadoc documentation for the Java Double class.
*
- * @param string
+ * @param string an input string
* @see java.lang.Double
* @return <code>true</code> if the string represents a valid number, <code>false</code> otherwise
*/
@@ -206,7 +212,7 @@ public class FormatUtils {
/**
* Determines if a string contains ALL CAPS
*
- * @param token
+ * @param token an input token
* @return true if the string is all in uppercase, false otherwise
*/
public static boolean ISALLUPPERCASE(String token) {
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/util/ListUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/ListUtil.java b/src/main/java/org/apache/joshua/util/ListUtil.java
index ab2109d..afb5af1 100644
--- a/src/main/java/org/apache/joshua/util/ListUtil.java
+++ b/src/main/java/org/apache/joshua/util/ListUtil.java
@@ -65,7 +65,7 @@ public class ListUtil {
* S1,...,Sn
*
* @param list A list of Strings
- * @return
+ * @return todo
*/
public static String stringListStringWithoutBrackets(List<String> list) {
return stringListStringWithoutBracketsWithSpecifiedSeparator(list, " ");
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/util/Ngram.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/Ngram.java b/src/main/java/org/apache/joshua/util/Ngram.java
index bb58457..73909ce 100644
--- a/src/main/java/org/apache/joshua/util/Ngram.java
+++ b/src/main/java/org/apache/joshua/util/Ngram.java
@@ -46,7 +46,13 @@ public class Ngram {
}
}
- /** if symbolTbl!=null, then convert interger to String */
+ /**
+ * If symbolTbl!=null, then convert interger to String
+ * @param tbl todo
+ * @param startOrder todo
+ * @param endOrder todo
+ * @param wrds todo
+ */
public static void getNgrams(Map<String, Integer> tbl, int startOrder, int endOrder,
final List<Integer> wrds) {
@@ -64,7 +70,13 @@ public class Ngram {
}
}
- /** if symbolTbl!=null, then convert string to integer */
+ /**
+ * If symbolTbl!=null, then convert string to integer
+ * @param tbl todo
+ * @param startOrder todo
+ * @param endOrder todo
+ * @param wrds todo
+ */
public static void getNgrams(Map<String, Integer> tbl, int startOrder, int endOrder,
final String[] wrds) {
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/util/Regex.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/Regex.java b/src/main/java/org/apache/joshua/util/Regex.java
index 5c54589..e592c11 100644
--- a/src/main/java/org/apache/joshua/util/Regex.java
+++ b/src/main/java/org/apache/joshua/util/Regex.java
@@ -88,6 +88,8 @@ public class Regex {
/**
* Returns whether the input string matches this <code>Regex</code>.
+ * @param input a String to match against the Regex
+ * @return true if the input string matches this Regex
*/
public final boolean matches(String input) {
return this.pattern.matcher(input).matches();
@@ -96,6 +98,8 @@ public class Regex {
/**
* Split a character sequence, removing instances of this <code>Regex</code>.
+ * @param input an input string to split
+ * @return a String array representing the split character sequences less the regex characters patterns
*/
public final String[] split(CharSequence input) {
return this.pattern.split(input);
@@ -105,6 +109,9 @@ public class Regex {
/**
* Split a character sequence, removing instances of this <code>Regex</code>, up to a limited
* number of segments.
+ * @param input an input string to split
+ * @param limit maximum number of splits
+ * @return a String array representing the split character sequences less the regex characters patterns
*/
public final String[] split(CharSequence input, int limit) {
return this.pattern.split(input, limit);
@@ -114,6 +121,9 @@ public class Regex {
/**
* Replace all substrings of the input which match this <code>Regex</code> with the specified
* replacement string.
+ * @param input an input string for which to make replacements
+ * @param replacement the replacement string
+ * @return a new replacement string
*/
public final String replaceAll(String input, String replacement) {
return this.pattern.matcher(input).replaceAll(replacement);
@@ -123,6 +133,9 @@ public class Regex {
/**
* Replace the first substring of the input which matches this <code>Regex</code> with the
* specified replacement string.
+ * @param input the input string for replacement
+ * @param replacement the first substring of the input to replace
+ * @return the new string
*/
public final String replaceFirst(String input, String replacement) {
return this.pattern.matcher(input).replaceFirst(replacement);
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/util/encoding/EncoderConfiguration.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/encoding/EncoderConfiguration.java b/src/main/java/org/apache/joshua/util/encoding/EncoderConfiguration.java
index 5f71f90..60fb838 100644
--- a/src/main/java/org/apache/joshua/util/encoding/EncoderConfiguration.java
+++ b/src/main/java/org/apache/joshua/util/encoding/EncoderConfiguration.java
@@ -130,7 +130,7 @@ public class EncoderConfiguration {
/**
* For now, this just loads a configuration and prints out the number of features.
*
- * @param args
+ * @param args an input configuration file
*/
public static void main(String[] args) {
String grammar_dir = null;
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/util/io/BinaryOut.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/io/BinaryOut.java b/src/main/java/org/apache/joshua/util/io/BinaryOut.java
index 8b189bb..a79d9ba 100644
--- a/src/main/java/org/apache/joshua/util/io/BinaryOut.java
+++ b/src/main/java/org/apache/joshua/util/io/BinaryOut.java
@@ -97,8 +97,8 @@ public class BinaryOut implements DataOutput, ObjectOutput, Flushable, Closeable
* If necessary, the current contents of the buffer will be written to the underlying output
* stream.
*
- * @param size
- * @throws IOException
+ * @param size the size of the buffer
+ * @throws IOException if there is an error determining the current size
*/
protected void prepareBuffer(int size) throws IOException {
if (bufferPosition > 0 && bufferPosition >= BUFFER_SIZE - size) {
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/util/io/IndexedReader.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/io/IndexedReader.java b/src/main/java/org/apache/joshua/util/io/IndexedReader.java
index b477333..f357e55 100644
--- a/src/main/java/org/apache/joshua/util/io/IndexedReader.java
+++ b/src/main/java/org/apache/joshua/util/io/IndexedReader.java
@@ -46,12 +46,10 @@ public class IndexedReader<E> implements Reader<E> {
this.reader = reader;
}
-
- // ===============================================================
- // Public (non-interface) methods
- // ===============================================================
-
- /** Return the number of elements delivered so far. */
+ /**
+ * Return the number of elements delivered so far.
+ * @return integer representing the number of elements delivered so far
+ */
public int index() {
return this.lineNumber;
}
@@ -59,6 +57,8 @@ public class IndexedReader<E> implements Reader<E> {
/**
* Wrap an IOException's message with the index when it occured.
+ * @param oldError the old {@link java.io.IOException} we wish to wrap
+ * @return the new wrapped {@link java.io.IOException}
*/
public IOException wrapIOException(IOException oldError) {
IOException newError =
@@ -72,7 +72,12 @@ public class IndexedReader<E> implements Reader<E> {
// Reader
// ===============================================================
- /** Delegated to the underlying reader. */
+ /**
+ * Delegated to the underlying reader.
+ * @return true if the reader is ready
+ * @throws IOException if there is an error determining readiness
+ */
+ @Override
public boolean ready() throws IOException {
try {
return this.reader.ready();
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/util/io/LineReader.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/io/LineReader.java b/src/main/java/org/apache/joshua/util/io/LineReader.java
index 659ec63..e61e79a 100644
--- a/src/main/java/org/apache/joshua/util/io/LineReader.java
+++ b/src/main/java/org/apache/joshua/util/io/LineReader.java
@@ -74,6 +74,7 @@ public class LineReader implements Reader<String> {
* STDIN. GZIP'd files are tested for automatically.
*
* @param filename the file to be opened ("-" for STDIN)
+ * @throws IOException if there is an error reading the input file
*/
public LineReader(String filename) throws IOException {
@@ -110,6 +111,7 @@ public class LineReader implements Reader<String> {
/**
* Wraps an InputStream for iterating line by line. Stream encoding is assumed to be UTF-8.
+ * @param in an {@link java.io.InputStream} to wrap and iterate over line by line
*/
public LineReader(InputStream in) {
this.reader = new BufferedReader(new InputStreamReader(in, FILE_ENCODING));
@@ -130,6 +132,7 @@ public class LineReader implements Reader<String> {
* iteration. The method is idempotent, and all calls after the first are no-ops (unless the
* thread was interrupted or killed). For correctness, you <b>must</b> call this method before the
* object falls out of scope.
+ * @throws IOException if there is an error closing the file handler
*/
public void close() throws IOException {
@@ -322,6 +325,7 @@ public class LineReader implements Reader<String> {
* remain after calling this method, we implicitly call close.
*
* @return the number of lines read
+ * @throws IOException if there is an error reading lines
*/
public int countLines() throws IOException {
int lines = 0;
@@ -335,11 +339,10 @@ public class LineReader implements Reader<String> {
return lines;
}
- // ===============================================================
- // Main
- // ===============================================================
-
- /** Example usage code. */
+ /**
+ * Example usage code.
+ * @param args an input file
+ */
public static void main(String[] args) {
if (1 != args.length) {
System.out.println("Usage: java LineReader filename");
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d8a68df3/src/main/java/org/apache/joshua/util/io/Reader.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/io/Reader.java b/src/main/java/org/apache/joshua/util/io/Reader.java
index 6e9cc34..cab6d74 100644
--- a/src/main/java/org/apache/joshua/util/io/Reader.java
+++ b/src/main/java/org/apache/joshua/util/io/Reader.java
@@ -29,12 +29,23 @@ import java.util.Iterator;
*/
public interface Reader<E> extends Iterable<E>, Iterator<E> {
- /** Close the reader, freeing all resources. */
+ /**
+ * Close the reader, freeing all resources.
+ * @throws IOException if there is an error closing the reader instance
+ */
void close() throws IOException;
- /** Determine if the reader is ready to read a line. */
+ /**
+ * Determine if the reader is ready to read a line.
+ * @return true if it is ready
+ * @throws IOException if there is an error whilst determining if the reader if ready
+ */
boolean ready() throws IOException;
- /** Read a "line" and return an object representing it. */
+ /**
+ * Read a "line" and return an object representing it.
+ * @return an object representing a single line
+ * @throws IOException if there is an error reading lines
+ */
E readLine() throws IOException;
}