def populate_ast_nsarg_defaults(ast, belast, species_id=None):
    """Recursively populate NSArg AST entries for default (de)canonical values

    This was added specifically for the BEL Pipeline. It is designed to
    run directly against ArangoDB and not through the BELAPI.

    Args:
        ast (BEL): BEL AST

    Returns:
        BEL: BEL AST
    """

    if isinstance(ast, NSArg):
        given_term_id = "{}:{}".format(ast.namespace, ast.value)

        r = bel.terms.terms.get_normalized_terms(given_term_id)
        ast.canonical = r["canonical"]
        ast.decanonical = r["decanonical"]

        r = bel.terms.terms.get_terms(ast.canonical)

        if len(r) > 0:
            ast.species_id = r[0].get("species_id", False)
            ast.species_label = r[0].get("species_label", False)

        # Check to see if species is set and if it's consistent
        #   if species is not consistent for the entire AST - set species_id/label
        #   on belast to False (instead of None)
        if ast.species_id and species_id is None:
            species_id = ast.species_id
            belast.species.add((ast.species_id, ast.species_label))

        elif ast.species_id and species_id and species_id != ast.species_id:
            belast.species_id = False
            belast.species_label = False

    # Recursively process every NSArg by processing BELAst and Functions
    if hasattr(ast, "args"):
        for arg in ast.args:
            populate_ast_nsarg_defaults(arg, belast, species_id)

    return ast