ocrd_cis/ocropy/segment.py
def page_subgroup_in_reading_order(roelem):
    """Replace given RO element by an equivalent OrderedGroup.
    
    Given a ReadingOrder element ``roelem`` (of any type),
    first look up its parent group. Remove it from the respective
    member list (of its region refs or un/ordered groups),
    even if it already was an OrderedGroup(Indexed).
    
    Then instantiate an empty OrderedGroup(Indexed), referencing
    the same region as ``roelem`` (and using the same index, if any).
    Add that group to the parent instead.
    
    Return the new group object.
    """
    LOG = getLogger('processor.OcropySegment')
    if not roelem:
        LOG.error('Cannot subgroup from empty ReadingOrder element')
        return roelem
    if not roelem.parent_object_:
        LOG.error('Cannot subgroup from orphan ReadingOrder element')
        return roelem
    if isinstance(roelem, (OrderedGroupType,OrderedGroupIndexedType)) and not (
            roelem.get_OrderedGroupIndexed() or
            roelem.get_UnorderedGroupIndexed() or
            roelem.get_RegionRefIndexed()):
        # is already a group and still empty
        return roelem
    if isinstance(roelem, (OrderedGroupType,
                           UnorderedGroupType,
                           RegionRefType)):
        getattr(roelem.parent_object_, {
            OrderedGroupType: 'get_OrderedGroup',
            UnorderedGroupType: 'get_UnorderedGroup',
            RegionRefType: 'get_RegionRef',
        }.get(roelem.__class__))().remove(roelem)
        roelem2 = OrderedGroupType(id=roelem.regionRef + '_group',
                                   regionRef=roelem.regionRef)
        roelem.parent_object_.add_OrderedGroup(roelem2)
        return roelem2
    if isinstance(roelem, (OrderedGroupIndexedType,
                           UnorderedGroupIndexedType,
                           RegionRefIndexedType)):
        getattr(roelem.parent_object_, {
            OrderedGroupIndexedType: 'get_OrderedIndexedGroup',
            UnorderedGroupIndexedType: 'get_UnorderedIndexedGroup',
            RegionRefIndexedType: 'get_RegionRefIndexed'
        }.get(roelem.__class__))().remove(roelem)
        roelem2 = OrderedGroupIndexedType(id=roelem.regionRef + '_group',
                                          index=roelem.index,
                                          regionRef=roelem.regionRef)
        roelem.parent_object_.add_OrderedGroupIndexed(roelem2)
        return roelem2
    return None
Replace given RO element by an equivalent OrderedGroup.
    
    Given a ReadingOrder element ``roelem`` (of any type),
    first look up its parent group. Remove it from the respective
    member list (of its region refs or un/ordered groups),
    even if it already was an OrderedGroup(Indexed).
    
    Then instantiate an empty OrderedGroup(Indexed), referencing
    the same region as ``roelem`` (and using the same index, if any).
    Add that group to the parent instead.
    
    Return the new group object.
    
Replace given RO element by an equivalent OrderedGroup.
Given a ReadingOrder element ``roelem`` (of any type),
first look up its parent group. Remove it from the respective
member list (of its region refs or un/ordered groups),
even if it already was an OrderedGroup(Indexed).

Then instantiate an empty OrderedGroup(Indexed), referencing
the same region as ``roelem`` (and using the same index, if any).
Add that group to the parent instead.

