folia.main.Quote

class folia.main.Quote(doc, *args, **kwargs)

Bases: folia.main.AbstractStructureElement

Quote: a structure element. For quotes/citations. May hold Word, Sentence or Paragraph data.

Method Summary

__init__(doc, *args, **kwargs) Initialize self.
accepts(Class[, raiseexceptions, parentinstance])
add(child, *args, **kwargs)
addable(parent[, set, raiseexceptions]) Tests whether a new element of this class can be added to the parent.
addidsuffix(idsuffix[, recursive]) Appends a suffix to this element’s ID, and optionally to all child IDs as well.
addtoindex([norecurse]) Makes sure this element (and all subelements), are properly added to the index.
alternatives([Class, set, returnelements]) Generator over alternatives, either all or only of a specific annotation type, and possibly restrained also by set.
ancestor(*Classes) Find the most immediate ancestor of the specified type, multiple classes may be specified.
ancestors([Class]) Generator yielding all ancestors of this element, effectively back-tracing its path to the root element.
annotation(type[, set]) Obtain a single annotation element.
annotations(Class[, set]) Obtain child elements (annotations) of the specified class.
annotator2processor([annotator, …]) Converts annotator information to processor information (FoLiA v2).
append(child, *args, **kwargs) See AbstractElement.append()
checkdeclaration() Internal method (usually no need to call this) that checks whether the element’s annotation type is properly declared, raises an exception if not so, or auto-declares the annotation type if need be.
context(size[, placeholder, scope]) Returns this word in context, {size} words to the left, the current word, and {size} words to the right
copy([newdoc, idsuffix]) Make a deep copy of this element and all its children.
copychildren([newdoc, idsuffix]) Generator creating a deep copy of the children of this element.
correct(**kwargs) Apply a correction (TODO: documentation to be written still)
count(Class[, set, recursive, ignore, node]) Like AbstractElement.select(), but instead of returning the elements, it merely counts them.
deepvalidation() Perform deep validation of this element.
depthfirstsearch(function) Generic depth first search algorithm using a callback function, continues as long as the callback function returns None
description() Obtain the description associated with the element.
elements([founditems]) Returns a depth-first flat list of all elements below this element
feat(subset) Obtain the feature class value of the specific subset.
findcorrectionhandling(cls) Find the proper correctionhandling given a textclass by looking in the underlying corrections where it is reused
findreplaceables(parent[, set]) Internal method to find replaceable elements.
generate_id(cls)
getindex(child[, recursive, ignore]) Get the index at which an element occurs, recursive by default!
getmetadata([key]) Get the metadata that applies to this element, automatically inherited from parent elements
gettextdelimiter([retaintokenisation]) Return the text delimiter for this class.
hasannotation(Class[, set]) Returns an integer indicating whether such as annotation exists, and if so, how many.
hasannotationlayer([annotationtype, set]) Does the specified annotation layer exist?
hasphon([cls, strict, correctionhandling, …]) Does this element have phonetic content (of the specified class)
hastext([cls, strict, correctionhandling, …]) Does this element have text (of the specified class)
incorrection() Is this element part of a correction? If it is, it returns the Correction element (evaluating to True), otherwise it returns None
insert(index, child, *args, **kwargs)
items([founditems]) Returns a depth-first flat list of all items below this element (not limited to AbstractElement)
json([attribs, recurse, ignorelist]) Serialises the FoLiA element and all its contents to a Python dictionary suitable for serialisation to JSON.
layers([annotationtype, set]) Returns a list of annotation layers found directly under this element, does not include alternative layers
leftcontext(size[, placeholder, scope]) Returns the left context for an element, as a list.
next([Class, scope, reverse]) Returns the next element, if it is of the specified type and if it does not cross the boundary of the defined scope.
originaltext([cls]) Alias for retrieving the original uncorrect text.
paragraphs([index]) Returns a generator of Paragraph elements found (recursively) under this element.
parsecommonarguments(doc, **kwargs) Internal function to parse common FoLiA attributes and sets up the instance accordingly.
parsexml(node, doc, **kwargs) Internal class method used for turning an XML element into an instance of the Class.
phon([cls, previousdelimiter, strict, …]) Get the phonetic representation associated with this element (of the specified class)
phoncontent([cls, correctionhandling, hidden]) Get the phonetic content explicitly associated with this element (of the specified class).
postappend() This method will be called after an element is added to another and does some checks.
precedes(other) Returns a boolean indicating whether this element precedes the other element
previous([Class, scope]) Returns the previous element, if it is of the specified type and if it does not cross the boundary of the defined scope.
relaxng([includechildren, extraattribs, …]) Returns a RelaxNG definition for this element (as an XML element (lxml.etree) rather than a string)
relaxng_backwards() internal helper function for backward compatibility
remove(child) Removes the child element
replace(child, *args, **kwargs) Appends a child element like append(), but replaces any existing child element of the same type and set.
resolveoffsets(begin, end[, …]) Resolves supplied character offset information and returns tokens (non-token structures like linebreaks etc are ignored!).
resolveword(id)
rightcontext(size[, placeholder, scope]) Returns the right context for an element, as a list.
select(Class[, set, recursive, ignore, node]) Select child elements of the specified class.
sentences([index]) Returns a generator of Sentence elements found (recursively) under this element
setdoc(newdoc) Set a different document.
setdocument(doc) Associate a document with this element.
setparents() Correct all parent relations for elements within the scop.
setprocessor(processor) Sets the processor for this element, taking care of adding an annotator in the declarations
settext(text[, cls]) Set the text for this element.
speech_speaker() Retrieves the speaker of the audio or video file associated with the element.
speech_src() Retrieves the URL/filename of the audio or video file associated with the element.
stricttext([cls]) Alias for text() with strict=True
text([cls, retaintokenisation, …]) Get the text associated with this element (of the specified class)
textcontent([cls, correctionhandling, hidden]) Get the text content explicitly associated with this element (of the specified class).
textvalidation([warnonly]) Run text validation on this element.
toktext([cls]) Alias for text() with retaintokenisation=True
updatetext() Recompute textual value based on the text content of the children.
words([index]) Returns a generator of Word elements found (recursively) under this element.
xml([attribs, elements, skipchildren, form]) Serialises the FoLiA element and all its contents to XML.
xmlstring([pretty_print, form]) Serialises this FoLiA element and all its contents to XML.
__iter__() Iterate over all children of this element.
__len__() Returns the number of child elements under the current element.
__str__() Alias for text()

