ocrd_models.ocrd_mets module¶
API to METS
-
class
ocrd_models.ocrd_mets.OcrdMets(**kwargs)[source]¶ Bases:
ocrd_models.ocrd_xml_base.OcrdXmlDocumentAPI to a single METS file
-
property
unique_identifier¶ Get the unique identifier by looking through
mods:identifierSee specs for details.
-
add_agent(*args, **kwargs)[source]¶ Add an
ocrd_models.ocrd_agent.OcrdAgentto the list of agents in themetsHdr.
-
find_all_files(*args, **kwargs)[source]¶ Like
find_files()but return a list of all results.Equivalent to
list(self.find_files(...))
-
find_files(ID=None, fileGrp=None, pageId=None, mimetype=None, url=None, local_only=False)[source]¶ Search
mets:fileentries in this METS document and yield results.The
ID,fileGrp,urlandmimetypeparameters can each be either a literal string, or a regular expression if the string starts with//(double slash).If it is a regex, the leading
//is removed and candidates are matched against the regex with re.fullmatch. If it is a literal string, comparison is done with string equality.The
pageIdparameter supports the numeric range operator... For example, to find all files in pagesPHYS_0001toPHYS_0003,PHYS_0001..PHYS_0003will be expanded toPHYS_0001,PHYS_0002,PHYS_0003.- Keyword Arguments
ID (string) –
@IDof themets:filefileGrp (string) –
@USEof themets:fileGrpto list files ofpageId (string) –
@IDof the corresponding physicalmets:structMapentry (physical page)url (string) –
@xlink:href(URL or path) ofmets:Flocatofmets:filemimetype (string) –
@MIMETYPEofmets:filelocal (boolean) – Whether to restrict results to local files in the filesystem
- Yields
ocrd_models:ocrd_file:OcrdFileinstantiations
-
add_file_group(fileGrp)[source]¶ Add a new
mets:fileGrp.- Parameters
fileGrp (string) –
@USEof the newmets:fileGrp.
-
remove_file_group(USE, recursive=False, force=False)[source]¶ Remove a
mets:fileGrp(single fixed@USEor multiple regex@USE)- Parameters
USE (string) –
@USEof themets:fileGrpto delete. Can be a regex if prefixed with//recursive (boolean) – Whether to recursively delete each
mets:filein the groupforce (boolean) – Do not raise an exception if
mets:fileGrpdoes not exist
-
add_file(fileGrp, mimetype=None, url=None, ID=None, pageId=None, force=False, local_filename=None, ignore=False, **kwargs)[source]¶ Instantiate and add a new
ocrd_models.ocrd_file.OcrdFile.- Parameters
fileGrp (string) –
@USEofmets:fileGrpto add to- Keyword Arguments
mimetype (string) –
@MIMETYPEof themets:fileto useurl (string) –
@xlink:href(URL or path) of themets:fileto useID (string) –
@IDof themets:fileto usepageId (string) –
@IDin the physicalmets:structMapto link toforce (boolean) – Whether to add the file even if a
mets:filewith the same@IDalready exists.ignore (boolean) – Do not look for existing files at all. Shift responsibility for preventing errors from duplicate ID to the user.
local_filename (string) –
-
remove_file(*args, **kwargs)[source]¶ Delete each
ocrd:filematching the query. Same arguments asfind_files()
-
remove_one_file(ID)[source]¶ Delete an existing
ocrd_models.ocrd_file.OcrdFile.- Parameters
ID (string) –
@IDof themets:fileto delete- Returns
The old
ocrd_models.ocrd_file.OcrdFilereference.
-
property
physical_pages¶ List all page IDs (the
@IDof each physicalmets:structMapmets:div)
-
get_physical_pages(for_fileIds=None)[source]¶ List all page IDs (the
@IDof each physicalmets:structMapmets:div), optionally for a subset ofmets:file@IDfor_fileIds.
-
set_physical_page_for_file(pageId, ocrd_file, order=None, orderlabel=None)[source]¶ Set the physical page ID (
@IDof the physicalmets:structMapmets:diventry) corresponding to themets:fileocrd_file, creating all structures if necessary.- Parameters
pageId (string) –
@IDof the physicalmets:structMapentry to useocrd_file (object) – existing
ocrd_models.ocrd_file.OcrdFileobject
- Keyword Arguments
order (string) –
@ORDERto useorderlabel (string) –
@ORDERLABELto use
-
get_physical_page_for_file(ocrd_file)[source]¶ Get the physical page ID (
@IDof the physicalmets:structMapmets:diventry) corresponding to themets:fileocrd_file.
-
merge(other_mets, fileGrp_mapping=None, after_add_cb=None, **kwargs)[source]¶ Add all files from other_mets.
Accepts the same kwargs as
find_files()- Keyword Arguments
fileGrp_mapping (dict) – Map
other_metsfileGrp to fileGrp in this METSafter_add_cb (function) – Callback received after file is added to the METS
-
property