Return the new group object.
Replace given RO element by an equivalent OrderedGroup . Given a ReadingOrder element ` ` roelem ` ` ( of any type ) first look up its parent group . Remove it from the respective member list ( of its region refs or un / ordered groups ) even if it already was an OrderedGroup ( Indexed ) . Then instantiate an empty OrderedGroup ( Indexed ) referencing the same region as ` ` roelem ` ` ( and using the same index if any ) . Add that group to the parent instead . Return the new group object .
def page_subgroup_in_reading_order(roelem):
    LOG = getLogger('processor.OcropySegment')
    if not roelem:
        LOG.error('Cannot subgroup from empty ReadingOrder element')
        return roelem
    if not roelem.parent_object_:
        LOG.error('Cannot subgroup from orphan ReadingOrder element')
        return roelem
    if isinstance(roelem, (OrderedGroupType,OrderedGroupIndexedType)) and not (
            roelem.get_OrderedGroupIndexed() or
            roelem.get_UnorderedGroupIndexed() or
            roelem.get_RegionRefIndexed()):
        return roelem
    if isinstance(roelem, (OrderedGroupType,
                           UnorderedGroupType,
                           RegionRefType)):
        getattr(roelem.parent_object_, {
            OrderedGroupType: 'get_OrderedGroup',
            UnorderedGroupType: 'get_UnorderedGroup',
            RegionRefType: 'get_RegionRef',
        }.get(roelem.__class__))().remove(roelem)
        roelem2 = OrderedGroupType(id=roelem.regionRef + '_group',
                                   regionRef=roelem.regionRef)
        roelem.parent_object_.add_OrderedGroup(roelem2)
        return roelem2
    if isinstance(roelem, (OrderedGroupIndexedType,
                           UnorderedGroupIndexedType,
                           RegionRefIndexedType)):
        getattr(roelem.parent_object_, {
            OrderedGroupIndexedType: 'get_OrderedIndexedGroup',
            UnorderedGroupIndexedType: 'get_UnorderedIndexedGroup',
            RegionRefIndexedType: 'get_RegionRefIndexed'
        }.get(roelem.__class__))().remove(roelem)
        roelem2 = OrderedGroupIndexedType(id=roelem.regionRef + '_group',
                                          index=roelem.index,
                                          regionRef=roelem.regionRef)
        roelem.parent_object_.add_OrderedGroupIndexed(roelem2)
        return roelem2
    return None
def page_subgroup_in_reading_order ( roelem ) : LOG = getLogger ( 'processor.OcropySegment' ) if not roelem : LOG . error ( 'Cannot subgroup from empty ReadingOrder element' ) return roelem if not roelem . parent_object_ : LOG . error ( 'Cannot subgroup from orphan ReadingOrder element' ) return roelem if isinstance ( roelem , ( OrderedGroupType , OrderedGroupIndexedType ) ) and not ( roelem . get_OrderedGroupIndexed ( ) or roelem . get_UnorderedGroupIndexed ( ) or roelem . get_RegionRefIndexed ( ) ) : return roelem if isinstance ( roelem , ( OrderedGroupType , UnorderedGroupType , RegionRefType ) ) : getattr ( roelem . parent_object_ , { OrderedGroupType : 'get_OrderedGroup' , UnorderedGroupType : 'get_UnorderedGroup' , RegionRefType : 'get_RegionRef' , } . get ( roelem . __class__ ) ) ( ) . remove ( roelem ) roelem2 = OrderedGroupType ( id = roelem . regionRef + '_group' , regionRef = roelem . regionRef ) roelem . parent_object_ . add_OrderedGroup ( roelem2 ) return roelem2 if isinstance ( roelem , ( OrderedGroupIndexedType , UnorderedGroupIndexedType , RegionRefIndexedType ) ) : getattr ( roelem . parent_object_ , { OrderedGroupIndexedType : 'get_OrderedIndexedGroup' , UnorderedGroupIndexedType : 'get_UnorderedIndexedGroup' , RegionRefIndexedType : 'get_RegionRefIndexed' } . get ( roelem . __class__ ) ) ( ) . remove ( roelem ) roelem2 = OrderedGroupIndexedType ( id = roelem . regionRef + '_group' , index = roelem . index , regionRef = roelem . regionRef ) roelem . parent_object_ . add_OrderedGroupIndexed ( roelem2 ) return roelem2 return None
Replace given RO element by an equivalent OrderedGroup.
Replace given RO element by an equivalent OrderedGroup .
"""Replace given RO element by an equivalent OrderedGroup.
    
    Given a ReadingOrder element ``roelem`` (of any type),
    first look up its parent group. Remove it from the respective
    member list (of its region refs or un/ordered groups),
    even if it already was an OrderedGroup(Indexed).
    
    Then instantiate an empty OrderedGroup(Indexed), referencing
    the same region as ``roelem`` (and using the same index, if any).
    Add that group to the parent instead.
    
    Return the new group object.
    """ # is already a group and still empty
roelem