Class Attributes

ACCEPTED_DATA = (<class 'folia.main.AbstractAnnotationLayer'>, <class 'folia.main.AbstractInlineAnnotation'>, <class 'folia.main.Alternative'>, <class 'folia.main.AlternativeLayers'>, <class 'folia.main.Comment'>, <class 'folia.main.Correction'>, <class 'folia.main.Description'>, <class 'folia.main.Division'>, <class 'folia.main.Feature'>, <class 'folia.main.ForeignData'>, <class 'folia.main.Gap'>, <class 'folia.main.Hiddenword'>, <class 'folia.main.Linebreak'>, <class 'folia.main.Metric'>, <class 'folia.main.Paragraph'>, <class 'folia.main.Part'>, <class 'folia.main.Quote'>, <class 'folia.main.Reference'>, <class 'folia.main.Relation'>, <class 'folia.main.Sentence'>, <class 'folia.main.String'>, <class 'folia.main.TextContent'>, <class 'folia.main.Utterance'>, <class 'folia.main.Whitespace'>, <class 'folia.main.Word'>)
ANNOTATIONTYPE = 26
AUTH = True
AUTO_GENERATE_ID = True
HIDDEN = False
LABEL = 'Quote'
OCCURRENCES = 0
OCCURRENCES_PER_SET = 0
OPTIONAL_ATTRIBS = (0, 1, 2, 4, 3, 5, 8, 6, 7, 9, 11, 13)
PHONCONTAINER = False
PRIMARYELEMENT = True
PRINTABLE = True
REQUIRED_ATTRIBS = None
REQUIRED_DATA = None
SETONLY = False
SPEAKABLE = True
SUBSET = None
TEXTCONTAINER = False
TEXTDELIMITER = '\n\n'
WREFABLE = False
XMLTAG = 'quote'

