MyCapytain.resources.texts package

class MyCapytain.resources.texts.tei.Citation(name=None, xpath=None, scope=None, refsDecl=None, child=None)[source]

Bases: MyCapytain.common.reference.Citation

Implementation of Citation for TEI markup

static ingest(resource, xpath='.//tei:cRefPattern')[source]

Ingest a resource and store data in its instance

Parameters:
  • resource (lxml.etree._Element) – XML node cRefPattern or list of them in ASC hierarchy order (deepest to highest, eg. lines to poem to book)
  • xpath (str) – XPath to use to retrieve citation
Returns:

A citation object

Return type:

Citation

class MyCapytain.resources.texts.tei.Passage(parent=None, **kwargs)[source]

Bases: MyCapytain.resources.proto.text.Passage

text(exclude=None)[source]

Text content of the passage

Parameters:

exclude (List) – Remove some nodes from text

Return type:

basestring

Returns:

Text of the xml node

Example:
>>>    P = Passage(resource='<l n="8">Ibis <note>hello<a>b</a></note> ab excusso missus in astra <hi>sago.</hi> </l>')
>>>    P.text == "Ibis hello b ab excusso missus in astra sago. "
>>>    P.text(exclude=["note"]) == "Ibis hello b ab excusso missus in astra sago. "
xml

XML Representation of the Passage

Return type:lxml.etree._Element
Returns:XML element representing the passage
class MyCapytain.resources.texts.local.Text(urn=None, citation=None, resource=None)[source]

Bases: MyCapytain.resources.proto.text.Text

Implementation of CTS tools for local files

Parameters:
Variables:

resource – lxml

citation

Get the lowest cRefPattern in the hierarchy

Return type:MyCapytain.resources.texts.tei.Citation
getPassage(reference)[source]

Finds a passage in the current text

Parameters:reference (List, MyCapytain.common.reference.Reference) – Identifier of the subreference / passages
Return type:Passage
Returns:Asked passage
getPassagePlus(reference)[source]

Finds a passage in the current text with its previous and following node

Parameters:reference (List, MyCapytain.common.reference.Reference) – Identifier of the subreference / passages
Return type:text.PassagePlus
Returns:Asked passage with metainformations
getValidReff(level=1, reference=None)[source]

Retrieve valid passages directly

Parameters:
  • level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
  • reference (Reference) – Subreference (optional)
Return type:

List.basestring

Returns:

List of levels

Note

GetValidReff works for now as a loop using Passage, subinstances of Text, to retrieve the valid informations. Maybe something is more powerfull ?

class MyCapytain.resources.texts.api.Text(urn, resource, citation=None, **kwargs)[source]

Bases: MyCapytain.resources.proto.text.Text

Passage representing object prototype

Parameters:
DEFAULT_LANG = u'eng'
getLabel()[source]

Retrieve metadata about the text

Return type:Metadata
Returns:Dictionary with label informations
getPassage(reference=None)[source]

Retrieve a passage and store it in the object

Parameters:reference (MyCapytain.common.reference.Reference or List of basestring) – Reference of the passage
Return type:Passage
Returns:Object representing the passage
Raises:TypeError when reference is not a list or a Reference
getPassagePlus(reference=None)[source]

Retrieve a passage and informations around it and store it in the object

Parameters:reference (MyCapytain.common.reference.Reference or List of basestring) – Reference of the passage
Return type:Passage
Returns:Object representing the passage
Raises:TypeError when reference is not a list or a Reference
getValidReff(level=1, reference=None)[source]

Given a resource, Text will compute valid reffs

Parameters:
  • level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
  • reference (Reference) – Subreference (optional)
Return type:

List.basestring

Returns:

List of levels

reffs

Get all valid reffs for every part of the Text

Return type:MyCapytain.resources.texts.tei.Citation
class MyCapytain.resources.texts.api.Passage(urn, resource, *args, **kwargs)[source]

Bases: MyCapytain.resources.texts.tei.Passage

next

Following passage

Return type:Passage
Returns:Following passage at same level
prev

Previous passage

Return type:Passage
Returns:Previous passage at same level
static prevnext(resource)[source]

Parse a resource to get the prev and next urn

Parameters:resource (etree._Element) – XML Resource
Returns:Tuple representing previous and next urn
Return type:(str, str)