Welcome to MyCapytains’s documentation!¶
MyCapytain is a python library which provides a large set of methods to interact with Text Services API such as the Canonical Text Services, the Distributed Text Services. It also provides a programming interface to exploit local textual resources developed according to the Capitains Guidelines.
Simple Example of what it does¶
The following code and example is badly displayed at the moment on Github. We recommend you to go to http://mycapytain.readthedocs.org
On Leipzig DH Chair’s Canonical Text Services API, we can find the Epigrammata of Martial. This texts are identified by the identifier “urn:cts:latinLit:phi1294.phi002.perseus-lat2”. We want to have some information about this text so we are gonna ask the API to give its metadata to us :
1 2 3 4 5 6 7 8 9 10 11 | from MyCapytain.resolvers.cts.api import HttpCtsResolver
from MyCapytain.retrievers.cts5 import CTS
from MyCapytain.common.constants import Mimetypes
# We set up a resolver which communicates with an API available in Leipzig
resolver = HttpCtsResolver(CTS("http://cts.dh.uni-leipzig.de/api/cts/"))
# We require some metadata information
textMetadata = resolver.getMetadata("urn:cts:latinLit:phi1294.phi002.perseus-lat2")
# Texts in CTS Metadata have one interesting property : its citation scheme.
# XmlCtsCitation are embedded objects that carries information about how a text can be quoted, what depth it has
print(type(textMetadata), [citation.name for citation in textMetadata.citation])
|
This query will return the following information :
<class 'MyCapytain.resources.collections.cts.Text'> ['book', 'poem', 'line']
12 13 14 15 | # Now, we want to retrieve the first line of poem seventy two of the second book
passage = resolver.getTextualNode("urn:cts:latinLit:phi1294.phi002.perseus-lat2", subreference="2.72.1")
# And we want to have its content exported to plain text and have the siblings of this passage (previous and next line)
print(passage.export(Mimetypes.PLAINTEXT), passage.siblingsId)
|
And we will get
Hesterna factum narratur, Postume, cena
If you want to play more with this, like having a list of what can be found in book three, you could go and do
16 17 | poemsInBook3 = resolver.getReffs("urn:cts:latinLit:phi1294.phi002.perseus-lat2", subreference="3")
print(poemsInBook3)
|
Which would be equal to :
['3.1', '3.2', '3.3', '3.4', '3.5', '3.6', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13', ...]
Now, it’s your time to work with the resource ! See the CapiTainS Classes page on ReadTheDocs to have a general introduction to MyCapytain objects !
Installation and Requirements¶
The best way to install MyCapytain is to use pip. MyCapytain tries to support Python over 3.4.
The work needed for supporting Python 2.7 is mostly done, however, since 2.0.0, we are giving up on ensuring that MyCapytain will be compatible with Python < 3 while accepting PR which would help doing so.
pip install MyCapytain
If you prefer to use setup.py, you should clone and use the following
git clone https://github.com/Capitains/MyCapytain.git
cd MyCapytain
python setup.py install
Contents¶
MyCapytain’s Main Objects Explained¶
Exportable Parent Classes¶
Description¶
MyCapytain.common.base.Exportable
The Exportable class is visible all across the library. It provides a common, standardized way to retrieve in an API fashion to what can an object be exported and to exports it. Any exportable object should have an EXPORT_TO constant variable and include a __export__(output, **kwargs) methods if it provides an export type.
Example¶
The following code block is a mere example of how to implement Exportable and what are its responsibilities. Exportabletypically loops over all the parents class of the current class until it find one exportable system matching the required one.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | from MyCapytain.common.constants import Mimetypes
from MyCapytain.common.base import Exportable
class Sentence(Exportable):
""" This class represent a Sentence
:param content: Content of the sentence
"""
# EXPORT_TO is a list of Mimetype the object is capable to export to
EXPORT_TO = [
Mimetypes.PLAINTEXT, Mimetypes.XML.Std
]
DEFAULT_EXPORT = Mimetypes.PLAINTEXT
def __init__(self, content):
self.content = content
def __export__(self, output=None, **kwargs):
""" Export the collection item in the Mimetype required.
:param output: Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes)
:type output: str
:return: Object using a different representation
"""
if output == Mimetypes.PLAINTEXT:
return self.content
elif output == Mimetypes.XML.Std:
return "<sentence>{}</sentence>".format(self.content)
class TEISentence(Sentence):
""" This class represent a Sentence but adds some exportable accepted output
:param content: Content of the sentence
"""
EXPORT_TO = [
Mimetypes.JSON.Std
]
def __export__(self, output=None, **kwargs):
""" Export the collection item in the Mimetype required.
:param output: Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes)
:type output: str
:return: Object using a different representation
"""
if output == Mimetypes.JSON.Std:
return {"http://www.tei-c.org/ns/1.0/sentence": self.content}
elif output == Mimetypes.XML.Std:
return "<sentence xmlns=\"http://www.tei-c.org/ns/1.0\">{}</sentence>".format(self.content)
s = Sentence("I love Martial's Epigrammatas")
print(s.export(Mimetypes.PLAINTEXT))
# I love Martial's Epigrammatas
print(s.export()) # Defaults to PLAINTEXT
# I love Martial's Epigrammatas
print(s.export(Mimetypes.XML.Std))
# <sentence>I love Martial's Epigrammatas</sentence>
tei = TEISentence("I love Martial's Epigrammatas")
print(tei.export(Mimetypes.PLAINTEXT))
# I love Martial's Epigrammatas
print(tei.export()) # Defaults to PLAINTEXT
# I love Martial's Epigrammatas
print(tei.export(Mimetypes.JSON.Std))
# {"http://www.tei-c.org/ns/1.0/sentence": I love Martial's Epigrammatas}
print(tei.export(Mimetypes.XML.Std)) # Has been rewritten by TEISentence
# <sentence xmlns="http://www.tei-c.org/ns/1.0">I love Martial's Epigrammatas</sentence>
try:
print(tei.export(Mimetypes.XML.RDF))
except NotImplementedError as error:
print(error)
# Raise the error and prints "Mimetype application/rdf+xml has not been implemented for this resource"
|
Retrievers¶
MyCapytain.retrievers.prototypes.API
Description¶
Retrievers are classes that help build requests to API and return standardized responses from them. There is no real perfect prototypes. The only requirements for a Retriever is that its query function should returns string only. It is not the role of the retrievers to parse response. It is merely to facilitate the communication to remote API most of the time.
Recommendations¶
For Textual API, it is recommended to implement the following requests
- getTextualNode(textId[str], subreference[str], prevnext[bool], metadata[bool])
- getMetadata(objectId[str], **kwargs)
- getSiblings(textId[str], subreference[str])
- getReffs(textId[str], subreference[str], depth[int])
Example of implementation : CTS 5¶
MyCapytain.retrievers.cts5.HttpCtsRetriever
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | from MyCapytain.retrievers.cts5 import HttpCtsRetriever
# We set up a retriever which communicates with an API available in Leipzig
retriever = HttpCtsRetriever("http://cts.dh.uni-leipzig.de/api/cts/")
# We require a passage : passage is now a Passage object
passage = retriever.getPassage("urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1")
# Passage is now equal to the string content of http://cts.dh.uni-leipzig.de/api/cts/?request=GetPassage&urn=urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1
print(passage)
"""
<GetPassage><request><requestName>GetPassage</requestName><requestUrn>urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1</requestUrn></request>
<reply><urn>urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1</urn><passage><TEI>
<text n="urn:cts:latinLit:phi1294.phi002.perseus-lat2" xml:id="stoa0045.stoa0"><body>
<div type="edition" n="urn:cts:latinLit:phi1294.phi002.perseus-lat2" xml:lang="lat">
<div type="textpart" subtype="book" n="1"><div type="textpart" subtype="poem" n="1">
<head>I</head>
<l n="1">Hic est quem legis ille, quem requiris, </l>
<l n="2">Toto notus in orbe Martialis </l>
<l n="3">Argutis epigrammaton libellis: <pb/></l>
<l n="4">Cui, lector studiose, quod dedisti </l>
<l n="5">Viventi decus atque sentienti, </l>
<l n="6">Rari post cineres habent poetae. </l>
</div></div></div></body></text></TEI></passage></reply>
"""
|
Text and Passages¶
Description¶
Hierarchy¶
The generic idea of both Text and Passage’s classes is that they inherit from a longer trail of text bearing object that complexified over different features. The basic is
- TextualElement is an object which can bear Metadata and Collection information. It has a .text property and is exportable
- TextualNode inherits from NodeId and unlike TextualElement, TextualNode is part of a graph of CitableObject. It bears informations about its siblings, parents, children.
- TextualGraph is a bit interactive : you can query for children nodes and get descendant references of the object.
- InteractiveTextualNode is completely interative . You can browse the graph by accessing the
.next
property for example : it should then return an InteractiveTextualNode as well - CtsNode has two unique methods more as well as a
urn
property. - From CtsNode we find CitableText and Passage, which represents complete and portion of a Text. The main difference is that CitableText has no parents, no siblings.
Objectives¶
Text and Passages object have been built around InteractiveTextualNode which fills the main purpose of MyCapytain :being able to interact with citable, in-graph texts that are retrieve through web API or local files. Any implementation should make sure that the whole set of navigation tool are covered. Those are :
Tree Identifiers(Returns str Identifiers) | Tree Navigations (Returns InteractiveTextualNode or children class) | Retrieval Methods | Other |
---|---|---|---|
prevId | prev | .getTextualNode(subreference) | id : TextualNode Identifier [str] |
nextId | nextId | .getReffs(subreference[optional]) | metadata : Metadata informations [Metadata] |
siblingsId [tuple[str]] | siblings [tuple[InteractiveTextualNode]] | ||
parentId | parent | citation : Citation Information [Citation] | |
childIds [list[str]] | children [list[InteractiveTextualNode]] | text : String Representation of the text without annotation | |
firstId | first | .export() | |
lastId | last |
The base module¶
The base module contains special implementations : they technically do not support interactive methods but provides generic parsing and export methods for specific type of contents such as TEI XML object or other formats such as json, csv, treebank objects in the future.
The TEIResource
for example requires the object to be set up with a resource parameters that will be furtherparsed using lxml. From there, it provides export such as plain/text, TEI XML, nested dictionaries or even anlxml etree interface.
Implementation example : HTTP API Passage work¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | from MyCapytain.retrievers.cts5 import HttpCtsRetriever
from MyCapytain.resources.texts.remote.cts import CtsText
# We set up a retriever which communicates with an API available in Leipzig
retriever = HttpCtsRetriever("http://cts.dh.uni-leipzig.de/api/cts/")
# Given that we have other examples that shows how to work with text,
# we will focus here on playing with the graph functionality of texts implementations.
# We are gonna retrieve a text passage and the retrieve all its siblings in different fashion#
# The main point is to find all children of the same parent.
# The use case could be the following : some one want to retrieve the full text around a citation
# To enhance the display a little.
# We will work with the line 7 of poem 39 of book 4 of Martial's Epigrammata
# The text is urn:cts:latinLit:phi1294.phi002.perseus-lat2
text = CtsText(retriever=retriever, urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2")
# We retrieve up the passage
target = text.getTextualNode(subreference="4.39.7")
print(target.text)
"""
Nec quae Callaico linuntur auro,
"""
# The parent way :
# - get to the parent,
# - retrieve each node,
# - print only the one which are not target
parent = target.parent
for node in parent.children:
if node.id != target.id:
print("{}\t{}".format(node.id, node.text))
else:
print("------Original Node-----------")
"""
4.39.1 Argenti genus omne comparasti,
4.39.2 Et solus veteres Myronos artes,
4.39.3 Solus Praxitelus manum Scopaeque,
4.39.4 Solus Phidiaci toreuma caeli,
4.39.5 Solus Mentoreos habes labores.
4.39.6 Nec desunt tibi vera Gratiana,
------Original Node-----------
4.39.8 Nec mensis anaglypta de paternis.
4.39.9 Argentum tamen inter omne miror
4.39.10 Quare non habeas, Charine, purum.
"""
print("\n\nSecond Method\n\n")
# We are gonna do another way this time :
# - get the previous until we change parent
# - get the next until we change parent
parentId = node.parentId
# Deal with the previous ones
current = target.prev
while current.parentId == parentId:
print("{}\t{}".format(current.id, current.text))
current = current.prev
print("------Original Node-----------")
# Deal with the next ones
current = target.next
while current.parentId == parentId:
print("{}\t{}".format(current.id, current.text))
current = current.next
"""
4.39.6 Nec desunt tibi vera Gratiana,
4.39.5 Solus Mentoreos habes labores.
4.39.4 Solus Phidiaci toreuma caeli,
4.39.3 Solus Praxitelus manum Scopaeque,
4.39.2 Et solus veteres Myronos artes,
4.39.1 Argenti genus omne comparasti,
------Original Node-----------
4.39.8 Nec mensis anaglypta de paternis.
4.39.9 Argentum tamen inter omne miror
4.39.10 Quare non habeas, Charine, purum.
"""
|
Other Example¶
See MyCapytain.resources.texts.local
Collection¶
Description¶
Collections are the metadata containers object in MyCapytain. Unlike other object, they will never contain textual content such as Texts and Passages but will in return help you browse through the catalog of one APIs collection and identify manually or automatically texts that are of relevant interests to you.
The main information that you should be interested in are :
- Collections are children from Exportable. As of 2.0.0, any collection can be exported to JSON DTS.
- Collections are built on a hierarchy. They have children and descendants
- Collections have identifiers and title (Main name of what the collection represents : if it’s an author, it’s her name, a title for a book, a volume label for a specific edition, etc.)
- Collections can inform the machine if it represents a readable object : if it is readable, it means that using its identifier, you can query for passages or references on the same API.
Main Properties¶
- Collection().id : Identifier of the object
- Collection().get_label(lang[Optional]) : Title of the object
- Collection().readable : If True, means that the Collection().id can be used in GetReffs or GetTextualNode queries
- Collection().members : Direct children of the object
- Collection().descendants : Direct and Indirect children of the objects
- Collection().readableDescendants : Descendants that have .readable as True
- Collection().export() : Export Method
- Collection().metadata : Metadata object that contain flat descriptive localized information about the object.
Implementation : CTS Collections¶
Note
For a recap on what Textgroup means or any CTS jargon, go to http://capitains.github.io/pages/vocabulary
CTS Collections are divided in 4 kinds : TextInventory, TextGroup, Work, Text. Their specificity is that the hierarchyof these objects are predefined and always follow the same order. They implement a special export (MyCapytain.common.constants.Mimetypes.XML.CTS
) which basically exports to the XML Text Inventory Formatthat one would find making a GetCapabilities request.
CapiTainS CTS Collections implement a parents property which represent a list of parents where .parents’ order is equalto Text.parents = [Work(), TextGroup(), TextInventory()]
).
Their finale implementation accepts to parse resources through the resource=
named argument.
Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | from MyCapytain.retrievers.cts5 import HttpCtsRetriever
from MyCapytain.resources.collections.cts import XmlCtsTextInventoryMetadata, XmlCtsWorkMetadata
from MyCapytain.common.constants import Mimetypes
from pprint import pprint
"""
In order to have a real life example,
we are gonna query for data in the Leipzig CTS API
We are gonna query for metadata about Seneca who
is represented by urn:cts:latinLit:stoa0255
To retrieve data, we are gonna make a GetMetadata query
to the CTS Retriever.
"""
retriever = HttpCtsRetriever("http://cts.dh.uni-leipzig.de/api/cts/")
# We store the response (Pure XML String)
response = retriever.getMetadata(objectId="urn:cts:latinLit:stoa0255")
"""
From here, we actually have the necessary data, we can now
play with collections. TextInventory is the main collection type that is needed to
parse the whole response.
"""
inventory = XmlCtsTextInventoryMetadata.parse(resource=response)
# What we are gonna do is print the title of each descendant :
for descendant in inventory.descendants:
# Metadatum resolve any non-existing language ("eng", "lat") to a default one
# Putting default is just making that clear
print(descendant.get_label())
"""
You should see in there things such as
- "Seneca, Lucius Annaeus" (The TextGroup or main object)
- "de Ira" (The Work object)
- "de Ira, Moral essays Vol 2" (The Edition specific Title)
We can now see other functions, such as the export to JSON DTS.
Collections have a unique feature built in : they allow for
accessing an item using its key as if it were a dictionary :
The identifier of a De Ira is urn:cts:latinLit:stoa0255.stoa0110
"""
deIra = inventory["urn:cts:latinLit:stoa0255.stoa010"]
assert isinstance(deIra, XmlCtsWorkMetadata)
pprint(deIra.export(output=Mimetypes.JSON.DTS.Std))
# you should see a DTS representation of the work
"""
What we might want to do is to browse metadata about seneca's De Ira
Remember that CtsCollections have a parents attribute !
"""
for descAsc in deIra.descendants + [deIra] + deIra.parents:
# We filter out Textgroup which has an empty Metadata value
if not isinstance(descAsc, HttpCtsRetriever):
print(
descAsc.metadata.export(output=Mimetypes.JSON.Std)
)
"""
And of course, we can simply export deIra to CTS XML format
"""
print(deIra.export(Mimetypes.XML.CTS))
|
Dispatchers¶
Description¶
Dispatcher are tools to be used to organize semi-automatically resources, most likely in the context of a resolver retrieving data from local directories.
Dispatcher has following properties :
- methods -> [tuple(Callable()->Bool, str)]
- add(func[Callable()], inventory_name[str])
- inventory(inventory_name[str]) -> @decorator
- dispatch(collection[Collection, **kwargs)
Implementation¶
-
class
MyCapytain.resolvers.utils.
CollectionDispatcher
(collection, default_inventory_name=None)[source]¶ Collection Dispatcher provides a utility to divide automatically texts and collections into different collections
Parameters: - collection – The root collection
- default_inventory_name – The default name of the default collection
-
add
(func, inventory_name)[source]¶ Register given function as a filter.
If this function “func” returns True when given an object, said object will be dispatched to Collection(inventory_name)
Parameters: - func – Callable
- inventory_name – Identifier of the collection to dispatch to
-
dispatch
(collection, **kwargs)[source]¶ Dispatch a collection using internal filters
Parameters: - collection – Collection object
- kwargs – Additional keyword arguments that could be used by internal filters
Returns: None
Raises:
-
inventory
(inventory_name)[source]¶ Decorator to register filters for given inventory. For a function “abc”, it has the same effect
Parameters: inventory_name – Returns: tic = CtsTextInventoryCollection() latin = CtsTextInventoryMetadata("urn:perseus:latinLit", parent=tic) latin.set_label("Classical Latin", "eng") dispatcher = CollectionDispatcher(tic) @dispatcher.inventory("urn:perseus:latinLit") def dispatchLatinLit(collection, path=None, **kwargs): if collection.id.startswith("urn:cts:latinLit:"): return True return False
-
methods
¶ List of methods to dispatch resources.
- Each element is a tuple with two elements :
- First one is the inventory identifier to dispatch to
- Second one is a function which, if returns true, will activate dispatching to given
Return type: List
Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | from MyCapytain.resolvers.cts.local import CtsCapitainsLocalResolver
from MyCapytain.resolvers.utils import CollectionDispatcher
from MyCapytain.common.constants import Mimetypes
from MyCapytain.resources.collections.cts import XmlCtsTextInventoryMetadata
from MyCapytain.resources.prototypes.cts.inventory import CtsTextInventoryCollection
# We set up a main collection
tic = CtsTextInventoryCollection()
# We register sub collection we want to dispatch to
latin = XmlCtsTextInventoryMetadata("urn:perseus:latinLit", parent=tic)
latin.set_label("Classical Latin", "eng")
farsi = XmlCtsTextInventoryMetadata("urn:perseus:farsiLit", parent=tic)
farsi.set_label("Farsi", "eng")
gc = XmlCtsTextInventoryMetadata("urn:perseus:greekLit", parent=tic)
gc.set_label("Ancient Greek", "eng")
gc.set_label("Grec Ancien", "fre")
# We create the dispatcher with the root collection
dispatcher = CollectionDispatcher(tic)
# And we record function for each given repository
# We could have two function dispatching for the same repository !
@dispatcher.inventory("urn:perseus:latinLit")
def dispatchLatinLit(collection, path=None, **kwargs):
if collection.id.startswith("urn:cts:latinLit:"):
return True
return False
@dispatcher.inventory("urn:perseus:farsiLit")
def dispatchfFarsiLit(collection, path=None, **kwargs):
if collection.id.startswith("urn:cts:farsiLit:"):
return True
return False
@dispatcher.inventory("urn:perseus:greekLit")
def dispatchGreekLit(collection, path=None, **kwargs):
if collection.id.startswith("urn:cts:greekLit:"):
return True
return False
# We set up a resolver which parses local file
NautilusDummy = CtsCapitainsLocalResolver(
resource=[
"./tests/testing_data/latinLit2"
],
# We give it the dispatcher
dispatcher=dispatcher
)
# If we want to read the main repository, we will have all children
all = NautilusDummy.getMetadata()
print(len(all.readableDescendants)) # 25 is the number of edition and translation
print([m.id for m in all.members]) # Direct members are dispatched-in collections
print(
all["urn:cts:latinLit:phi1294"] == all["urn:perseus:latinLit"]["urn:cts:latinLit:phi1294"]
) # Is true because they are dispatched this way
try:
all["urn:perseus:greekLit"]["urn:cts:latinLit:phi1294"]
except KeyError:
print("But this won't work because the object has been dispatched to latinLit !")
print(len(all["urn:perseus:greekLit"].readableDescendants)) # Is 6 because there is 6 recorded texts in __cts__
print(len(all["urn:perseus:latinLit"].readableDescendants)) # Is 19 because there is 6 recorded texts in __cts__
|
Resolvers¶
Description¶
Resolvers were introduced in 2.0.0b0 and came as a solution to build tools around Text Services APIs where you can seamlessly switch a resolver for another and not changing your code, join together multiple resolvers, etc. The principle behind resolver is to provide native python object based on API-Like methods which are restricted to four simple commands :
- getTextualNode(textId[str], subreference[str], prevnext[bool], metadata[bool]) -> Passage
- getMetadata(objectId[str], **kwargs) -> Collection
- getSiblings(textId[str], subreference[str]) -> tuple([str, str])
- getReffs(textId[str], subreference[str], depth[int]) -> list([str])
These function will always return objects derived from the major classes, i.e. Passage and Collection for the two firsts and simple collections of strings for the two others. Resolvers fills the hole between these base objects and the original retriever objects that were designed to return plain strings from remote or local APIs.
The base functions are represented in the prototype, and only getMetadata might be expanded in terms of arguments depending on what filtering can be offered. Though, any additional filter has not necessarily effects with other resolvers.
Historical Perspective¶
The original incentive to build resolvers was the situation with retrievers, in the context of the Nautilus API and Nemo UI : Nemo took a retriever as object, which means that, based on the prototype, Nemo was retrieving string objects. That made sense as long as Nemo was running with HTTP remote API because it was actually receiving string objects which were not even (pre-)processed by the Retriever object. But since Nautilus was developed (a fully native python CTS API), we had the situation where Nemo was parsing strings that were exported from python etree objects by Nautilus which parsed strings.
Introducing Resolvers, we managed to avoid this double parsing effect in any situation : MyCapytain now provides a default class to provide access to querying text no matter what kind of transactions there is behind the Python object. At the same time, Resolvers provide a now unified system to retrieve texts independently from the retrieverstandard type (CTS, DTS, Proprietary, etc.).
Prototype¶
-
class
MyCapytain.resolvers.prototypes.
Resolver
[source]¶ Resolver provide a native python API which returns python objects.
Initiation of resolvers are dependent on the implementation of the prototype
-
getMetadata
(objectId=None, **filters)[source]¶ Request metadata about a text or a collection
Parameters: Returns: Collection
-
getReffs
(textId, level=1, subreference=None)[source]¶ Retrieve the siblings of a textual node
Parameters: Returns: List of references
Return type: [str]
-
getSiblings
(textId, subreference)[source]¶ Retrieve the siblings of a textual node
Parameters: Returns: Tuple of references
Return type:
-
Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | from MyCapytain.resolvers.cts.api import HttpCtsResolver
from MyCapytain.retrievers.cts5 import HttpCtsRetriever
from MyCapytain.common.constants import Mimetypes, XPATH_NAMESPACES
# We set up a resolver which communicates with an API available in Leipzig
resolver = HttpCtsResolver(HttpCtsRetriever("http://cts.dh.uni-leipzig.de/api/cts"))
# We require a passage : passage is now a Passage object
# This is an entry from the Smith Myth Dictionary
# The inner methods will resolve to the URI http://cts.dh.uni-leipzig.de/api/cts?request=GetPassage&urn=urn:cts:pdlrefwk:viaf88890045.003.perseus-eng1:A.abaeus_1
# And parse it into interactive objects
passage = resolver.getTextualNode("urn:cts:pdlrefwk:viaf88890045.003.perseus-eng1", "A.abaeus_1")
# We need an export as plaintext
print(passage.export(
output=Mimetypes.PLAINTEXT
))
"""
Abaeus ( Ἀβαῖος ), a surname of Apollo
derived from the town of Abae in Phocis, where the god had a rich temple. (Hesych. s. v.
Ἄβαι ; Hdt. 8.33 ; Paus. 10.35.1 , &c.) [ L.S ]
"""
# We want to find bibliographic information in the passage of this dictionary
# We need an export as LXML ETREE object to perform XPath
print(
passage.export(
output=Mimetypes.PYTHON.ETREE
).xpath(".//tei:bibl/text()", namespaces=XPATH_NAMESPACES, magic_string=False)
)
["Hdt. 8.33", "Paus. 10.35.1"]
|
Project using MyCapytain¶
If you are using MyCapytain and wish to appear here, please feel free to open an issue
Extensions¶
Nautilus¶
Nautilus provides a local retriever to build inventory based on a set of folders available locally.
Flask Capitains Nemo¶
Flask Capitains Nemo is an extension for Flask to build a browsing interface using both retrievers and resources modules. You will find example of use in a web based environment.
HookTest¶
HookTest is a library and command line tools for checking resources against the Capitains Guidelines You’ll find uses mainly in units.py
CLTK Corpora Converter¶
Capitains Corpora Converter Converts CapiTainS-based Repository ( http://capitains.github.io ) to JSON for CLTK
Working with Local CapiTainS XML File¶
Introduction¶
The class MyCapytain.resources.texts.locals.tei.Text
requires the guidelines of Capitains to be implemented in your file.
Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | # We import the correct classes from the local module
from MyCapytain.resources.texts.local.capitains.cts import CapitainsCtsText
from MyCapytain.common.constants import Mimetypes, XPATH_NAMESPACES
from lxml.etree import tostring
# We open a file
with open("./tests/testing_data/examples/text.martial.xml") as f:
# We initiate a Text object giving the IO instance to resource argument
text = CapitainsCtsText(resource=f)
# Text objects have a citation property
# len(Citation(...)) gives the depth of the citation scheme
# in the case of this sample, this would be 3 (Book, Poem, Line)
for ref in text.getReffs(level=len(text.citation)):
# We retrieve a Passage object for each reference that we find
# We can pass the reference many way, including in the form of a list of strings
# We use the _simple parameter to get a fairly simple object
# Simple makes a straight object that has only the targeted node inside of it
psg = text.getTextualNode(subreference=ref, simple=True)
# We print the passage from which we retrieve <note> nodes
print("\t".join([ref, psg.export(Mimetypes.PLAINTEXT, exclude=["tei:note"])]))
"""
You'll print something like the following :
1.pr.1 Spero me secutum in libellis meis tale temperamen-
1.pr.2 tum, ut de illis queri non possit quisquis de se bene
1.pr.3 senserit, cum salva infimarum quoque personarum re-
1.pr.4 verentia ludant; quae adeo antiquis auctoribus defuit, ut
1.pr.5 nominibus non tantum veris abusi sint, sed et magnis.
1.pr.6 Mihi fama vilius constet et probetur in me novissimum
"""
# It is possible that what you're interested in is a little more complex
# Like for example, getting a specific text sample with a specific reference
# In TEI !
# We open another such as Cicero's texts !
with open("./tests/testing_data/examples/text.cicero.xml") as f:
# We initiate a Text object giving the IO instance to resource argument
text = CapitainsCtsText(resource=f)
# We are specifically interest in the portion 28-30
# Note that we won't use 28-30 as cross passage reference won't work properly
p28_29 = text.getTextualNode("28-29")
# And we want to be able to work with the xml
# To be injected in a third party API for lemmatization purposes
xml = p28_29.export(Mimetypes.XML.Std)
print("XML of 28-29")
print(xml)
print("------------")
# But what we really want to do, is suppress the note from the XML.
# So we export to an LXML Object
document = p28_29.export(Mimetypes.PYTHON.ETREE)
# We remove some XML
for element in document.xpath("//tei:note", namespaces=XPATH_NAMESPACES):
element.getparent().remove(element)
# And we print using LXML constants
print("Clean XML of 28-29")
print(tostring(document, encoding=str))
print("------------")
|
Known issues and recommendations¶
XPath Issues¶
lxml, which is the package powering xml support here, does not accept XPath notations such as /div/(a or b)[@n]. Solution for this edge case is /div/*[self::a or self::b][@n]
MyCapytain API Documentation¶
Utilities, metadata and references¶
Module common contains tools such as a namespace dictionary as well as cross-implementation objects, like URN, Citations...
Base¶
-
class
MyCapytain.common.base.
Exportable
(*args, **kwargs)[source] Objects that supports Export
Variables: EXPORT_TO – List of Mimetypes the resource can export to -
export
(output=None, **kwargs)[source] Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
Constants¶
-
class
MyCapytain.common.constants.
Mimetypes
[source] Mimetypes constants that are used to provide export functionality to base MyCapytain object.
Variables: - JSON – JSON Resource mimetype
- XML – XML Resource mimetype
- PYTHON – Python Native Object
- PLAINTEXT – Plain string format
-
class
JSON
[source] Json Mimetype
Variables: - Std – Standard JSON Export
- CTS – CTS Json Export
-
class
DTS
[source] JSON DTS Expression
Variables: - Std – Standard DTS Json-LD Expression
- NoParents – DTS Json-LD Expression without parents expression
-
class
MyCapytain.common.constants.
RDF_NAMESPACES
[source] Namespaces Constants used to provide Namespace capacities across the library
Variables: - CTS – CTS Namespace
- TEI – TEI Namespace
- DC – DC Elements
- CAPITAINS – CapiTainS Ontology
-
MyCapytain.common.constants.
XPATH_NAMESPACES
= {'xml': 'http://www.w3.org/XML/1998/namespace', 'ti': 'http://chs.harvard.edu/xmlns/cts', 'cpt': 'http://purl.org/capitains/ns/1.0#', 'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'xsd': 'http://www.w3.org/2001/XMLSchema#', 'tei': 'http://www.tei-c.org/ns/1.0'} List of XPath Namespaces used in guidelines
URN, References and Citations¶
-
class
MyCapytain.common.reference.
NodeId
(identifier=None, children=None, parent=None, siblings=(None, None), depth=None)[source]¶ Collection of directional references for a Tree
Parameters:
-
class
MyCapytain.common.reference.
URN
(urn)[source]¶ A URN object giving all useful sections
Parameters: urn (str) – A CTS URN
Variables: - NAMESPACE – Constant representing the URN until its namespace
- TEXTGROUP – Constant representing the URN until its textgroup
- WORK – Constant representing the URN until its work
- VERSION – Constant representing the URN until its version
- PASSAGE – Constant representing the URN until its full passage
- PASSAGE_START – Constant representing the URN until its passage (end excluded)
- PASSAGE_END – Constant representing the URN until its passage (start excluded)
- NO_PASSAGE – Constant representing the URN until its passage excluding its passage
- COMPLETE – Constant representing the complete URN
Example: >>> a = URN(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1")
URN object supports the following magic methods : len(), str() and eq(), gt() and lt().
Example: >>> b = URN("urn:cts:latinLit:phi1294.phi002") >>> a != b >>> a > b # It has more member. Only member count is compared >>> b < a >>> len(a) == 5 # Reference is not counted to not induce count equivalencies with the optional version >>> len(b) == 4
-
static
model
()[source]¶ Generate a standard dictionary model for URN inside function
Returns: Dictionary of CTS elements
-
upTo
(key)[source]¶ Returns the urn up to given level using URN Constants
Parameters: key (int) – Identifier of the wished resource using URN constants
Returns: String representation of the partial URN requested
Return type: Example: >>> a = URN(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1") >>> a.upTo(URN.TEXTGROUP) == "urn:cts:latinLit:phi1294"
-
class
MyCapytain.common.reference.
Reference
(reference='')[source]¶ A reference object giving information
Parameters: reference (basestring) – CapitainsCtsPassage Reference part of a Urn
Example: >>> a = Reference(reference="1.1@Achiles[1]-1.2@Zeus[1]") >>> b = Reference(reference="1.1") >>> Reference("1.1-2.2.2").highest == ["1", "1"]
Reference object supports the following magic methods : len(), str() and eq().
Example: >>> len(a) == 2 && len(b) == 1 >>> str(a) == "1.1@Achiles[1]-1.2@Zeus[1]" >>> b == Reference("1.1") && b != a
Note
While Reference(...).subreference and .list are not available for range, Reference(..).start.subreference and Reference(..).end.subreference as well as .list are available
-
static
convert_subreference
(word, counter)[source]¶ Convert a word and a counter into a standard tuple representation
Parameters: - word – Word Element of the subreference
- counter – Index of the Word
Returns: Tuple representing the element
Return type:
-
highest
¶ Return highest reference level
For references such as 1.1-1.2.8, with different level, it can be useful to access to the highest node in the hierarchy. In this case, the highest level would be 1.1. The function would return [“1”, “1”]
Note
By default, this property returns the start level
Return type: Reference
-
static
-
class
MyCapytain.common.reference.
Citation
(name=None, xpath=None, scope=None, refsDecl=None, child=None)[source]¶ 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
Variables: - name – Name of the citation (e.g. “book”)
- xpath – Xpath of the citation (As described by CTS norm)
- scope – Scope of the citation (As described by CTS norm)
- refsDecl – refsDecl version
- child – A citation
-
__iter__
()[source]¶ Iteration method
Loop over the citation childs
Example: >>> c = XmlCtsCitation(name="line") >>> b = XmlCtsCitation(name="poem", child=c) >>> a = XmlCtsCitation(name="book", child=b) >>> [e for e in a] == [a, b, c]
-
fill
(passage=None, xpath=None)[source]¶ Fill the xpath with given informations
Parameters: Return type: Returns: Xpath to find the passage
citation = XmlCtsCitation(name="line", scope="/TEI/text/body/div/div[@n="?"]",xpath="//l[@n="?"]") print(citation.fill(["1", None])) # /TEI/text/body/div/div[@n='1']//l[@n] print(citation.fill(None)) # /TEI/text/body/div/div[@n]//l[@n] print(citation.fill(Reference("1.1")) # /TEI/text/body/div/div[@n='1']//l[@n='1'] print(citation.fill("1", xpath=True) # //l[@n='1']
Metadata containers¶
-
class
MyCapytain.common.metadata.
Metadata
(node=None, *args, **kwargs)[source] A metadatum aggregation object provided to centralize metadata
Parameters: keys ([text_type]) – A metadata field names list
Variables: - EXPORT_TO – List of exportable supported formats
- DEFAULT_EXPORT – Default export (CTS XML Inventory)
- STORE – RDF Store
-
add
(key, value, lang=None)[source] Add a triple to the graph related to this node
Parameters: - key – Predicate of the triple
- value – Object of the triple
- lang – Language of the triple if applicable
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get
(key, lang=None)[source] Returns triple related to this node. Can filter on lang
Parameters: - key – Predicate of the triple
- lang – Language of the triple if applicable
Return type: Literal or BNode or URIRef
-
static
getOr
(subject, predicate, *args, **kwargs)[source] Retrieve a metadata node or generate a new one
Parameters: - subject – Subject to which the metadata node should be connected
- predicate – Predicate by which the metadata node should be connected
Returns: Metadata for given node
Return type: Metadata
-
get_single
(key, lang=None)[source] Returns a single triple related to this node.
Parameters: - key – Predicate of the triple
- lang – Language of the triple if applicable
Return type: Literal or BNode or URIRef
-
graph
Quick access to the graph this node is connected to
Return type: Graph
-
predicate_object
(predicate=None, obj=None)[source] Retrieve predicate and object around this object
Parameters: - predicate – Predicate to match, None to match all
- obj – Object to match, None to match all
Returns: List of resources
-
remove
(predicate=None, obj=None)[source] Remove triple matching the predicate or the object
Parameters: - predicate – Predicate to match, None to match all
- obj – Object to match, None to match all
-
unlink
(subj=None, predicate=None)[source] Remove triple where Metadata is the object
Parameters: - subj – Subject to match, None to match all
- predicate – Predicate to match, None to match all
Utilities¶
-
MyCapytain.common.utils.
LiteralToDict
(value)[source] Transform an object value into a dict readable value
Parameters: value (Literal or URIRef) – Object of a triple which is not a BNode Returns: dict or str or list
-
class
MyCapytain.common.utils.
OrderedDefaultDict
(default_factory=None, *args, **kwargs)[source] Extension of Default Dict that makes an OrderedDefaultDict
Parameters: default_factory – Default class to initiate
-
class
MyCapytain.common.utils.
Subgraph
(namespace_manager)[source] Utility class to generate subgraph around one or more items
:param
-
graphiter
(graph, target, ascendants=0, descendants=1)[source] Iter on a graph to finds object connected
Parameters: - graph (Graph) – Graph to serialize
- target (Node) – Node to iterate over
- ascendants – Number of level to iter over upwards (-1 = No Limit)
- descendants – Number of level to iter over downwards (-1 = No limit)
Returns:
-
-
MyCapytain.common.utils.
copyNode
(node, children=False, parent=False)[source] Copy an XML Node
Parameters: - node – Etree Node
- children – Copy children nodes is set to True
- parent – Append copied node to parent if given
Returns: New Element
-
MyCapytain.common.utils.
expand_namespace
(nsmap, string)[source] If the string starts with a known prefix in nsmap, replace it by full URI
Parameters: - nsmap – Dictionary of prefix -> uri of namespace
- string – String in which to replace the namespace
Returns: Expanded string with no namespace
-
MyCapytain.common.utils.
make_xml_node
(graph, name, close=False, attributes=None, text='', complete=False, innerXML='')[source] Create an XML Node
Parameters: - graph – Graph used to geneates prefixes
- name – Name of the tag
- close – Produce closing tag (close=False -> “<tag>”, close=True -> “</tag>”)
- attributes – Dictionary of attributes
- text – CapitainsCtsText to put inside the node
- complete – Complete node (node with opening and closing tag)
- innerXML – XML to append to the node
Returns: String representation of the node
Return type:
-
MyCapytain.common.utils.
nested_get
(dictionary, keys)[source] Get value in dictionary for dictionary[keys[0]][keys[1]][keys[..n]]
Parameters: - dictionary – An input dictionary
- keys – Keys where to store data
Returns:
-
MyCapytain.common.utils.
nested_ordered_dictionary
()[source] Helper to create a nested ordered default dictionary
Rtype OrderedDefaultDict: Returns: Nested Ordered Default Dictionary instance
-
MyCapytain.common.utils.
nested_set
(dictionary, keys, value)[source] Set value in dictionary for dictionary[keys[0]][keys[1]][keys[..n]]
Parameters: - dictionary – An input dictionary
- keys – Keys where to store data
- value – Value to set at keys** target
Returns: None
-
MyCapytain.common.utils.
normalize
(string)[source] Remove double-or-more spaces in a string
Parameters: string (text_type) – A string to change Return type: text_type Returns: Clean string
-
MyCapytain.common.utils.
normalizeXpath
(xpath)[source] Normalize XPATH split around slashes
Parameters: xpath ([str]) – List of xpath elements Returns: List of refined xpath Return type: [str]
-
MyCapytain.common.utils.
passageLoop
(parent, new_tree, xpath1, xpath2=None, preceding_siblings=False, following_siblings=False)[source] Loop over passages to construct and increment new tree given a parent and XPaths
Parameters: - parent – Parent on which to perform xpath
- new_tree – Parent on which to add nodes
- xpath1 ([str]) – List of xpath elements
- xpath2 ([str]) – List of xpath elements
- preceding_siblings – Append preceding siblings of XPath 1/2 match to the tree
- following_siblings – Append following siblings of XPath 1/2 match to the tree
Returns: Newly incremented tree
-
MyCapytain.common.utils.
performXpath
(parent, xpath)[source] Perform an XPath on an element and indicate if we need to loop over it to find something
Parameters: - parent – XML Node on which to perform XPath
- xpath – XPath to run
Returns: (Result, Need to loop Indicator)
-
MyCapytain.common.utils.
xmliter
(node)[source] Provides a simple XML Iter method which complies with either _Element or _ObjectifiedElement
Parameters: node – XML Node Returns: Iterator for iterating over children of said node.
-
MyCapytain.common.utils.
xmlparser
(xml, objectify=True)[source] Parse xml
Parameters: xml (Union[text_type, lxml.etree._Element]) – XML element Return type: lxml.etree._Element Returns: An element object Raises: TypeError if element is not in accepted type
API Retrievers¶
Module endpoints contains prototypes and implementation of retrievers in MyCapytain
CTS 5 API¶
-
class
MyCapytain.retrievers.cts5.
HttpCtsRetriever
(endpoint, inventory=None)[source] Bases:
MyCapytain.retrievers.prototypes.CtsRetriever
Basic integration of the MyCapytain.retrievers.proto.CTS abstraction
-
call
(parameters)[source] Call an endpoint given the parameters
Parameters: parameters (dict) – Dictionary of parameters Return type: text
-
getCapabilities
(inventory=None, urn=None)[source] Retrieve the inventory information of an API
Parameters: Return type:
-
getFirstUrn
(urn, inventory=None)[source] Retrieve the first passage urn of a text
Parameters: Return type:
-
getLabel
(urn, inventory=None)[source] Retrieve informations about a CTS Urn
Parameters: Return type:
-
getMetadata
(objectId=None, **filters)[source] Request metadata about a text or a collection
Parameters: - objectId – Filter for some object identifier
- filters – Kwargs parameters. URN and Inv are available
Returns: GetCapabilities CTS API request response
-
getPassage
(urn, inventory=None, context=None)[source] Retrieve a passage
Parameters: - urn (text) – URN identifying the text’s passage (Minimum depth : 1)
- inventory (text) – Name of the inventory
- context (int) – Number of citation units at the same level of the citation hierarchy as the requested urn, immediately preceding and immediately following the requested urn to include in the reply
Return type:
-
getPassagePlus
(urn, inventory=None, context=None)[source] Retrieve a passage and information about it
Parameters: - urn (text) – URN identifying the text’s passage (Minimum depth : 1)
- inventory (text) – Name of the inventory
- context (int) – Number of citation units at the same level of the citation hierarchy as the requested urn, immediately preceding and immediately following the requested urn to include in the reply
Return type:
-
getPrevNextUrn
(urn, inventory=None)[source] Retrieve the previous and next passage urn of one passage
Parameters: Return type:
-
getReffs
(textId, level=1, subreference=None)[source] Retrieve the siblings of a textual node
Parameters: Returns: List of references
Return type: [str]
-
getSiblings
(textId, subreference)[source] Retrieve the siblings of a textual node
Parameters: - textId – CtsTextMetadata Identifier
- reference – CapitainsCtsPassage Reference
Returns: GetPrevNextUrn request response from the endpoint
-
getTextualNode
(textId, subreference=None, prevnext=False, metadata=False)[source] Retrieve a text node from the API
Parameters: - textId – CtsTextMetadata Identifier
- subreference – CapitainsCtsPassage Reference
- prevnext – Retrieve graph representing previous and next passage
- metadata – Retrieve metadata about the passage and the text
Returns: GetPassage or GetPassagePlus CTS API request response
-
Prototypes¶
-
class
MyCapytain.retrievers.prototypes.
API
(endpoint)[source] Bases:
object
API Prototype object
Parameters: - self (API) – Object
- endpoint (text) – URL of the API
Variables: endpoint – Url of the endpoint
-
class
MyCapytain.retrievers.prototypes.
CitableTextServiceRetriever
(endpoint)[source] Bases:
MyCapytain.retrievers.prototypes.API
Citable CtsTextMetadata Service retrievers should have at least have some of the following properties
-
getMetadata
(objectId=None, **filters)[source] Request metadata about a text or a collection
Parameters: - objectId – CtsTextMetadata Identifier
- filters – Kwargs parameters. URN and Inv are available
Returns: Metadata of text from an API or the likes as bytes
-
getReffs
(textId, level=1, subreference=None)[source] Retrieve the siblings of a textual node
Parameters: Returns: List of references
Return type: [str]
-
getSiblings
(textId, subreference)[source] Retrieve the siblings of a textual node
Parameters: - textId – CtsTextMetadata Identifier
- subreference – CapitainsCtsPassage Reference
Returns: Siblings references from an API or the likes as bytes
-
getTextualNode
(textId, subreference=None, prevnext=False, metadata=False)[source] Retrieve a text node from the API
Parameters: - textId – CtsTextMetadata Identifier
- subreference – CapitainsCtsPassage Reference
- prevnext – Retrieve graph representing previous and next passage
- metadata – Retrieve metadata about the passage and the text
Returns: CtsTextMetadata of a CapitainsCtsPassage from an API or the likes as bytes
-
-
class
MyCapytain.retrievers.prototypes.
CtsRetriever
(endpoint)[source] Bases:
MyCapytain.retrievers.prototypes.CitableTextServiceRetriever
CTS API Endpoint Prototype
-
getCapabilities
(inventory)[source] Retrieve the inventory information of an API
Parameters: inventory (text) – Name of the inventory Return type: str
-
getFirstUrn
(urn, inventory)[source] Retrieve the first passage urn of a text
Parameters: Return type:
-
getLabel
(urn, inventory)[source] Retrieve informations about a CTS Urn
Parameters: Return type:
-
getMetadata
(objectId=None, **filters) Request metadata about a text or a collection
Parameters: - objectId – CtsTextMetadata Identifier
- filters – Kwargs parameters. URN and Inv are available
Returns: Metadata of text from an API or the likes as bytes
-
getPassage
(urn, inventory, context=None)[source] Retrieve a passage
Parameters: - urn (text) – URN identifying the text’s passage (Minimum depth : 1)
- inventory (text) – Name of the inventory
- context (int) – Number of citation units at the same level of the citation hierarchy as the requested urn, immediately preceding and immediately following the requested urn to include in the reply
Return type:
-
getPassagePlus
(urn, inventory, context=None)[source] Retrieve a passage and informations about it
Parameters: - urn (text) – URN identifying the text’s passage (Minimum depth : 1)
- inventory (text) – Name of the inventory
- context (int) – Number of citation units at the same level of the citation hierarchy as the requested urn, immediately preceding and immediately following the requested urn to include in the reply
Return type:
-
getPrevNextUrn
(urn, inventory)[source] Retrieve the previous and next passage urn of one passage
Parameters: Return type:
-
getReffs
(textId, level=1, subreference=None) Retrieve the siblings of a textual node
Parameters: Returns: List of references
Return type: [str]
-
getSiblings
(textId, subreference) Retrieve the siblings of a textual node
Parameters: - textId – CtsTextMetadata Identifier
- subreference – CapitainsCtsPassage Reference
Returns: Siblings references from an API or the likes as bytes
-
getTextualNode
(textId, subreference=None, prevnext=False, metadata=False) Retrieve a text node from the API
Parameters: - textId – CtsTextMetadata Identifier
- subreference – CapitainsCtsPassage Reference
- prevnext – Retrieve graph representing previous and next passage
- metadata – Retrieve metadata about the passage and the text
Returns: CtsTextMetadata of a CapitainsCtsPassage from an API or the likes as bytes
-
Resolvers¶
Remote CTS API¶
-
class
MyCapytain.resolvers.cts.api.
HttpCtsResolver
(endpoint)[source]¶ HttpCtsResolver provide a resolver for CTS API http endpoint.
Parameters: endpoint (HttpCtsRetriever) – CTS API Retriever Variables: endpoint – CTS API Retriever -
endpoint
¶ CTS Endpoint of the resolver
Returns: CTS Endpoint Return type: HttpCtsRetriever
-
getMetadata
(objectId=None, **filters)[source]¶ Request metadata about a text or a collection
Parameters: Returns: Collection
-
getReffs
(textId, level=1, subreference=None)[source]¶ Retrieve the siblings of a textual node
Parameters: Returns: List of references
Return type: [str]
-
getSiblings
(textId, subreference)[source]¶ Retrieve the siblings of a textual node
Parameters: Returns: Tuple of references
Return type:
-
Local CapiTainS Guidelines CTS Resolver¶
-
class
MyCapytain.resolvers.cts.local.
CtsCapitainsLocalResolver
(resource, name=None, logger=None, dispatcher=None)[source]¶ XML Folder Based resolver. CtsTextMetadata and metadata resolver based on local directories
Parameters: Variables: - TEXT_CLASS – CtsTextMetadata Class [not instantiated] to be used to parse Texts. Can be changed to support Cache for example
- DEFAULT_PAGE – Default Page to show
- PER_PAGE – Tuple representing the minimal number of texts returned, the default number and the maximum number of texts returned
-
TEXT_CLASS
¶ alias of
CapitainsCtsText
-
getMetadata
(objectId=None, **filters)[source]¶ Request metadata about a text or a collection
Parameters: Returns: Collection
-
getReffs
(textId, level=1, subreference=None)[source]¶ Retrieve the siblings of a textual node
Parameters: Returns: List of references
Return type: [str]
-
getSiblings
(textId, subreference)[source]¶ Retrieve the siblings of a textual node
Parameters: Returns: Tuple of references
Return type:
-
getTextualNode
(textId, subreference=None, prevnext=False, metadata=False)[source]¶ Retrieve a text node from the API
Parameters: Returns: CapitainsCtsPassage
Return type:
-
static
pagination
(page, limit, length)[source]¶ Help for pagination :param page: Provided Page :param limit: Number of item to show :param length: Length of the list to paginate :return: (Start Index, End Index, Page Number, Item Count)
Dispatcher¶
-
class
MyCapytain.resolvers.utils.
CollectionDispatcher
(collection, default_inventory_name=None)[source] Collection Dispatcher provides a utility to divide automatically texts and collections into different collections
Parameters: - collection – The root collection
- default_inventory_name – The default name of the default collection
-
add
(func, inventory_name)[source] Register given function as a filter.
If this function “func” returns True when given an object, said object will be dispatched to Collection(inventory_name)
Parameters: - func – Callable
- inventory_name – Identifier of the collection to dispatch to
-
dispatch
(collection, **kwargs)[source] Dispatch a collection using internal filters
Parameters: - collection – Collection object
- kwargs – Additional keyword arguments that could be used by internal filters
Returns: None
Raises:
-
inventory
(inventory_name)[source] Decorator to register filters for given inventory. For a function “abc”, it has the same effect
Parameters: inventory_name – Returns: tic = CtsTextInventoryCollection() latin = CtsTextInventoryMetadata("urn:perseus:latinLit", parent=tic) latin.set_label("Classical Latin", "eng") dispatcher = CollectionDispatcher(tic) @dispatcher.inventory("urn:perseus:latinLit") def dispatchLatinLit(collection, path=None, **kwargs): if collection.id.startswith("urn:cts:latinLit:"): return True return False
-
methods
List of methods to dispatch resources.
- Each element is a tuple with two elements :
- First one is the inventory identifier to dispatch to
- Second one is a function which, if returns true, will activate dispatching to given
Return type: List
Prototypes¶
-
class
MyCapytain.resolvers.prototypes.
Resolver
[source] Resolver provide a native python API which returns python objects.
Initiation of resolvers are dependent on the implementation of the prototype
-
getMetadata
(objectId=None, **filters)[source] Request metadata about a text or a collection
Parameters: Returns: Collection
-
getReffs
(textId, level=1, subreference=None)[source] Retrieve the siblings of a textual node
Parameters: Returns: List of references
Return type: [str]
-
getSiblings
(textId, subreference)[source] Retrieve the siblings of a textual node
Parameters: Returns: Tuple of references
Return type:
-
getTextualNode
(textId, subreference=None, prevnext=False, metadata=False)[source] Retrieve a text node from the API
Parameters: Returns: CapitainsCtsPassage
Return type:
-
Texts and inventories¶
Text¶
TEI based texts¶
-
class
MyCapytain.resources.texts.base.tei.
TEIResource
(resource, **kwargs)[source]¶ Bases:
MyCapytain.resources.prototypes.text.InteractiveTextualNode
TEI Encoded Resource
Parameters: resource (Union[str,_Element]) – XML Resource that needs to be parsed into a CapitainsCtsPassage/CtsTextMetadata
Variables: - EXPORT_TO – List of exportable supported formats
- DEFAULT_EXPORT – Default export (Plain/CtsTextMetadata)
-
DEFAULT_EXPORT
= 'text/plain'¶
-
EXPORT_TO
= ['python/lxml', 'text/xml', 'python/NestedDict', 'text/plain', 'text/xml:tei']¶
-
asNode
()¶
-
children
¶ Children Passages
Return type: iterator(CapitainsCtsPassage)
-
citation
¶ XmlCtsCitation Object of the CtsTextMetadata
Returns: XmlCtsCitation Object of the CtsTextMetadata Return type: Citation
-
default_exclude
= []¶
-
export
(output=None, exclude=None, **kwargs)¶ Export the collection item in the Mimetype required.
..note:: If current implementation does not have special mimetypes, reuses default_export method
Parameters: Returns: Object using a different representation
-
export_capacities
¶ List Mimetypes that current object can export to
-
first
¶ First CapitainsCtsPassage
Return type: Passage
-
firstId
¶ First child of current CapitainsCtsPassage
Return type: str Returns: First passage node Information
-
getReffs
(level=1, subreference=None)¶ Reference available at a given level
Parameters: - level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
- passage (Reference) – Subreference (optional)
Return type: [text_type]
Returns: List of levels
-
getTextualNode
(subreference)¶ Retrieve a passage and store it in the object
Parameters: subreference (str or Node or Reference) – Reference of the passage to retrieve Return type: TextualNode Returns: Object representing the passage Raises: TypeError when reference is not a list or a Reference
-
get_creator
(lang=None)¶ Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_description
(lang=None)¶ Get the description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_subject
(lang=None)¶ Get the subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None)¶ Get the title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
¶
-
id
¶ Identifier of the text
Returns: Identifier of the text Return type: text_type
-
last
¶ Last CapitainsCtsPassage
Return type: Passage
-
lastId
¶ Last child of current CapitainsCtsPassage
Return type: str Returns: Last passage Node representation
-
metadata
¶ Metadata information about the text
Returns: Collection object with metadata about the text Return type: Metadata
-
next
¶ Get Next CapitainsCtsPassage
Return type: Passage
-
parent
¶ Parent CapitainsCtsPassage
Return type: Passage
-
prev
¶ Get Previous CapitainsCtsPassage
Return type: Passage
-
set_creator
(value, lang)¶ Set the DC Creator literal value
Parameters: lang – Language in which the value is
-
set_description
(value, lang=None)¶ Set the DC Description literal value
Parameters: lang – Language in which the value is
-
set_subject
(value, lang=None)¶ Set the DC Subject literal value
Parameters: lang – Language in which the value is
-
set_title
(value, lang=None)¶ Set the DC Title literal value
Parameters: lang – Language in which the value is
-
text
¶ String representation of the text
Returns: String representation of the text Return type: text_type
-
xml
¶ XML Representation of the CapitainsCtsPassage
Return type: lxml.etree._Element Returns: XML element representing the passage
Locally read text¶
-
class
MyCapytain.resources.texts.local.capitains.cts.
CapitainsCtsText
(urn=None, citation=None, resource=None)[source]¶ Bases:
MyCapytain.resources.texts.local.capitains.cts.__SharedMethods__
,MyCapytain.resources.texts.base.tei.TEIResource
,MyCapytain.resources.prototypes.text.CitableText
Implementation of CTS tools for local files
Parameters: - urn (MyCapytain.common.reference.URN) – A URN identifier
- resource (lxml.etree._Element) – A resource
- citation (Citation) – Highest XmlCtsCitation level
- autoreffs (bool) – Parse references on load (default : True)
Variables: resource – lxml
-
DEFAULT_EXPORT
= 'text/plain'¶
-
EXPORT_TO
= ['python/lxml', 'text/xml', 'python/NestedDict', 'text/plain', 'text/xml:tei']¶
-
asNode
()¶
-
children
¶ Children Passages
Return type: iterator(CapitainsCtsPassage)
-
citation
¶ XmlCtsCitation Object of the CtsTextMetadata
Returns: XmlCtsCitation Object of the CtsTextMetadata Return type: Citation
-
default_exclude
= []¶
-
export
(output=None, exclude=None, **kwargs)¶ Export the collection item in the Mimetype required.
..note:: If current implementation does not have special mimetypes, reuses default_export method
Parameters: Returns: Object using a different representation
-
export_capacities
¶ List Mimetypes that current object can export to
-
first
¶ First CapitainsCtsPassage
Return type: Passage
-
firstId
¶ First child of current CapitainsCtsPassage
Return type: str Returns: First passage node Information
-
getLabel
()¶ Retrieve metadata about the text
Return type: Collection Returns: Retrieve Label informations in a Collection format
-
getReffs
(level=1, subreference=None)¶ Reference available at a given level
Parameters: - level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
- subreference (str) – Subreference (optional)
Return type: List.basestring
Returns: List of levels
-
getTextualNode
(subreference=None, simple=False)¶ Finds a passage in the current text
Parameters: Return type: CapitainsCtsPassage, ContextPassage
Returns: Asked passage
-
getValidReff
(level=None, reference=None, _debug=False)¶ Retrieve valid passages directly
Parameters: Returns: List of levels
Return type: Note
GetValidReff works for now as a loop using CapitainsCtsPassage, subinstances of CtsTextMetadata, to retrieve the valid informations. Maybe something is more powerfull ?
-
get_creator
(lang=None)¶ Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_cts_metadata
(key, lang=None)¶
-
get_description
(lang=None)¶ Get the description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_subject
(lang=None)¶ Get the subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None)¶ Get the title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
¶
-
id
¶ Identifier of the text
Returns: Identifier of the text Return type: text_type
-
last
¶ Last CapitainsCtsPassage
Return type: Passage
-
lastId
¶ Last child of current CapitainsCtsPassage
Return type: str Returns: Last passage Node representation
-
metadata
¶ Metadata information about the text
Returns: Collection object with metadata about the text Return type: Metadata
-
next
¶ Get Next CapitainsCtsPassage
Return type: Passage
-
parent
¶ Parent CapitainsCtsPassage
Return type: Passage
-
prev
¶ Get Previous CapitainsCtsPassage
Return type: Passage
-
set_creator
(value, lang)¶ Set the DC Creator literal value
Parameters: lang – Language in which the value is
-
set_description
(value, lang=None)¶ Set the DC Description literal value
Parameters: lang – Language in which the value is
-
set_metadata_from_collection
(text_metadata)¶ Set the object metadata using its collections recursively
Parameters: text_metadata (CtsEditionMetadata or CtsTranslationMetadata) – Object representing the current text as a collection
-
set_subject
(value, lang=None)¶ Set the DC Subject literal value
Parameters: lang – Language in which the value is
-
set_title
(value, lang=None)¶ Set the DC Title literal value
Parameters: lang – Language in which the value is
-
text
¶ String representation of the text
Returns: String representation of the text Return type: text_type
-
textObject
¶ Textual Object with full capacities (Unlike Simple CapitainsCtsPassage)
Return type: CtsTextMetadata, CapitainsCtsPassage Returns: Textual Object with full capacities (Unlike Simple CapitainsCtsPassage)
-
tostring
(*args, **kwargs)¶ Transform the CapitainsCtsPassage in XML string
Parameters: - args – Ordered arguments for etree.tostring() (except the first one)
- kwargs – Named arguments
Returns:
-
xml
¶ XML Representation of the CapitainsCtsPassage
Return type: lxml.etree._Element Returns: XML element representing the passage
-
class
MyCapytain.resources.texts.local.capitains.cts.
CapitainsCtsPassage
(reference, urn=None, citation=None, resource=None, text=None)[source]¶ Bases:
MyCapytain.resources.texts.local.capitains.cts.__SharedMethods__
,MyCapytain.resources.texts.base.tei.TEIResource
,MyCapytain.resources.prototypes.text.Passage
CapitainsCtsPassage class for local texts which rebuilds the tree up to the passage.
For design purposes, some people would prefer the output of GetPassage to be consistent. ContextPassage rebuilds the tree of the text up to the passage, keeping attributes of original nodes
Example : for a text with a citation scheme with following refsDecl : /TEI/text/body/div[@type=’edition’]/div[@n=’$1’]/div[@n=’$2’]/l[@n=’$3’] and a passage 1.1.1-1.2.3, this class will build an XML tree looking like the following
<TEI ...> <text ...> <body ...> <div type='edition' ...> <div n='1' ...> <div n='1' ...> <l n='1'>...</l> ... </div> <div n='2' ...> <l n='3'>...</l> </div> </div> </div> </body> </text> </TEI>
Parameters: Note
.prev, .next, .first and .last won’t run on passage with a range made of two different level, such as 1.1-1.2.3 or 1-a.b. Those will raise InvalidSiblingRequest
-
DEFAULT_EXPORT
= 'text/plain'¶
-
EXPORT_TO
= ['python/lxml', 'text/xml', 'python/NestedDict', 'text/plain', 'text/xml:tei']¶
-
asNode
()¶
-
childIds
¶ Children of the passage
Return type: None, Reference Returns: Dictionary of chidren, where key are subreferences
-
children
¶ Children Passages
Return type: iterator(CapitainsCtsPassage)
-
citation
¶ XmlCtsCitation Object of the CtsTextMetadata
Returns: XmlCtsCitation Object of the CtsTextMetadata Return type: Citation
-
default_exclude
= []¶
-
export
(output=None, exclude=None, **kwargs)¶ Export the collection item in the Mimetype required.
..note:: If current implementation does not have special mimetypes, reuses default_export method
Parameters: Returns: Object using a different representation
-
export_capacities
¶ List Mimetypes that current object can export to
-
first
¶ First CapitainsCtsPassage
Return type: Passage
-
firstId
¶ First child of current CapitainsCtsPassage
Return type: str Returns: First passage node Information
-
getLabel
()¶ Retrieve metadata about the text
Return type: Collection Returns: Retrieve Label informations in a Collection format
-
getReffs
(level=1, subreference=None)¶ Reference available at a given level
Parameters: - level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
- subreference (str) – Subreference (optional)
Return type: List.basestring
Returns: List of levels
-
getValidReff
(level=None, reference=None, _debug=False)¶ Retrieve valid passages directly
Parameters: Returns: List of levels
Return type: Note
GetValidReff works for now as a loop using CapitainsCtsPassage, subinstances of CtsTextMetadata, to retrieve the valid informations. Maybe something is more powerfull ?
-
get_creator
(lang=None)¶ Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_cts_metadata
(key, lang=None)¶
-
get_description
(lang=None)¶ Get the description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_subject
(lang=None)¶ Get the subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None)¶ Get the title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
¶
-
id
¶ Identifier of the text
Returns: Identifier of the text Return type: text_type
-
last
¶ Last CapitainsCtsPassage
Return type: Passage
-
lastId
¶ Last child of current CapitainsCtsPassage
Return type: str Returns: Last passage Node representation
-
metadata
¶ Metadata information about the text
Returns: Collection object with metadata about the text Return type: Metadata
-
next
¶ Next CapitainsCtsPassage (Interactive CapitainsCtsPassage)
-
parent
¶ Parent CapitainsCtsPassage
Return type: Passage
-
prev
¶ Previous CapitainsCtsPassage (Interactive CapitainsCtsPassage)
-
prevId
¶ Get the Previous passage reference
Returns: Previous passage reference at the same level Return type: None, Reference
-
reference
¶ Reference of the object
-
set_creator
(value, lang)¶ Set the DC Creator literal value
Parameters: lang – Language in which the value is
-
set_description
(value, lang=None)¶ Set the DC Description literal value
Parameters: lang – Language in which the value is
-
set_metadata_from_collection
(text_metadata)¶ Set the object metadata using its collections recursively
Parameters: text_metadata (CtsEditionMetadata or CtsTranslationMetadata) – Object representing the current text as a collection
-
set_subject
(value, lang=None)¶ Set the DC Subject literal value
Parameters: lang – Language in which the value is
-
set_title
(value, lang=None)¶ Set the DC Title literal value
Parameters: lang – Language in which the value is
-
text
¶ String representation of the text
Returns: String representation of the text Return type: text_type
-
textObject
¶ CtsTextMetadata Object. Required for NextPrev
Return type: CapitainsCtsText
-
tostring
(*args, **kwargs)¶ Transform the CapitainsCtsPassage in XML string
Parameters: - args – Ordered arguments for etree.tostring() (except the first one)
- kwargs – Named arguments
Returns:
-
xml
¶ XML Representation of the CapitainsCtsPassage
Return type: lxml.etree._Element Returns: XML element representing the passage
-
-
class
MyCapytain.resources.texts.local.capitains.cts.
__SimplePassage__
(resource, reference, citation, text, urn=None)[source]¶ Bases:
MyCapytain.resources.texts.local.capitains.cts.__SharedMethods__
,MyCapytain.resources.texts.base.tei.TEIResource
,MyCapytain.resources.prototypes.text.Passage
CapitainsCtsPassage for simple and quick parsing of texts
Parameters: - resource (etree._Element) – Element representing the passage
- reference (Reference) – CapitainsCtsPassage reference
- urn (URN) – URN of the source text or of the passage
- citation (Citation) – XmlCtsCitation scheme of the text
- text (CapitainsCtsText) – CtsTextMetadata containing the passage
-
childIds
¶ Children of the passage
Return type: None, Reference Returns: Dictionary of chidren, where key are subreferences
-
children
¶ Children Passages
Return type: iterator(CapitainsCtsPassage)
-
citation
¶ XmlCtsCitation Object of the CtsTextMetadata
Returns: XmlCtsCitation Object of the CtsTextMetadata Return type: Citation
-
export
(output=None, exclude=None, **kwargs)¶ Export the collection item in the Mimetype required.
..note:: If current implementation does not have special mimetypes, reuses default_export method
Parameters: Returns: Object using a different representation
-
export_capacities
¶ List Mimetypes that current object can export to
-
first
¶ First CapitainsCtsPassage
Return type: Passage
-
firstId
¶ First child of current CapitainsCtsPassage
Return type: str Returns: First passage node Information
-
getLabel
()¶ Retrieve metadata about the text
Return type: Collection Returns: Retrieve Label informations in a Collection format
-
getReffs
(level=1, subreference=None)[source]¶ Reference available at a given level
Parameters: - level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
- subreference (Reference) – Subreference (optional)
Return type: List.basestring
Returns: List of levels
-
getTextualNode
(subreference=None)[source]¶ Special GetPassage implementation for SimplePassage (Simple is True by default)
Parameters: subreference – Returns:
-
getValidReff
(level=None, reference=None, _debug=False)¶ Retrieve valid passages directly
Parameters: Returns: List of levels
Return type: Note
GetValidReff works for now as a loop using CapitainsCtsPassage, subinstances of CtsTextMetadata, to retrieve the valid informations. Maybe something is more powerfull ?
-
get_creator
(lang=None)¶ Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_description
(lang=None)¶ Get the description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_subject
(lang=None)¶ Get the subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None)¶ Get the title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
id
¶ Identifier of the text
Returns: Identifier of the text Return type: text_type
-
last
¶ Last CapitainsCtsPassage
Return type: Passage
-
lastId
¶ Last child of current CapitainsCtsPassage
Return type: str Returns: Last passage Node representation
-
metadata
¶ Metadata information about the text
Returns: Collection object with metadata about the text Return type: Metadata
-
next
¶ Get Next CapitainsCtsPassage
Return type: Passage
-
parent
¶ Parent CapitainsCtsPassage
Return type: Passage
-
prev
¶ Get Previous CapitainsCtsPassage
Return type: Passage
-
prevId
¶ Get the Previous passage reference
Returns: Previous passage reference at the same level Return type: None, Reference
-
set_creator
(value, lang)¶ Set the DC Creator literal value
Parameters: lang – Language in which the value is
-
set_description
(value, lang=None)¶ Set the DC Description literal value
Parameters: lang – Language in which the value is
-
set_metadata_from_collection
(text_metadata)¶ Set the object metadata using its collections recursively
Parameters: text_metadata (CtsEditionMetadata or CtsTranslationMetadata) – Object representing the current text as a collection
-
set_subject
(value, lang=None)¶ Set the DC Subject literal value
Parameters: lang – Language in which the value is
-
set_title
(value, lang=None)¶ Set the DC Title literal value
Parameters: lang – Language in which the value is
-
text
¶ String representation of the text
Returns: String representation of the text Return type: text_type
-
textObject
¶ CtsTextMetadata Object. Required for NextPrev
Return type: CapitainsCtsText
-
tostring
(*args, **kwargs)¶ Transform the CapitainsCtsPassage in XML string
Parameters: - args – Ordered arguments for etree.tostring() (except the first one)
- kwargs – Named arguments
Returns:
-
xml
¶ XML Representation of the CapitainsCtsPassage
Return type: lxml.etree._Element Returns: XML element representing the passage
CTS API Texts¶
Formerly MyCapytain.resources.texts.api (< 2.0.0)
-
class
MyCapytain.resources.texts.remote.cts.
CtsText
(urn, retriever, citation=None, **kwargs)[source]¶ Bases:
MyCapytain.resources.texts.remote.cts.__SharedMethod__
,MyCapytain.resources.prototypes.text.CitableText
API CtsTextMetadata object
Parameters: -
DEFAULT_EXPORT
= None¶
-
DEFAULT_LANG
= 'eng'¶
-
EXPORT_TO
= []¶
-
asNode
()¶
-
children
¶ Children Passages
Return type: iterator(CapitainsCtsPassage)
-
citation
¶ XmlCtsCitation Object of the CtsTextMetadata
Returns: XmlCtsCitation Object of the CtsTextMetadata Return type: Citation
-
default_exclude
= []¶
-
depth
¶ Depth of the current opbject
Returns: Int representation of the depth based on URN information Return type: int
-
export
(output='text/plain', exclude=None, **kwargs)[source]¶ Export the collection item in the Mimetype required.
..note:: If current implementation does not have special mimetypes, reuses default_export method
Parameters: Returns: Object using a different representation
-
export_capacities
¶ List Mimetypes that current object can export to
-
first
¶ First CapitainsCtsPassage
Return type: Passage
-
firstId
¶ Children passage
Return type: str Returns: First children of the graph. Shortcut to self.graph.children[0]
-
firstUrn
(resource)¶ Parse a resource to get the first URN
Parameters: resource (etree._Element) – XML Resource Returns: Tuple representing previous and next urn Return type: str
-
getFirstUrn
(reference=None)¶ Get the first children URN for a given resource
Parameters: reference (Reference, str) – Reference from which to find child (If None, find first reference) Returns: Children URN Return type: URN
-
getLabel
()¶ Retrieve metadata about the text
Return type: Metadata Returns: Dictionary with label informations
-
getPassagePlus
(reference=None)¶ Retrieve a passage and informations around it and store it in the object
Parameters: reference (Reference or List of text_type) – Reference of the passage Return type: CtsPassage Returns: Object representing the passage Raises: TypeError when reference is not a list or a Reference
-
getPrevNextUrn
(reference)¶ Get the previous URN of a reference of the text
Parameters: reference (Union[Reference, str]) – Reference from which to find siblings Returns: (Previous CapitainsCtsPassage Reference,Next CapitainsCtsPassage Reference)
-
getReffs
(level=1, subreference=None)¶ Reference available at a given level
Parameters: - level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
- subreference (Reference) – Subreference (optional)
Return type: [text_type]
Returns: List of levels
-
getTextualNode
(subreference=None)¶ Retrieve a passage and store it in the object
Parameters: subreference (Union[Reference, URN, str, list]) – Reference of the passage (Note : if given a list, this should be a list of string that compose the reference) Return type: CtsPassage Returns: Object representing the passage Raises: TypeError when reference is not a list or a Reference
-
getValidReff
(level=1, reference=None)¶ Given a resource, CitableText will compute valid reffs
Parameters: - level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
- reference (Reference) – CapitainsCtsPassage reference
Return type: Returns: List of levels
-
get_creator
(lang=None)¶ Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_cts_metadata
(key, lang=None)¶
-
get_description
(lang=None)¶ Get the description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_subject
(lang=None)¶ Get the subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None)¶ Get the title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
¶
-
id
¶ Identifier of the text
Returns: Identifier of the text Return type: text_type
-
last
¶ Last CapitainsCtsPassage
Return type: Passage
-
lastId
¶ Children passage
Return type: str Returns: First children of the graph. Shortcut to self.graph.children[0]
-
metadata
¶ Metadata information about the text
Returns: Collection object with metadata about the text Return type: Metadata
-
next
¶
-
nextId
¶
-
parent
¶ Parent CapitainsCtsPassage
Return type: Passage
-
prev
¶
-
prevId
¶
-
prevnext
(resource)¶ 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)
-
reffs
¶ Get all valid reffs for every part of the CitableText
Return type: MyCapytain.resources.texts.tei.XmlCtsCitation
-
retriever
¶ Retriever object used to query for more data
Return type: CitableTextServiceRetriever
-
set_creator
(value, lang)¶ Set the DC Creator literal value
Parameters: lang – Language in which the value is
-
set_description
(value, lang=None)¶ Set the DC Description literal value
Parameters: lang – Language in which the value is
-
set_metadata_from_collection
(text_metadata)¶ Set the object metadata using its collections recursively
Parameters: text_metadata (CtsEditionMetadata or CtsTranslationMetadata) – Object representing the current text as a collection
-
set_subject
(value, lang=None)¶ Set the DC Subject literal value
Parameters: lang – Language in which the value is
-
set_title
(value, lang=None)¶ Set the DC Title literal value
Parameters: lang – Language in which the value is
-
siblingsId
¶
-
text
¶ String representation of the text
Returns: String representation of the text Return type: text_type
-
-
class
MyCapytain.resources.texts.remote.cts.
CtsPassage
(urn, resource, *args, **kwargs)[source]¶ Bases:
MyCapytain.resources.texts.remote.cts.__SharedMethod__
,MyCapytain.resources.prototypes.text.Passage
,MyCapytain.resources.texts.base.tei.TEIResource
CapitainsCtsPassage representing
Parameters: - urn –
- resource –
- retriever –
- args –
- kwargs –
-
DEFAULT_EXPORT
= 'text/plain'¶
-
EXPORT_TO
= ['python/lxml', 'text/xml', 'python/NestedDict', 'text/plain', 'text/xml:tei']¶
-
asNode
()¶
-
children
¶ Children Passages
Return type: iterator(CapitainsCtsPassage)
-
citation
¶ XmlCtsCitation Object of the CtsTextMetadata
Returns: XmlCtsCitation Object of the CtsTextMetadata Return type: Citation
-
default_exclude
= []¶
-
depth
¶ Depth of the current opbject
Returns: Int representation of the depth based on URN information Return type: int
-
export
(output=None, exclude=None, **kwargs)¶ Export the collection item in the Mimetype required.
..note:: If current implementation does not have special mimetypes, reuses default_export method
Parameters: Returns: Object using a different representation
-
export_capacities
¶ List Mimetypes that current object can export to
-
first
¶ First CapitainsCtsPassage
Return type: Passage
-
firstId
¶ Children passage
Return type: str Returns: First children of the graph. Shortcut to self.graph.children[0]
-
firstUrn
(resource)¶ Parse a resource to get the first URN
Parameters: resource (etree._Element) – XML Resource Returns: Tuple representing previous and next urn Return type: str
-
getFirstUrn
(reference=None)¶ Get the first children URN for a given resource
Parameters: reference (Reference, str) – Reference from which to find child (If None, find first reference) Returns: Children URN Return type: URN
-
getLabel
()¶ Retrieve metadata about the text
Return type: Metadata Returns: Dictionary with label informations
-
getPassagePlus
(reference=None)¶ Retrieve a passage and informations around it and store it in the object
Parameters: reference (Reference or List of text_type) – Reference of the passage Return type: CtsPassage Returns: Object representing the passage Raises: TypeError when reference is not a list or a Reference
-
getPrevNextUrn
(reference)¶ Get the previous URN of a reference of the text
Parameters: reference (Union[Reference, str]) – Reference from which to find siblings Returns: (Previous CapitainsCtsPassage Reference,Next CapitainsCtsPassage Reference)
-
getReffs
(level=1, subreference=None)¶ Reference available at a given level
Parameters: - level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
- subreference (Reference) – Subreference (optional)
Return type: [text_type]
Returns: List of levels
-
getTextualNode
(subreference=None)¶ Retrieve a passage and store it in the object
Parameters: subreference (Union[Reference, URN, str, list]) – Reference of the passage (Note : if given a list, this should be a list of string that compose the reference) Return type: CtsPassage Returns: Object representing the passage Raises: TypeError when reference is not a list or a Reference
-
getValidReff
(level=1, reference=None)¶ Given a resource, CitableText will compute valid reffs
Parameters: - level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
- reference (Reference) – CapitainsCtsPassage reference
Return type: Returns: List of levels
-
get_creator
(lang=None)¶ Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_cts_metadata
(key, lang=None)¶
-
get_description
(lang=None)¶ Get the description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_subject
(lang=None)¶ Get the subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None)¶ Get the title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
¶
-
id
¶
-
last
¶ Last CapitainsCtsPassage
Return type: Passage
-
lastId
¶ Children passage
Return type: str Returns: First children of the graph. Shortcut to self.graph.children[0]
-
metadata
¶ Metadata information about the text
Returns: Collection object with metadata about the text Return type: Metadata
-
next
¶ Get Next CapitainsCtsPassage
Return type: Passage
-
nextId
¶ Shortcut for getting the following passage identifier
Return type: Reference Returns: Following passage reference
-
parent
¶ Parent CapitainsCtsPassage
Return type: Passage
-
parentId
¶ Shortcut for getting the parent passage identifier
Return type: Reference Returns: Following passage reference
-
prev
¶ Get Previous CapitainsCtsPassage
Return type: Passage
-
prevId
¶ Previous passage Identifier
Return type: CtsPassage Returns: Previous passage at same level
-
prevnext
(resource)¶ 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)
-
reference
¶
-
retriever
¶ Retriever object used to query for more data
Return type: CitableTextServiceRetriever
-
set_creator
(value, lang)¶ Set the DC Creator literal value
Parameters: lang – Language in which the value is
-
set_description
(value, lang=None)¶ Set the DC Description literal value
Parameters: lang – Language in which the value is
-
set_metadata_from_collection
(text_metadata)¶ Set the object metadata using its collections recursively
Parameters: text_metadata (CtsEditionMetadata or CtsTranslationMetadata) – Object representing the current text as a collection
-
set_subject
(value, lang=None)¶ Set the DC Subject literal value
Parameters: lang – Language in which the value is
-
set_title
(value, lang=None)¶ Set the DC Title literal value
Parameters: lang – Language in which the value is
-
siblingsId
¶ Shortcut for getting the previous and next passage identifier
Return type: Reference Returns: Following passage reference
-
text
¶ String representation of the text
Returns: String representation of the text Return type: text_type
-
xml
¶ XML Representation of the CapitainsCtsPassage
Return type: lxml.etree._Element Returns: XML element representing the passage
Collections¶
Metadata¶
-
class
MyCapytain.resources.prototypes.metadata.
Collection
(identifier='', *args, **kwargs)[source] Bases:
MyCapytain.common.base.Exportable
Collection represents any resource’s metadata. It has members and parents
Variables: - properties – Properties of the collection
- parents – Parent of the node from the direct parent to the highest ascendant
- metadata – Metadata
-
DEFAULT_EXPORT
= None
-
EXPORT_TO
= ['application/ld+json', 'application/ld+json:DTS', 'application/rdf+xml']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/collection')
-
TYPE_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/collection')
-
asNode
()[source] Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Any descendant (no max level) of the collection’s item
Return type: [Collection]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_label
(lang=None)[source] Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
members
Children of the collection’s item
Return type: [Collection]
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
readable
Readable property should return elements where the element can be queried for getPassage / getReffs
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_label
(label, lang)[source] Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
size
-
type
-
version
-
class
MyCapytain.resources.prototypes.metadata.
ResourceCollection
(identifier='', *args, **kwargs)[source] Bases:
MyCapytain.resources.prototypes.metadata.Collection
-
DEFAULT_EXPORT
= None
-
EXPORT_TO
= ['application/ld+json', 'application/ld+json:DTS', 'application/rdf+xml']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/collection')
-
TYPE_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/collection')
-
asNode
() Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Any descendant (no max level) of the collection’s item
Return type: [Collection]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_creator
(lang=None)[source] Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_description
(lang=None)[source] Get the description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_label
(lang=None) Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
get_subject
(lang=None)[source] Get the subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None)[source] Get the title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
lang
Languages this text is in
Returns: List of available languages
-
members
Children of the collection’s item
Return type: [Collection]
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
readable
Readable property should return elements where the element can be queried for getPassage / getReffs
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_label
(label, lang) Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
size
-
type
-
version
-
CTS inventory¶
-
class
MyCapytain.resources.collections.cts.
XmlCtsCitation
(name=None, xpath=None, scope=None, refsDecl=None, child=None)[source] Bases:
MyCapytain.common.reference.Citation
XmlCtsCitation XML implementation for CtsTextInventoryMetadata
-
DEFAULT_EXPORT
= 'text/xml:CTS'
-
EXPORT_TO
= ['text/xml:CTS', 'text/xml:tei']
-
attribute
Attribute that serves as a reference getter
-
child
Child of a citation
Type: XmlCtsCitation or None Example: XmlCtsCitation.name==poem would have a child XmlCtsCitation.name==line
-
escape
= re.compile('(")')
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
fill
(passage=None, xpath=None) Fill the xpath with given informations
Parameters: Return type: Returns: Xpath to find the passage
citation = XmlCtsCitation(name="line", scope="/TEI/text/body/div/div[@n="?"]",xpath="//l[@n="?"]") print(citation.fill(["1", None])) # /TEI/text/body/div/div[@n='1']//l[@n] print(citation.fill(None)) # /TEI/text/body/div/div[@n]//l[@n] print(citation.fill(Reference("1.1")) # /TEI/text/body/div/div[@n='1']//l[@n='1'] print(citation.fill("1", xpath=True) # //l[@n='1']
-
static
ingest
(resource, element=None, xpath='ti:citation')[source] Ingest xml to create a citation
Parameters: - resource – XML on which to do xpath
- element – Element where the citation should be stored
- xpath – XPath to use to retrieve citation
Returns: XmlCtsCitation
-
isEmpty
() Check if the citation has not been set
Returns: True if nothing was setup Return type: bool
-
name
Type of the citation represented
Type: text_type Example: Book, Chapter, Textpart, Section, Poem...
-
refsDecl
ResfDecl expression of the citation scheme
Return type: str Example: /tei:TEI/tei:text/tei:body/tei:div//tei:l[@n=’$1’]
-
scope
CtsTextInventoryMetadata 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
CtsTextInventoryMetadata xpath property of a citation (ie. identifier of the last element of the citation)
Type: basestring Example: //tei:l[@n=”?”]
-
-
class
MyCapytain.resources.collections.cts.
XmlCtsCommentaryMetadata
(urn='', parent=None, lang=None)[source] Bases:
MyCapytain.resources.prototypes.cts.inventory.CtsCommentaryMetadata
,MyCapytain.resources.collections.cts.XmlCtsTextMetadata
Create a commentary subtyped PrototypeText object
-
CTS_LINKS
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/about')]
-
CTS_MODEL
= 'CtsCollection'
-
CTS_PROPERTIES
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/label'), rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/description')]
-
DC_TITLE_KEY
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/label')
-
DEFAULT_EXPORT
= 'python/lxml'
-
EXPORT_TO
= ['text/xml:CTS', 'text/xml:CTS_CapiTainS']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/resource')
-
SUBTYPE
= 'commentary'
-
TYPE_URI
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/commentary')
-
asNode
() Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Descendants of the collection’s item
Warning
CapitainsCtsText has no Descendants
Return type: list
-
editions
() Get all editions of the texts
Returns: List of editions Return type: [CtsTextMetadata]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_creator
(lang=None) Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_cts_property
(prop, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to get (Without namespace)
- lang – Language to get for given value
Returns: Value or default if lang is set, else whole set of values
Return type: dict or Literal
-
get_description
(lang=None) Get the DC description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_label
(lang=None) Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
get_link
(prop) Get given link in CTS Namespace
Parameters: prop – Property to get (Without namespace) Returns: whole set of values Return type: list
-
get_subject
(lang=None) Get the DC subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None) Get the DC Title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
lang
Languages this text is in
Returns: List of available languages
-
members
Children of the collection’s item
Warning
CapitainsCtsText has no children
Return type: list
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
static
parse
(resource, parent=None)[source]
-
parse_metadata
(obj, xml) Parse a resource to feed the object
Parameters: - obj (XmlCtsTextMetadata) – Obj to set metadata of
- xml (lxml.etree._Element) – An xml representation object
-
readable
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_cts_property
(prop, value, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
- lang – Language to set for given value
-
set_label
(label, lang) Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
set_link
(prop, value) Set given link in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
-
size
-
subtype
Subtype of the object
Returns: string representation of subtype
-
translations
(key=None) Get translations in given language
Parameters: key – Language ISO Code to filter on Returns:
-
type
-
urn
-
version
-
-
class
MyCapytain.resources.collections.cts.
XmlCtsEditionMetadata
(urn='', parent=None, lang=None)[source] Bases:
MyCapytain.resources.prototypes.cts.inventory.CtsEditionMetadata
,MyCapytain.resources.collections.cts.XmlCtsTextMetadata
Create an edition subtyped CtsTextMetadata object
-
CTS_LINKS
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/about')]
-
CTS_MODEL
= 'CtsCollection'
-
CTS_PROPERTIES
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/label'), rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/description')]
-
DC_TITLE_KEY
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/label')
-
DEFAULT_EXPORT
= 'python/lxml'
-
EXPORT_TO
= ['text/xml:CTS', 'text/xml:CTS_CapiTainS']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/resource')
-
SUBTYPE
= 'edition'
-
TYPE_URI
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/edition')
-
asNode
() Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Descendants of the collection’s item
Warning
CapitainsCtsText has no Descendants
Return type: list
-
editions
() Get all editions of the texts
Returns: List of editions Return type: [CtsTextMetadata]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_creator
(lang=None) Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_cts_property
(prop, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to get (Without namespace)
- lang – Language to get for given value
Returns: Value or default if lang is set, else whole set of values
Return type: dict or Literal
-
get_description
(lang=None) Get the DC description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_label
(lang=None) Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
get_link
(prop) Get given link in CTS Namespace
Parameters: prop – Property to get (Without namespace) Returns: whole set of values Return type: list
-
get_subject
(lang=None) Get the DC subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None) Get the DC Title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
lang
Languages this text is in
Returns: List of available languages
-
members
Children of the collection’s item
Warning
CapitainsCtsText has no children
Return type: list
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
static
parse
(resource, parent=None)[source]
-
parse_metadata
(obj, xml) Parse a resource to feed the object
Parameters: - obj (XmlCtsTextMetadata) – Obj to set metadata of
- xml (lxml.etree._Element) – An xml representation object
-
readable
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_cts_property
(prop, value, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
- lang – Language to set for given value
-
set_label
(label, lang) Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
set_link
(prop, value) Set given link in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
-
size
-
subtype
Subtype of the object
Returns: string representation of subtype
-
translations
(key=None) Get translations in given language
Parameters: key – Language ISO Code to filter on Returns:
-
type
-
urn
-
version
-
-
class
MyCapytain.resources.collections.cts.
XmlCtsTextInventoryMetadata
(name='defaultInventory', parent=None)[source] Bases:
MyCapytain.resources.prototypes.cts.inventory.CtsTextInventoryMetadata
Represents a CTS Inventory file
-
CTS_LINKS
= []
-
CTS_MODEL
= 'CtsCollection'
-
CTS_PROPERTIES
= []
-
DC_TITLE_KEY
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/name')
-
DEFAULT_EXPORT
= 'python/lxml'
-
EXPORT_TO
= ['text/xml:CTS', 'text/xml:CTS_CapiTainS']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/collection')
-
TYPE_URI
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/TextInventory')
-
asNode
() Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Any descendant (no max level) of the collection’s item
Return type: [Collection]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_cts_property
(prop, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to get (Without namespace)
- lang – Language to get for given value
Returns: Value or default if lang is set, else whole set of values
Return type: dict or Literal
-
get_label
(lang=None) Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
get_link
(prop) Get given link in CTS Namespace
Parameters: prop – Property to get (Without namespace) Returns: whole set of values Return type: list
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
members
Children of the collection’s item
Return type: [Collection]
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
static
parse
(resource)[source] Parse a resource
Parameters: - resource – Element representing the text inventory
- type – basestring, etree._Element
-
readable
Readable property should return elements where the element can be queried for getPassage / getReffs
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_cts_property
(prop, value, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
- lang – Language to set for given value
-
set_label
(label, lang) Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
set_link
(prop, value) Set given link in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
-
size
-
textgroups
Textgroups
Returns: Dictionary of textgroups Return type: defaultdict( CtsTextgroupMetadata
)
-
type
-
urn
-
version
-
-
class
MyCapytain.resources.collections.cts.
XmlCtsTextMetadata
(urn='', parent=None, lang=None)[source] Bases:
MyCapytain.resources.prototypes.cts.inventory.CtsTextMetadata
Represents a CTS CtsTextMetadata
-
CTS_LINKS
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/about')]
-
CTS_MODEL
= 'CtsCollection'
-
CTS_PROPERTIES
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/label'), rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/description')]
-
DC_TITLE_KEY
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/label')
-
DEFAULT_EXPORT
= 'python/lxml'
-
EXPORT_TO
= ['text/xml:CTS', 'text/xml:CTS_CapiTainS']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/resource')
-
SUBTYPE
= 'unknown'
-
TYPE_URI
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/text')
-
asNode
() Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Descendants of the collection’s item
Warning
CapitainsCtsText has no Descendants
Return type: list
-
editions
() Get all editions of the texts
Returns: List of editions Return type: [CtsTextMetadata]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_creator
(lang=None) Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_cts_property
(prop, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to get (Without namespace)
- lang – Language to get for given value
Returns: Value or default if lang is set, else whole set of values
Return type: dict or Literal
-
get_description
(lang=None) Get the DC description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_label
(lang=None) Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
get_link
(prop) Get given link in CTS Namespace
Parameters: prop – Property to get (Without namespace) Returns: whole set of values Return type: list
-
get_subject
(lang=None) Get the DC subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None) Get the DC Title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
lang
Languages this text is in
Returns: List of available languages
-
members
Children of the collection’s item
Warning
CapitainsCtsText has no children
Return type: list
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
static
parse_metadata
(obj, xml)[source] Parse a resource to feed the object
Parameters: - obj (XmlCtsTextMetadata) – Obj to set metadata of
- xml (lxml.etree._Element) – An xml representation object
-
readable
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_cts_property
(prop, value, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
- lang – Language to set for given value
-
set_label
(label, lang) Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
set_link
(prop, value) Set given link in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
-
size
-
subtype
Subtype of the object
Returns: string representation of subtype
-
translations
(key=None) Get translations in given language
Parameters: key – Language ISO Code to filter on Returns:
-
type
-
urn
-
version
-
-
class
MyCapytain.resources.collections.cts.
XmlCtsTextgroupMetadata
(urn='', parent=None)[source] Bases:
MyCapytain.resources.prototypes.cts.inventory.CtsTextgroupMetadata
Represents a CTS Textgroup in XML
-
CTS_LINKS
= []
-
CTS_MODEL
= 'CtsCollection'
-
CTS_PROPERTIES
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/groupname')]
-
DC_TITLE_KEY
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/groupname')
-
DEFAULT_EXPORT
= 'python/lxml'
-
EXPORT_TO
= ['text/xml:CTS', 'text/xml:CTS_CapiTainS']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/collection')
-
TYPE_URI
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/textgroup')
-
asNode
() Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Any descendant (no max level) of the collection’s item
Return type: [Collection]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_cts_property
(prop, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to get (Without namespace)
- lang – Language to get for given value
Returns: Value or default if lang is set, else whole set of values
Return type: dict or Literal
-
get_label
(lang=None) Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
get_link
(prop) Get given link in CTS Namespace
Parameters: prop – Property to get (Without namespace) Returns: whole set of values Return type: list
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
members
Children of the collection’s item
Return type: [Collection]
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
static
parse
(resource, parent=None)[source] Parse a textgroup resource
Parameters: - resource – Element representing the textgroup
- parent – Parent of the textgroup
-
readable
Readable property should return elements where the element can be queried for getPassage / getReffs
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_cts_property
(prop, value, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
- lang – Language to set for given value
-
set_label
(label, lang) Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
set_link
(prop, value) Set given link in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
-
size
-
type
-
update
(other) Merge two Textgroup Objects.
- Original (left Object) keeps his parent.
- Added document merges with work if it already exists
Parameters: other (CtsTextgroupMetadata) – Textgroup object Returns: Textgroup Object Return type: CtsTextgroupMetadata
-
urn
-
version
-
works
Works
Returns: Dictionary of works Return type: defaultdict( PrototypeWorks
)
-
-
class
MyCapytain.resources.collections.cts.
XmlCtsTranslationMetadata
(urn='', parent=None, lang=None)[source] Bases:
MyCapytain.resources.prototypes.cts.inventory.CtsTranslationMetadata
,MyCapytain.resources.collections.cts.XmlCtsTextMetadata
Create a translation subtyped CtsTextMetadata object
-
CTS_LINKS
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/about')]
-
CTS_MODEL
= 'CtsCollection'
-
CTS_PROPERTIES
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/label'), rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/description')]
-
DC_TITLE_KEY
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/label')
-
DEFAULT_EXPORT
= 'python/lxml'
-
EXPORT_TO
= ['text/xml:CTS', 'text/xml:CTS_CapiTainS']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/resource')
-
SUBTYPE
= 'translation'
-
TYPE_URI
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/translation')
-
asNode
() Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Descendants of the collection’s item
Warning
CapitainsCtsText has no Descendants
Return type: list
-
editions
() Get all editions of the texts
Returns: List of editions Return type: [CtsTextMetadata]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_creator
(lang=None) Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_cts_property
(prop, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to get (Without namespace)
- lang – Language to get for given value
Returns: Value or default if lang is set, else whole set of values
Return type: dict or Literal
-
get_description
(lang=None) Get the DC description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_label
(lang=None) Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
get_link
(prop) Get given link in CTS Namespace
Parameters: prop – Property to get (Without namespace) Returns: whole set of values Return type: list
-
get_subject
(lang=None) Get the DC subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None) Get the DC Title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
lang
Languages this text is in
Returns: List of available languages
-
members
Children of the collection’s item
Warning
CapitainsCtsText has no children
Return type: list
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
static
parse
(resource, parent=None)[source]
-
parse_metadata
(obj, xml) Parse a resource to feed the object
Parameters: - obj (XmlCtsTextMetadata) – Obj to set metadata of
- xml (lxml.etree._Element) – An xml representation object
-
readable
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_cts_property
(prop, value, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
- lang – Language to set for given value
-
set_label
(label, lang) Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
set_link
(prop, value) Set given link in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
-
size
-
subtype
Subtype of the object
Returns: string representation of subtype
-
translations
(key=None) Get translations in given language
Parameters: key – Language ISO Code to filter on Returns:
-
type
-
urn
-
version
-
-
class
MyCapytain.resources.collections.cts.
XmlCtsWorkMetadata
(urn=None, parent=None)[source] Bases:
MyCapytain.resources.prototypes.cts.inventory.CtsWorkMetadata
Represents a CTS Textgroup in XML
-
CTS_LINKS
= []
-
CTS_MODEL
= 'CtsCollection'
-
CTS_PROPERTIES
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/title')]
-
DC_TITLE_KEY
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/title')
-
DEFAULT_EXPORT
= 'python/lxml'
-
EXPORT_TO
= ['text/xml:CTS', 'text/xml:CTS_CapiTainS']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/collection')
-
TYPE_URI
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/work')
-
asNode
() Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Any descendant (no max level) of the collection’s item
Return type: [Collection]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_cts_property
(prop, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to get (Without namespace)
- lang – Language to get for given value
Returns: Value or default if lang is set, else whole set of values
Return type: dict or Literal
-
get_label
(lang=None) Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
get_link
(prop) Get given link in CTS Namespace
Parameters: prop – Property to get (Without namespace) Returns: whole set of values Return type: list
-
get_translation_in
(key=None) Find a translation with given language
Parameters: key (text_type) – Language to find Return type: [CtsTextMetadata] Returns: List of availables translations
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
lang
Languages this text is in
Returns: List of available languages
-
members
Children of the collection’s item
Return type: [Collection]
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
static
parse
(resource, parent=None)[source] Parse a resource
Parameters: - resource – Element rerpresenting a work
- type – basestring, etree._Element
- parent (XmlCtsTextgroupMetadata) – Parent of the object
-
readable
Readable property should return elements where the element can be queried for getPassage / getReffs
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_cts_property
(prop, value, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
- lang – Language to set for given value
-
set_label
(label, lang) Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
set_link
(prop, value) Set given link in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
-
size
-
texts
Texts
Returns: Dictionary of texts Return type: defaultdict( PrototypeTexts
)
-
type
-
update
(other) Merge two XmlCtsWorkMetadata Objects.
- Original (left Object) keeps his parent.
- Added document overwrite text if it already exists
Parameters: other (CtsWorkMetadata) – XmlCtsWorkMetadata object Returns: XmlCtsWorkMetadata Object Rtype XmlCtsWorkMetadata:
-
urn
-
version
-
-
MyCapytain.resources.collections.cts.
xpathDict
(xml, xpath, cls, parent, **kwargs)[source] Returns a default Dict given certain information
Parameters: - xml (etree) – An xml tree
- xpath (str) – XPath to find children
- cls (inventory.Resource) – Class identifying children
- parent (CtsCollection) – Parent of object
Return type: collections.defaultdict.<basestring, inventory.Resource>
Returns: Dictionary of children
CTS Inventory Prototypes¶
-
class
MyCapytain.resources.prototypes.cts.inventory.
CtsCommentaryMetadata
(urn='', parent=None, lang=None)[source] Bases:
MyCapytain.resources.prototypes.cts.inventory.CtsTextMetadata
Represents a CTS Commentary
Parameters: - urn (str) – Identifier of the PrototypeText
- parent (PrototypeWork) – Parent of current item
- lang (Lang) – Language of the commentary
-
CTS_LINKS
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/about')]
-
CTS_MODEL
= 'CtsCollection'
-
CTS_PROPERTIES
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/label'), rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/description')]
-
DC_TITLE_KEY
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/label')
-
DEFAULT_EXPORT
= 'python/lxml'
-
EXPORT_TO
= ['text/xml:CTS', 'text/xml:CTS_CapiTainS']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/resource')
-
SUBTYPE
= 'commentary'
-
TYPE_URI
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/commentary')
-
asNode
() Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Descendants of the collection’s item
Warning
CapitainsCtsText has no Descendants
Return type: list
-
editions
() Get all editions of the texts
Returns: List of editions Return type: [CtsTextMetadata]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_creator
(lang=None) Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_cts_property
(prop, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to get (Without namespace)
- lang – Language to get for given value
Returns: Value or default if lang is set, else whole set of values
Return type: dict or Literal
-
get_description
(lang=None) Get the DC description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_label
(lang=None) Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
get_link
(prop) Get given link in CTS Namespace
Parameters: prop – Property to get (Without namespace) Returns: whole set of values Return type: list
-
get_subject
(lang=None) Get the DC subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None) Get the DC Title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
lang
Languages this text is in
Returns: List of available languages
-
members
Children of the collection’s item
Warning
CapitainsCtsText has no children
Return type: list
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
readable
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_cts_property
(prop, value, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
- lang – Language to set for given value
-
set_label
(label, lang) Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
set_link
(prop, value) Set given link in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
-
size
-
subtype
Subtype of the object
Returns: string representation of subtype
-
translations
(key=None) Get translations in given language
Parameters: key – Language ISO Code to filter on Returns:
-
type
-
urn
-
version
-
class
MyCapytain.resources.prototypes.cts.inventory.
CtsEditionMetadata
(urn='', parent=None, lang=None)[source] Bases:
MyCapytain.resources.prototypes.cts.inventory.CtsTextMetadata
Represents a CTS XmlCtsEditionMetadata
Parameters: - urn (str) – Identifier of the CtsTextMetadata
- parent (CtsWorkMetadata) – Parent of current item
-
CTS_LINKS
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/about')]
-
CTS_MODEL
= 'CtsCollection'
-
CTS_PROPERTIES
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/label'), rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/description')]
-
DC_TITLE_KEY
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/label')
-
DEFAULT_EXPORT
= 'python/lxml'
-
EXPORT_TO
= ['text/xml:CTS', 'text/xml:CTS_CapiTainS']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/resource')
-
SUBTYPE
= 'edition'
-
TYPE_URI
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/edition')
-
asNode
() Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Descendants of the collection’s item
Warning
CapitainsCtsText has no Descendants
Return type: list
-
editions
() Get all editions of the texts
Returns: List of editions Return type: [CtsTextMetadata]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_creator
(lang=None) Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_cts_property
(prop, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to get (Without namespace)
- lang – Language to get for given value
Returns: Value or default if lang is set, else whole set of values
Return type: dict or Literal
-
get_description
(lang=None) Get the DC description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_label
(lang=None) Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
get_link
(prop) Get given link in CTS Namespace
Parameters: prop – Property to get (Without namespace) Returns: whole set of values Return type: list
-
get_subject
(lang=None) Get the DC subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None) Get the DC Title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
lang
Languages this text is in
Returns: List of available languages
-
members
Children of the collection’s item
Warning
CapitainsCtsText has no children
Return type: list
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
readable
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_cts_property
(prop, value, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
- lang – Language to set for given value
-
set_label
(label, lang) Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
set_link
(prop, value) Set given link in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
-
size
-
subtype
Subtype of the object
Returns: string representation of subtype
-
translations
(key=None) Get translations in given language
Parameters: key – Language ISO Code to filter on Returns:
-
type
-
urn
-
version
-
class
MyCapytain.resources.prototypes.cts.inventory.
CtsTextInventoryCollection
(identifier='default')[source] Bases:
MyCapytain.resources.prototypes.cts.inventory.PrototypeCtsCollection
Initiate a CtsTextInventoryMetadata resource
Parameters: - resource (Any) – Resource representing the CtsTextInventoryMetadata
- name (str) – Identifier of the CtsTextInventoryMetadata
-
CTS_LINKS
= []
-
CTS_MODEL
= 'CtsCollection'
-
CTS_PROPERTIES
= []
-
DC_TITLE_KEY
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/name')
-
DEFAULT_EXPORT
= 'python/lxml'
-
EXPORT_TO
= ['text/xml:CTS', 'application/ld+json:DTS', 'text/xml:CTS_CapiTainS']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/collection')
-
TYPE_URI
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/CtsTextInventoryCollection')
-
asNode
() Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Any descendant (no max level) of the collection’s item
Return type: [Collection]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_cts_property
(prop, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to get (Without namespace)
- lang – Language to get for given value
Returns: Value or default if lang is set, else whole set of values
Return type: dict or Literal
-
get_label
(lang=None) Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
get_link
(prop) Get given link in CTS Namespace
Parameters: prop – Property to get (Without namespace) Returns: whole set of values Return type: list
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
members
Children of the collection’s item
Return type: [Collection]
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
readable
Readable property should return elements where the element can be queried for getPassage / getReffs
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_cts_property
(prop, value, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
- lang – Language to set for given value
-
set_label
(label, lang) Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
set_link
(prop, value) Set given link in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
-
size
-
type
-
urn
-
version
-
class
MyCapytain.resources.prototypes.cts.inventory.
CtsTextInventoryMetadata
(name='defaultInventory', parent=None)[source] Bases:
MyCapytain.resources.prototypes.cts.inventory.PrototypeCtsCollection
Initiate a CtsTextInventoryMetadata resource
Parameters: - resource (Any) – Resource representing the CtsTextInventoryMetadata
- name (str) – Identifier of the CtsTextInventoryMetadata
-
CTS_LINKS
= []
-
CTS_MODEL
= 'CtsCollection'
-
CTS_PROPERTIES
= []
-
DC_TITLE_KEY
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/name')
-
DEFAULT_EXPORT
= 'python/lxml'
-
EXPORT_TO
= ['text/xml:CTS', 'text/xml:CTS_CapiTainS']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/collection')
-
TYPE_URI
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/TextInventory')
-
asNode
() Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Any descendant (no max level) of the collection’s item
Return type: [Collection]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_cts_property
(prop, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to get (Without namespace)
- lang – Language to get for given value
Returns: Value or default if lang is set, else whole set of values
Return type: dict or Literal
-
get_label
(lang=None) Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
get_link
(prop) Get given link in CTS Namespace
Parameters: prop – Property to get (Without namespace) Returns: whole set of values Return type: list
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
members
Children of the collection’s item
Return type: [Collection]
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
readable
Readable property should return elements where the element can be queried for getPassage / getReffs
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_cts_property
(prop, value, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
- lang – Language to set for given value
-
set_label
(label, lang) Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
set_link
(prop, value) Set given link in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
-
size
-
textgroups
Textgroups
Returns: Dictionary of textgroups Return type: defaultdict( CtsTextgroupMetadata
)
-
type
-
urn
-
version
-
class
MyCapytain.resources.prototypes.cts.inventory.
CtsTextMetadata
(urn='', parent=None, lang=None)[source] Bases:
MyCapytain.resources.prototypes.metadata.ResourceCollection
,MyCapytain.resources.prototypes.cts.inventory.PrototypeCtsCollection
Represents a CTS CtsTextMetadata
Parameters: - urn (URN) – Identifier of the CtsTextMetadata
- parent ([PrototypeCtsCollection]) – Item parents of the current collection
Variables: urn – URN Identifier
-
CTS_LINKS
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/about')]
-
CTS_MODEL
= 'CtsCollection'
-
CTS_PROPERTIES
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/label'), rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/description')]
-
DC_TITLE_KEY
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/label')
-
DEFAULT_EXPORT
= 'python/lxml'
-
EXPORT_TO
= ['text/xml:CTS', 'text/xml:CTS_CapiTainS']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/resource')
-
SUBTYPE
= 'unknown'
-
TYPE_URI
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/text')
-
asNode
() Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Descendants of the collection’s item
Warning
CapitainsCtsText has no Descendants
Return type: list
-
editions
()[source] Get all editions of the texts
Returns: List of editions Return type: [CtsTextMetadata]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_creator
(lang=None)[source] Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_cts_property
(prop, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to get (Without namespace)
- lang – Language to get for given value
Returns: Value or default if lang is set, else whole set of values
Return type: dict or Literal
-
get_description
(lang=None)[source] Get the DC description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_label
(lang=None) Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
get_link
(prop) Get given link in CTS Namespace
Parameters: prop – Property to get (Without namespace) Returns: whole set of values Return type: list
-
get_subject
(lang=None)[source] Get the DC subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None)[source] Get the DC Title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
lang
Languages this text is in
Returns: List of available languages
-
members
Children of the collection’s item
Warning
CapitainsCtsText has no children
Return type: list
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
readable
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_cts_property
(prop, value, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
- lang – Language to set for given value
-
set_label
(label, lang) Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
set_link
(prop, value) Set given link in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
-
size
-
subtype
Subtype of the object
Returns: string representation of subtype
-
translations
(key=None)[source] Get translations in given language
Parameters: key – Language ISO Code to filter on Returns:
-
type
-
urn
-
version
-
class
MyCapytain.resources.prototypes.cts.inventory.
CtsTextgroupMetadata
(urn='', parent=None)[source] Bases:
MyCapytain.resources.prototypes.cts.inventory.PrototypeCtsCollection
Represents a CTS Textgroup
CTS CtsTextgroupMetadata can be added to each other which would most likely happen if you take your data from multiple API or Textual repository. This works close to dictionary update in Python. See update
Parameters: - urn (URN) – Identifier of the CtsTextgroupMetadata
- parent (CtsTextInventoryMetadata) – Parent of the current object
Variables: urn – URN Identifier
-
CTS_LINKS
= []
-
CTS_MODEL
= 'CtsCollection'
-
CTS_PROPERTIES
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/groupname')]
-
DC_TITLE_KEY
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/groupname')
-
DEFAULT_EXPORT
= 'python/lxml'
-
EXPORT_TO
= ['text/xml:CTS', 'text/xml:CTS_CapiTainS']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/collection')
-
TYPE_URI
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/textgroup')
-
asNode
() Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Any descendant (no max level) of the collection’s item
Return type: [Collection]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_cts_property
(prop, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to get (Without namespace)
- lang – Language to get for given value
Returns: Value or default if lang is set, else whole set of values
Return type: dict or Literal
-
get_label
(lang=None) Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
get_link
(prop) Get given link in CTS Namespace
Parameters: prop – Property to get (Without namespace) Returns: whole set of values Return type: list
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
members
Children of the collection’s item
Return type: [Collection]
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
readable
Readable property should return elements where the element can be queried for getPassage / getReffs
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_cts_property
(prop, value, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
- lang – Language to set for given value
-
set_label
(label, lang) Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
set_link
(prop, value) Set given link in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
-
size
-
type
-
update
(other)[source] Merge two Textgroup Objects.
- Original (left Object) keeps his parent.
- Added document merges with work if it already exists
Parameters: other (CtsTextgroupMetadata) – Textgroup object Returns: Textgroup Object Return type: CtsTextgroupMetadata
-
urn
-
version
-
works
Works
Returns: Dictionary of works Return type: defaultdict( PrototypeWorks
)
-
class
MyCapytain.resources.prototypes.cts.inventory.
CtsTranslationMetadata
(urn='', parent=None, lang=None)[source] Bases:
MyCapytain.resources.prototypes.cts.inventory.CtsTextMetadata
Represents a CTS XmlCtsTranslationMetadata
Parameters: - urn (str) – Identifier of the CtsTextMetadata
- parent (CtsWorkMetadata) – Parent of current item
- lang (Lang) – Language of the translation
-
CTS_LINKS
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/about')]
-
CTS_MODEL
= 'CtsCollection'
-
CTS_PROPERTIES
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/label'), rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/description')]
-
DC_TITLE_KEY
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/label')
-
DEFAULT_EXPORT
= 'python/lxml'
-
EXPORT_TO
= ['text/xml:CTS', 'text/xml:CTS_CapiTainS']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/resource')
-
SUBTYPE
= 'translation'
-
TYPE_URI
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/translation')
-
asNode
() Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Descendants of the collection’s item
Warning
CapitainsCtsText has no Descendants
Return type: list
-
editions
() Get all editions of the texts
Returns: List of editions Return type: [CtsTextMetadata]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_creator
(lang=None) Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_cts_property
(prop, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to get (Without namespace)
- lang – Language to get for given value
Returns: Value or default if lang is set, else whole set of values
Return type: dict or Literal
-
get_description
(lang=None) Get the DC description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_label
(lang=None) Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
get_link
(prop) Get given link in CTS Namespace
Parameters: prop – Property to get (Without namespace) Returns: whole set of values Return type: list
-
get_subject
(lang=None) Get the DC subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None) Get the DC Title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
lang
Languages this text is in
Returns: List of available languages
-
members
Children of the collection’s item
Warning
CapitainsCtsText has no children
Return type: list
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
readable
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_cts_property
(prop, value, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
- lang – Language to set for given value
-
set_label
(label, lang) Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
set_link
(prop, value) Set given link in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
-
size
-
subtype
Subtype of the object
Returns: string representation of subtype
-
translations
(key=None) Get translations in given language
Parameters: key – Language ISO Code to filter on Returns:
-
type
-
urn
-
version
-
class
MyCapytain.resources.prototypes.cts.inventory.
CtsWorkMetadata
(urn=None, parent=None)[source] Bases:
MyCapytain.resources.prototypes.cts.inventory.PrototypeCtsCollection
Represents a CTS CtsWorkMetadata
CTS CtsWorkMetadata can be added to each other which would most likely happen if you take your data from multiple API or Textual repository. This works close to dictionary update in Python. See update
Parameters: - urn (URN) – Identifier of the CtsWorkMetadata
- parent (CtsTextgroupMetadata) – Parent of current object
Variables: urn – URN Identifier
-
CTS_LINKS
= []
-
CTS_MODEL
= 'CtsCollection'
-
CTS_PROPERTIES
= [rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/title')]
-
DC_TITLE_KEY
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/title')
-
DEFAULT_EXPORT
= 'python/lxml'
-
EXPORT_TO
= ['text/xml:CTS', 'text/xml:CTS_CapiTainS']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/collection')
-
TYPE_URI
= rdflib.term.URIRef('http://chs.harvard.edu/xmlns/cts/work')
-
asNode
() Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Any descendant (no max level) of the collection’s item
Return type: [Collection]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_cts_property
(prop, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to get (Without namespace)
- lang – Language to get for given value
Returns: Value or default if lang is set, else whole set of values
Return type: dict or Literal
-
get_label
(lang=None) Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
get_link
(prop) Get given link in CTS Namespace
Parameters: prop – Property to get (Without namespace) Returns: whole set of values Return type: list
-
get_translation_in
(key=None)[source] Find a translation with given language
Parameters: key (text_type) – Language to find Return type: [CtsTextMetadata] Returns: List of availables translations
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
lang
Languages this text is in
Returns: List of available languages
-
members
Children of the collection’s item
Return type: [Collection]
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
readable
Readable property should return elements where the element can be queried for getPassage / getReffs
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_cts_property
(prop, value, lang=None) Set given property in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
- lang – Language to set for given value
-
set_label
(label, lang) Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
set_link
(prop, value) Set given link in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
-
size
-
texts
Texts
Returns: Dictionary of texts Return type: defaultdict( PrototypeTexts
)
-
type
-
update
(other)[source] Merge two XmlCtsWorkMetadata Objects.
- Original (left Object) keeps his parent.
- Added document overwrite text if it already exists
Parameters: other (CtsWorkMetadata) – XmlCtsWorkMetadata object Returns: XmlCtsWorkMetadata Object Rtype XmlCtsWorkMetadata:
-
urn
-
version
-
class
MyCapytain.resources.prototypes.cts.inventory.
PrototypeCtsCollection
(identifier='')[source] Bases:
MyCapytain.resources.prototypes.metadata.Collection
Resource represents any resource from the inventory
Parameters: identifier (str,URN) – Identifier representing the CtsTextInventoryMetadata Variables: CTS_MODEL – String Representation of the type of collection -
CTS_LINKS
= []
-
CTS_MODEL
= 'CtsCollection'
-
CTS_PROPERTIES
= []
-
DC_TITLE_KEY
= None
-
DEFAULT_EXPORT
= 'python/lxml'
-
EXPORT_TO
= ['python/lxml']
-
MODEL_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/collection')
-
TYPE_URI
= rdflib.term.URIRef('http://w3id.org/dts-ontology/collection')
-
asNode
() Node representation of the collection in the graph
Return type: URIRef
-
capabilities
-
children
Dictionary of childrens {Identifier: Collection}
Return type: dict
-
descendants
Any descendant (no max level) of the collection’s item
Return type: [Collection]
-
export
(output=None, **kwargs) Export the collection item in the Mimetype required.
Parameters: output (str) – Mimetype to export to (Uses MyCapytain.common.utils.Mimetypes) Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_cts_property
(prop, lang=None)[source] Set given property in CTS Namespace
Parameters: - prop – Property to get (Without namespace)
- lang – Language to get for given value
Returns: Value or default if lang is set, else whole set of values
Return type: dict or Literal
-
get_label
(lang=None) Return label for given lang or any default
Parameters: lang – Language to request Returns: Label value Return type: Literal
-
get_link
(prop)[source] Get given link in CTS Namespace
Parameters: prop – Property to get (Without namespace) Returns: whole set of values Return type: list
-
graph
RDFLib Graph space
Return type: Graph
-
id
-
members
Children of the collection’s item
Return type: [Collection]
-
metadata
-
model
-
parent
Parent of current object
Return type: Collection
-
parents
Iterator to find parents of current collection, from closest to furthest
Return type: Generator[ Collection
]
-
readable
Readable property should return elements where the element can be queried for getPassage / getReffs
-
readableDescendants
List of element available which are readable
Return type: [Collection]
-
set_cts_property
(prop, value, lang=None)[source] Set given property in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
- lang – Language to set for given value
-
set_label
(label, lang) Add the label of the collection in given lang
Parameters: - label – Label Value
- lang – Language code
-
set_link
(prop, value)[source] Set given link in CTS Namespace
Parameters: - prop – Property to set (Without namespace)
- value – Value to set for given property
-
size
-
type
-
urn
-
version
-
Text Prototypes¶
-
class
MyCapytain.resources.prototypes.text.
CitableText
(citation=None, metadata=None, **kwargs)[source] Bases:
MyCapytain.resources.prototypes.text.CtsNode
A CTS CitableText
-
DEFAULT_EXPORT
= None
-
EXPORT_TO
= []
-
asNode
()
-
childIds
Identifiers of children
Returns: Identifiers of children Return type: [str]
-
children
Children Passages
Return type: iterator(CapitainsCtsPassage)
-
citation
XmlCtsCitation Object of the CtsTextMetadata
Returns: XmlCtsCitation Object of the CtsTextMetadata Return type: Citation
-
default_exclude
= []
-
depth
Depth of the node in the global hierarchy of the text tree
Return type: int
-
export
(output=None, exclude=None, **kwargs) Export the collection item in the Mimetype required.
..note:: If current implementation does not have special mimetypes, reuses default_export method
Parameters: Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
first
First CapitainsCtsPassage
Return type: Passage
-
firstId
First child of current CapitainsCtsPassage
Return type: str Returns: First passage node Information
-
getLabel
() Retrieve metadata about the text
Return type: Collection Returns: Retrieve Label informations in a Collection format
-
getReffs
(level=1, subreference=None) Reference available at a given level
Parameters: - level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
- passage (Reference) – Subreference (optional)
Return type: [text_type]
Returns: List of levels
-
getTextualNode
(subreference) Retrieve a passage and store it in the object
Parameters: subreference (str or Node or Reference) – Reference of the passage to retrieve Return type: TextualNode Returns: Object representing the passage Raises: TypeError when reference is not a list or a Reference
-
getValidReff
(level=1, reference=None) Given a resource, CitableText will compute valid reffs
Parameters: - level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
- passage (Reference) – Subreference (optional)
Return type: List.text_type
Returns: List of levels
-
get_creator
(lang=None) Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_cts_metadata
(key, lang=None)
-
get_description
(lang=None) Get the description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_subject
(lang=None) Get the subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None) Get the title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
-
id
Identifier of the text
Returns: Identifier of the text Return type: text_type
-
last
Last CapitainsCtsPassage
Return type: Passage
-
lastId
Last child of current CapitainsCtsPassage
Return type: str Returns: Last passage Node representation
-
metadata
Metadata information about the text
Returns: Collection object with metadata about the text Return type: Metadata
-
next
Get Next CapitainsCtsPassage
Return type: Passage
-
nextId
Next Node (Sibling)
Return type: str
-
parent
Parent CapitainsCtsPassage
Return type: Passage
-
parentId
Parent Node
Return type: str
-
prev
Get Previous CapitainsCtsPassage
Return type: Passage
-
prevId
Previous Node (Sibling)
Return type: str
-
reffs
Get all valid reffs for every part of the CitableText
Return type: [str]
-
set_creator
(value, lang) Set the DC Creator literal value
Parameters: lang – Language in which the value is
-
set_description
(value, lang=None) Set the DC Description literal value
Parameters: lang – Language in which the value is
-
set_metadata_from_collection
(text_metadata) Set the object metadata using its collections recursively
Parameters: text_metadata (CtsEditionMetadata or CtsTranslationMetadata) – Object representing the current text as a collection
-
set_subject
(value, lang=None) Set the DC Subject literal value
Parameters: lang – Language in which the value is
-
set_title
(value, lang=None) Set the DC Title literal value
Parameters: lang – Language in which the value is
-
text
String representation of the text
Returns: String representation of the text Return type: text_type
-
urn
URN Identifier of the object
Return type: URN
-
-
class
MyCapytain.resources.prototypes.text.
CtsNode
(urn=None, **kwargs)[source] Bases:
MyCapytain.resources.prototypes.text.InteractiveTextualNode
Initiate a Resource object
Parameters: - urn (URN) – A URN identifier
- metadata (Collection) – Collection Information about the Item
- citation (Citation) – XmlCtsCitation system of the text
- children ([str]) – Current node Children’s Identifier
- parent (str) – Parent of the current node
- siblings (str) – Previous and next node of the current node
- depth (int) – Depth of the node in the global hierarchy of the text tree
- resource – Resource used to navigate through the textual graph
Variables: default_exclude – Default exclude for exports
-
DEFAULT_EXPORT
= None
-
EXPORT_TO
= []
-
asNode
()
-
childIds
Identifiers of children
Returns: Identifiers of children Return type: [str]
-
children
Children Passages
Return type: iterator(CapitainsCtsPassage)
-
citation
XmlCtsCitation Object of the CtsTextMetadata
Returns: XmlCtsCitation Object of the CtsTextMetadata Return type: Citation
-
default_exclude
= []
-
depth
Depth of the node in the global hierarchy of the text tree
Return type: int
-
export
(output=None, exclude=None, **kwargs) Export the collection item in the Mimetype required.
..note:: If current implementation does not have special mimetypes, reuses default_export method
Parameters: Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
first
First CapitainsCtsPassage
Return type: Passage
-
firstId
First child of current CapitainsCtsPassage
Return type: str Returns: First passage node Information
-
getLabel
()[source] Retrieve metadata about the text
Return type: Collection Returns: Retrieve Label informations in a Collection format
-
getReffs
(level=1, subreference=None) Reference available at a given level
Parameters: - level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
- passage (Reference) – Subreference (optional)
Return type: [text_type]
Returns: List of levels
-
getTextualNode
(subreference) Retrieve a passage and store it in the object
Parameters: subreference (str or Node or Reference) – Reference of the passage to retrieve Return type: TextualNode 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, CitableText will compute valid reffs
Parameters: - level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
- passage (Reference) – Subreference (optional)
Return type: List.text_type
Returns: List of levels
-
get_creator
(lang=None) Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_cts_metadata
(key, lang=None)[source]
-
get_description
(lang=None) Get the description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_subject
(lang=None) Get the subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None) Get the title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
-
id
Identifier of the text
Returns: Identifier of the text Return type: text_type
-
last
Last CapitainsCtsPassage
Return type: Passage
-
lastId
Last child of current CapitainsCtsPassage
Return type: str Returns: Last passage Node representation
-
metadata
Metadata information about the text
Returns: Collection object with metadata about the text Return type: Metadata
-
next
Get Next CapitainsCtsPassage
Return type: Passage
-
nextId
Next Node (Sibling)
Return type: str
-
parent
Parent CapitainsCtsPassage
Return type: Passage
-
parentId
Parent Node
Return type: str
-
prev
Get Previous CapitainsCtsPassage
Return type: Passage
-
prevId
Previous Node (Sibling)
Return type: str
-
set_creator
(value, lang) Set the DC Creator literal value
Parameters: lang – Language in which the value is
-
set_description
(value, lang=None) Set the DC Description literal value
Parameters: lang – Language in which the value is
-
set_metadata_from_collection
(text_metadata)[source] Set the object metadata using its collections recursively
Parameters: text_metadata (CtsEditionMetadata or CtsTranslationMetadata) – Object representing the current text as a collection
-
set_subject
(value, lang=None) Set the DC Subject literal value
Parameters: lang – Language in which the value is
-
set_title
(value, lang=None) Set the DC Title literal value
Parameters: lang – Language in which the value is
-
text
String representation of the text
Returns: String representation of the text Return type: text_type
-
urn
URN Identifier of the object
Return type: URN
-
class
MyCapytain.resources.prototypes.text.
InteractiveTextualNode
(identifier=None, **kwargs)[source] Bases:
MyCapytain.resources.prototypes.text.TextualGraph
Node representing a text passage.
Parameters: - identifier (str) – Identifier of the text
- metadata (Collection) – Collection Information about the Item
- citation (Citation) – XmlCtsCitation system of the text
- children ([str]) – Current node Children’s Identifier
- parent (str) – Parent of the current node
- siblings (str) – Previous and next node of the current node
- depth (int) – Depth of the node in the global hierarchy of the text tree
- resource – Resource used to navigate through the textual graph
Variables: default_exclude – Default exclude for exports
-
DEFAULT_EXPORT
= None
-
EXPORT_TO
= []
-
asNode
()
-
childIds
Identifiers of children
Returns: Identifiers of children Return type: [str]
-
children
Children Passages
Return type: iterator(CapitainsCtsPassage)
-
citation
XmlCtsCitation Object of the CtsTextMetadata
Returns: XmlCtsCitation Object of the CtsTextMetadata Return type: Citation
-
default_exclude
= []
-
depth
Depth of the node in the global hierarchy of the text tree
Return type: int
-
export
(output=None, exclude=None, **kwargs) Export the collection item in the Mimetype required.
..note:: If current implementation does not have special mimetypes, reuses default_export method
Parameters: Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
first
First CapitainsCtsPassage
Return type: Passage
-
firstId
First child of current CapitainsCtsPassage
Return type: str Returns: First passage node Information
-
getReffs
(level=1, subreference=None) Reference available at a given level
Parameters: - level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
- passage (Reference) – Subreference (optional)
Return type: [text_type]
Returns: List of levels
-
getTextualNode
(subreference) Retrieve a passage and store it in the object
Parameters: subreference (str or Node or Reference) – Reference of the passage to retrieve Return type: TextualNode Returns: Object representing the passage Raises: TypeError when reference is not a list or a Reference
-
get_creator
(lang=None) Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_description
(lang=None) Get the description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_subject
(lang=None) Get the subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None) Get the title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
-
id
Identifier of the text
Returns: Identifier of the text Return type: text_type
-
last
Last CapitainsCtsPassage
Return type: Passage
-
lastId
Last child of current CapitainsCtsPassage
Return type: str Returns: Last passage Node representation
-
metadata
Metadata information about the text
Returns: Collection object with metadata about the text Return type: Metadata
-
next
Get Next CapitainsCtsPassage
Return type: Passage
-
nextId
Next Node (Sibling)
Return type: str
-
parent
Parent CapitainsCtsPassage
Return type: Passage
-
parentId
Parent Node
Return type: str
-
prev
Get Previous CapitainsCtsPassage
Return type: Passage
-
prevId
Previous Node (Sibling)
Return type: str
-
set_creator
(value, lang) Set the DC Creator literal value
Parameters: lang – Language in which the value is
-
set_description
(value, lang=None) Set the DC Description literal value
Parameters: lang – Language in which the value is
-
set_subject
(value, lang=None) Set the DC Subject literal value
Parameters: lang – Language in which the value is
-
set_title
(value, lang=None) Set the DC Title literal value
Parameters: lang – Language in which the value is
-
text
String representation of the text
Returns: String representation of the text Return type: text_type
-
class
MyCapytain.resources.prototypes.text.
Passage
(**kwargs)[source] Bases:
MyCapytain.resources.prototypes.text.CtsNode
CapitainsCtsPassage objects possess metadata informations
Parameters: - urn (URN) – A URN identifier
- metadata (Collection) – Collection Information about the Item
- citation (Citation) – XmlCtsCitation system of the text
- children ([str]) – Current node Children’s Identifier
- parent (str) – Parent of the current node
- siblings (str) – Previous and next node of the current node
- depth (int) – Depth of the node in the global hierarchy of the text tree
- resource – Resource used to navigate through the textual graph
Variables: default_exclude – Default exclude for exports
-
DEFAULT_EXPORT
= None
-
EXPORT_TO
= []
-
asNode
()
-
childIds
Identifiers of children
Returns: Identifiers of children Return type: [str]
-
children
Children Passages
Return type: iterator(CapitainsCtsPassage)
-
citation
XmlCtsCitation Object of the CtsTextMetadata
Returns: XmlCtsCitation Object of the CtsTextMetadata Return type: Citation
-
default_exclude
= []
-
depth
Depth of the node in the global hierarchy of the text tree
Return type: int
-
export
(output=None, exclude=None, **kwargs) Export the collection item in the Mimetype required.
..note:: If current implementation does not have special mimetypes, reuses default_export method
Parameters: Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
first
First CapitainsCtsPassage
Return type: Passage
-
firstId
First child of current CapitainsCtsPassage
Return type: str Returns: First passage node Information
-
getLabel
() Retrieve metadata about the text
Return type: Collection Returns: Retrieve Label informations in a Collection format
-
getReffs
(level=1, subreference=None) Reference available at a given level
Parameters: - level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
- passage (Reference) – Subreference (optional)
Return type: [text_type]
Returns: List of levels
-
getTextualNode
(subreference) Retrieve a passage and store it in the object
Parameters: subreference (str or Node or Reference) – Reference of the passage to retrieve Return type: TextualNode Returns: Object representing the passage Raises: TypeError when reference is not a list or a Reference
-
getValidReff
(level=1, reference=None) Given a resource, CitableText will compute valid reffs
Parameters: - level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
- passage (Reference) – Subreference (optional)
Return type: List.text_type
Returns: List of levels
-
get_creator
(lang=None) Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_cts_metadata
(key, lang=None)
-
get_description
(lang=None) Get the description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_subject
(lang=None) Get the subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None) Get the title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
-
id
Identifier of the text
Returns: Identifier of the text Return type: text_type
-
last
Last CapitainsCtsPassage
Return type: Passage
-
lastId
Last child of current CapitainsCtsPassage
Return type: str Returns: Last passage Node representation
-
metadata
Metadata information about the text
Returns: Collection object with metadata about the text Return type: Metadata
-
next
Get Next CapitainsCtsPassage
Return type: Passage
-
nextId
Next Node (Sibling)
Return type: str
-
parent
Parent CapitainsCtsPassage
Return type: Passage
-
parentId
Parent Node
Return type: str
-
prev
Get Previous CapitainsCtsPassage
Return type: Passage
-
prevId
Previous Node (Sibling)
Return type: str
-
reference
-
set_creator
(value, lang) Set the DC Creator literal value
Parameters: lang – Language in which the value is
-
set_description
(value, lang=None) Set the DC Description literal value
Parameters: lang – Language in which the value is
-
set_metadata_from_collection
(text_metadata) Set the object metadata using its collections recursively
Parameters: text_metadata (CtsEditionMetadata or CtsTranslationMetadata) – Object representing the current text as a collection
-
set_subject
(value, lang=None) Set the DC Subject literal value
Parameters: lang – Language in which the value is
-
set_title
(value, lang=None) Set the DC Title literal value
Parameters: lang – Language in which the value is
-
text
String representation of the text
Returns: String representation of the text Return type: text_type
-
urn
URN Identifier of the object
Return type: URN
-
class
MyCapytain.resources.prototypes.text.
TextualElement
(identifier=None, metadata=None)[source] Bases:
MyCapytain.common.base.Exportable
Node representing a text passage.
Parameters: - identifier (str) – Identifier of the text
- metadata (Collection) – Collection Information about the Item
Variables: default_exclude – Default exclude for exports
-
DEFAULT_EXPORT
= None
-
EXPORT_TO
= []
-
asNode
()[source]
-
default_exclude
= []
-
export
(output=None, exclude=None, **kwargs)[source] Export the collection item in the Mimetype required.
..note:: If current implementation does not have special mimetypes, reuses default_export method
Parameters: Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
get_creator
(lang=None)[source] Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_description
(lang=None)[source] Get the description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_subject
(lang=None)[source] Get the subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None)[source] Get the title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
-
id
Identifier of the text
Returns: Identifier of the text Return type: text_type
-
metadata
Metadata information about the text
Returns: Collection object with metadata about the text Return type: Metadata
-
set_creator
(value, lang)[source] Set the DC Creator literal value
Parameters: lang – Language in which the value is
-
set_description
(value, lang=None)[source] Set the DC Description literal value
Parameters: lang – Language in which the value is
-
set_subject
(value, lang=None)[source] Set the DC Subject literal value
Parameters: lang – Language in which the value is
-
set_title
(value, lang=None)[source] Set the DC Title literal value
Parameters: lang – Language in which the value is
-
text
String representation of the text
Returns: String representation of the text Return type: text_type
-
class
MyCapytain.resources.prototypes.text.
TextualGraph
(identifier=None, **kwargs)[source] Bases:
MyCapytain.resources.prototypes.text.TextualNode
Node representing a text passage.
Parameters: - identifier (str) – Identifier of the text
- metadata (Collection) – Collection Information about the Item
- citation (Citation) – XmlCtsCitation system of the text
- children ([str]) – Current node Children’s Identifier
- parent (str) – Parent of the current node
- siblings (str) – Previous and next node of the current node
- depth (int) – Depth of the node in the global hierarchy of the text tree
- resource – Resource used to navigate through the textual graph
Variables: default_exclude – Default exclude for exports
-
DEFAULT_EXPORT
= None
-
EXPORT_TO
= []
-
asNode
()
-
childIds
Children Node
Return type: [str]
-
citation
XmlCtsCitation Object of the CtsTextMetadata
Returns: XmlCtsCitation Object of the CtsTextMetadata Return type: Citation
-
default_exclude
= []
-
depth
Depth of the node in the global hierarchy of the text tree
Return type: int
-
export
(output=None, exclude=None, **kwargs) Export the collection item in the Mimetype required.
..note:: If current implementation does not have special mimetypes, reuses default_export method
Parameters: Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
firstId
First child Node
Return type: str
-
getReffs
(level=1, subreference=None)[source] Reference available at a given level
Parameters: - level (Int) – Depth required. If not set, should retrieve first encountered level (1 based)
- passage (Reference) – Subreference (optional)
Return type: [text_type]
Returns: List of levels
-
getTextualNode
(subreference)[source] Retrieve a passage and store it in the object
Parameters: subreference (str or Node or Reference) – Reference of the passage to retrieve Return type: TextualNode Returns: Object representing the passage Raises: TypeError when reference is not a list or a Reference
-
get_creator
(lang=None) Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_description
(lang=None) Get the description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_subject
(lang=None) Get the subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None) Get the title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
-
id
Identifier of the text
Returns: Identifier of the text Return type: text_type
-
lastId
Last child Node
Return type: str
-
metadata
Metadata information about the text
Returns: Collection object with metadata about the text Return type: Metadata
-
nextId
Next Node (Sibling)
Return type: str
-
parentId
Parent Node
Return type: str
-
prevId
Previous Node (Sibling)
Return type: str
-
set_creator
(value, lang) Set the DC Creator literal value
Parameters: lang – Language in which the value is
-
set_description
(value, lang=None) Set the DC Description literal value
Parameters: lang – Language in which the value is
-
set_subject
(value, lang=None) Set the DC Subject literal value
Parameters: lang – Language in which the value is
-
set_title
(value, lang=None) Set the DC Title literal value
Parameters: lang – Language in which the value is
-
text
String representation of the text
Returns: String representation of the text Return type: text_type
-
class
MyCapytain.resources.prototypes.text.
TextualNode
(identifier=None, citation=None, **kwargs)[source] Bases:
MyCapytain.resources.prototypes.text.TextualElement
,MyCapytain.common.reference.NodeId
Node representing a text passage.
Parameters: - identifier (str) – Identifier of the text
- metadata (Collection) – Collection Information about the Item
- citation (Citation) – XmlCtsCitation system of the text
- children ([str]) – Current node Children’s Identifier
- parent (str) – Parent of the current node
- siblings (str) – Previous and next node of the current node
- depth (int) – Depth of the node in the global hierarchy of the text tree
Variables: default_exclude – Default exclude for exports
-
DEFAULT_EXPORT
= None
-
EXPORT_TO
= []
-
asNode
()
-
childIds
Children Node
Return type: [str]
-
citation
XmlCtsCitation Object of the CtsTextMetadata
Returns: XmlCtsCitation Object of the CtsTextMetadata Return type: Citation
-
default_exclude
= []
-
depth
Depth of the node in the global hierarchy of the text tree
Return type: int
-
export
(output=None, exclude=None, **kwargs) Export the collection item in the Mimetype required.
..note:: If current implementation does not have special mimetypes, reuses default_export method
Parameters: Returns: Object using a different representation
-
export_capacities
List Mimetypes that current object can export to
-
firstId
First child Node
Return type: str
-
get_creator
(lang=None) Get the DC Creator literal value
Parameters: lang – Language to retrieve Returns: Creator string representation Return type: Literal
-
get_description
(lang=None) Get the description of the object
Parameters: lang – Lang to retrieve Returns: Description string representation Return type: Literal
-
get_subject
(lang=None) Get the subject of the object
Parameters: lang – Lang to retrieve Returns: Subject string representation Return type: Literal
-
get_title
(lang=None) Get the title of the object
Parameters: lang – Lang to retrieve Returns: Title string representation Return type: Literal
-
graph
-
id
Identifier of the text
Returns: Identifier of the text Return type: text_type
-
lastId
Last child Node
Return type: str
-
metadata
Metadata information about the text
Returns: Collection object with metadata about the text Return type: Metadata
-
nextId
Next Node (Sibling)
Return type: str
-
parentId
Parent Node
Return type: str
-
prevId
Previous Node (Sibling)
Return type: str
-
set_creator
(value, lang) Set the DC Creator literal value
Parameters: lang – Language in which the value is
-
set_description
(value, lang=None) Set the DC Description literal value
Parameters: lang – Language in which the value is
-
set_subject
(value, lang=None) Set the DC Subject literal value
Parameters: lang – Language in which the value is
-
set_title
(value, lang=None) Set the DC Title literal value
Parameters: lang – Language in which the value is
-
text
String representation of the text
Returns: String representation of the text Return type: text_type
Benchmarks¶
In the recent attempt to boost our system, we had a look on the performance of MyCapytain with different parser. Even if as 1.0.1 xmlparser() is the recommended tool, we highly recommend to switch to lxml.objectify.parse() parser for performance. In the following benchmark run with timeit.sh on the main repo (You need PerseusDL/canonical-latinLit somewhere ), the first line is run with lxml.etree, the second with objectify and the third with a pickled object.
Testing on Seneca, Single Simple Passage
- 100 loops, best of 3: 4.45 msec per loop
- 100 loops, best of 3: 4.15 msec per loop
- 100 loops, best of 3: 3.75 msec per loop
Testing range
- 100 loops, best of 3: 7.63 msec per loop
- 100 loops, best of 3: 7.72 msec per loop
- 100 loops, best of 3: 6.66 msec per loop
Testing with a deeper architecture
- 100 loops, best of 3: 18.2 msec per loop
- 100 loops, best of 3: 14.3 msec per loop
- 100 loops, best of 3: 9.31 msec per loop
Testing with a deeper architecture at the end
- 100 loops, best of 3: 18.2 msec per loop
- 100 loops, best of 3: 14.2 msec per loop
- 100 loops, best of 3: 9.34 msec per loop
Testing with a deeper architecture with range
- 100 loops, best of 3: 19.3 msec per loop
- 100 loops, best of 3: 14.3 msec per loop
- 100 loops, best of 3: 9.9 msec per loop
Testing with complicated XPATH
- 100 loops, best of 3: 751 usec per loop
- 100 loops, best of 3: 770 usec per loop
- 100 loops, best of 3: 617 usec per loop