Method Details

__init__(doc, *args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

__init__(doc, *args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

classmethod accepts(Class, raiseexceptions=True, parentinstance=None)
add(child, *args, **kwargs)
classmethod addable(parent, set=False, raiseexceptions=True)

Tests whether a new element of this class can be added to the parent.

This method is mostly for internal use. This will use the OCCURRENCES property, but may be overidden by subclasses for more customised behaviour.

Parameters:
  • parent (AbstractElement) – The element that is being added to
  • set (str,None, or False) – The set
  • raiseexceptions (bool) – Raise an exception if the element can’t be added?
Returns:

bool

Raises:

ValueError

addidsuffix(idsuffix, recursive=True)

Appends a suffix to this element’s ID, and optionally to all child IDs as well. There is sually no need to call this directly, invoked implicitly by copy()

addtoindex(norecurse=[])

Makes sure this element (and all subelements), are properly added to the index.

Mostly for internal use.

alternatives(Class=None, set=False, returnelements=False)

Generator over alternatives, either all or only of a specific annotation type, and possibly restrained also by set.

Parameters:
  • Class (class) – The python Class you want to retrieve (e.g. PosAnnotation). Or set to None to select all alternatives regardless of what type they are.
  • set (str) – The set you want to retrieve (defaults to None, which selects irregardless of set)
  • returnelements – Return the actual matches within the alternatives, will return two-tuples where the first is an instance of Alternative and the second an instance of Class.
Yields:

Alternative elements

ancestor(*Classes)

Find the most immediate ancestor of the specified type, multiple classes may be specified. Raise a NoSuchAnnotation exception if not found.

Parameters:Classes (*) – The possible classes (AbstractElement or subclasses) to select from. Not instances!

Example:

paragraph = word.ancestor(folia.Paragraph)
ancestors(Class=None)

Generator yielding all ancestors of this element, effectively back-tracing its path to the root element. A tuple of multiple classes may be specified.

Parameters:*Class – The class or (tuple of) classes (AbstractElement or subclasses). Not instances!
Yields:elements (instances derived from AbstractElement)
annotation(type, set=False)

Obtain a single annotation element.

A further restriction can be made based on set.

Parameters:
  • Class (class) – The class to select; any python class (not instance) subclassed off AbstractElement
  • Set (str) – The set to match against, only elements pertaining to this set will be returned. If set to False (default), all elements regardless of set will be returned.
Returns:

An element (instance derived from AbstractElement)

Example:

sense = word.annotation(folia.Sense, 'http://some/path/cornetto').cls

See also

AllowInlineAnnotation.annotations() AbstractElement.select()

Raises:NoSuchAnnotation if no such annotation exists
annotations(Class, set=False)

Obtain child elements (annotations) of the specified class.

A further restriction can be made based on set.

Parameters:
  • Class (class) – The class to select; any python class (not instance) subclassed off AbstractElement
  • Set (str) – The set to match against, only elements pertaining to this set will be returned. If set to False (default), all elements regardless of set will be returned.
Yields:

Elements (instances derived from AbstractElement)

Example:

for sense in text.annotations(folia.Sense, 'http://some/path/cornetto'):
    ..
Raises:
  • AllowInlineAnnotation.annotations()
  • NoSuchAnnotation if no such annotation exists
annotator2processor(annotator=None, annotatortype=None, parentprocessor=None)

Converts annotator information to processor information (FoLiA v2). Can be called with arguments to override defaults.

append(child, *args, **kwargs)

See AbstractElement.append()

checkdeclaration()

Internal method (usually no need to call this) that checks whether the element’s annotation type is properly declared, raises an exception if not so, or auto-declares the annotation type if need be.

context(size, placeholder=None, scope=None)

Returns this word in context, {size} words to the left, the current word, and {size} words to the right

copy(newdoc=None, idsuffix='')

Make a deep copy of this element and all its children.

Parameters:
  • newdoc (Document) – The document the copy should be associated with.
  • idsuffix (str or bool) – If set to a string, the ID of the copy will be append with this (prevents duplicate IDs when making copies for the same document). If set to True, a random suffix will be generated.
Returns:

a copy of the element

copychildren(newdoc=None, idsuffix='')

Generator creating a deep copy of the children of this element.

Invokes copy() on all children, parameters are the same.

correct(**kwargs)

Apply a correction (TODO: documentation to be written still)

count(Class, set=False, recursive=True, ignore=True, node=None)

Like AbstractElement.select(), but instead of returning the elements, it merely counts them.

Returns:int
deepvalidation()

Perform deep validation of this element.

Raises:DeepValidationError
depthfirstsearch(function)

Generic depth first search algorithm using a callback function, continues as long as the callback function returns None

description()

Obtain the description associated with the element.

Raises:NoSuchAnnotation if there is no associated description.
elements(founditems=None)

Returns a depth-first flat list of all elements below this element

feat(subset)

Obtain the feature class value of the specific subset.

If a feature occurs multiple times, the values will be returned in a list.

Example:

sense = word.annotation(folia.Sense)
synset = sense.feat('synset')
Returns:str or list
findcorrectionhandling(cls)

Find the proper correctionhandling given a textclass by looking in the underlying corrections where it is reused

classmethod findreplaceables(parent, set=False, **kwargs)

Internal method to find replaceable elements. Auxiliary function used by AbstractElement.replace(). Can be overriden for more fine-grained control.

generate_id(cls)
getindex(child, recursive=True, ignore=True)

Get the index at which an element occurs, recursive by default!

Returns:int
getmetadata(key=None)

Get the metadata that applies to this element, automatically inherited from parent elements

gettextdelimiter(retaintokenisation=False)

Return the text delimiter for this class.

Uses the TEXTDELIMITER attribute but may return a customised one instead.

hasannotation(Class, set=False)

Returns an integer indicating whether such as annotation exists, and if so, how many.

See AllowInlineAnnotation.annotations`() for a description of the parameters.

hasannotationlayer(annotationtype=None, set=False)

Does the specified annotation layer exist?

hasphon(cls='current', strict=True, correctionhandling=1, hidden=False)

Does this element have phonetic content (of the specified class)

By default, and unlike phon(), this checks strictly, i.e. the element itself must have the phonetic content and it is not inherited from its children.

Parameters:
  • cls (str) – The class of the phonetic content to obtain, defaults to current.
  • strict (bool) – Set this if you are strictly interested in the phonetic content explicitly associated with the element, without recursing into children. Defaults to True.
  • correctionhandling – Specifies what phonetic content to check for when corrections are encountered. The default is CorrectionHandling.CURRENT, which will retrieve the corrected/current phonetic content. You can set this to CorrectionHandling.ORIGINAL if you want the phonetic content prior to correction, and CorrectionHandling.EITHER if you don’t care.
Returns:

bool

hastext(cls='current', strict=True, correctionhandling=1, hidden=False)

Does this element have text (of the specified class)

By default, and unlike text(), this checks strictly, i.e. the element itself must have the text and it is not inherited from its children.

Parameters:
  • cls (str) – The class of the text content to obtain, defaults to current.
  • strict (bool) – Set this if you are strictly interested in the text explicitly associated with the element, without recursing into children. Defaults to True.
  • correctionhandling – Specifies what text to check for when corrections are encountered. The default is CorrectionHandling.CURRENT, which will retrieve the corrected/current text. You can set this to CorrectionHandling.ORIGINAL if you want the text prior to correction, and CorrectionHandling.EITHER if you don’t care.
Returns:

bool

incorrection()

Is this element part of a correction? If it is, it returns the Correction element (evaluating to True), otherwise it returns None

insert(index, child, *args, **kwargs)
items(founditems=None)

Returns a depth-first flat list of all items below this element (not limited to AbstractElement)

json(attribs=None, recurse=True, ignorelist=False)

Serialises the FoLiA element and all its contents to a Python dictionary suitable for serialisation to JSON.

Example:

import json
json.dumps(word.json())
Returns:dict
layers(annotationtype=None, set=False)

Returns a list of annotation layers found directly under this element, does not include alternative layers

leftcontext(size, placeholder=None, scope=None)

Returns the left context for an element, as a list. This method crosses sentence/paragraph boundaries by default, which can be restricted by setting scope

next(Class=True, scope=True, reverse=False)

Returns the next element, if it is of the specified type and if it does not cross the boundary of the defined scope. Returns None if no next element is found. Non-authoritative elements are never returned.

Parameters:
  • Class (*) – The class to select; any python class subclassed off ‘AbstractElement`, may also be a tuple of multiple classes. Set to True to constrain to the same class as that of the current instance, set to None to not constrain at all
  • scope (*) – A list of classes which are never crossed looking for a next element. Set to True to constrain to a default list of structure elements (Sentence,Paragraph,Division,Event, ListItem,Caption), set to None to not constrain at all.
originaltext(cls='original')

Alias for retrieving the original uncorrect text.

A call to text() with correctionhandling=CorrectionHandling.ORIGINAL

paragraphs(index=None)

Returns a generator of Paragraph elements found (recursively) under this element.

Parameters:index (int or None) – If set to an integer, will retrieve and return the n’th element (starting at 0) instead of returning the generator of all
parsecommonarguments(doc, **kwargs)

Internal function to parse common FoLiA attributes and sets up the instance accordingly. Do not invoke directly.

classmethod parsexml(node, doc, **kwargs)

Internal class method used for turning an XML element into an instance of the Class.

Parameters:
  • node - XML Element (*) –
  • doc - Document (*) –
Returns:

An instance of the current Class.

phon(cls='current', previousdelimiter='', strict=False, correctionhandling=1, hidden=False)

Get the phonetic representation associated with this element (of the specified class)

The phonetic content will be constructed from child-elements whereever possible, as they are more specific. If no phonetic content can be obtained from the children and the element has itself phonetic content associated with it, then that will be used.

Parameters:
  • cls (str) – The class of the phonetic content to obtain, defaults to current.
  • retaintokenisation (bool) – If set, the space attribute on words will be ignored, otherwise it will be adhered to and phonetic content will be detokenised as much as possible. Defaults to False.
  • previousdelimiter (str) – Can be set to a delimiter that was last outputed, useful when chaining calls to phon(). Defaults to an empty string.
  • strict (bool) – Set this if you are strictly interested in the phonetic content explicitly associated with the element, without recursing into children. Defaults to False.
  • correctionhandling – Specifies what phonetic content to retrieve when corrections are encountered. The default is CorrectionHandling.CURRENT, which will retrieve the corrected/current phonetic content. You can set this to CorrectionHandling.ORIGINAL if you want the phonetic content prior to correction, and CorrectionHandling.EITHER if you don’t care.
  • hidden (bool) – Include hidden elements, defaults to False.

Example:

word.phon()
Returns:The phonetic content of the element (unicode instance in Python 2, str in Python 3)
Raises:NoSuchPhon – if no phonetic conent is found at all.

See also

phoncontent(): Retrieves the phonetic content as an element rather than a string text() textcontent()

phoncontent(cls='current', correctionhandling=1, hidden=False)

Get the phonetic content explicitly associated with this element (of the specified class).

Unlike phon(), this method does not recurse into child elements (with the sole exception of the Correction/New element), and it returns the PhonContent instance rather than the actual text!

Parameters:
  • cls (str) – The class of the phonetic content to obtain, defaults to current.
  • correctionhandling – Specifies what content to retrieve when corrections are encountered. The default is CorrectionHandling.CURRENT, which will retrieve the corrected/current content. You can set this to CorrectionHandling.ORIGINAL if you want the content prior to correction, and CorrectionHandling.EITHER if you don’t care.
Returns:

The phonetic content (PhonContent)

Raises:

NoSuchPhon if there is no phonetic content for the element

postappend()

This method will be called after an element is added to another and does some checks.

It can do extra checks and if necessary raise exceptions to prevent addition. By default makes sure the right document is associated.

This method is mostly for internal use.

precedes(other)

Returns a boolean indicating whether this element precedes the other element

previous(Class=True, scope=True)

Returns the previous element, if it is of the specified type and if it does not cross the boundary of the defined scope. Returns None if no next element is found. Non-authoritative elements are never returned.

Parameters:
  • Class (*) – The class to select; any python class subclassed off ‘AbstractElement`, may also be a tuple of multiple classes. Set to True to constrain to the same class as that of the current instance, set to None to not constrain at all
  • scope (*) – A list of classes which are never crossed looking for a next element. Set to True to constrain to a default list of structure elements (Sentence,Paragraph,Division,Event, ListItem,Caption), set to None to not constrain at all.
classmethod relaxng(includechildren=True, extraattribs=None, extraelements=None, origclass=None)

Returns a RelaxNG definition for this element (as an XML element (lxml.etree) rather than a string)

classmethod relaxng_backwards()

internal helper function for backward compatibility

remove(child)

Removes the child element

replace(child, *args, **kwargs)

Appends a child element like append(), but replaces any existing child element of the same type and set. If no such child element exists, this will act the same as append()

Keyword Arguments:
 
  • alternative (bool) – If set to True, the replaced element will be made into an alternative. Simply use AbstractElement.append() if you want the added element
  • be an alternative. (to) –

See AbstractElement.append() for more information and all parameters.

resolveoffsets(begin, end, retaintokenisation=True, strictend=True, cls='current')

Resolves supplied character offset information and returns tokens (non-token structures like linebreaks etc are ignored!). Note: offsets are zero-indexed and the end is non-inclusive!

resolveword(id)
rightcontext(size, placeholder=None, scope=None)

Returns the right context for an element, as a list. This method crosses sentence/paragraph boundaries by default, which can be restricted by setting scope

select(Class, set=False, recursive=True, ignore=True, node=None)

Select child elements of the specified class.

A further restriction can be made based on set.

Parameters:
  • Class (class) – The class to select; any python class (not instance) subclassed off AbstractElement
  • Set (str) – The set to match against, only elements pertaining to this set will be returned. If set to False (default), all elements regardless of set will be returned.
  • recursive (bool) – Select recursively? Descending into child elements? Defaults to True.
  • ignore – A list of Classes to ignore, if set to True instead of a list, all non-authoritative elements will be skipped (this is the default behaviour and corresponds to the following elements: Alternative, AlternativeLayers, Suggestion, and folia.Original. These elements and those contained within are never authorative. You may also include the boolean True as a member of a list, if you want to skip additional tags along the predefined non-authoritative ones.
  • node (*) – Reserved for internal usage, used in recursion.
Yields:

Elements (instances derived from AbstractElement)

Example:

for sense in text.select(folia.Sense, 'cornetto', True, [folia.Original, folia.Suggestion, folia.Alternative] ):
    ..
sentences(index=None)

Returns a generator of Sentence elements found (recursively) under this element

Parameters:index (int or None) – If set to an integer, will retrieve and return the n’th element (starting at 0) instead of returning a generator of all
setdoc(newdoc)

Set a different document. Usually no need to call this directly, invoked implicitly by copy()

setdocument(doc)

Associate a document with this element.

Parameters:doc (Document) – A document

Each element must be associated with a FoLiA document.

setparents()

Correct all parent relations for elements within the scop. There is sually no need to call this directly, invoked implicitly by copy()

setprocessor(processor)

Sets the processor for this element, taking care of adding an annotator in the declarations

settext(text, cls='current')

Set the text for this element.

Parameters:
  • text (str) – The text
  • cls (str) – The class of the text, defaults to current (leave this unless you know what you are doing). There may be only one text content element of each class associated with the element.
speech_speaker()

Retrieves the speaker of the audio or video file associated with the element.

The source is inherited from ancestor elements if none is specified. For this reason, always use this method rather than access the src attribute directly.

Returns:str or None if not found
speech_src()

Retrieves the URL/filename of the audio or video file associated with the element.

The source is inherited from ancestor elements if none is specified. For this reason, always use this method rather than access the src attribute directly.

Returns:str or None if not found
stricttext(cls='current')

Alias for text() with strict=True

text(cls='current', retaintokenisation=False, previousdelimiter='', strict=False, correctionhandling=1, normalize_spaces=False, hidden=False)

Get the text associated with this element (of the specified class)

The text will be constructed from child-elements whereever possible, as they are more specific. If no text can be obtained from the children and the element has itself text associated with it, then that will be used.

Parameters:
  • cls (str) – The class of the text content to obtain, defaults to current.
  • retaintokenisation (bool) – If set, the space attribute on words will be ignored, otherwise it will be adhered to and text will be detokenised as much as possible. Defaults to False.
  • previousdelimiter (str) – Can be set to a delimiter that was last outputed, useful when chaining calls to text(). Defaults to an empty string.
  • strict (bool) – Set this iif you are strictly interested in the text explicitly associated with the element, without recursing into children. Defaults to False.
  • correctionhandling – Specifies what text to retrieve when corrections are encountered. The default is CorrectionHandling.CURRENT, which will retrieve the corrected/current text. You can set this to CorrectionHandling.ORIGINAL if you want the text prior to correction, and CorrectionHandling.EITHER if you don’t care.
  • normalize_spaces (bool) – Return the text with multiple spaces, linebreaks, tabs normalized to single spaces
  • hidden (bool) – Include hidden elements, defaults to False.

Example:

word.text()
Returns:The text of the element (unicode instance in Python 2, str in Python 3)
Raises:NoSuchText – if no text is found at all.
textcontent(cls='current', correctionhandling=1, hidden=False)

Get the text content explicitly associated with this element (of the specified class).

Unlike text(), this method does not recurse into child elements (with the sole exception of the Correction/New element), and it returns the TextContent instance rather than the actual text!

Parameters:
  • cls (str) – The class of the text content to obtain, defaults to current.
  • correctionhandling – Specifies what content to retrieve when corrections are encountered. The default is CorrectionHandling.CURRENT, which will retrieve the corrected/current content. You can set this to CorrectionHandling.ORIGINAL if you want the content prior to correction, and CorrectionHandling.EITHER if you don’t care.
  • hidden (bool) – Include hidden elements, defaults to False.
Returns:

The phonetic content (TextContent)

Raises:

NoSuchText if there is no text content for the element

textvalidation(warnonly=None)

Run text validation on this element. Checks whether any text redundancy is consistent and whether offsets are valid.

Parameters:warnonly (bool) – Warn only (True) or raise exceptions (False). If set to None then this value will be determined based on the document’s FoLiA version (Warn only before FoLiA v1.5)
Returns:bool
toktext(cls='current')

Alias for text() with retaintokenisation=True

updatetext()

Recompute textual value based on the text content of the children. Only supported on elements that are a TEXTCONTAINER

words(index=None)

Returns a generator of Word elements found (recursively) under this element.

Parameters:index (*) – If set to an integer, will retrieve and return the n’th element (starting at 0) instead of returning the list of all
xml(attribs=None, elements=None, skipchildren=False, form=0)

Serialises the FoLiA element and all its contents to XML.

Arguments are mostly for internal use.

Returns:an lxml.etree.Element

See also

AbstractElement.xmlstring() - for direct string output

xmlstring(pretty_print=False, form=0)

Serialises this FoLiA element and all its contents to XML.

Returns:a string with XML representation for this element and all its children
Return type:str
__iter__()

Iterate over all children of this element.

Example:

for annotation in word:
    ...
__len__()

Returns the number of child elements under the current element.

__str__()

Alias for text()