Beispiel #1
0
def expandPagesFromChildrenToParent(dict_tree):
    div_key = '{http://www.loc.gov/METS/}div'
    logical_struct_map = log_struct_map_tools.getLogicalStructMap(dict_tree)
    temp_dict_tree = addPagesOnLevel(logical_struct_map[div_key], dict_tree)
    if temp_dict_tree: # If temp_dict_tree is None, root already has pages
        return  addAllPagesToRoot(logical_struct_map[div_key], dict_tree)
    return dict_tree
Beispiel #2
0
def addNewDocStruct(dict_tree,doc_struct_info,parrent_attrib=None):
    '''
    Returns a dict tree with a (new) doc struct inserted. 
    
    {'doc_type': 'Article',
     'content':
            [{'name': 'Abstract', 'data' : 'From the Roman Empire...' }, 
             {'name' : 'TitleDocMain', 'data' : 'Return of the oppressed'},
             {'name' : 'Author', 'type' : 'person', 'fields' :
                 [{'tag' : 'goobi:firstName', 'data' : 'Peter'},
                  {'tag' : 'goobi:lastName', 'data' : 'Turchin'}]
            }],
     'start_page':5,
     'end_page':10'
    }
    
    :param dict_tree: dictionary tree to insert
    :param doc_struct_info: dictionary with the information to add
    '''
    # Get available DMDLOG and LOG in logical struct map
    log_strct_map = log_struct_map_tools.getLogicalStructMap(dict_tree)
    log_id = log_struct_map_tools.getAvailableStructMapLogId(log_strct_map)
    dmd_log_id = log_struct_map_tools.getAvailableStructMapDmdLogId(log_strct_map) 
    # Insert these in logical struct map
    dict_tree = log_struct_map_tools.addSectionToLogicalStructMap(dict_tree=dict_tree,
                                                                  sec_id = log_id,
                                                                  sec_type = doc_struct_info['doc_type'],
                                                                  parent_attrib=parrent_attrib,
                                                                  sec_dmdid=dmd_log_id)
    # Insert the relevant pages linked to LOG in struct link
    if 'start_page' in doc_struct_info: # Only add pages if start_page exist
        dict_tree = struct_link_tools.addStructLinks(dict_tree, log_id, doc_struct_info)
    # Create and insert dmdSec
    dict_tree = dmd_sec_tools.addDmdSec(dict_tree,dmd_log_id,doc_struct_info['content'])
    return dict_tree
def docTypeExists(dict_tree,doc_type):
    log_struct_map = log_struct_map_tools.getLogicalStructMap(dict_tree)
    ns = '{http://www.loc.gov/METS/}'
    elem_name = 'div'
    elem_attrib_key = 'TYPE'
    elem_attrib_val = doc_type
    dmd_sec = xml_tools.getAllSubTrees(log_struct_map,
                                       ns,
                                       elem_name,
                                       elem_attrib_key,
                                       elem_attrib_val)
    #pprint.pprint(dmd_sec)
    return len(dmd_sec) > 0