MyCapytain.common.reference

>>> from MyCapytain.common.reference import (URN, Reference, Citation)
class MyCapytain.common.reference.Citation(name=None, xpath=None, scope=None, refsDecl=None, child=None)[source]

Bases: future.types.newobject.newobject

A citation object gives informations about the scheme

Parameters:
  • name (basestring) – Name of the citation (e.g. “book”)
  • xpath (basestring) – Xpath of the citation (As described by CTS norm)
  • scope – Scope of the citation (As described by CTS norm)
  • refsDecl (basestring) – refsDecl version
  • child (Citation) – A citation
__iter__()[source]

Iteration method

Loop over the citation childs

Example:
>>>    c = Citation(name="line")
>>>    b = Citation(name="poem", child=c)
>>>    a = Citation(name="book", child=b)
>>>    [e for e in a] == [a, b, c]
__len__()[source]

Length method

Return type:int
Returns:Number of nested citations
child

Child of a citation

Type:Citation or None
Example:Citation.name==poem would have a child Citation.name==line
fill(passage=None, xpath=None)[source]

Fill the xpath with given informations

Parameters:
  • passage (Reference or lsit) – Passage reference
  • xpath (Boolean) – If set to True, will return the replaced self.xpath value and not the whole self.refsDecl
Return type:

basestring

Returns:

Xpath to find the passage

name

Type of the citation represented

Type:basestring
Example:Book, Chapter, Textpart, Section, Poem...
refsDecl

ResfDecl expression of the citation scheme

Type:basestring
Example:/tei:TEI/tei:text/tei:body/tei:div//tei:l[@n=’$1’]
scope

TextInventory scope property of a citation (ie. identifier of all element but the last of the citation)

Type:basestring
Example:/tei:TEI/tei:text/tei:body/tei:div
xpath

TextInventory xpath property of a citation (ie. identifier of the last element of the citation)

Type:basestring
Example://tei:l[@n=”?”]
MyCapytain.common.reference.REF_REPLACER(match, passage)[source]

Helper to replace xpath/scope/refsDecl on iteration with passage value

Parameters:
  • match (re.SRE_MATCH) – A RegExp match
  • passage (iter) – A list with subreference informations
Return type:

basestring

Returns:

Replaced string

class MyCapytain.common.reference.Reference(reference)[source]

Bases: future.types.newobject.newobject

A reference object giving informations

Parameters:

reference (basestring) – Passage Reference part of a Urn

Example:
>>>    a = Reference(reference="1.1@Achiles[1]-1.2@Zeus[1]")
>>>    b = Reference(reference="1.1")
__str__()[source]

Return full reference in string format

Return type:

basestring

Returns:

String representation of Reference Object

Example:
>>>    a = Reference(reference="1.1@Achiles[1]-1.2@Zeus[1]")
>>>    b = Reference(reference="1.1")
>>>    str(a) == "1.1@Achiles[1]-1.2@Zeus[1]"
>>>    str(b) == "1.1"
__eq__(other)[source]

Equality checker for Reference object

Parameters:

other – An object to be checked against

Return type:

boolean

Returns:

Equality between other and self

Example:
>>>    a = Reference(reference="1.1@Achiles[1]-1.2@Zeus[1]")
>>>    b = Reference(reference="1.1")
>>>    c = Reference(reference="1.1")
>>>    (a == b) == False
>>>    (c == b) == True
__getitem__(key)[source]

Return part of or full passage reference

Available keys :
  • 1 | start : First part of the reference
  • 2 | start_list : Reference start parsed into a list
  • 3 | start_sub : Subreference start parsed into a tuple
  • 4 | end : Last part of the reference
  • 5 | end_list : Reference start parsed into a list
  • 6 | end_sub : Subreference end parsed into a tuple
  • default : full string reference
Parameters:

key (basestring or int) – Identifier of the part to return

Return type:

basestring or List.<int> or None or Tuple.<string>

Returns:

Desired part of the passage reference

Example:
>>>    a = Reference(reference="1.1@Achiles[1]-1.2@Zeus[1]")
>>>    print(a[1]) # "1.1@Achiles[1]"
>>>    print(a["start_list"]) # ("1", "1")
>>>    print(a[6]) # ("Zeus", "1")
>>>    print(a[7]) # "1.1@Achiles[1]-1.2@Zeus[1]"
parent
Returns:
class MyCapytain.common.reference.URN(urn)[source]

Bases: future.types.newobject.newobject

A URN object giving all useful sections

Parameters:

urn (basestring) – A CTS URN

Example:
>>>    a = URN(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1")
__len__()[source]

Returns the len of the URN

Return type:int
Returns:Length of the URN

Warning

Does not take into account the passage !

Example:
>>>    a = URN(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1") 
>>>    print(len(a)) # 
__gt__(other)[source]

Allows for greater comparison

Parameters:other (URN) – Comparison object
Return type:boolean
Returns:Indicator of bigger size

Warning

Does not take into account the passage !

Example:
>>>    a = URN(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1") 
>>>    b = URN(urn="urn:cts:latinLit:phi1294.phi002:1.1") 
>>>    (a > b) == True # 
__lt__(other)[source]

Allows for lower comparison

Parameters:other (URN) – Comparison object
Return type:boolean
Returns:Indicator of lower size

Warning

Does not take into account the passage !

Example:
>>>    a = URN(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1") 
>>>    b = URN(urn="urn:cts:latinLit:phi1294.phi002:1.1") 
>>>    (b < a) == True # 
__eq__(other)[source]

Equality checker for URN object

Parameters:

other (URN) – An object to be checked against

Return type:

boolean

Returns:

Equality between other and self

Example:
>>>    a = URN(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1") 
>>>    b = URN(urn="urn:cts:latinLit:phi1294.phi002:1.1") 
>>>    (b == a) == False # 
__str__()[source]

Return full initial urn

Return type:

basestring

Returns:

String representation of URN Object

Example:
>>>    a = URN(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1") 
>>>    str(a) == "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1"
__getitem__(key)[source]

Returns the urn (int) level or up to (str) level.

Available keys :
  • 0 : URN
  • full : URN
  • 1 : Namespace of the urn (cts)
  • urn_namespace : URN until the Namespace of the urn
  • 2 : CTS Namespace of the URN (e.g. latinLit)
  • cts_namespace : URN until the CTS Namespace
  • 3 : Textgroup of the URN
  • textgroup : URN until the Textgroup
  • 4 : Work of the URN
  • work : URN until the Work
  • 5 : Text of the URN
  • text : URN until the Text
  • 6 or passage: Passage of URN
Parameters:

key (int or basestring) – Identifier of the wished resource

Return type:

basestring or Reference

Returns:

Part or complete URN

Warning:

urn: is not counted as an element !

Example:
>>>    a = URN(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1") 
>>>    a["textgroup"] == "urn:cts:latinLit:phi1294"
>>>    a[3] == "phi1294