本文整理汇总了Python中BibleOrgSysGlobals.checkXMLNoAttributes方法的典型用法代码示例。如果您正苦于以下问题:Python BibleOrgSysGlobals.checkXMLNoAttributes方法的具体用法?Python BibleOrgSysGlobals.checkXMLNoAttributes怎么用?Python BibleOrgSysGlobals.checkXMLNoAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BibleOrgSysGlobals
的用法示例。
在下文中一共展示了BibleOrgSysGlobals.checkXMLNoAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadTable
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoAttributes [as 别名]
def loadTable( self, element, location ):
"""
"""
BibleOrgSysGlobals.checkXMLNoText( element, location, 'kg92' )
BibleOrgSysGlobals.checkXMLNoTail( element, location, 'ka92' )
BibleOrgSysGlobals.checkXMLNoAttributes( element, location, 'ks63' )
for subelement in element:
sublocation = subelement.tag + " of " + location
if subelement.tag == 'tr':
#print( "table", sublocation )
self.thisBook.addLine( 'tr', '' )
BibleOrgSysGlobals.checkXMLNoText( subelement, sublocation, 'sg32' )
BibleOrgSysGlobals.checkXMLNoTail( subelement, sublocation, 'dh82' )
BibleOrgSysGlobals.checkXMLNoAttributes( subelement, sublocation, 'mniq' )
for sub2element in subelement:
sub2location = sub2element.tag + " of " + sublocation
tag, text = sub2element.tag, clean(sub2element.text)
assert( tag in ('th', 'thr', 'tc', 'tcr',) )
BibleOrgSysGlobals.checkXMLNoTail( sub2element, sub2location, 'ah82' )
BibleOrgSysGlobals.checkXMLNoSubelements( sub2element, sub2location, 'ka63' )
level = None
for attrib,value in sub2element.items():
if attrib == 'level': level = value
else:
logging.warning( _("vx25 Unprocessed {} attribute ({}) in {}").format( attrib, value, location ) )
marker = tag + (level if level else '')
self.thisBook.appendToLastLine( ' \\{} {}'.format( marker, text ) )
else:
logging.warning( _("kv64 Unprocessed {} element after {} {}:{} in {}").format( subelement.tag, self.thisBook.BBB, C, V, sublocation ) )
示例2: loadSystems
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoAttributes [as 别名]
def loadSystems( self, XMLFolder=None ):
"""
Load and pre-process the specified book order systems.
"""
if not self._XMLSystems: # Only ever do this once
if XMLFolder==None: XMLFolder = os.path.join( os.path.dirname(__file__), "DataFiles", "BookOrders" ) # Relative to module, not cwd
self.__XMLFolder = XMLFolder
if BibleOrgSysGlobals.verbosityLevel > 2: print( _("Loading book order systems from {}…").format( self.__XMLFolder ) )
filenamePrefix = "BIBLEBOOKORDER_"
for filename in os.listdir( self.__XMLFolder ):
filepart, extension = os.path.splitext( filename )
if extension.upper() == '.XML' and filepart.upper().startswith(filenamePrefix):
bookOrderSystemCode = filepart[len(filenamePrefix):]
if BibleOrgSysGlobals.verbosityLevel > 3: print( _(" Loading{} book order system from {}…").format( bookOrderSystemCode, filename ) )
self._XMLSystems[bookOrderSystemCode] = {}
self._XMLSystems[bookOrderSystemCode]['tree'] = ElementTree().parse( os.path.join( self.__XMLFolder, filename ) )
assert self._XMLSystems[bookOrderSystemCode]['tree'] # Fail here if we didn't load anything at all
# Check and remove the header element
if self._XMLSystems[bookOrderSystemCode]['tree'].tag == self.XMLTreeTag:
header = self._XMLSystems[bookOrderSystemCode]['tree'][0]
if header.tag == self.headerTag:
self._XMLSystems[bookOrderSystemCode]["header"] = header
self._XMLSystems[bookOrderSystemCode]['tree'].remove( header )
BibleOrgSysGlobals.checkXMLNoText( header, "header" )
BibleOrgSysGlobals.checkXMLNoTail( header, "header" )
BibleOrgSysGlobals.checkXMLNoAttributes( header, "header" )
if len(header)>1:
logging.info( _("Unexpected elements in header") )
elif len(header)==0:
logging.info( _("Missing work element in header") )
else:
work = header[0]
BibleOrgSysGlobals.checkXMLNoText( work, "work in header" )
BibleOrgSysGlobals.checkXMLNoTail( work, "work in header" )
BibleOrgSysGlobals.checkXMLNoAttributes( work, "work in header" )
if work.tag == "work":
self._XMLSystems[bookOrderSystemCode]['version'] = work.find('version').text
self._XMLSystems[bookOrderSystemCode]["date"] = work.find("date").text
self._XMLSystems[bookOrderSystemCode]["title"] = work.find("title").text
else:
logging.warning( _("Missing work element in header") )
else:
logging.warning( _("Missing header element (looking for {!r} tag)").format( self.headerTag ) )
else:
logging.error( _("Expected to load {!r} but got {!r}").format( self.XMLTreeTag, self._XMLSystems[bookOrderSystemCode]['tree'].tag ) )
bookCount = 0 # There must be an easier way to do this
for subelement in self._XMLSystems[bookOrderSystemCode]['tree']:
bookCount += 1
if BibleOrgSysGlobals.verbosityLevel > 2:
print( _(" Loaded {} books for {}").format( bookCount, bookOrderSystemCode ) )
logging.info( _(" Loaded {} books for {}").format( bookCount, bookOrderSystemCode ) )
if BibleOrgSysGlobals.strictCheckingFlag:
self.__validateSystem( self._XMLSystems[bookOrderSystemCode]['tree'], bookOrderSystemCode )
else: # The data must have been already loaded
if XMLFolder is not None and XMLFolder!=self.__XMLFolder: logging.error( _("Bible book order systems are already loaded -- your different folder of {!r} was ignored").format( self.__XMLFolder ) )
return self
示例3: loadSystems
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoAttributes [as 别名]
def loadSystems( self, XMLFolder=None ):
"""
Load and pre-process the specified punctuation systems.
"""
if not self._XMLSystems: # Only ever do this once
if XMLFolder==None: XMLFolder = os.path.join( os.path.dirname(__file__), "DataFiles", "PunctuationSystems" ) # Relative to module, not cwd
self.__XMLFolder = XMLFolder
if BibleOrgSysGlobals.verbosityLevel > 2: print( _("Loading punctuations systems from {}...").format( self.__XMLFolder ) )
filenamePrefix = "BIBLEPUNCTUATIONSYSTEM_"
for filename in os.listdir( self.__XMLFolder ):
filepart, extension = os.path.splitext( filename )
if extension.upper() == '.XML' and filepart.upper().startswith(filenamePrefix):
punctuationSystemCode = filepart[len(filenamePrefix):]
if BibleOrgSysGlobals.verbosityLevel > 3: print( _("Loading {} punctuation system from {}...").format( punctuationSystemCode, filename ) )
self._XMLSystems[punctuationSystemCode] = {}
self._XMLSystems[punctuationSystemCode]["tree"] = ElementTree().parse( os.path.join( self.__XMLFolder, filename ) )
assert( self._XMLSystems[punctuationSystemCode]["tree"] ) # Fail here if we didn't load anything at all
# Check and remove the header element
if self._XMLSystems[punctuationSystemCode]["tree"].tag == self.treeTag:
header = self._XMLSystems[punctuationSystemCode]["tree"][0]
if header.tag == self.headerTag:
self._XMLSystems[punctuationSystemCode]["header"] = header
self._XMLSystems[punctuationSystemCode]["tree"].remove( header )
BibleOrgSysGlobals.checkXMLNoText( header, "header" )
BibleOrgSysGlobals.checkXMLNoTail( header, "header" )
BibleOrgSysGlobals.checkXMLNoAttributes( header, "header" )
if len(header)>1:
logging.info( _("Unexpected elements in header") )
elif len(header)==0:
logging.info( _("Missing work element in header") )
else:
work = header[0]
BibleOrgSysGlobals.checkXMLNoText( work, "work in header" )
BibleOrgSysGlobals.checkXMLNoTail( work, "work in header" )
BibleOrgSysGlobals.checkXMLNoAttributes( work, "work in header" )
if work.tag == "work":
self._XMLSystems[punctuationSystemCode]["version"] = work.find("version").text
self._XMLSystems[punctuationSystemCode]["date"] = work.find("date").text
self._XMLSystems[punctuationSystemCode]["title"] = work.find("title").text
else:
logging.warning( _("Missing work element in header") )
else:
logging.warning( _("Missing header element (looking for {!r} tag)").format( headerTag ) )
else:
logging.error( _("Expected to load {!r} but got {!r}").format( treeTag, self._XMLSystems[punctuationSystemCode]["tree"].tag ) )
bookCount = 0 # There must be an easier way to do this
for subelement in self._XMLSystems[punctuationSystemCode]["tree"]:
bookCount += 1
logging.info( _(" Loaded {} books").format( bookCount ) )
if BibleOrgSysGlobals.strictCheckingFlag:
self._validateSystem( self._XMLSystems[punctuationSystemCode]["tree"], punctuationSystemCode )
return self
示例4: loadCrossreference
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoAttributes [as 别名]
def loadCrossreference( self, element, location ):
"""
Has to handle: <x caller="+"><ref tgt="EXO.30.12">Exodus 30:12</ref></x>
"""
text, tail = clean(element.text), clean(element.tail)
caller = None
for attrib,value in element.items():
if attrib == 'caller':
caller = value
else:
logging.warning( _("fhj2 Unprocessed {} attribute ({}) in {}").format( attrib, value, location ) )
self.thisBook.appendToLastLine( ' \\x {}'.format( caller ) )
for subelement in element:
sublocation = subelement.tag + " of " + location
marker, xText, xTail = subelement.tag, clean(subelement.text), clean(subelement.tail)
#print( "USFX.loadCrossreference", repr(caller), repr(text), repr(tail), repr(marker), repr(xText), repr(xTail) )
#if BibleOrgSysGlobals.verbosityLevel > 0 and marker not in ('ref','xo','xt',):
#print( "USFX.loadCrossreference found", repr(caller), repr(marker), repr(xText), repr(xTail) )
if BibleOrgSysGlobals.debugFlag: assert( marker in ('ref','xo','xt',) )
if marker=='ref':
assert( xText )
BibleOrgSysGlobals.checkXMLNoSubelements( subelement, sublocation, 's1sd' )
target = None
for attrib,value in subelement.items():
if attrib == 'tgt': target = value
else:
logging.warning( _("aj41 Unprocessed {} attribute ({}) in {}").format( attrib, value, sublocation ) )
if target:
self.thisBook.appendToLastLine( ' \\{} {}\\{}*{}'.format( marker, target, marker, xText ) )
else: halt
else:
BibleOrgSysGlobals.checkXMLNoAttributes( subelement, sublocation, 'sc35' )
self.thisBook.appendToLastLine( ' \\{} {}'.format( marker, xText ) )
if marker[0] == 'x': # Starts with x, e.g., xo, xt
for sub2element in subelement:
sub2location = sub2element.tag + " of " + sublocation
marker2, xText2, xTail2 = sub2element.tag, clean(sub2element.text), clean(sub2element.tail)
BibleOrgSysGlobals.checkXMLNoSubelements( sub2element, sub2location, 'fs63' )
if marker2=='ref':
if xText2:
#print( 'xt2', marker2, repr(xText2), repr(xTail2), sub2location )
self.thisBook.appendToLastLine( xText2 )
target = None
for attrib,value in sub2element.items():
if attrib == 'tgt': target = value
else:
logging.warning( _("gs34 Unprocessed {} attribute ({}) in {}").format( attrib, value, sub2location ) )
if target: self.thisBook.appendToLastLine( ' \\{} {}'.format( marker2, target ) )
else: halt
else: halt
if xTail2: self.thisBook.appendToLastLine( xTail2 )
else: halt
if xTail:
self.thisBook.appendToLastLine( '\\{}*{}'.format( marker, xTail ) )
self.thisBook.appendToLastLine( '\\x*{}'.format( (' '+tail) if tail else '' ) )
示例5: validateEntries
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoAttributes [as 别名]
def validateEntries( self, segment ):
"""
Check/validate the given Strongs lexicon entries.
"""
if BibleOrgSysGlobals.debugFlag: assert segment.tag == "entries"
BibleOrgSysGlobals.checkXMLNoText( segment, segment.tag, "kw99" )
BibleOrgSysGlobals.checkXMLNoTail( segment, segment.tag, "ls90" )
BibleOrgSysGlobals.checkXMLNoAttributes( segment, segment.tag, "hsj2" )
self.StrongsEntries = {}
for element in segment:
if element.tag == "entry":
self.validateEntry( element )
示例6: loadCharacterFormatting
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoAttributes [as 别名]
def loadCharacterFormatting( self, element, location, BBB, C, V ):
"""
"""
marker, text, tail = element.tag, clean(element.text), clean(element.tail)
BibleOrgSysGlobals.checkXMLNoAttributes( element, location, 'sd12' )
self.thisBook.appendToLastLine( ' \\{} {}'.format( marker, text ) )
for subelement in element:
sublocation = subelement.tag + " of " + location
#print( "element", repr(element.tag) )
if subelement.tag == 'f':
#print( "USFX.loadParagraph Found footnote at", sublocation, C, V, repr(subelement.text) )
self.loadFootnote( subelement, sublocation, BBB, C, V )
else:
logging.warning( _("sf31 Unprocessed {} element after {} {}:{} in {}").format( repr(subelement.tag), self.thisBook.BBB, C, V, location ) )
if BibleOrgSysGlobals.debugFlag and debuggingThisModule: halt
self.thisBook.appendToLastLine( '\\{}*{}'.format( marker, (' '+tail) if tail else '' ) )
示例7: __validateAndExtractBook
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoAttributes [as 别名]
def __validateAndExtractBook( self, book ):
"""
Check/validate and extract book data from the given XML book record
finding chapter subelements.
"""
if BibleOrgSysGlobals.verbosityLevel > 3: print( _("Validating XML book…") )
# Process the div attributes first
BBB = bookName = bookShortName = bookNumber = None
for attrib,value in book.items():
if attrib=="bnumber":
bookNumber = value
elif attrib=="bname":
bookName = value
elif attrib=="bsname":
bookShortName = value
else: logging.warning( "Unprocessed {!r} attribute ({}) in book element".format( attrib, value ) )
if bookNumber:
try: BBB = BibleOrgSysGlobals.BibleBooksCodes.getBBBFromReferenceNumber( bookNumber )
except KeyError:
logging.warning( "Unable to deduce which book is number={}, name={}, shortName={} -- ignoring it" \
.format( bookNumber, bookName, bookShortName ) )
elif bookName:
BBB = self.genericBOS.getBBBFromText( bookName )
if BBB:
if BibleOrgSysGlobals.verbosityLevel > 2: print( _("Validating {} {}…").format( BBB, bookName ) )
thisBook = BibleBook( self, BBB )
thisBook.objectNameString = 'Haggai XML Bible Book object'
thisBook.objectTypeString = 'Haggai'
#thisBook.sourceFilepath = self.sourceFilepath
for element in book:
if element.tag == HaggaiXMLBible.captionTag:
sublocation = "caption in {}".format( BBB )
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'jhl6' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, 'jk21' )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'kjh6' )
thisBook.addLine( 'mt', element.text )
elif element.tag == HaggaiXMLBible.chapterTag:
sublocation = "chapter in {}".format( BBB )
BibleOrgSysGlobals.checkXMLNoText( element, sublocation, 'j3jd' )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'al1d' )
self.__validateAndExtractChapter( BBB, thisBook, element )
else: logging.error( "Expected to find {!r} but got {!r}".format( HaggaiXMLBible.chapterTag, element.tag ) )
if BibleOrgSysGlobals.verbosityLevel > 2: print( " Saving {} into results…".format( BBB ) )
self.stashBook( thisBook )
示例8: loadFigure
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoAttributes [as 别名]
def loadFigure( self, element, location ):
"""
"""
BibleOrgSysGlobals.checkXMLNoText( element, location, 'ff36' )
BibleOrgSysGlobals.checkXMLNoAttributes( element, location, 'cf35' )
figDict = { 'description':'', 'catalog':'', 'size':'', 'location':'', 'copyright':'', 'caption':'', 'reference':'' }
for subelement in element:
sublocation = subelement.tag + " of " + location
figTag, figText = subelement.tag, clean(subelement.text)
assert( figTag in figDict )
figDict[figTag] = '' if figText is None else figText
BibleOrgSysGlobals.checkXMLNoTail( subelement, sublocation, 'jkf5' )
BibleOrgSysGlobals.checkXMLNoAttributes( subelement, sublocation, 'ld18' )
BibleOrgSysGlobals.checkXMLNoSubelements( subelement, sublocation, 'hb46' )
newString = ''
for j,tag in enumerate( ('description', 'catalog', 'size', 'location', 'copyright', 'caption', 'reference',) ):
newString += ('' if j==0 else '|') + figDict[tag]
figTail = clean( element.tail )
self.thisBook.appendToLastLine( ' \\fig {}\\fig*{}'.format( newString, (' '+figTail) if figTail else '' ) )
示例9: __load
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoAttributes [as 别名]
def __load( self, XMLFilepath ):
"""
Load the source XML file and remove the header from the tree.
Also, extracts some useful elements from the header element.
"""
assert XMLFilepath
self.__XMLFilepath = XMLFilepath
assert self._XMLtree is None or len(self._XMLtree)==0 # Make sure we're not doing this twice
if BibleOrgSysGlobals.verbosityLevel > 2: print( _("Loading USFMMarkers XML file from {!r}…").format( self.__XMLFilepath ) )
self._XMLtree = ElementTree().parse( self.__XMLFilepath )
assert self._XMLtree # Fail here if we didn't load anything at all
if self._XMLtree.tag == self._treeTag:
header = self._XMLtree[0]
if header.tag == self._headerTag:
self.XMLheader = header
self._XMLtree.remove( header )
BibleOrgSysGlobals.checkXMLNoText( header, "header" )
BibleOrgSysGlobals.checkXMLNoTail( header, "header" )
BibleOrgSysGlobals.checkXMLNoAttributes( header, "header" )
if len(header)>1:
logging.info( _("Unexpected elements in header") )
elif len(header)==0:
logging.info( _("Missing work element in header") )
else:
work = header[0]
BibleOrgSysGlobals.checkXMLNoText( work, "work in header" )
BibleOrgSysGlobals.checkXMLNoTail( work, "work in header" )
BibleOrgSysGlobals.checkXMLNoAttributes( work, "work in header" )
if work.tag == "work":
self.ProgVersion = work.find('version').text
self.dateString = work.find("date").text
self.titleString = work.find("title").text
else:
logging.warning( _("Missing work element in header") )
else:
logging.warning( _("Missing header element (looking for {!r} tag)".format( self._headerTag ) ) )
if header.tail is not None and header.tail.strip(): logging.error( _("Unexpected {!r} tail data after header").format( element.tail ) )
else:
logging.error( _("Expected to load {!r} but got {!r}").format( self._treeTag, self._XMLtree.tag ) )
示例10: __validateAndExtractParagraph
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoAttributes [as 别名]
def __validateAndExtractParagraph( self, BBB, chapterNumber, thisBook, paragraph ):
"""
Check/validate and extract paragraph data from the given XML book record
finding and saving paragraphs and
finding and saving verse elements.
"""
if BibleOrgSysGlobals.verbosityLevel > 3: print( _("Validating XML paragraph…") )
location = "paragraph in {} {}".format( BBB, chapterNumber )
BibleOrgSysGlobals.checkXMLNoAttributes( paragraph, location, 'brgw3' )
BibleOrgSysGlobals.checkXMLNoText( paragraph, location, 'brgw3' )
BibleOrgSysGlobals.checkXMLNoTail( paragraph, location, 'brgw3' )
thisBook.addLine( 'p', '' )
# Handle verse subelements (verses)
for element in paragraph:
if element.tag == HaggaiXMLBible.verseTag:
location = "verse in {} {}".format( BBB, chapterNumber )
self.__validateAndExtractVerse( BBB, chapterNumber, thisBook, element )
elif element.tag == HaggaiXMLBible.captionTag+'disabled': # Used in Psalms
location = "caption in {} {}".format( BBB, chapterNumber )
BibleOrgSysGlobals.checkXMLNoTail( element, location, 'k5k8' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, location, 'd3f5' )
# Handle caption attributes
vRef = None
for attrib,value in element.items():
if attrib=="vref":
vRef = value
if BibleOrgSysGlobals.debugFlag: assert vRef == '1'
else: logging.warning( "Unprocessed {!r} attribute ({}) in caption element".format( attrib, value ) )
if BibleOrgSysGlobals.debugFlag: assert vRef
vText = element.text
if not vText:
logging.warning( "{} {}:{} has no text".format( BBB, chapterNumber, vRef ) )
if vText: # This is the main text of the caption
#print( "{} {}:{} {!r}".format( BBB, chapterNumber, verseNumber, vText ) )
thisBook.addLine( 'v', '0' + ' ' + vText ) # We save it as verse zero
else: logging.error( "Expected to find {!r} but got {!r}".format( HaggaiXMLBible.verseTag, element.tag ) )
示例11: __validateAndExtractChapter
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoAttributes [as 别名]
def __validateAndExtractChapter( self, BBB, thisBook, chapter ):
"""
Check/validate and extract chapter data from the given XML book record
finding and saving chapter numbers and
finding and saving verse elements.
"""
if BibleOrgSysGlobals.verbosityLevel > 3: print( _("Validating XML chapter…") )
# Process the div attributes first
chapterNumber = numVerses = None
for attrib,value in chapter.items():
if attrib=="n":
chapterNumber = value
elif attrib=="VERSES":
numVerses = value
else: logging.warning( "Unprocessed {!r} attribute ({}) in chapter element".format( attrib, value ) )
if chapterNumber:
#print( BBB, 'c', chapterNumber )
chapterNumber = chapterNumber.replace( 'of Solomon ', '' ) # Fix a mistake in the Chinese_SU module
thisBook.addLine( 'c', chapterNumber )
else: logging.error( "Missing 'n' attribute in chapter element for {}".format( BBB ) )
for element in chapter:
if element.tag == OpenSongXMLBible.verseTag:
sublocation = "verse in {} {}".format( BBB, chapterNumber )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'l5ks' )
verseNumber = toVerseNumber = None
for attrib,value in element.items():
if attrib=="n":
verseNumber = value
elif attrib=="t":
toVerseNumber = value
else: logging.warning( "Unprocessed {!r} attribute ({}) in verse element".format( attrib, value ) )
if BibleOrgSysGlobals.debugFlag: assert verseNumber
#thisBook.addLine( 'v', verseNumber )
vText = element.text if element.text else ''
for subelement in element:
sub2location = "{} in {}".format( subelement.tag, sublocation )
BibleOrgSysGlobals.checkXMLNoAttributes( subelement, sub2location, 'ks03' )
BibleOrgSysGlobals.checkXMLNoSubelements( subelement, sub2location, 'ks05' )
if subelement.tag == 'i':
vText += '\\it {}\\it*{}'.format( subelement.text, subelement.tail )
else: logging.error( "Expected to find 'i' but got {!r}".format( subelement.tag ) )
vText += element.tail if element.tail else ''
if not vText:
logging.warning( "{} {}:{} has no text".format( BBB, chapterNumber, verseNumber ) )
#print( 'vText1', vText )
if vText: # This is the main text of the verse (follows the verse milestone)
#print( "{} {}:{} {!r}".format( BBB, chapterNumber, verseNumber, vText ) )
if '\n' in vText: # This is how they represent poety
#print( "vText", repr(vText), repr(element.text) )
for j, textBit in enumerate( vText.split( '\n' ) ):
if j==0:
thisBook.addLine( 'q1', '' )
thisBook.addLine( 'v', verseNumber + ' ' + textBit )
else: thisBook.addLine( 'q1', textBit )
else: # Just one verse line
thisBook.addLine( 'v', verseNumber + ' ' + vText )
#print( 'vText2', vText )
else: logging.error( "Expected to find {!r} but got {!r}".format( OpenSongXMLBible.verseTag, element.tag ) )
示例12: __validateAndExtractHeader
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoAttributes [as 别名]
def __validateAndExtractHeader( self ):
"""
Extracts information out of the header record, such as:
<INFORMATION>
<title>King James Version</title>
<creator></creator>
<subject>The Holy Bible</subject>
<description>In 1604, King James I of England authorized that a new translation of the Bible into English be started. It was finished in 1611, just 85 years after the first translation of the New Testament into English appeared (Tyndale, 1526). The Authorized Version, or King James Version, quickly became the standard for English-speaking Protestants. Its flowing language and prose rhythm has had a profound influence on the literature of the past 300 years.</description>
<publisher>FREE BIBLE SOFTWARE GROUP</publisher>
<contributors />
<date>2009-01-23</date>
<type>Bible</type>
<format>Haggai XML Bible Markup Language</format>
<identifier>kjv</identifier>
<source>http://www.unboundbible.com/zips/index.cfm?lang=English</source>
<language>ENG</language>
<coverage>provide the Bible to the nations of the world</coverage>
<rights>We believe that this Bible is found in the Public Domain.</rights>
</INFORMATION>
"""
if BibleOrgSysGlobals.debugFlag: assert self.header
location = 'Header'
BibleOrgSysGlobals.checkXMLNoAttributes( self.header, location, 'j4j6' )
BibleOrgSysGlobals.checkXMLNoText( self.header, location, 'sk4l' )
BibleOrgSysGlobals.checkXMLNoTail( self.header, location, 'a2d4' )
# TODO: We probably need to rationalise some of the self.xxx stores
for element in self.header:
#print( "header", element.tag )
if element.tag == 'title':
sublocation = "title in {}".format( location )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'al1d' )
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'j3jd' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, '5g78' )
if BibleOrgSysGlobals.debugFlag: assert element.text
self.title = element.text
elif element.tag == 'creator':
sublocation = "creator in {}".format( location )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'al1d' )
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'j3jd' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, '5g78' )
if element.text: self.creator = element.text
elif element.tag == 'subject':
sublocation = "subject in {}".format( location )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'al1d' )
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'j3jd' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, '5g78' )
if element.text: self.subject = element.text
elif element.tag == 'description':
sublocation = "description in {}".format( location )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'al1d' )
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'j3jd' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, '5g78' )
if BibleOrgSysGlobals.debugFlag: assert element.text
self.description = element.text
elif element.tag == 'publisher':
sublocation = "publisher in {}".format( location )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'al1d' )
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'j3jd' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, '5g78' )
if element.text: self.publisher = element.text
elif element.tag == 'contributor':
sublocation = "contributor in {}".format( location )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'alj1d' )
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'j3jjd' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, '5gk78' )
if element.text:
try: self.contributor = [ self.contributor, element.text ] # Put multiples into a list
except AttributeError: self.contributor = element.text # Must be the first (and possibly only) one
elif element.tag == 'contributors':
sublocation = "contributors in {}".format( location )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'al1d' )
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'j3jd' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, '5g78' )
if element.text: self.contributors = element.text
elif element.tag == 'date':
sublocation = "date in {}".format( location )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'al1d' )
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'j3jd' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, '5g78' )
if BibleOrgSysGlobals.debugFlag: assert element.text
self.date = element.text
elif element.tag == 'type':
sublocation = "type in {}".format( location )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'al1d' )
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'j3jd' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, '5g78' )
if element.text: self.documentType = element.text
elif element.tag == 'format':
sublocation = "format in {}".format( location )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'al1d' )
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'j3jd' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, '5g78' )
if BibleOrgSysGlobals.debugFlag: assert element.text
if BibleOrgSysGlobals.debugFlag: assert element.text == 'Haggai XML Bible Markup Language'
elif element.tag == 'identifier':
sublocation = "identifier in {}".format( location )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'al1d' )
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'j3jd' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, '5g78' )
#.........这里部分代码省略.........
示例13: _validateSystem
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoAttributes [as 别名]
def _validateSystem( self, punctuationTree, systemName ):
"""
"""
assert punctuationTree
uniqueDict = {}
for elementName in self.uniqueElements: uniqueDict["Element_"+elementName] = []
for attributeName in self.uniqueAttributes: uniqueDict["Attribute_"+attributeName] = []
for k,element in enumerate(punctuationTree):
if element.tag in self.mainElementTags:
BibleOrgSysGlobals.checkXMLNoTail( element, element.tag )
if not self.compulsoryAttributes and not self.optionalAttributes: BibleOrgSysGlobals.checkXMLNoAttributes( element, element.tag )
if not self.compulsoryElements and not self.optionalElements: BibleOrgSysGlobals.checkXMLNoSubelements( element, element.tag )
# Check compulsory attributes on this main element
for attributeName in self.compulsoryAttributes:
attributeValue = element.get( attributeName )
if attributeValue is None:
logging.error( _("Compulsory {!r} attribute is missing from {} element in record {}").format( attributeName, element.tag, k ) )
if not attributeValue:
logging.warning( _("Compulsory {!r} attribute is blank on {} element in record {}").format( attributeName, element.tag, k ) )
# Check optional attributes on this main element
for attributeName in self.optionalAttributes:
attributeValue = element.get( attributeName )
if attributeValue is not None:
if not attributeValue:
logging.warning( _("Optional {!r} attribute is blank on {} element in record {}").format( attributeName, element.tag, k ) )
# Check for unexpected additional attributes on this main element
for attributeName in element.keys():
attributeValue = element.get( attributeName )
if attributeName not in self.compulsoryAttributes and attributeName not in self.optionalAttributes:
logging.warning( _("Additional {!r} attribute ({!r}) found on {} element in record {}").format( attributeName, attributeValue, element.tag, k ) )
# Check the attributes that must contain unique information (in that particular field -- doesn't check across different attributes)
for attributeName in self.uniqueAttributes:
attributeValue = element.get( attributeName )
if attributeValue is not None:
if attributeValue in uniqueDict["Attribute_"+attributeName]:
logging.error( _("Found {!r} data repeated in {!r} field on {} element in record {}").format( attributeValue, attributeName, element.tag, k ) )
uniqueDict["Attribute_"+attributeName].append( attributeValue )
# Check compulsory elements
for elementName in self.compulsoryElements:
if element.find( elementName ) is None:
logging.error( _("Compulsory {!r} element is missing in record with ID {!r} (record {})").format( elementName, ID, k ) )
if not element.find( elementName ).text:
logging.warning( _("Compulsory {!r} element is blank in record with ID {!r} (record {})").format( elementName, ID, k ) )
# Check optional elements
for elementName in self.optionalElements:
if element.find( elementName ) is not None:
if not element.find( elementName ).text:
logging.warning( _("Optional {!r} element is blank in record with ID {!r} (record {})").format( elementName, ID, k ) )
# Check for unexpected additional elements
for subelement in element:
if subelement.tag not in self.compulsoryElements and subelement.tag not in self.optionalElements:
logging.warning( _("Additional {!r} element ({!r}) found in record with ID {!r} (record {})").format( subelement.tag, subelement.text, ID, k ) )
# Check the elements that must contain unique information (in that particular element -- doesn't check across different elements)
for elementName in self.uniqueElements:
if element.find( elementName ) is not None:
text = element.find( elementName ).text
if text in uniqueDict["Element_"+elementName]:
logging.error( _("Found {!r} data repeated in {!r} element in record with ID {!r} (record {})").format( text, elementName, ID, k ) )
uniqueDict["Element_"+elementName].append( text )
else:
logging.warning( _("Unexpected element: {} in record {}").format( element.tag, k ) )
示例14: __validateSystem
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoAttributes [as 别名]
def __validateSystem( self, bookOrderTree, systemName ):
""" Do a semi-automatic check of the XML file validity. """
assert bookOrderTree
uniqueDict = {}
for elementName in self.uniqueElements: uniqueDict["Element_"+elementName] = []
for attributeName in self.uniqueAttributes: uniqueDict["Attribute_"+attributeName] = []
expectedID = 1
for k,element in enumerate(bookOrderTree):
if element.tag == self.mainElementTag:
BibleOrgSysGlobals.checkXMLNoTail( element, element.tag )
if not self.compulsoryAttributes and not self.optionalAttributes: BibleOrgSysGlobals.checkXMLNoAttributes( element, element.tag )
if not self.compulsoryElements and not self.optionalElements: BibleOrgSysGlobals.checkXMLNoSubelements( element, element.tag )
# Check ascending ID field
ID = element.get("id")
intID = int( ID )
if intID != expectedID:
logging.error( _("ID numbers out of sequence in record {} (got {} when expecting {}) for {}").format( k, intID, expectedID, systemName ) )
expectedID += 1
# Check that this is unique
if element.text:
if element.text in uniqueDict:
logging.error( _("Found {!r} data repeated in {!r} element in record with ID {!r} (record {}) for {}").format( element.text, element.tag, ID, k, systemName ) )
uniqueDict[element.text] = None
# Check compulsory attributes on this main element
for attributeName in self.compulsoryAttributes:
attributeValue = element.get( attributeName )
if attributeValue is None:
logging.error( _("Compulsory {!r} attribute is missing from {} element in record {}").format( attributeName, element.tag, k ) )
if not attributeValue:
logging.warning( _("Compulsory {!r} attribute is blank on {} element in record {}").format( attributeName, element.tag, k ) )
# Check optional attributes on this main element
for attributeName in self.optionalAttributes:
attributeValue = element.get( attributeName )
if attributeValue is not None:
if not attributeValue:
logging.warning( _("Optional {!r} attribute is blank on {} element in record {}").format( attributeName, element.tag, k ) )
# Check for unexpected additional attributes on this main element
for attributeName in element.keys():
attributeValue = element.get( attributeName )
if attributeName not in self.compulsoryAttributes and attributeName not in self.optionalAttributes:
logging.warning( _("Additional {!r} attribute ({!r}) found on {} element in record {}").format( attributeName, attributeValue, element.tag, k ) )
# Check the attributes that must contain unique information (in that particular field -- doesn't check across different attributes)
for attributeName in self.uniqueAttributes:
attributeValue = element.get( attributeName )
if attributeValue is not None:
if attributeValue in uniqueDict["Attribute_"+attributeName]:
logging.error( _("Found {!r} data repeated in {!r} field on {} element in record {}").format( attributeValue, attributeName, element.tag, k ) )
uniqueDict["Attribute_"+attributeName].append( attributeValue )
# Check compulsory elements
for elementName in self.compulsoryElements:
if element.find( elementName ) is None:
logging.error( _("Compulsory {!r} element is missing in record with ID {!r} (record {})").format( elementName, ID, k ) )
if not element.find( elementName ).text:
logging.warning( _("Compulsory {!r} element is blank in record with ID {!r} (record {})").format( elementName, ID, k ) )
# Check optional elements
for elementName in self.optionalElements:
if element.find( elementName ) is not None:
if not element.find( elementName ).text:
logging.warning( _("Optional {!r} element is blank in record with ID {!r} (record {})").format( elementName, ID, k ) )
# Check for unexpected additional elements
for subelement in element:
if subelement.tag not in self.compulsoryElements and subelement.tag not in self.optionalElements:
logging.warning( _("Additional {!r} element ({!r}) found in record with ID {!r} (record {})").format( subelement.tag, subelement.text, ID, k ) )
# Check the elements that must contain unique information (in that particular element -- doesn't check across different elements)
for elementName in self.uniqueElements:
if element.find( elementName ) is not None:
text = element.find( elementName ).text
if text in uniqueDict["Element_"+elementName]:
logging.error( _("Found {!r} data repeated in {!r} element in record with ID {!r} (record {})").format( text, elementName, ID, k ) )
uniqueDict["Element_"+elementName].append( text )
else:
logging.warning( _("Unexpected element: {} in record {}").format( element.tag, k ) )
示例15: load
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoAttributes [as 别名]
def load( self ):
"""
Load a single source XML file and load book elements.
"""
if BibleOrgSysGlobals.verbosityLevel > 2: print( _("Loading {}…").format( self.sourceFilepath ) )
self.tree = ElementTree().parse( self.sourceFilepath )
if BibleOrgSysGlobals.debugFlag: assert len ( self.tree ) # Fail here if we didn't load anything at all
if self.suppliedMetadata is None: self.suppliedMetadata = {}
self.suppliedMetadata['VerseView'] = {}
# Find the main (bible) container
if self.tree.tag == VerseViewXMLBible.treeTag:
location = "VerseView XML file"
BibleOrgSysGlobals.checkXMLNoText( self.tree, location, '4f6h' )
BibleOrgSysGlobals.checkXMLNoAttributes( self.tree, location, 'js24' )
BibleOrgSysGlobals.checkXMLNoTail( self.tree, location, '1wk8' )
# Find the submain (various info and then book) containers
bookNumber = 0
for element in self.tree:
if element.tag == VerseViewXMLBible.filenameTag:
sublocation = "filename in " + location
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'jk86' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, 'hjk7' )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'bh09' )
#self.filename = element.text
elif element.tag == VerseViewXMLBible.revisionTag:
sublocation = "revision in " + location
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'jk86' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, 'hjk7' )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'bh09' )
self.suppliedMetadata['VerseView']['Revision'] = element.text
elif element.tag == VerseViewXMLBible.titleTag:
sublocation = "title in " + location
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'jk86' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, 'hjk7' )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'bh09' )
self.suppliedMetadata['VerseView']['Title'] = element.text
elif element.tag == VerseViewXMLBible.fontTag:
sublocation = "font in " + location
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'jk86' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, 'hjk7' )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'bh09' )
self.suppliedMetadata['VerseView']['Font'] = element.text
elif element.tag == VerseViewXMLBible.copyrightTag:
sublocation = "copyright in " + location
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'jk86' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, 'hjk7' )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'bh09' )
self.suppliedMetadata['VerseView']['Copyright'] = element.text
elif element.tag == VerseViewXMLBible.sizefactorTag:
sublocation = "sizefactor in " + location
BibleOrgSysGlobals.checkXMLNoAttributes( element, sublocation, 'jk86' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, 'hjk7' )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'bh09' )
if BibleOrgSysGlobals.debugFlag: assert element.text == '1'
elif element.tag == VerseViewXMLBible.bookTag:
sublocation = "book in " + location
BibleOrgSysGlobals.checkXMLNoText( element, sublocation, 'g3g5' )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'd3f6' )
bookNumber += 1
self.__validateAndExtractBook( element, bookNumber )
else: logging.error( "xk15 Expected to find {!r} but got {!r}".format( VerseViewXMLBible.bookTag, element.tag ) )
else: logging.error( "Expected to load {!r} but got {!r}".format( VerseViewXMLBible.treeTag, self.tree.tag ) )
if BibleOrgSysGlobals.debugFlag or BibleOrgSysGlobals.verbosityLevel > 2:
# These are all compulsory so they should all exist
#print( "Filename is {!r}".format( self.filename ) )
print( "Revision is {!r}".format( self.suppliedMetadata['VerseView']['Revision'] ) )
print( "Title is {!r}".format( self.suppliedMetadata['VerseView']['Title'] ) )
print( "Font is {!r}".format( self.suppliedMetadata['VerseView']['Font'] ) )
print( "Copyright is {!r}".format( self.suppliedMetadata['VerseView']['Copyright'] ) )
#print( "SizeFactor is {!r}".format( self.sizeFactor ) )
self.applySuppliedMetadata( 'VerseView' ) # Copy some to self.settingsDict
self.doPostLoadProcessing()