(
    doc_or_tokens: types.DocOrTokens, *, lang: Optional[str] = None
)
return tuple(len(hyphenator.positions(word.lower_)) + 1 for word in words)
Compute the number of syllables for each word in a document.

    Args:
        doc_or_tokens: If a spaCy ``Doc``, non-punctuation tokens (words) are extracted;
            if an iterable of spaCy ``Token`` s, all non-punct elements are used.
        lang: Standard 2-letter language code used to load hyphenator.
            If not specified and ``doc_or_tokens`` is a spaCy ``Doc`` ,
            the value will be gotten from ``Doc.lang_`` .

    Note:
        Identifying syllables is _tricky_; this method relies on hyphenation, which is
        more straightforward but doesn't always give the correct number of syllables.
        While all hyphenation points fall on syllable divisions, not all syllable
        divisions are valid hyphenation points.

        Also: This function is cached, since other functions rely upon its outputs
        to compute theirs. As such, ``doc_or_tokens`` must be hashable -- for example,
        it may be a ``Doc`` or ``Tuple[Token, ...]`` , but not a ``List[Token]`` .
Compute the number of syllables for each word in a document.
Compute the number of syllables for each word in a document .
def n_syllables_per_word(
    doc_or_tokens: types.DocOrTokens, *, lang: Optional[str] = None
) -> Tuple[int, ...]:
    """
    Compute the number of syllables for each word in a document.

    Args:
        doc_or_tokens: If a spaCy ``Doc``, non-punctuation tokens (words) are extracted;
            if an iterable of spaCy ``Token`` s, all non-punct elements are used.
        lang: Standard 2-letter language code used to load hyphenator.
            If not specified and ``doc_or_tokens`` is a spaCy ``Doc`` ,
            the value will be gotten from ``Doc.lang_`` .

    Note:
        Identifying syllables is _tricky_; this method relies on hyphenation, which is
        more straightforward but doesn't always give the correct number of syllables.
        While all hyphenation points fall on syllable divisions, not all syllable
        divisions are valid hyphenation points.

        Also: This function is cached, since other functions rely upon its outputs
        to compute theirs. As such, ``doc_or_tokens`` must be hashable -- for example,
        it may be a ``Doc`` or ``Tuple[Token, ...]`` , but not a ``List[Token]`` .
    """
    if lang is None:
        if isinstance(doc_or_tokens, Doc):
            lang = doc_or_tokens.lang_
        else:
            raise ValueError(
                "`lang` must be specified when computing n syllables per word "
                "from an iterable of tokens"
            )
    hyphenator = utils.load_hyphenator(lang=lang)
    words = utils.get_words(doc_or_tokens)
    return tuple(len(hyphenator.positions(word.lower_)) + 1 for word in words)
def n_syllables_per_word ( doc_or_tokens : types . DocOrTokens , * , lang : Optional [ str ] = None ) -> Tuple [ int , ... ] : if lang is None : if isinstance ( doc_or_tokens , Doc ) : lang = doc_or_tokens . lang_ else : raise ValueError ( "`lang` must be specified when computing n syllables per word " "from an iterable of tokens" ) hyphenator = utils . load_hyphenator ( lang = lang ) words = utils . get_words ( doc_or_tokens ) return tuple ( len ( hyphenator . positions ( word . lower_ ) ) + 1 for word in words )