text:
"""Tests for tensorflow_text.python.ops.viterbi_constrained_sequence_op."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import numpy as np

from tensorflow.python.framework import test_util
from tensorflow.python.ops.ragged import ragged_factory_ops
from tensorflow.python.platform import test
from tensorflow_text.python.numpy import viterbi_decode
from tensorflow_text.python.ops import viterbi_constrained_sequence_op as sequence_op

# TODO(b/122968457): Refactor this test logic.
@test_util.run_all_in_graph_and_eager_modes
class ViterbiConstrainedSequenceOpTest(test_util.TensorFlowTestCase):

  # Test a corner case when there is no data for a batch. In this case there
  # may be garbage data for the scores in the batch matrix, but the
  # sequence_length is zero for the batch.
  def test_empty_rows(self):
    use_log_space = True
    use_start_and_end_states = False
    # [batch, num_tokens, num_states]
    scores = np.array(
        [
            [[10.0, 12.0, 6.0, 4.0], [-13.0, -12.0, -11.0, -10.0]],
            # This batch should be ignored
            [[10.0, 12.0, 6.0, 4.0], [-13.0, -12.0, -11.0, -10.0]],
        ],
        dtype='f')

    # [batch] each indicating row size for batch. The second row has no data.
    sequence_length = [2, 0]

    # [num_states, num_states]
    allowed_transitions = np.array([[True, True, True, True],
                                    [True, True, True, True],
                                    [True, False, True, False],
                                    [True, True, True, True]])

    multiple_sequence_op = sequence_op.viterbi_constrained_sequence(
        scores,
        sequence_length,
        allowed_transitions=allowed_transitions,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    multiple_sequence_result = self.evaluate(multiple_sequence_op)
    self.assertAllEqual(multiple_sequence_result, [[1, 3], []])

  def test_sequence_in_exp_space_with_start_end_states_single_input(self):
    use_log_space = False
    use_start_and_end_states = True
    scores = np.array([[10.0, 12.0, 6.0, 4.0], [13.0, 12.0, 11.0, 10.0]])
    # pyformat: disable
    # pylint: disable=bad-whitespace
    # pylint: disable=bad-continuation
    transition_weights = np.array([[ .1,  .2,  .3,  .4, .1],
                                   [ .5,  .6,  .7,  .8, .1],
                                   [ .9,   1, .15,   1, .1],
                                   [.25, .35, .45, .55, .5],
                                   [ .1,  .5,  .1,  .1,  1]], dtype=np.float32)

    allowed_transitions = np.array([[True,  True,  True,  True,  True],
                                    [True,  True,  True,  True,  True],
                                    [True, False,  True, False,  True],
                                    [True,  True,  True,  True,  True],
                                    [True,  True,  True,  True, False]])
    # pyformat: enable
    # pylint: enable=bad-whitespace
    # pylint: enable=bad-continuation
    sequence, _ = viterbi_decode.decode(
        scores,
        transition_weights,
        allowed_transitions,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)

    # Test a multi-item batch.
    multiple_input = np.array([scores, scores, scores], dtype=np.float32)

    multiple_sequence_op = sequence_op.viterbi_constrained_sequence(
        multiple_input, [2, 2, 2],
        allowed_transitions=allowed_transitions,
        transition_weights=transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    multiple_sequence_result = self.evaluate(multiple_sequence_op)
    self.assertAllEqual(multiple_sequence_result,
                        [sequence, sequence, sequence])

  def test_sequence_in_exp_space_with_start_end_states_multi_input(self):
    use_log_space = False
    use_start_and_end_states = True
    scores = np.array([[10.0, 12.0, 6.0, 4.0], [13.0, 12.0, 11.0, 10.0]])
    # pyformat: disable
    # pylint: disable=bad-whitespace
    # pylint: disable=bad-continuation
    transition_weights = np.array([[ .1,  .2,  .3,  .4, .1],
                                   [ .5,  .6,  .7,  .8, .1],
                                   [ .9,   1, .15,   1, .1],
                                   [.25, .35, .45, .55, .5],
                                   [ .1,  .5,  .1,  .1,  1]], dtype=np.float32)

    allowed_transitions = np.array([[True,  True,  True,  True,  True],
                                    [True,  True,  True,  True,  True],
                                    [True, False,  True, False,  True],
                                    [True,  True,  True,  True,  True],
                                    [True,  True,  True,  True, False]])
    # pyformat: enable
    # pylint: enable=bad-whitespace
    # pylint: enable=bad-continuation
    sequence, _ = viterbi_decode.decode(
        scores,
        transition_weights,
        allowed_transitions,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)

    # Test a multi-item batch.
    multiple_input = np.array([scores, scores, scores], dtype=np.float32)

    multiple_sequence_op = sequence_op.viterbi_constrained_sequence(
        multiple_input, [2, 2, 2],
        allowed_transitions=allowed_transitions,
        transition_weights=transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    multiple_sequence_result = self.evaluate(multiple_sequence_op)
    self.assertAllEqual(multiple_sequence_result,
                        [sequence, sequence, sequence])

  def test_sequence_in_exp_space_without_start_end_states_single_input(self):
    use_log_space = False
    use_start_and_end_states = False
    scores = np.array([[10.0, 12.0, 6.0, 4.0], [13.0, 12.0, 11.0, 10.0]])
    # pyformat: disable
    # pylint: disable=bad-whitespace
    # pylint: disable=bad-continuation
    transition_weights = np.array([[ .1,  .2,  .3,  .4],
                                   [ .5,  .6,  .7,  .8],
                                   [ .9,  .1, .15,  .2],
                                   [.25, .35, .45, .55]], dtype=np.float32)

    allowed_transitions = np.array([[True,  True,  True,  True],
                                    [True,  True,  True,  True],
                                    [True, False,  True, False],
                                    [True,  True,  True,  True]])
    # pyformat: enable
    # pylint: enable=bad-whitespace
    # pylint: enable=bad-continuation
    sequence, _ = viterbi_decode.decode(
        scores,
        transition_weights,
        allowed_transitions,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)

    # Test a single-item batch.
    single_input = np.array([scores], dtype=np.float32)
    single_sequence_op = sequence_op.viterbi_constrained_sequence(
        single_input, [2],
        allowed_transitions=allowed_transitions,
        transition_weights=transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    single_result = self.evaluate(single_sequence_op)
    self.assertAllEqual(single_result, [sequence])

  def test_sequence_in_exp_space_without_start_end_states_multi_input(self):
    use_log_space = False
    use_start_and_end_states = False
    scores = np.array([[10.0, 12.0, 6.0, 4.0], [13.0, 12.0, 11.0, 10.0]])
    # pyformat: disable
    # pylint: disable=bad-whitespace
    # pylint: disable=bad-continuation
    transition_weights = np.array([[ .1,  .2,  .3,  .4],
                                   [ .5,  .6,  .7,  .8],
                                   [ .9,  .1, .15,  .2],
                                   [.25, .35, .45, .55]], dtype=np.float32)

    allowed_transitions = np.array([[True,  True,  True,  True],
                                    [True,  True,  True,  True],
                                    [True, False,  True, False],
                                    [True,  True,  True,  True]])
    # pyformat: enable
    # pylint: enable=bad-whitespace
    # pylint: enable=bad-continuation
    sequence, _ = viterbi_decode.decode(
        scores,
        transition_weights,
        allowed_transitions,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)

    # Test a multi-item batch.
    multiple_input = np.array([scores, scores, scores], dtype=np.float32)

    multiple_sequence_op = sequence_op.viterbi_constrained_sequence(
        multiple_input, [2, 2, 2],
        allowed_transitions=allowed_transitions,
        transition_weights=transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    multiple_sequence_result = self.evaluate(multiple_sequence_op)
    self.assertAllEqual(multiple_sequence_result,
                        [sequence, sequence, sequence])

  def test_sequence_in_log_space_with_start_end_states_single_input(self):
    use_log_space = True
    use_start_and_end_states = True
    scores = np.array([[10.0, 12.0, 7.0, 4.0], [13.0, 12.0, 11.0, 10.0]])
    # pyformat: disable
    # pylint: disable=bad-whitespace
    # pylint: disable=bad-continuation
    transition_weights = np.array([[-1.0,  1.0, -2.0,  2.0, 0.0],
                                   [ 3.0, -3.0,  4.0, -4.0, 0.0],
                                   [ 5.0,  1.0, 10.0,  1.0, 1.0],
                                   [-7.0,  7.0, -8.0,  8.0, 0.0],
                                   [ 0.0,  1.0,  2.0,  3.0, 0.0]],
                                  dtype=np.float32)

    allowed_transitions = np.array([[True,  True,  True,  True,  True],
                                    [True,  True,  True,  True,  True],
                                    [True, False,  True, False, False],
                                    [True,  True,  True,  True,  True],
                                    [True, False,  True,  True,  True]])
    # pyformat: enable
    # pylint: enable=bad-whitespace
    # pylint: enable=bad-continuation
    sequence, _ = viterbi_decode.decode(
        scores,
        transition_weights,
        allowed_transitions,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)

    # Test a single-item batch.
    single_input = np.array([scores], dtype=np.float32)
    single_sequence_op = sequence_op.viterbi_constrained_sequence(
        single_input, [2],
        allowed_transitions=allowed_transitions,
        transition_weights=transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    single_result = self.evaluate(single_sequence_op)
    self.assertAllEqual(single_result, [sequence])

  def test_sequence_in_log_space_with_start_end_states_multi_input(self):
    use_log_space = True
    use_start_and_end_states = True
    scores = np.array([[10.0, 12.0, 7.0, 4.0], [13.0, 12.0, 11.0, 10.0]])
    # pyformat: disable
    # pylint: disable=bad-whitespace
    # pylint: disable=bad-continuation
    transition_weights = np.array([[-1.0,  1.0, -2.0,  2.0, 0.0],
                                   [ 3.0, -3.0,  4.0, -4.0, 0.0],
                                   [ 5.0,  1.0, 10.0,  1.0, 1.0],
                                   [-7.0,  7.0, -8.0,  8.0, 0.0],
                                   [ 0.0,  1.0,  2.0,  3.0, 0.0]],
                                  dtype=np.float32)

    allowed_transitions = np.array([[True,  True,  True,  True,  True],
                                    [True,  True,  True,  True,  True],
                                    [True, False,  True, False, False],
                                    [True,  True,  True,  True,  True],
                                    [True, False,  True,  True,  True]])
    # pyformat: enable
    # pylint: enable=bad-whitespace
    # pylint: enable=bad-continuation
    sequence, _ = viterbi_decode.decode(
        scores,
        transition_weights,
        allowed_transitions,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)

    # Test a multi-item batch.
    multiple_input = np.array([scores, scores, scores], dtype=np.float32)

    multiple_sequence_op = sequence_op.viterbi_constrained_sequence(
        multiple_input, [2, 2, 2],
        allowed_transitions=allowed_transitions,
        transition_weights=transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    multiple_sequence_result = self.evaluate(multiple_sequence_op)
    self.assertAllEqual(multiple_sequence_result,
                        [sequence, sequence, sequence])

  def test_sequence_in_log_space_without_start_end_states_single_input(self):
    use_log_space = True
    use_start_and_end_states = False
    scores = np.array([[10.0, 12.0, 6.0, 4.0], [13.0, 12.0, 11.0, 10.0]])
    # pyformat: disable
    # pylint: disable=bad-whitespace
    # pylint: disable=bad-continuation
    transition_weights = np.array([[-1.0,  1.0, -2.0,  2.0],
                                   [ 3.0, -3.0,  4.0, -4.0],
                                   [ 5.0,  1.0, 10.0,  1.0],
                                   [-7.0,  7.0, -8.0,  8.0]], dtype=np.float32)

    allowed_transitions = np.array([[True,  True,  True,  True],
                                    [True,  True,  True,  True],
                                    [True, False,  True, False],
                                    [True,  True,  True,  True]])
    # pyformat: enable
    # pylint: enable=bad-whitespace
    # pylint: enable=bad-continuation
    sequence, _ = viterbi_decode.decode(
        scores,
        transition_weights,
        allowed_transitions,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)

    # Test a single-item batch.
    single_input = np.array([scores], dtype=np.float32)
    single_sequence_op = sequence_op.viterbi_constrained_sequence(
        single_input, [2],
        allowed_transitions=allowed_transitions,
        transition_weights=transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    single_result = self.evaluate(single_sequence_op)
    self.assertAllEqual(single_result, [sequence])

  def test_sequence_in_log_space_without_start_end_states_multi_input(self):
    use_log_space = True
    use_start_and_end_states = False
    scores = np.array([[10.0, 12.0, 6.0, 4.0], [13.0, 12.0, 11.0, 10.0]])
    # pyformat: disable
    # pylint: disable=bad-whitespace
    # pylint: disable=bad-continuation
    transition_weights = np.array([[-1.0,  1.0, -2.0,  2.0],
                                   [ 3.0, -3.0,  4.0, -4.0],
                                   [ 5.0,  1.0, 10.0,  1.0],
                                   [-7.0,  7.0, -8.0,  8.0]], dtype=np.float32)

    allowed_transitions = np.array([[True,  True,  True,  True],
                                    [True,  True,  True,  True],
                                    [True, False,  True, False],
                                    [True,  True,  True,  True]])
    # pyformat: enable
    # pylint: enable=bad-whitespace
    # pylint: enable=bad-continuation
    sequence, _ = viterbi_decode.decode(
        scores,
        transition_weights,
        allowed_transitions,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)

    # Test a multi-item batch.
    multiple_input = np.array([scores, scores, scores], dtype=np.float32)

    multiple_sequence_op = sequence_op.viterbi_constrained_sequence(
        multiple_input, [2, 2, 2],
        allowed_transitions=allowed_transitions,
        transition_weights=transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    multiple_sequence_result = self.evaluate(multiple_sequence_op)
    self.assertAllEqual(multiple_sequence_result,
                        [sequence, sequence, sequence])

  def test_sequence_with_none_weights_single_input(self):
    use_log_space = True
    use_start_and_end_states = False
    scores = np.array([[10.0, 12.0, 6.0, 4.0], [13.0, 12.0, 11.0, 10.0]])
    # pyformat: disable
    # pylint: disable=bad-whitespace
    # pylint: disable=bad-continuation
    transition_weights = np.array([[-1.0,  1.0, -2.0,  2.0],
                                   [ 3.0, -3.0,  4.0, -4.0],
                                   [ 5.0,  1.0, 10.0,  1.0],
                                   [-7.0,  7.0, -8.0,  8.0]], dtype=np.float32)

    allowed_transitions = np.array([[True,  True,  True,  True],
                                    [True,  True,  True,  True],
                                    [True, False,  True, False],
                                    [True,  True,  True,  True]])
    # pyformat: enable
    # pylint: enable=bad-whitespace
    # pylint: enable=bad-continuation
    sequence, _ = viterbi_decode.decode(
        scores,
        transition_weights,
        allowed_transitions,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)

    # Test a single-item batch.
    single_input = np.array([scores], dtype=np.float32)
    single_sequence_op = sequence_op.viterbi_constrained_sequence(
        single_input, [2],
        allowed_transitions=allowed_transitions,
        transition_weights=transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    single_result = self.evaluate(single_sequence_op)
    self.assertAllEqual(single_result, [sequence])

  def test_sequence_with_none_weights_multi_input(self):
    use_log_space = True
    use_start_and_end_states = False
    scores = np.array([[10.0, 12.0, 6.0, 4.0], [13.0, 12.0, 11.0, 10.0]])
    # pyformat: disable
    # pylint: disable=bad-whitespace
    # pylint: disable=bad-continuation
    transition_weights = np.array([[-1.0,  1.0, -2.0,  2.0],
                                   [ 3.0, -3.0,  4.0, -4.0],
                                   [ 5.0,  1.0, 10.0,  1.0],
                                   [-7.0,  7.0, -8.0,  8.0]], dtype=np.float32)

    allowed_transitions = np.array([[True,  True,  True,  True],
                                    [True,  True,  True,  True],
                                    [True, False,  True, False],
                                    [True,  True,  True,  True]])
    # pyformat: enable
    # pylint: enable=bad-whitespace
    # pylint: enable=bad-continuation
    sequence, _ = viterbi_decode.decode(
        scores,
        transition_weights,
        allowed_transitions,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)

    # Test a multi-item batch.
    multiple_input = np.array([scores, scores, scores], dtype=np.float32)

    multiple_sequence_op = sequence_op.viterbi_constrained_sequence(
        multiple_input, [2, 2, 2],
        allowed_transitions=allowed_transitions,
        transition_weights=transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    multiple_sequence_result = self.evaluate(multiple_sequence_op)
    self.assertAllEqual(multiple_sequence_result,
                        [sequence, sequence, sequence])

  def test_sequence_with_none_permissions_single_input(self):
    use_log_space = True
    use_start_and_end_states = False
    scores = np.array([[10.0, 12.0, 6.0, 4.0], [13.0, 12.0, 11.0, 10.0]])
    # pyformat: disable
    # pylint: disable=bad-whitespace
    # pylint: disable=bad-continuation
    transition_weights = np.array([[-1.0,  1.0, -2.0,  2.0],
                                   [ 3.0, -3.0,  4.0, -4.0],
                                   [ 5.0,  1.0, 10.0,  1.0],
                                   [-7.0,  7.0, -8.0,  8.0]], dtype=np.float32)

    # pyformat: enable
    # pylint: enable=bad-whitespace
    # pylint: enable=bad-continuation
    sequence, _ = viterbi_decode.decode(
        scores,
        transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)

    # Test a single-item batch.
    single_input = np.array([scores], dtype=np.float32)
    single_sequence_op = sequence_op.viterbi_constrained_sequence(
        single_input, [2],
        transition_weights=transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    single_result = self.evaluate(single_sequence_op)
    self.assertAllEqual(single_result, [sequence])

  def test_sequence_with_none_permissions_multi_input(self):
    use_log_space = True
    use_start_and_end_states = False
    scores = np.array([[10.0, 12.0, 6.0, 4.0], [13.0, 12.0, 11.0, 10.0]])
    # pyformat: disable
    # pylint: disable=bad-whitespace
    # pylint: disable=bad-continuation
    transition_weights = np.array([[-1.0,  1.0, -2.0,  2.0],
                                   [ 3.0, -3.0,  4.0, -4.0],
                                   [ 5.0,  1.0, 10.0,  1.0],
                                   [-7.0,  7.0, -8.0,  8.0]], dtype=np.float32)

    # pyformat: enable
    # pylint: enable=bad-whitespace
    # pylint: enable=bad-continuation
    sequence, _ = viterbi_decode.decode(
        scores,
        transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)

    # Test a multi-item batch.
    multiple_input = np.array([scores, scores, scores], dtype=np.float32)

    multiple_sequence_op = sequence_op.viterbi_constrained_sequence(
        multiple_input, [2, 2, 2],
        transition_weights=transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    multiple_sequence_result = self.evaluate(multiple_sequence_op)
    self.assertAllEqual(multiple_sequence_result,
                        [sequence, sequence, sequence])

  def test_multi_input_sequence_with_implicit_lengths(self):
    use_log_space = True
    use_start_and_end_states = False
    scores = np.array([[10.0, 12.0, 6.0, 4.0], [13.0, 12.0, 11.0, 10.0]])
    # pyformat: disable
    # pylint: disable=bad-whitespace
    # pylint: disable=bad-continuation
    transition_weights = np.array([[-1.0,  1.0, -2.0,  2.0],
                                   [ 3.0, -3.0,  4.0, -4.0],
                                   [ 5.0,  1.0, 10.0,  1.0],
                                   [-7.0,  7.0, -8.0,  8.0]], dtype=np.float32)

    # pyformat: enable
    # pylint: enable=bad-whitespace
    # pylint: enable=bad-continuation
    sequence, _ = viterbi_decode.decode(
        scores,
        transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)

    # Test a multi-item batch.
    multiple_input = np.array([scores, scores, scores], dtype=np.float32)

    multiple_sequence_op = sequence_op.viterbi_constrained_sequence(
        multiple_input,
        transition_weights=transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    multiple_sequence_result = self.evaluate(multiple_sequence_op)
    self.assertAllEqual(multiple_sequence_result,
                        [sequence, sequence, sequence])

  def test_single_input_sequence_with_implicit_lengths(self):
    use_log_space = True
    use_start_and_end_states = False
    scores = np.array([[10.0, 13.0, 6.0, 4.0], [13.0, 12.0, 11.0, 10.0],
                       [13.0, 12.0, 11.0, 10.0]])
    # pyformat: disable
    # pylint: disable=bad-whitespace
    # pylint: disable=bad-continuation
    transition_weights = np.array([[-1.0,  1.0, -2.0,  2.0],
                                   [ 3.0, -3.0,  4.0, -4.0],
                                   [ 5.0,  1.0, 10.0,  1.0],
                                   [-7.0,  7.0, -8.0,  8.0]], dtype=np.float32)

    # pyformat: enable
    # pylint: enable=bad-whitespace
    # pylint: enable=bad-continuation
    sequence, _ = viterbi_decode.decode(
        scores,
        transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)

    # Test a multi-item batch.
    multiple_input = np.array([scores], dtype=np.float32)

    single_sequence_op = sequence_op.viterbi_constrained_sequence(
        multiple_input,
        transition_weights=transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    single_sequence_result = self.evaluate(single_sequence_op)
    self.assertAllEqual(single_sequence_result, [sequence])

  def test_ragged_input_sequence(self):
    use_log_space = True
    use_start_and_end_states = False
    input_1 = np.array([[10.0, 13.0, 6.0, 4.0], [13.0, 12.0, 11.0, 10.0],
                        [13.0, 12.0, 11.0, 10.0]])
    input_2 = np.array([[10.0, 12.0, 6.0, 4.0], [13.0, 12.0, 11.0, 10.0]])
    # TODO(b/122968457): Extend RT support to lists-of-ndarrays.
    scores = ragged_factory_ops.constant([input_1.tolist(), input_2.tolist()])
    # pyformat: disable
    # pylint: disable=bad-whitespace
    # pylint: disable=bad-continuation
    transition_weights = np.array([[-1.0,  1.0, -2.0,  2.0],
                                   [ 3.0, -3.0,  4.0, -4.0],
                                   [ 5.0,  1.0, 10.0,  1.0],
                                   [-7.0,  7.0, -8.0,  8.0]], dtype=np.float32)

    # pyformat: enable
    # pylint: enable=bad-whitespace
    # pylint: enable=bad-continuation
    sequence_1, _ = viterbi_decode.decode(
        input_1,
        transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    sequence_2, _ = viterbi_decode.decode(
        input_2,
        transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    expected_sequence = ragged_factory_ops.constant([sequence_1, sequence_2])

    # Test a ragged batch
    single_sequence_op = sequence_op.viterbi_constrained_sequence(
        scores,
        transition_weights=transition_weights,
        use_log_space=use_log_space,
        use_start_and_end_states=use_start_and_end_states)
    single_sequence_result = self.evaluate(single_sequence_op)
    self.assertAllEqual(single_sequence_result, expected_sequence)

if __name__ == '__main__':
  test.main()


text:
<?php

/**
 * Suite for .phpt test cases.
 */
class PHPUnit_Extensions_PhptTestSuite extends PHPUnit_Framework_TestSuite
{
    /**
     * Constructs a new TestSuite for .phpt test cases.
     *
     * @param string $directory
     *
     * @throws PHPUnit_Framework_Exception
     */
    public function __construct($directory)
    {
        if (is_string($directory) && is_dir($directory)) {
            $this->setName($directory);

            $facade = new File_Iterator_Facade;
            $files  = $facade->getFilesAsArray($directory, '.phpt');

            foreach ($files as $file) {
                $this->addTestFile($file);
            }
        } else {
            throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'directory name');
        }
    }
}

redpajama_set_name: RedPajamaGithub


text:
package org.kiji.schema.shell.spi

import org.kiji.annotations.ApiAudience
import org.kiji.annotations.ApiStability
import org.kiji.delegation.NamedProvider
import org.kiji.schema.shell.Environment

/**
 * An API that allows you to unit test your {@link ParserPlugin} and {@link ParserPluginFactory}
 * implementations.
 *
 *
Create an instance of this class parameterized by the {@link Class} object
 * that represents your `ParserPluginFactory`. Then call the test methods
 * to test different aspects of its functionality. Call {@link #testAll} to run
 * all test methods.

 *
 *
Each test throws {@link IllegalStateException} on error.

 */
@ApiAudience.Framework
@ApiStability.Experimental
final class ParserPluginTestKit(val klazz: Class[_ <: ParserPluginFactory]) {
  /** Tests that klazz is non-null. */
  def testNonNull(): Unit = {
    require(klazz != null, "Specified class under test is null.")
  }

  /** Tests we can instantiate your factory with a parameterless constructor. */
  def testInstantiation(): Unit = {
    try {
      val instance: ParserPluginFactory = klazz.newInstance
    } catch { case e: Exception =>
      throw new IllegalStateException("Cannot create a new instance of " + klazz.getName()
          + "through reflection", e)
    }
  }

  /** Tests that the getName() method returns the same value every time. */
  def testNameConstant(): Unit = {
    val instance1: ParserPluginFactory = klazz.newInstance
    val instance2: ParserPluginFactory = klazz.newInstance

    val name1 = instance1.getName
    val name2 = instance2.getName

    require(null != name1, klazz.getName() + " getName() method returns null")
    require(name1 == name2, klazz.getName() + " getName() method returns non-constant value")
  }

  /** Tests that ParserPluginFactory creates a valid ParserPlugin instance. */
  def testCreatesParserPlugin(): Unit = {
    val factory: ParserPluginFactory = klazz.newInstance
    val parser = factory.create(new Environment())
    require(null != parser, "Factory class " + klazz.getName() + " creates null parser.")
  }

  /** Tests that ParserPluginFactory.create() respects the env parameter. */
  def testCreateRespectsEnv(): Unit = {
    val factory: ParserPluginFactory = klazz.newInstance
    val env1 = new Environment()
    val env2 = new Environment()
    val parser1 = factory.create(env1)
    val parser2 = factory.create(env2)

    if (env1 == env2) {
      // Sanity check that we haven't overridden == on environments.
      sys.error("Internal error: env1 and env2 were the same")
    }

    require(env1 == parser1.env, "Factory class " + klazz.getName()
          + " create() doesn't respect the 'env' argument.")

    require(env2 == parser2.env, "Factory class " + klazz.getName()
          + " create() doesn't respect the 'env' argument on subsequent calls.")
  }

  /** Tests that the parser returned by ParserPlugin.command is non-null. */
  def testParserPluginCreatesNonNullParser(): Unit = {
    val factory: ParserPluginFactory = klazz.newInstance
    val parser = factory.create(new Environment())
    require(null != parser.command,
        "Factory class creates ParserPlugin but plugin.command returns null.")
  }

  /** Run all unit tests. */
  def testAll(): Unit = {
    testNonNull
    testInstantiation
    testNameConstant
    testCreatesParserPlugin
    testCreateRespectsEnv
    testParserPluginCreatesNonNullParser
  }
}


text:
require 'workflow_rb/mongo/version'
require 'workflow_rb/mongo/mongo_persistence_provider'

module WorkflowRb
  module Mongo
    # Your code goes here...
  end
end


text:
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">TestProjectGradleFirst</string>
    <string name="hello_world">Hello world First!</string>
    <string name="action_settings">Settings</string>

</resources>


text:
define({
  "configText": "Definér dine filtergrupper nedenfor",
  "labels": {
    "groupName": "Filtrér på angivet navn:",
    "groupNameTip": "Navn på det filter, som brugeren skal vælge fra.",
    "groupDesc": "Beskrivelse:",
    "groupDescTip": "Beskrivelse af det indstillede filter.",
    "groupOperator": "Forudindstillet operator:",
    "groupOperatorTip": "Indstilling til prædefinition af operatoren til filtret. Hvis der ikke er valgt nogen Forudindstillet operator, vil filtret benytte operatoren Lig med.",
    "groupDefault": "Foruddefineret værdi:",
    "groupDefaultTip": "Indstilling til valg af en værdi fra et eksisterende lag.",
    "sameLayerAppend": "Når et lag er angivet mere end én gang, skal du benytte følgende operator mellem felterne:",
    "sameLayerConjunc": "Tilknyt ved hjælp af:"
  },
  "buttons": {
    "addNewGroup": "Tilføj en ny gruppe",
    "addNewGroupTip": "Tilføj et nyt filtersæt.",
    "addLayer": "Tilføj lag",
    "addLayerTip": "Tilføj et lag til filtersættet."
  },
  "inputs": {
    "groupName": "Giv din gruppe et navn",
    "groupDesc": "Beskrivelse af din gruppe",
    "groupDefault": "Angiv en foruddefineret værdi",
    "simpleMode": "Start i Simpel visning",
    "simpleModeTip": "Indstilling til forenkling af den konfigurerede widget-grænseflade. Når indstillingen er valgt, fjernes operator-rullelisten og tilføj kriterier-knappen fra grænsefladen.",
    "webmapAppendMode": "Tilknyt filter til eksisterende webkortfilter ved hjælp af ",
    "webmapAppendModeTip": "Indstilling til tilknytning af det indstillede filter til et eksisterende webkortfilter. Understøttede operatorer er ELLER og OG.",
    "optionsMode": "Skjul widget-indstillinger",
    "optionsModeTip": "Indstilling til visning af flere widget-indstillinger. Når indstillingen er valgt, fjernes lagring og indlæsning af definerede filtre samt bevarelse af filtret, efter at widget'en er blevet lukket, fra grænsefladen.",
    "optionOR": "ELLER",
    "optionAND": "OG",
    "optionEQUAL": "LIG MED",
    "optionNOTEQUAL": "IKKE LIG MED",
    "optionGREATERTHAN": "STØRRE END",
    "optionGREATERTHANEQUAL": "STØRRE END ELLER LIG MED",
    "optionLESSTHAN": "MINDRE END",
    "optionLESSTHANEQUAL": "MINDRE END ELLER LIG MED",
    "optionSTART": "BEGYNDER MED",
    "optionEND": "SLUTTER MED",
    "optionLIKE": "INDEHOLDER",
    "optionNOTLIKE": "INDEHOLDER IKKE",
    "optionNONE": "INGEN"
  },
  "tables": {
    "layer": "Lag",
    "layerTip": "Navnet på laget, som det er defineret i kortet.",
    "field": "Felter",
    "fieldTip": "Det felt, som laget filtreres på.",
    "value": "Brug værdi",
    "valueTip": "Indstilling til brug af rullelisteværdierne fra laget. Hvis ingen lag bruger denne parameter, vises der en almindelig tekstboks for brugeren.",
    "zoom": "Zoom",
    "zoomTip": "Indstilling til at zoome udstrækningen af objekter, efter at filtret er taget i brug. Der kan kun vælges ét lag at zoome til.",
    "action": "download fuldført",
    "actionTip": "Fjern lag fra det indstillede filter."
  },
  "popup": {
    "label": "Vælg en værdi"
  },
  "errors": {
    "noGroups": "Du skal bruge mindst én gruppe.",
    "noGroupName": "Ét eller flere gruppenavne mangler.",
    "noDuplicates": "Ét eller flere gruppenavne er duplikerede.",
    "noRows": "Du skal bruge mindst én række i tabellen.",
    "noLayers": "Du har ikke nogen lag i kortet."
  },
  "picker": {
    "description": "Brug denne formular til at finde en forudindstillet værdi for denne gruppe.",
    "layer": "Vælg et lag",
    "layerTip": "Navnet på laget, som det er defineret i webkortet.",
    "field": "Vælg et felt",
    "fieldTip": "Det felt, som den forudindstillede værdi skal hentes fra.",
    "value": "Vælg en værdi",
    "valueTip": "Den værdi, der skal være standarden for widget'en."
  }
});


text:
ACCEPTED

#### According to
Index Fungorum

#### Published in
Mycologia 69(5): 916 (1977)

#### Original name
Hyponectria gregaria M.E. Barr

### Remarks
null


text:
import refractor from 'refractor';
import toTokenTrees from '../toTokenTrees';

// eslint-disable-next-line max-len
const content = '<img style="width:<?php echo (80 / count($images)) ?>%" src=\'<?php echo Component_Union_FinanceInfoModel::UNION_LICEPIC_URL_PREFIX . $image?>\'/>';

describe('toTokenTrees', () => {
    test('php will renders __PHP__', () => {
        const options = {
            highlight: true,
            refractor: refractor,
            language: 'php',
            oldSource: null,
            enhancers: [],
        };

        const hunks = [{
            changes: [
                {
                    content,
                    isInsert: true,
                    lineNumber: 1,
                    type: 'insert',
                },
            ],
            content: '@@ -1,10 +1,17 @@',
            isPlain: false,
            newLines: 17,
            newStart: 1,
            oldLines: 10,
            oldStart: 1,
        }];

        const tokens = toTokenTrees(hunks, options);
        expect(tokens).toMatchSnapshot();
    });

    test('refractor highlight', () => {
        expect(refractor.highlight(content, 'php')).toMatchSnapshot();
    });
});


text:
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-comp-3645',
  templateUrl: './comp-3645.component.html',
  styleUrls: ['./comp-3645.component.css']
})
export class Comp3645Component implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}


text:
namespace PackageManager.Tests.Models.PackageTest
{
    using Moq;
    using NUnit.Framework;
    using PackageManager.Models;
    using PackageManager.Models.Contracts;
    using System;
    using System.Collections.Generic;

    [TestFixture]
    public class ConstructorTest
    {

        [Test]
        public void Constructor_ShouldSetCorrectlyDependencies_WhenParameterIsOptional()
        {
            var versionMocked = new Mock<IVersion>();
            var package = new Package("Test", versionMocked.Object);

            Assert.IsInstanceOf(typeof(HashSet<IPackage>), package.Dependencies);
        }

        [Test]
        public void Constructor_ShouldSetCorrectlyDependencies_WhenParameterArePassed()
        {
            var versionMocked = new Mock<IVersion>();
            var dependenciesMocked = new Mock<ICollection<IPackage>>();

            var package = new Package("Test", versionMocked.Object,dependenciesMocked.Object );

            Assert.IsInstanceOf(typeof(ICollection<IPackage>), package.Dependencies);
        }
    }
}


text:
namespace MMS.ServiceBus.Pipeline.Outgoing
{
    using System.Collections.Concurrent;
    using System.Threading.Tasks;
    using Microsoft.ServiceBus.Messaging;
    using ServiceBusMessageSender = Microsoft.ServiceBus.Messaging.MessageSender;

    public class MessageSender : ISendMessages
    {
        private readonly ConcurrentDictionary<Queue, ServiceBusMessageSender> senderCache =
            new ConcurrentDictionary<Queue, ServiceBusMessageSender>();

        private readonly MessagingFactory factory;

        public MessageSender(MessagingFactory factory)
        {
            this.factory = factory;
        }

        public async Task SendAsync(TransportMessage message, SendOptions options)
        {
            ServiceBusMessageSender sender;
            if (!this.senderCache.TryGetValue(options.Queue, out sender))
            {
                sender = await this.factory.CreateMessageSenderAsync(options.Destination())
                    .ConfigureAwait(false);
                this.senderCache.TryAdd(options.Queue, sender);
            }

            await sender.SendAsync(message.ToBrokeredMessage())
                .ConfigureAwait(false);
        }

        public async Task CloseAsync()
        {
            foreach (var sender in this.senderCache.Values)
            {
                await sender.CloseAsync()
                    .ConfigureAwait(false);
            }

            this.senderCache.Clear();
        }
    }
}


text:
from django.apps import AppConfig

class WePayConfig(AppConfig):
    name = 'djwepay'
    label = 'djwepay'
    verbose_name = 'Django WePay'


text:
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;

exports.__esModule = true;
exports.default = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));

var React = _interopRequireWildcard(require("react"));

var _StyleSheet = _interopRequireDefault(require("../StyleSheet"));

var _View = _interopRequireDefault(require("../View"));

var _ExecutionEnvironment = _interopRequireDefault(require("fbjs/lib/ExecutionEnvironment"));

const _excluded = ["style"];
const canUseDOM = _ExecutionEnvironment.default.canUseDOM;

const cssFunction = function () {
  if (canUseDOM && window.CSS && window.CSS.supports && window.CSS.supports('top: constant(safe-area-inset-top)')) {
    return 'constant';
  }

  return 'env';
}();

const SafeAreaView = /*#__PURE__*/React.forwardRef((props, ref) => {
  const style = props.style,
        rest = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
  return /*#__PURE__*/React.createElement(_View.default, (0, _extends2.default)({}, rest, {
    ref: ref,
    style: _StyleSheet.default.compose(styles.root, style)
  }));
});
SafeAreaView.displayName = 'SafeAreaView';

const styles = _StyleSheet.default.create({
  root: {
    paddingTop: cssFunction + "(safe-area-inset-top)",
    paddingRight: cssFunction + "(safe-area-inset-right)",
    paddingBottom: cssFunction + "(safe-area-inset-bottom)",
    paddingLeft: cssFunction + "(safe-area-inset-left)"
  }
});

var _default = SafeAreaView;
exports.default = _default;
module.exports = exports.default;


text:
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->libdir . '/statslib.php');
require_once($CFG->libdir . '/cronlib.php');

/**
 * Test functions that affect daily stats.
 */
class core_statslib_testcase extends advanced_testcase {
    /** The student role ID **/
    const STID = 5;

    /** The day to use for testing **/
    const DAY = 1272672000;

    /** The timezone to use for testing **/
    const TIMEZONE = 0;

    /** @var array The list of temporary tables created for the statistic calculations **/
    protected $tables = array('temp_log1', 'temp_log2', 'temp_stats_daily', 'temp_stats_user_daily');

    /** @var array The replacements to be used when loading XML files **/
    protected $replacements = null;

    /**
     * Set up the database for tests.
     *
     * This function is needed so that daily_log_provider has the before-test set up from setUp()
     */
    protected function set_up_db() {
        global $DB;

        if ($DB->record_exists('user', array('username' => 'user1'))) {
            return;
        }

        $datagen = self::getDataGenerator();

        $user1   = $datagen->create_user(array('username'=>'user1'));
        $user2   = $datagen->create_user(array('username'=>'user2'));

        $course1 = $datagen->create_course(array('shortname'=>'course1'));

        $success = enrol_try_internal_enrol($course1->id, $user1->id, 5);

        if (!$success) {
            trigger_error('User enrollment failed', E_USER_ERROR);
        }

        $context = context_system::instance();
        role_assign(self::STID, $user2->id, $context->id);

        $this->generate_replacement_list();
    }

    /**
     * Setup function
     *   - Allow changes to CFG->debug for testing purposes.
     */
    protected function setUp() {
        global $CFG;
        parent::setUp();

        // Settings to force statistic to run during testing.
        $CFG->timezone                = self::TIMEZONE;
        $CFG->statsfirstrun           = 'all';
        $CFG->statslastdaily          = 0;
        $CFG->statslastexecution      = 0;

        // Figure out the broken day start so I can figure out when to the start time should be.
        $time   = time();
        $offset = get_timezone_offset($CFG->timezone);
        $stime  = $time + $offset;
        $stime  = intval($stime / (60*60*24)) * 60*60*24;
        $stime -= $offset;

        $shour  = intval(($time - $stime) / (60*60));

        $CFG->statsruntimestarthour   = $shour;
        $CFG->statsruntimestartminute = 0;

        $this->set_up_db();

        $this->resetAfterTest();
    }

    protected function tearDown() {
        // Reset the timeouts.
        set_time_limit(0);
    }

    /**
     * Function to setup database.
     *
     * @param array $dataset An array of tables including the log table.
     * @param array $tables
     */
    protected function prepare_db($dataset, $tables) {
        global $DB;

        foreach ($tables as $tablename) {
            $DB->delete_records($tablename);

            foreach ($dataset as $name => $table) {

                if ($tablename == $name) {

                    $rows = $table->getRowCount();

                    for ($i = 0; $i < $rows; $i++) {
                        $row = $table->getRow($i);

                        $DB->insert_record($tablename, $row, false, true);
                    }
                }
            }
        }
    }

    /**
     * Load dataset from XML file.
     */
    protected function generate_replacement_list() {
        global $CFG, $DB;

        if ($this->replacements !== null) {
            return;
        }

        $CFG->timezone = self::TIMEZONE;

        $guest = $DB->get_record('user', array('id' => $CFG->siteguest));
        $user1 = $DB->get_record('user', array('username' => 'user1'));
        $user2 = $DB->get_record('user', array('username' => 'user2'));

        if (($guest === false) || ($user1 === false) || ($user2 === false)) {
            trigger_error('User setup incomplete', E_USER_ERROR);
        }

        $site    = $DB->get_record('course', array('id' => SITEID));
        $course1 = $DB->get_record('course', array('shortname' => 'course1'));

        if (($site === false) || ($course1 === false)) {
            trigger_error('Course setup incomplete', E_USER_ERROR);
        }

        $offset = get_timezone_offset($CFG->timezone);

        $start      = stats_get_base_daily(self::DAY + 3600);
        $startnolog = stats_get_base_daily(stats_get_start_from('daily'));
        $gr         = get_guest_role();

        $this->replacements = array(
            // Start and end times.
            '[start_0]'          => $start -  14410,  // 4 hours before.
            '[start_1]'          => $start +  14410,  // 4 hours after.
            '[start_2]'          => $start +  14420,
            '[start_3]'          => $start +  14430,
            '[start_4]'          => $start + 100800, // 28 hours after.
            '[end]'              => stats_get_next_day_start($start),
            '[end_no_logs]'      => stats_get_next_day_start($startnolog),

            // User ids.
            '[guest_id]'         => $guest->id,
            '[user1_id]'         => $user1->id,
            '[user2_id]'         => $user2->id,

            // Course ids.
            '[course1_id]'       => $course1->id,
            '[site_id]'          => SITEID,

            // Role ids.
            '[frontpage_roleid]' => (int) $CFG->defaultfrontpageroleid,
            '[guest_roleid]'     => $gr->id,
            '[student_roleid]'   => self::STID,
        );
    }

    /**
     * Load dataset from XML file.
     *
     * @param string $file The name of the file to load
     * @return array
     */
    protected function load_xml_data_file($file) {
        static $replacements = null;

        $raw   = $this->createXMLDataSet($file);
        $clean = new PHPUnit_Extensions_Database_DataSet_ReplacementDataSet($raw);

        foreach ($this->replacements as $placeholder => $value) {
            $clean->addFullReplacement($placeholder, $value);
        }

        $logs = new PHPUnit_Extensions_Database_DataSet_DataSetFilter($clean);
        $logs->addIncludeTables(array('log'));

        $stats = new PHPUnit_Extensions_Database_DataSet_DataSetFilter($clean);
        $stats->addIncludeTables(array('stats_daily', 'stats_user_daily'));

        return array($logs, $stats);
    }

    /**
     * Provides the log data for test_statslib_cron_daily.
     */
    public function daily_log_provider() {
        global $CFG, $DB;

        $this->set_up_db();

        $tests = array('00', '01', '02', '03', '04', '05', '06', '07', '08');

        $dataset = array();

        foreach ($tests as $test) {
            $dataset[] = $this->load_xml_data_file(__DIR__."/fixtures/statslib-test{$test}.xml");
        }

        return $dataset;
    }

    /**
     * Compare the expected stats to those in the database.
     *
     * @param array $expected
     * @param string $output
     */
    protected function verify_stats($expected, $output = '') {
        global $DB;

        // Note: We can not use $this->assertDataSetEqual($expected, $actual) because there's no
        //       $this->getConnection() in advanced_testcase.

        foreach ($expected as $type => $table) {
            $records = $DB->get_records($type);

            $rows = $table->getRowCount();

            $message = 'Incorrect number of results returned for '. $type;

            if ($output != '') {
                $message .= "\nCron output:\n$output";
            }

            $this->assertCount($rows, $records, $message);

            for ($i = 0; $i < $rows; $i++) {
                $row   = $table->getRow($i);
                $found = 0;

                foreach ($records as $key => $record) {
                    $record = (array) $record;
                    unset($record['id']);
                    $diff = array_merge(array_diff_assoc($row, $record),
                            array_diff_assoc($record, $row));

                    if (empty($diff)) {
                        $found = $key;
                        break;
                    }
                }

                $this->assertGreaterThan(0, $found, 'Expected log '. var_export($row, true)
                                        ." was not found in $type ". var_export($records, true));
                unset($records[$found]);
            }
        }
    }

    /**
     * Test progress output when debug is on.
     */
    public function test_statslib_progress_debug() {
        set_debugging(DEBUG_ALL);
        $this->expectOutputString('1:0 ');
        stats_progress('init');
        stats_progress('1');
        $this->resetDebugging();
    }

    /**
     * Test progress output when debug is off.
     */
    public function test_statslib_progress_no_debug() {
        set_debugging(DEBUG_NONE);
        $this->expectOutputString('.');
        stats_progress('init');
        stats_progress('1');
        $this->resetDebugging();
    }

    /**
     * Test the function that gets the start date from the config.
     */
    public function test_statslib_get_start_from() {
        global $CFG, $DB;

        $dataset = $this->load_xml_data_file(__DIR__."/fixtures/statslib-test01.xml");
        $time = time();
        $DB->delete_records('log');

        // Don't ask.  I don't think get_timezone_offset works correctly.
        $day = self::DAY - get_timezone_offset($CFG->timezone);

        $CFG->statsfirstrun = 'all';
        // Allow 1 second difference in case we cross a second boundary.
        // Note: within 3 days of a DST change - -3 days != 3 * 24 hours (it may be more or less).
        $this->assertLessThanOrEqual(1, stats_get_start_from('daily') - strtotime('-3 days', $time), 'All start time');

        $this->prepare_db($dataset[0], array('log'));
        $records = $DB->get_records('log');

        $this->assertEquals($day + 14410, stats_get_start_from('daily'), 'Log entry start');

        $CFG->statsfirstrun = 'none';
        $this->assertLessThanOrEqual(1, stats_get_start_from('daily') - strtotime('-3 days', $time), 'None start time');

        $CFG->statsfirstrun = 14515200;
        $this->assertLessThanOrEqual(1, stats_get_start_from('daily') - ($time - (14515200)), 'Specified start time');

        $this->prepare_db($dataset[1], array('stats_daily'));
        $this->assertEquals($day + (24 * 3600), stats_get_start_from('daily'), 'Daily stats start time');
    }

    /**
     * Test the function that calculates the start of the day.
     *
     * NOTE: I don't think this is the way this function should work.
     *       This test documents the current functionality.
     */
    public function test_statslib_get_base_daily() {
        global $CFG;

        for ($x = 0; $x < 24; $x += 1) {
            $CFG->timezone = $x;

            $start = 1272672000 - ($x * 3600);
            if ($x >= 20) {
                $start += (24 * 3600);
            }

            $this->assertEquals($start, stats_get_base_daily(1272686410), "Timezone $x check");
        }
    }

    /**
     * Test the function that gets the start of the next day.
     */
    public function test_statslib_get_next_day_start() {
        global $CFG;

        $CFG->timezone = 0;
        $this->assertEquals(1272758400, stats_get_next_day_start(1272686410));
    }

    /**
     * Test the function that gets the action names.
     *
     * Note: The function results depend on installed modules.  The hard coded lists are the
     *       defaults for a new Moodle 2.3 install.
     */
    public function test_statslib_get_action_names() {
        $basepostactions = array (
            0 => 'add',
            1 => 'delete',
            2 => 'edit',
            3 => 'add mod',
            4 => 'delete mod',
            5 => 'edit sectionenrol',
            6 => 'loginas',
            7 => 'new',
            8 => 'unenrol',
            9 => 'update',
            10 => 'update mod',
            11 => 'upload',
            12 => 'submit',
            13 => 'submit for grading',
            14 => 'talk',
            15 => 'choose',
            16 => 'choose again',
            17 => 'record delete',
            18 => 'add discussion',
            19 => 'add post',
            20 => 'delete discussion',
            21 => 'delete post',
            22 => 'move discussion',
            23 => 'prune post',
            24 => 'update post',
            25 => 'add category',
            26 => 'add entry',
            27 => 'approve entry',
            28 => 'delete category',
            29 => 'delete entry',
            30 => 'edit category',
            31 => 'update entry',
            32 => 'end',
            33 => 'start',
            34 => 'attempt',
            35 => 'close attempt',
            36 => 'preview',
            37 => 'editquestions',
            38 => 'delete attempt',
            39 => 'manualgrade',
        );

         $baseviewactions = array (
            0 => 'view',
            1 => 'view all',
            2 => 'history',
            3 => 'view submission',
            4 => 'view feedback',
            5 => 'print',
            6 => 'report',
            7 => 'view discussion',
            8 => 'search',
            9 => 'forum',
            10 => 'forums',
            11 => 'subscribers',
            12 => 'view forum',
            13 => 'view entry',
            14 => 'review',
            15 => 'pre-view',
            16 => 'download',
            17 => 'view form',
            18 => 'view graph',
            19 => 'view report',
        );

        $postactions = stats_get_action_names('post');

        foreach ($basepostactions as $action) {
            $this->assertContains($action, $postactions);
        }

        $viewactions = stats_get_action_names('view');

        foreach ($baseviewactions as $action) {
            $this->assertContains($action, $viewactions);
        }
    }

    /**
     * Test the temporary table creation and deletion.
     */
    public function test_statslib_temp_table_create_and_drop() {
        global $DB;

        foreach ($this->tables as $table) {
            $this->assertFalse($DB->get_manager()->table_exists($table));
        }

        stats_temp_table_create();

        foreach ($this->tables as $table) {
            $this->assertTrue($DB->get_manager()->table_exists($table));
        }

        stats_temp_table_drop();

        foreach ($this->tables as $table) {
            $this->assertFalse($DB->get_manager()->table_exists($table));
        }
    }

    /**
     * Test the temporary table creation and deletion.
     *
     * @depends test_statslib_temp_table_create_and_drop
     */
    public function test_statslib_temp_table_fill() {
        global $CFG, $DB;

        $dataset = $this->load_xml_data_file(__DIR__."/fixtures/statslib-test09.xml");

        $this->prepare_db($dataset[0], array('log'));

        $start = self::DAY - get_timezone_offset($CFG->timezone);
        $end   = $start + (24 * 3600);

        stats_temp_table_create();
        stats_temp_table_fill($start, $end);

        $this->assertEquals(1, $DB->count_records('temp_log1'));
        $this->assertEquals(1, $DB->count_records('temp_log2'));

        stats_temp_table_drop();
    }

    /**
     * Test the temporary table creation and deletion.
     *
     * @depends test_statslib_temp_table_create_and_drop
     */
    public function test_statslib_temp_table_setup() {
        global $DB;

        $logs = array();
        $this->prepare_db($logs, array('log'));

        stats_temp_table_create();
        stats_temp_table_setup();

        $this->assertEquals(1, $DB->count_records('temp_enroled'));

        stats_temp_table_drop();
    }

    /**
     * Test the function that clean out the temporary tables.
     *
     * @depends test_statslib_temp_table_create_and_drop
     */
    public function test_statslib_temp_table_clean() {
        global $DB;

        $rows = array(
            'temp_log1'             => array('id' => 1, 'course' => 1),
            'temp_log2'             => array('id' => 1, 'course' => 1),
            'temp_stats_daily'      => array('id' => 1, 'courseid' => 1),
            'temp_stats_user_daily' => array('id' => 1, 'courseid' => 1),
        );

        stats_temp_table_create();

        foreach ($rows as $table => $row) {
            $DB->insert_record_raw($table, $row);
            $this->assertEquals(1, $DB->count_records($table));
        }

        stats_temp_table_clean();

        foreach ($rows as $table => $row) {
            $this->assertEquals(0, $DB->count_records($table));
        }

        $this->assertEquals(1, $DB->count_records('stats_daily'));
        $this->assertEquals(1, $DB->count_records('stats_user_daily'));

        stats_temp_table_drop();
    }

    /**
     * Test the daily stats function.
     *
     * @depends test_statslib_get_base_daily
     * @depends test_statslib_get_next_day_start
     * @depends test_statslib_get_start_from
     * @depends test_statslib_temp_table_create_and_drop
     * @depends test_statslib_temp_table_setup
     * @depends test_statslib_temp_table_fill
     * @dataProvider daily_log_provider
     */
    public function test_statslib_cron_daily($logs, $stats) {
        global $CFG, $DB;

        $this->prepare_db($logs, array('log'));

        // Stats cron daily uses mtrace, turn on buffering to silence output.
        ob_start();
        stats_cron_daily(1);
        $output = ob_get_contents();
        ob_end_clean();

        $this->verify_stats($stats, $output);
    }

    /**
     * Test the daily stats function.
     *
     * @depends test_statslib_get_base_daily
     * @depends test_statslib_get_next_day_start
     */
    public function test_statslib_cron_daily_no_default_profile_id() {
        global $CFG, $DB;
        $CFG->defaultfrontpageroleid = 0;

        $course1  = $DB->get_record('course', array('shortname' => 'course1'));
        $guestid  = $CFG->siteguest;
        $start    = stats_get_base_daily(1272758400);
        $end      = stats_get_next_day_start($start);
        $fpid     = (int) $CFG->defaultfrontpageroleid;
        $gr       = get_guest_role();

        $dataset = $this->load_xml_data_file(__DIR__."/fixtures/statslib-test10.xml");

        $this->prepare_db($dataset[0], array('log'));

        // Stats cron daily uses mtrace, turn on buffering to silence output.
        ob_start();
        stats_cron_daily($maxdays=1);
        $output = ob_get_contents();
        ob_end_clean();

        $this->verify_stats($dataset[1], $output);
    }
}


text:
using System;
using EnvDTE;

namespace NuGet.VisualStudio
{
    public static class VsVersionHelper
    {
        private const int MaxVsVersion = 12;
        private static readonly Lazy<int> _vsMajorVersion = new Lazy<int>(GetMajorVsVersion);
        private static readonly Lazy<string> _fullVsEdition = new Lazy<string>(GetFullVsVersionString);

        public static int VsMajorVersion
        {
            get { return _vsMajorVersion.Value; }
        }

        public static bool IsVisualStudio2010
        {
            get { return VsMajorVersion == 10; }
        }

        public static bool IsVisualStudio2012
        {
            get { return VsMajorVersion == 11; }
        }

        public static bool IsVisualStudio2013
        {
            get { return VsMajorVersion == 12; }
        }

        public static bool IsVisualStudio2014
        {
            get { return VsMajorVersion == 14; }
        }

        public static string FullVsEdition
        {
            get { return _fullVsEdition.Value; }
        }

        private static int GetMajorVsVersion()
        {
            DTE dte = ServiceLocator.GetInstance<DTE>();
            string vsVersion = dte.Version;
            Version version;
            if (Version.TryParse(vsVersion, out version))
            {
                return version.Major;
            }
            return MaxVsVersion;
        }

        private static string GetFullVsVersionString()
        {
            DTE dte = ServiceLocator.GetInstance<DTE>();

            string edition = dte.Edition;
            if (!edition.StartsWith("VS", StringComparison.OrdinalIgnoreCase))
            {
                edition = "VS " + edition;
            }

            return edition + "/" + dte.Version;
        }

        public static string GetSKU()
        {
            DTE dte = ServiceLocator.GetInstance<DTE>();
            string sku = dte.Edition;
            if (sku.Equals("Ultimate", StringComparison.OrdinalIgnoreCase) ||
                sku.Equals("Premium", StringComparison.OrdinalIgnoreCase) ||
                sku.Equals("Professional", StringComparison.OrdinalIgnoreCase))
            {
                sku = "Pro";
            }

            return sku;
        }
    }
}


text:
<tool profile="16.07" id="mothur_get_oturep" name="Get.oturep" version="@WRAPPER_VERSION@.0">
    <description>Generate a fasta with a representative sequence for each OTU</description>
    <macros>
        <import>macros.xml</import>
    </macros>
    <expand macro="requirements"/>
    <expand macro="version_command"/>
    <command detect_errors="aggressive"><![CDATA[
        ## create symlinks to input datasets
        ln -s "$otu" otu.dat &&
        ln -s "$fasta" fasta.dat &&
        ln -s "$input.dist" input.dist.dat &&
        ln -s "$input.name" input.name.dat &&
        ln -s "$count" count.dat &&
        #if $pick.type == "yes":
            ln -s "$pick.group" pick.group.dat &&
        #end if

        echo 'get.oturep(
            list=otu.dat,
            #if $fasta:
                fasta=fasta.dat,
            #end if
            #if $input.source == "column":
                column=input.dist.dat,
                name=input.name.dat,
            #elif $input.source == "phylip":
                phylip=input.dist.dat,
                #if $input.name:
                    name=input.name.dat,
                #end if
            #end if
            #if $label:
                label=${ str($label).replace(",","-") },
            #end if
            #if $pick.type == "yes":
                #if $pick.group:
                    group=pick.group.dat,
                #end if
                #if $pick.groups:
                    groups=${ str($pick.groups).replace(",","-") },
                #end if
            #end if
            #if $sorted:
                sorted=$sorted,
            #end if
            #if $count and not $input.name:
                count=count.dat,
            #end if
            method=$method,
            large=$large
        )'
        | sed 's/ //g'  ## mothur trips over whitespace
        | mothur
    ]]></command>
    <inputs>
        <param name="otu" type="data" format="mothur.list" label="list - OTU List"/>
        <conditional name="input">
            <param name="source" type="select" label="Distance Matrix Format">
                <option value="column">Pairwise Column Distance Matrix</option>
                <option value="phylip">Phylip Distance Matrix</option>
            </param>
            <when value="column">
                <param name="dist" type="data" format="mothur.pair.dist" label="column - Distance Matrix"/>
                <param name="name" type="data" format="mothur.names" label="name - Sequences Name reference"/>
            </when>
            <when value="phylip">
                <param name="dist" type="data" format="mothur.lower.dist,mothur.square.dist" label="phylip - Distance Matrix"/>
                <param name="name" type="data" format="mothur.names" optional="true" label="name - Names"/>
            </when>
        </conditional>
        <param name="fasta" type="data" format="fasta" optional="true" label="fasta - Fasta"/>
        <conditional name="pick">
            <param name="type" type="select" label="Parse a group file into abundant and rare groups?" help="">
                <option value="no" selected="true">No</option>
                <option value="yes">Yes</option>
            </param>
            <when value="no"/>
            <when value="yes">
                <param name="group" type="data" format="mothur.groups" label="group - Group file for the OTU List"/>
                <param name="groups" type="select"  multiple="true" label="groups - Group Selection (all used if none are selected)">
                    <options>
                        <filter type="data_meta" ref="group" key="groups"/>
                    </options>
                </param>
            </when>
        </conditional>
        <param name="label" type="select" multiple="true" label="label - OTU Labels">
            <expand macro="labeloptions"/>
        </param>
        <param name="sorted" type="select" label="sorted - Sort Sequences by">
            <option value="">Don't sort</option>
            <option value="name">Sequence Name</option>
            <option value="number">Bin Number</option>
            <option value="size">Bin Size</option>
            <option value="group">Group</option>
        </param>
        <param name="large" type="boolean" checked="false" truevalue="true" falsevalue="false" label="large - Distance Matrix is very Large"/>
        <param name="count" type="data" format="mothur.count_table" optional="true" label="count - a count table" help="Cannot supply both a names and count table. Will be ignored if you also supplied a name file. Generated by count.seqs"/>
        <param name="method" type="select" label="method - select the method of selecting the representative sequence" help="the distance method finds the sequence with the smallest maximum distance to other sequences. The abundance method chooses the abundant sequence in the OTU as the representative. Default=distance">
            <option value="distance" selected="true">distance</option>
            <option value="abundance">abundance</option>
        </param>
    </inputs>
    <outputs>
        <expand macro="logfile-output"/>
        <collection name="names_out" type="list" label="${tool.name} on ${on_string}: rep.names">
            <filter>input['name'] or not count</filter>
            <discover_datasets pattern=".*?\.(?P<designation>.*)\.rep\.names" format="mothur.names"/>
        </collection>
        <collection name="fasta_out" type="list" label="${tool.name} on ${on_string}: rep.fasta">
            <filter>fasta</filter>
            <discover_datasets pattern=".*?\.(?P<designation>.*)\.rep\.fasta" format="fasta"/>
        </collection>
        <collection name="count_out" type="list" label="${tool.name} on ${on_string}: rep.count_table">
            <filter>count and not input['name']</filter>
            <discover_datasets pattern=".*?\.(?P<designation>.*)\.rep\.count_table" format="mothur.count_table"/>
        </collection>
    </outputs>
    <tests>
        <test><!-- test with phylip -->
            <param name="otu" value="amazon.an.list" ftype="mothur.list"/>
            <param name="source" value="phylip"/>
            <param name="dist" value="98_sq_phylip_amazon.dist" ftype="mothur.square.dist"/>
            <param name="name" value="amazon1.names" ftype="mothur.names"/>
            <output_collection name="names_out" count="36">
                <element name="0.27" md5="39ff2858909d49633871d5a625585de5" ftype="mothur.names"/>
            </output_collection>
            <expand macro="logfile-test"/>
        </test>
        <test><!-- test with column and label select -->
            <param name="otu" value="amazon.an.list" ftype="mothur.list"/>
            <param name="source" value="column"/>
            <param name="dist" value="amazon.pair.dist" ftype="mothur.pair.dist"/>
            <param name="name" value="amazon1.names" ftype="mothur.names"/>
            <param name="label" value="unique,0.05,0.27,0.45"/>
            <output_collection name="names_out" count="4">
                <element name="0.27" md5="be6dccdd3d4619c3ac465246c826209a" ftype="mothur.names"/>
            </output_collection>
            <expand macro="logfile-test"/>
        </test>
        <test><!-- test with fasta and sorting-->
            <param name="otu" value="amazon.an.list" ftype="mothur.list"/>
            <param name="source" value="phylip"/>
            <param name="dist" value="98_sq_phylip_amazon.dist" ftype="mothur.square.dist"/>
            <param name="fasta" value="amazon.fasta" ftype="fasta"/>
            <param name="label" value="0.05,0.27"/>
            <param name="sorted" value="name"/>
            <output_collection name="names_out" count="2">
                <element name="0.27" md5="39ff2858909d49633871d5a625585de5" ftype="mothur.names"/>
            </output_collection>
            <output_collection name="fasta_out" count="2">
                <element name="0.27" md5="a9d9622b6f5fcbe8acdc05df5484ffc4" ftype="fasta"/>
            </output_collection>
            <expand macro="logfile-test"/>
        </test>
        <test><!-- test with group file -->
            <param name="otu" value="amazon.an.list" ftype="mothur.list"/>
            <param name="source" value="column"/>
            <param name="dist" value="amazon.pair.dist" ftype="mothur.pair.dist"/>
            <param name="name" value="amazon1.names" ftype="mothur.names"/>
            <param name="label" value="unique,0.05,0.27,0.45"/>
            <param name="type" value="yes"/>
            <param name="group" value="amazon.groups" ftype="mothur.groups"/>
            <param name="groups" value="forest,pasture"/>
            <param name="count" value="amazon1.count_table" ftype="mothur.count_table"/> <!-- should be ignored as we also supplied name file -->
            <output_collection name="names_out" count="8">
                <element name="0.27.pasture" md5="34f87d93fd9ebbefed9754f627f502fd" ftype="mothur.names"/>
            </output_collection>
            <expand macro="logfile-test"/>
        </test>
        <test><!-- test with count table -->
            <param name="otu" value="amazon.an.list" ftype="mothur.list"/>
            <param name="source" value="phylip"/>
            <param name="dist" value="98_sq_phylip_amazon.dist" ftype="mothur.square.dist"/>
            <param name="label" value="unique,0.05,0.27"/>
            <param name="count" value="amazon1.count_table" ftype="mothur.count_table"/>
            <output_collection name="count_out" count="3">
                <element name="0.27" md5="6b1afd712825af4bf8cb4ab8304df903" ftype="mothur.count_table"/>
            </output_collection>
            <expand macro="logfile-test"/>
        </test>
    </tests>
    <help>
<![CDATA[

@MOTHUR_OVERVIEW@

**Command Documenation**

The get.oturep_ command generates a fasta-formatted sequence file containing only a representative sequence for each OTU.  The opposite of the bin.seqs command.

.. _get.oturep: http://www.mothur.org/wiki/Get.oturep

v1.23.0: Updated to Mothur 1.33, added count and method parameter
]]>
    </help>
    <expand macro="citations"/>
</tool>


text:
package com.github.markusbernhardt.xmldoclet;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.markusbernhardt.xmldoclet.xjc.Root;
import com.sun.javadoc.DocErrorReporter;
import com.sun.javadoc.LanguageVersion;
import com.sun.javadoc.RootDoc;

public class XmlDoclet {

	private final static Logger log = LoggerFactory.getLogger(Parser.class);

	/**
	 * The parsed object model. Used in unit tests.
	 */
	public static Root root;

	/**
	 * The Options instance to parse command line strings.
	 */
	public final static Options options;

	static {
		options = new Options();

		OptionBuilder.withArgName("directory");
		OptionBuilder.isRequired(false);
		OptionBuilder.hasArg();
		OptionBuilder.withDescription("Destination directory for output file.\nDefault: .");
		options.addOption(OptionBuilder.create("d"));

		OptionBuilder.withArgName("encoding");
		OptionBuilder.isRequired(false);
		OptionBuilder.hasArg();
		OptionBuilder.withDescription("Encoding of the output file.\nDefault: UTF8");
		options.addOption(OptionBuilder.create("docencoding"));

		OptionBuilder.withArgName("dryrun");
		OptionBuilder.isRequired(false);
		OptionBuilder.hasArgs(0);
		OptionBuilder.withDescription("Parse javadoc, but don't write output file.\nDefault: false");
		options.addOption(OptionBuilder.create("dryrun"));

		OptionBuilder.withArgName("filename");
		OptionBuilder.isRequired(false);
		OptionBuilder.hasArg();
		OptionBuilder.withDescription("Name of the output file.\nDefault: javadoc.xml");
		options.addOption(OptionBuilder.create("filename"));
	}

	/**
	 * Check for doclet-added options. Returns the number of arguments you must
	 * specify on the command line for the given option. For example, "-d docs"
	 * would return 2.
	 *

	 * This method is required if the doclet contains any options. If this
	 * method is missing, Javadoc will print an invalid flag error for every
	 * option.
	 *
	 * @see com.sun.javadoc.Doclet#optionLength(String)
	 *
	 * @param optionName
	 *            The name of the option.
	 * @return number of arguments on the command line for an option including
	 *         the option name itself. Zero return means option not known.
	 *         Negative value means error occurred.
	 */
	public static int optionLength(String optionName) {
		Option option = options.getOption(optionName);
		if (option == null) {
			return 0;
		}
		return option.getArgs() + 1;
	}

	/**
	 * Check that options have the correct arguments.
	 *

	 * This method is not required, but is recommended, as every option will be
	 * considered valid if this method is not present. It will default
	 * gracefully (to true) if absent.
	 *

	 * Printing option related error messages (using the provided
	 * DocErrorReporter) is the responsibility of this method.
	 *
	 * @see com.sun.javadoc.Doclet#validOptions(String[][], DocErrorReporter)
	 *
	 * @param options
	 *            The two dimensional array of options.
	 * @param reporter
	 *            The error reporter.
	 *
	 * @return true if the options are valid.
	 */
	public static boolean validOptions(String optionsArrayArray[][], DocErrorReporter reporter) {
		return null != parseCommandLine(optionsArrayArray);
	}

	/**
	 * Processes the JavaDoc documentation.
	 *

	 * This method is required for all doclets.
	 *
	 * @see com.sun.javadoc.Doclet#start(RootDoc)
	 *
	 * @param root
	 *            The root of the documentation tree.
	 *
	 * @return true if processing was successful.
	 */
	public static boolean start(RootDoc rootDoc) {
		CommandLine commandLine = parseCommandLine(rootDoc.options());
		Parser parser = new Parser("/");
		root = parser.parseRootDoc(rootDoc);
		save(commandLine, root);
		return true;
	}

	/**
	 * Save XML object model to a file via JAXB.
	 *
	 * @param commandLine
	 * @param root
	 */
	public static void save(CommandLine commandLine, Root root) {
		if (commandLine.hasOption("dryrun")) {
			return;
		}

		FileOutputStream fileOutputStream = null;
		BufferedOutputStream bufferedOutputStream = null;
		try {
			JAXBContext contextObj = JAXBContext.newInstance(Root.class);

			Marshaller marshaller = contextObj.createMarshaller();
			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
			if (commandLine.hasOption("docencoding")) {
				marshaller.setProperty(Marshaller.JAXB_ENCODING, commandLine.getOptionValue("docencoding"));
			}

			String filename = "javadoc.xml";
			if (commandLine.hasOption("filename")) {
				filename = commandLine.getOptionValue("filename");
			}
			if (commandLine.hasOption("d")) {
				filename = commandLine.getOptionValue("d") + File.separator + filename;
			}

			fileOutputStream = new FileOutputStream(filename);
			bufferedOutputStream = new BufferedOutputStream(fileOutputStream, 1024 * 1024);

			marshaller.marshal(root, bufferedOutputStream);
			bufferedOutputStream.flush();
			fileOutputStream.flush();

		} catch (JAXBException e) {
			log.error(e.getMessage(), e);
		} catch (FileNotFoundException e) {
			log.error(e.getMessage(), e);
		} catch (IOException e) {
			log.error(e.getMessage(), e);
		} finally {
			try {
				if (bufferedOutputStream != null) {
					bufferedOutputStream.close();
				}
				if (fileOutputStream != null) {
					fileOutputStream.close();
				}
			} catch (IOException e) {
				log.error(e.getMessage(), e);
			}
		}
	}

	/**
	 * Return the version of the Java Programming Language supported by this
	 * doclet.
	 *

	 * This method is required by any doclet supporting a language version newer
	 * than 1.1.
	 *

	 * This Doclet supports Java 5.
	 *
	 * @see com.sun.javadoc.Doclet#languageVersion()
	 *
	 * @return {@value LanguageVersion#JAVA_1_5}
	 */
	public static LanguageVersion languageVersion() {
		return LanguageVersion.JAVA_1_5;
	}

	/**
	 * Parse the given options.
	 *
	 * @param optionsArrayArray
	 * @return
	 * @throws ParseException
	 */
	public static CommandLine parseCommandLine(String[][] optionsArrayArray) {
		try {
			List<String> argumentList = new ArrayList<String>();
			for (String[] optionsArray : optionsArrayArray) {
				argumentList.addAll(Arrays.asList(optionsArray));
			}

			CommandLineParser commandLineParser = new BasicParser() {
				@Override
				protected void processOption(final String arg, @SuppressWarnings("rawtypes") final ListIterator iter)
						throws ParseException {
					boolean hasOption = getOptions().hasOption(arg);
					if (hasOption) {
						super.processOption(arg, iter);
					}
				}
			};
			CommandLine commandLine = commandLineParser.parse(options, argumentList.toArray(new String[] {}));
			return commandLine;
		} catch (ParseException e) {
			LoggingOutputStream loggingOutputStream = new LoggingOutputStream(log, LoggingLevelEnum.INFO);
			PrintWriter printWriter = new PrintWriter(loggingOutputStream);

			HelpFormatter helpFormatter = new HelpFormatter();
			helpFormatter.printHelp(printWriter, 74, "javadoc -doclet " + XmlDoclet.class.getName() + " [options]",
					null, options, 1, 3, null, false);
			return null;
		}
	}
}


text:
package com.battlelancer.seriesguide.loaders;

import android.content.Context;
import android.text.TextUtils;
import com.battlelancer.seriesguide.R;
import com.battlelancer.seriesguide.items.SearchResult;
import com.battlelancer.seriesguide.util.ServiceUtils;
import com.uwetrottmann.androidutils.AndroidUtils;
import com.uwetrottmann.androidutils.GenericSimpleLoader;
import com.uwetrottmann.trakt.v2.entities.Show;
import com.uwetrottmann.trakt.v2.entities.TrendingShow;
import com.uwetrottmann.trakt.v2.enums.Extended;
import com.uwetrottmann.trakt.v2.enums.Type;
import java.util.LinkedList;
import java.util.List;
import retrofit.RetrofitError;
import timber.log.Timber;

/**
 * Loads a list of trending shows or searches TheTVDB for shows matching the given query.
 */
public class TvdbAddLoader extends GenericSimpleLoader<TvdbAddLoader.Result> {

    public static class Result {
        public List<SearchResult> results;
        public int emptyTextResId;

        public Result(List<SearchResult> results, int emptyTextResId) {
            this.results = results;
            this.emptyTextResId = emptyTextResId;
        }
    }

    private final String query;

    public TvdbAddLoader(Context context, String query) {
        super(context);
        this.query = query;
    }

    @Override
    public Result loadInBackground() {
        List<SearchResult> results;

        if (TextUtils.isEmpty(query)) {
            // no query? load a list of trending shows from trakt
            try {
                List<TrendingShow> trendingShows = ServiceUtils.getTraktV2(getContext())
                        .shows()
                        .trending(1, 35, Extended.IMAGES);
                List<Show> shows = new LinkedList<>();
                for (TrendingShow show : trendingShows) {
                    if (show.show == null || show.show.ids == null
                            || show.show.ids.tvdb == null) {
                        // skip if required values are missing
                        continue;
                    }
                    shows.add(show.show);
                }
                results = TraktAddLoader.parseTraktShowsToSearchResults(getContext(), shows);
            } catch (RetrofitError e) {
                Timber.e(e, "Loading trending shows failed");
                return buildResultFailure(getContext(), R.string.trakt_error_general);
            }
        } else {
            // have a query? search trakt (has better search) for TheTVDB shows
            try {
                List<com.uwetrottmann.trakt.v2.entities.SearchResult> traktResults
                        = ServiceUtils.getTraktV2(getContext()).search()
                        .textQuery(query, Type.SHOW, null, 1, 30);

                List<Show> shows = new LinkedList<>();
                for (com.uwetrottmann.trakt.v2.entities.SearchResult result : traktResults) {
                    if (result.show == null || result.show.ids == null
                            || result.show.ids.tvdb == null) {
                        // skip, TVDB id required
                        continue;
                    }
                    shows.add(result.show);
                }

                results = TraktAddLoader.parseTraktShowsToSearchResults(getContext(), shows);
            } catch (RetrofitError e) {
                Timber.e(e, "Searching show failed");
                return buildResultFailure(getContext(), R.string.search_error);
            }
        }

        return buildResultSuccess(results, R.string.no_results);
    }

    private static Result buildResultSuccess(List<SearchResult> results, int emptyTextResId) {
        if (results == null) {
            results = new LinkedList<>();
        }
        return new Result(results, emptyTextResId);
    }

    private static Result buildResultFailure(Context context, int emptyTextResId) {
        // only check for network here to allow hitting the response cache
        if (!AndroidUtils.isNetworkConnected(context)) {
            emptyTextResId = R.string.offline;
        }
        return new Result(new LinkedList<SearchResult>(), emptyTextResId);
    }
}


text:
namespace android.media
{
	[global::MonoJavaBridge.JavaClass()]
	public partial class FaceDetector : java.lang.Object
	{
		internal new static global::MonoJavaBridge.JniGlobalHandle staticClass;
		static FaceDetector()
		{
			InitJNI();
		}
		protected FaceDetector(global::MonoJavaBridge.JNIEnv @__env) : base(@__env)
		{
		}
		[global::MonoJavaBridge.JavaClass()]
		public partial class Face : java.lang.Object
		{
			internal new static global::MonoJavaBridge.JniGlobalHandle staticClass;
			static Face()
			{
				InitJNI();
			}
			protected Face(global::MonoJavaBridge.JNIEnv @__env) : base(@__env)
			{
			}
			internal static global::MonoJavaBridge.MethodId _confidence4951;
			public virtual float confidence()
			{
				global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
				if (!IsClrObject)
					return @__env.CallFloatMethod(this.JvmHandle, global::android.media.FaceDetector.Face._confidence4951);
				else
					return @__env.CallNonVirtualFloatMethod(this.JvmHandle, global::android.media.FaceDetector.Face.staticClass, global::android.media.FaceDetector.Face._confidence4951);
			}
			internal static global::MonoJavaBridge.MethodId _getMidPoint4952;
			public virtual void getMidPoint(android.graphics.PointF arg0)
			{
				global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
				if (!IsClrObject)
					@__env.CallVoidMethod(this.JvmHandle, global::android.media.FaceDetector.Face._getMidPoint4952, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0));
				else
					@__env.CallNonVirtualVoidMethod(this.JvmHandle, global::android.media.FaceDetector.Face.staticClass, global::android.media.FaceDetector.Face._getMidPoint4952, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0));
			}
			internal static global::MonoJavaBridge.MethodId _eyesDistance4953;
			public virtual float eyesDistance()
			{
				global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
				if (!IsClrObject)
					return @__env.CallFloatMethod(this.JvmHandle, global::android.media.FaceDetector.Face._eyesDistance4953);
				else
					return @__env.CallNonVirtualFloatMethod(this.JvmHandle, global::android.media.FaceDetector.Face.staticClass, global::android.media.FaceDetector.Face._eyesDistance4953);
			}
			internal static global::MonoJavaBridge.MethodId _pose4954;
			public virtual float pose(int arg0)
			{
				global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
				if (!IsClrObject)
					return @__env.CallFloatMethod(this.JvmHandle, global::android.media.FaceDetector.Face._pose4954, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0));
				else
					return @__env.CallNonVirtualFloatMethod(this.JvmHandle, global::android.media.FaceDetector.Face.staticClass, global::android.media.FaceDetector.Face._pose4954, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0));
			}
			public static float CONFIDENCE_THRESHOLD
			{
				get
				{
					return 0.4f;
				}
			}
			public static int EULER_X
			{
				get
				{
					return 0;
				}
			}
			public static int EULER_Y
			{
				get
				{
					return 1;
				}
			}
			public static int EULER_Z
			{
				get
				{
					return 2;
				}
			}
			private static void InitJNI()
			{
				global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
				global::android.media.FaceDetector.Face.staticClass = @__env.NewGlobalRef(@__env.FindClass("android/media/FaceDetector$Face"));
				global::android.media.FaceDetector.Face._confidence4951 = @__env.GetMethodIDNoThrow(global::android.media.FaceDetector.Face.staticClass, "confidence", "()F");
				global::android.media.FaceDetector.Face._getMidPoint4952 = @__env.GetMethodIDNoThrow(global::android.media.FaceDetector.Face.staticClass, "getMidPoint", "(Landroid/graphics/PointF;)V");
				global::android.media.FaceDetector.Face._eyesDistance4953 = @__env.GetMethodIDNoThrow(global::android.media.FaceDetector.Face.staticClass, "eyesDistance", "()F");
				global::android.media.FaceDetector.Face._pose4954 = @__env.GetMethodIDNoThrow(global::android.media.FaceDetector.Face.staticClass, "pose", "(I)F");
			}
		}
		internal static global::MonoJavaBridge.MethodId _finalize4955;
		protected override void finalize()
		{
			global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
			if (!IsClrObject)
				@__env.CallVoidMethod(this.JvmHandle, global::android.media.FaceDetector._finalize4955);
			else
				@__env.CallNonVirtualVoidMethod(this.JvmHandle, global::android.media.FaceDetector.staticClass, global::android.media.FaceDetector._finalize4955);
		}
		internal static global::MonoJavaBridge.MethodId _findFaces4956;
		public virtual int findFaces(android.graphics.Bitmap arg0, android.media.FaceDetector.Face[] arg1)
		{
			global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
			if (!IsClrObject)
				return @__env.CallIntMethod(this.JvmHandle, global::android.media.FaceDetector._findFaces4956, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1));
			else
				return @__env.CallNonVirtualIntMethod(this.JvmHandle, global::android.media.FaceDetector.staticClass, global::android.media.FaceDetector._findFaces4956, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1));
		}
		internal static global::MonoJavaBridge.MethodId _FaceDetector4957;
		public FaceDetector(int arg0, int arg1, int arg2)  : base(global::MonoJavaBridge.JNIEnv.ThreadEnv)
		{
			global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
			global::MonoJavaBridge.JniLocalHandle handle = @__env.NewObject(android.media.FaceDetector.staticClass, global::android.media.FaceDetector._FaceDetector4957, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2));
			Init(@__env, handle);
		}
		private static void InitJNI()
		{
			global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
			global::android.media.FaceDetector.staticClass = @__env.NewGlobalRef(@__env.FindClass("android/media/FaceDetector"));
			global::android.media.FaceDetector._finalize4955 = @__env.GetMethodIDNoThrow(global::android.media.FaceDetector.staticClass, "finalize", "()V");
			global::android.media.FaceDetector._findFaces4956 = @__env.GetMethodIDNoThrow(global::android.media.FaceDetector.staticClass, "findFaces", "(Landroid/graphics/Bitmap;[Landroid/media/FaceDetector/Face;)I");
			global::android.media.FaceDetector._FaceDetector4957 = @__env.GetMethodIDNoThrow(global::android.media.FaceDetector.staticClass, "<init>", "(III)V");
		}
	}
}


text:
package cartago.tools;

import java.util.*;
import java.io.*;

import cartago.*;

public class Latch extends Artifact {

	boolean isSet;

	@OPERATION void init(){
		isSet = false;
	}

	@OPERATION void set(){
		isSet = true;
	}

	@OPERATION(guard="isSet") void waitForSet(){}

	@GUARD boolean isSet(){
		return isSet;
	}
}


text:
<!doctype html>
<html>
<head>

    <meta charset="utf-8">
    <title><hello-world></title>

    <!-- Imports custom element -->
    <link rel="import" href="hello-world.html">

</head>
<body>

    <!-- Runs custom element -->
    <hello-world></hello-world>

</body>
</html>