from typing import List
from typing import Optional


def process_pubmed_sentences(text: List[List[str]],
                      sentence_tokenize: bool = True,
                      max_num_sentences: Optional[int] = None,
                      max_sentence_length: Optional[int] = None) -> List[str]:
    """
    Splits text into sentences (if desired).
    Also enforces a maximum sentence length
    and maximum number of sentences.
    :param text: The text to split.
    :param sentence_tokenize: Whether to split into sentences.
    :param max_num_sentences: Maximum number of sentences.
    :param max_sentence_length: Maximum length of a sentence (in tokens).
    :return: The text split into sentences (if desired)
    or as just a single sentence.
    """
    # Sentence tokenize
    if sentence_tokenize:
        sentences = text[:max_num_sentences]
    else:
        sentences = [word for sent in text for word in sent]

    # Enforce maximum sentence length
    sentences = [' '.join(sentence[:max_sentence_length]) for sentence in sentences]

    return sentences