<commit_before>"""Utility functions for the j2cl_* build rules / macros"""

def get_java_package(path):
    """Extract the java package from path"""

    segments = path.split("/")

    # Find different root start indecies based on potential java roots
    java_root_start_indecies = [_find(segments, root) for root in ["java", "javatests"]]

    # Choose the root that starts earliest
    start_index = min(java_root_start_indecies)

    if start_index == len(segments):
        fail("Cannot find java root: " + path)

    return ".".join(segments[start_index + 1:])

def _find(segments, s):
    return segments.index(s) if s in segments else len(segments)<commit_msg>Make the java search path find the smallest path matching the search that bazel java rules use.<commit_after>"""Utility functions for the j2cl_* build rules / macros"""

def get_java_package(path):
    """Extract the java package from path

    Finds the smallest path inside a java class eg:
      java/com/foo/bard/javatests/com/google/java/emptyclass will return
      emptyclass.

    Args:
        path: Path to extra the java package from.
    Returns:
        Java package name (path from last java or javatest sperated by a '.')
    """

    segments = path.split("/")

    # Find different root start indecies based on potential java roots.
    java_root_start_indecies = [_find(segments, root) for root in ["java", "javatests"]]

    # Choose the root that starts latest.
    start_index = max(java_root_start_indecies)

    if start_index < 0:
        fail("Cannot find java root: " + path)

    return ".".join(segments[start_index + 1:])

def _find(segments, s):
    for i in reversed(range(len(segments))):
        if segments[i] == s:
            return i

    return -1
{'fraction_non_alphanumeric': 0.10091220068415051, 'fraction_numerical': 0.0034207525655644243, 'mean_word_length': 3.312039312039312, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5206935', 'n_tokens_mistral': 537, 'n_tokens_neox': 518, 'n_words': 185}