def test_dependency_parser(parser, dataset, predict_pos_tags=False):
    """
    Estimate the UAS achieved by a parser on a dataset

    The UAS correspond to the Unlabeled accuary. Punctuation token are
    ignored.

    Parameters
    ----------

    - parser, an instance of Parser
      the dependency parser to evaluate

    - dataset, a list of example
      the dataset to consider

    - predict_pos_tags, a boolean
      if True, the POS tags given in the test are not considered and,
      during inference, the parser is used to predict them.
    """
    correct = 0
    n_words = 0

    for words, tags, gold_heads, gold_labels in dataset:
        if not predict_pos_tags:
            _, heads = parser.parse(words, tags)
        else:
            _, heads = parser.parse(words)

        # we have to convert enumerate to a list so that we can slice
        # it and avoid considering the padding symbols
        for i, w in list(enumerate(words))[1:-1]:
            if gold_labels[i] in ('P', 'punct'):
                continue
            if heads[i] == gold_heads[i]:
                correct += 1
            n_words += 1

    return correct / n_words