rantanplan¶
-
rantanplan.core.
apply_exception_rules
(word)[source]¶ Applies presyllabification rules to a word, based on Antonio Ríos Mestre’s work
Parameters: word – A string to be checked for exceptions Returns: A string with the presyllabified word Return type: str
-
rantanplan.core.
apply_exception_rules_post
(word)[source]¶ Applies presyllabification rules to a word, based on Antonio Ríos Mestre’s work
Parameters: word – A string to be checked for exceptions Returns: A string with the presyllabified word with hyphens Return type: str
-
rantanplan.core.
clean_phonological_groups
(groups, liaison_positions, liaison_property)[source]¶ Clean phonological groups so their liaison property is consistently set according to the the liaison positions
Parameters: - groups – Phonological groups to be cleaned
- liaison_positions – Positions of the liaisons
- liaison_property – The liaison type (synaeresis or synalepha)
Returns: Cleaned phonological groups
Return type: dict
-
rantanplan.core.
format_stress
(stresses, rhythm_format='pattern', indexed_separator='-')[source]¶ - Converts a list of boolean elements into a string that matches the chosen
- rhythm format: “indexed”: 2,5,8 “pattern”: -++–+-+- “binary”: 01101001
Parameters: - stresses – List of boolean elements representing stressed syllables
- rhythm_format – Format to be used: indexed, pattern, or binary
- indexed_separator – String to use as a separator for indexed pattern
Returns: String with the stress pattern
Return type: str
-
rantanplan.core.
generate_liaison_positions
(syllables, liaison)[source]¶ Generates all possible combinations for the liaisons on a list of syllables
Parameters: - syllables – List of syllables with
- liaison – Type of liaison combination to be generated
Returns: Generator with a list of possible combinations
Return type: generator
-
rantanplan.core.
generate_phonological_groups
(tokens)[source]¶ Generates phonological groups from a list of tokens
Parameters: tokens – list of spaCy tokens Returns: Generator with a list of phonological groups Return type: generator
-
rantanplan.core.
get_last_syllable
(token_list)[source]¶ Gets last syllable from a word in a dictionary
Parameters: token_list – list of dictionaries with line tokens Returns: Last syllable Return type: str
-
rantanplan.core.
get_orthographic_accent
(syllable_list)[source]¶ Given a list of str representing syllables, return position in the list of a syllable bearing orthographic stress (with the acute accent mark in Spanish)
Parameters: syllable_list – list of syllables as str or unicode each Returns: Position or None if no orthographic stress Return type: int
-
rantanplan.core.
get_phonological_groups
(word_syllables, liaison_type='synalepha', breakage_func=None, liaison_positions=None)[source]¶ Get a list of dictionaries for each phonological group on a line and joins the syllables to create phonological groups (pronounced together) according to a type of liaison, either synaloepha or sinaeresis
Parameters: - word_syllables – List of dictionaries for each word of the line
- liaison_type – Which liaison is going to be performed synalepha or sinaeresis
- breakage_func – Function to decide when not to break a liaison that is specified in liaison_positions
- liaison_positions – Positions of the liaisons
Returns: A list of conjoined syllables
Return type: list
-
rantanplan.core.
get_rhythmical_pattern
(phonological_groups, rhythm_format='pattern', rhyme_analysis=False)[source]¶ Gets a rhythm pattern for a poem in either “pattern”: “-++-+-+-” “binary”: “01101010” or “indexed”: [1,2,4,6] format
Parameters: - phonological_groups – a dictionary with the syllables of the line
- rhythm_format – The output format for the rhythm
- rhyme_analysis – Whether or not rhyme analysis is to be performed
Returns: Dictionary with with rhythm and phonological groups
Return type: dict
-
rantanplan.core.
get_scansion
(text, rhyme_analysis=False, rhythm_format='pattern', rhythmical_lengths=None, split_stanzas_on=None, pos_output=False, always_return_rhyme=False, rhythmical_lengths_window=8, alternative_output=False)[source]¶ Generates a list of dictionaries for each line
Parameters: - text – Full text to be analyzed
- rhyme_analysis – Specify if rhyme analysis is to be performed
- rhythm_format – output format for rhythm analysis
- rhythmical_lengths – List with explicit rhythmical lengths per line that the analysed lines has to meet
- split_stanzas_on – Regular expression to split text in stanzas. Defaults to None for not splitting.
- pos_output – True or False for printing the PoS of the words
- always_return_rhyme – True or False for printing rhyme pattern even if no structure is detected
- rhythmical_lengths_window – Size of the window to calculate the most frequent line length when rhythmical_lengths is False. Defaults to 8
- alternative_output – Wheter or not to return the scansion in a new format compliant with postdata API
Returns: list of dictionaries per line (or list of list of dictionaries if split on stanzas)
Return type: list
-
rantanplan.core.
get_stresses
(phonological_groups)[source]¶ Gets a list of stress marks, True for stressed, False for unstressed from a list of phonological groups applying rules depending on the ending stress.
Parameters: phonological_groups – a dictionary with the phonological groups (syllables) of the line Returns: List of boolean values indicating whether a group is stressed (True) or not (False) Return type: list
-
rantanplan.core.
get_structure_from_context
(lines, n, window=3)[source]¶ Get the most frequent line length around line n using a window
Parameters: - lines – List of dictionary lines of the poem
- n – Integer with the reference position
- window – Integer with the size of the window around the reference position. Defaults to 3
Returns: The most frequent line length
-
rantanplan.core.
get_syllables_word_end
(words)[source]¶ Get a list of syllables from a list of words extracting word boundaries
Parameters: words – List of dictonaries of syllables for each word in a line Returns: List of dictionaries of syllables with an extra is_word_end key Return type: list
-
rantanplan.core.
get_word_stress
(word, pos, tag, alternative_syllabification=False, is_last_word=False)[source]¶ Gets a list of syllables from a word and creates a list with syllabified word and stressed syllable index
Parameters: - word – Word string
- is_last_word – Wether or not the word is the last one of a verse
- alternative_syllabification – Wether or not the alternative syllabification is used
- pos – PoS tag from spacy (“DET”)
- tag – Extended PoS tag info from spacy (“Definite=Ind|Gender=Masc|Number=Sing|PronType=Art”)
Returns: Dict with [original syllab word, stressed syllabified word, negative index position of stressed syllable or 0 if not stressed]
Return type: dict
-
rantanplan.core.
get_words
(word_list, alternative_syllabification=False)[source]¶ Gets a list of syllables from a word and creates a list with syllabified word and stressed syllable index
Parameters: - word_list – List of spacy objects representing a word or sentence
- alternative_syllabification – Whether or not the alternative syllabification is used
Returns: List with [original syllab. word, stressed syllab. word, negative index position of stressed syllable]
Return type: list
-
rantanplan.core.
has_single_liaisons
(liaisons)[source]¶ - Checks whether liaisons (a list of 1’s and 0’s) has consecutive liaisons
- (1’s) or not
Parameters: liaisons – List of possible liaisons to apply per phonological group Returns: True if no consecutive liaisons, False otherwise Return type: bool
-
rantanplan.core.
have_prosodic_liaison
(first_syllable, second_syllable)[source]¶ Checks for prosodic liaison between two syllables
Parameters: - first_syllable – Dictionary with key syllable (str) and is_stressed (bool) representing the first syllable
- second_syllable – Dictionary with key syllable (str) and is_stressed (bool) representing the second syllable
Returns: True if there is prosodic liaison and False otherwise
Return type: bool
-
rantanplan.core.
is_paroxytone
(syllables)[source]¶ Given a list of str representing syllables from a single word, check if it is paroxytonic (llana) or not
Parameters: syllables – List of syllables as str Returns: True if paroxytone, False if not Return type: bool
-
rantanplan.core.
join_affixes
(line)[source]¶ Join affixes of split words and recalculates stress
Parameters: line – List of syllabified words (dict) Returns: List of syllabified words (dict) with joined affixes Return type: list
-
rantanplan.core.
join_syllables
(token)[source]¶ Join all symbols and syllables from a list of tokens into a string.” :param token: List of dictionaries representing tokens :return: String of syllables
-
rantanplan.core.
remove_exact_length_matches
(lines)[source]¶ Removes key “length_range” on lines with an exact length match :param lines: List of dictionary lines of the poem :return: Returns the lines list without the “length_range” on lines with an exact length match
-
rantanplan.core.
remove_pos_from_output
(lines)[source]¶ Remove pos tag from the output dictionary
Parameters: lines – List of dictionary lines of the poem Returns: Dictionary with the key removed Return type: dict
-
rantanplan.core.
set_stress_exceptions
(word)[source]¶ Changes stresses of a word to only the last one
Parameters: word – The word that is going to be changed Returns: Word with the new stresses
-
rantanplan.core.
spacy_tag_to_dict
(tag)[source]¶ Creates a dict from spacy pos tags
Parameters: tag – Extended spacy pos tag (“Definite=Ind|Gender=Masc|Number=Sing|PronType=Art”) Returns: A dictionary in the form of “{‘Definite’: ‘Ind’, ‘Gender’: ‘Masc’, ‘Number’: ‘Sing’, ‘PronType’: ‘Art’}” Return type: dict
-
rantanplan.core.
syllabify
(word, alternative_syllabification=False)[source]¶ Syllabifies a word.
Parameters: - word – The word to be syllabified.
- alternative_syllabification – Wether or not the alternative syllabification is used
Returns: List of syllables and exceptions where appropriate.
Return type: list