本文整理汇总了Python中BibleOrgSysGlobals.checkXMLNoTail方法的典型用法代码示例。如果您正苦于以下问题:Python BibleOrgSysGlobals.checkXMLNoTail方法的具体用法?Python BibleOrgSysGlobals.checkXMLNoTail怎么用?Python BibleOrgSysGlobals.checkXMLNoTail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BibleOrgSysGlobals
的用法示例。
在下文中一共展示了BibleOrgSysGlobals.checkXMLNoTail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadSystems
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoTail [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
示例2: load
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoTail [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
# Find the main (bible) container
if self.tree.tag == HaggaiXMLBible.treeTag:
location = "Haggai XML file"
BibleOrgSysGlobals.checkXMLNoText( self.tree, location, '4f6h' )
BibleOrgSysGlobals.checkXMLNoTail( self.tree, location, '1wk8' )
schema = name = status = BibleType = revision = version = lgid = None
for attrib,value in self.tree.items():
if attrib == HaggaiXMLBible.XMLNameSpace + 'noNamespaceSchemaLocation':
schema = value
elif attrib == "biblename":
name = value
elif attrib == "lgid":
lgid = value # In italian.xml this is set to "german"
elif attrib == "status":
status = value
elif attrib == "type":
BibleType = value
elif attrib == "revision":
revision = value
elif attrib == "version":
version = value
else: logging.warning( "Unprocessed {!r} attribute ({}) in main element".format( attrib, value ) )
if name: self.name = name
if status: self.status = status
if revision: self.revision = revision
if version: self.version = version
if self.tree[0].tag == 'INFORMATION':
self.header = self.tree[0]
self.tree.remove( self.header )
self.__validateAndExtractHeader()
else: # Handle information records at the END of the file
ix = len(self.tree) - 1
if self.tree[ix].tag == 'INFORMATION':
self.header = self.tree[ix]
self.tree.remove( self.header )
self.__validateAndExtractHeader()
# Find the submain (book) containers
for element in self.tree:
if element.tag == HaggaiXMLBible.bookTag:
sublocation = "book in " + location
BibleOrgSysGlobals.checkXMLNoText( element, sublocation, 'g3g5' )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'd3f6' )
self.__validateAndExtractBook( element )
else: logging.error( "Expected to find {!r} but got {!r}".format( HaggaiXMLBible.bookTag, element.tag ) )
else: logging.error( "Expected to load {!r} but got {!r}".format( HaggaiXMLBible.treeTag, self.tree.tag ) )
self.doPostLoadProcessing()
示例3: loadSystems
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoTail [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: __validateAndExtractChapter
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoTail [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 BBB".format( BBB ) )
for element in chapter:
if element.tag == OpenSongXMLBible.verseTag:
sublocation = "verse in {} {}".format( BBB, chapterNumber )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'l5ks' )
BibleOrgSysGlobals.checkXMLNoSubelements( element, sublocation, '5f7h' )
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 not vText:
logging.warning( "{} {}:{} has no text".format( BBB, chapterNumber, verseNumber ) )
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 )
else: logging.error( "Expected to find {!r} but got {!r}".format( OpenSongXMLBible.verseTag, element.tag ) )
示例5: validateEntries
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoTail [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: __validateAndExtractBook
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoTail [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 )
示例7: _validate
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoTail [as 别名]
def _validate( self ):
"""
Check/validate the loaded data.
"""
assert self._XMLtree
uniqueDict = {}
#for elementName in self._uniqueElements: uniqueDict["Element_"+elementName] = []
for attributeName in self._uniqueAttributes: uniqueDict["Attribute_"+attributeName] = []
for j,element in enumerate(self._XMLtree):
if element.tag == self._mainElementTag:
BibleOrgSysGlobals.checkXMLNoText( element, element.tag )
BibleOrgSysGlobals.checkXMLNoTail( element, element.tag )
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, j ) )
if not attributeValue and attributeName!="type":
logging.warning( "Compulsory {!r} attribute is blank on {} element in record {}".format( attributeName, element.tag, j ) )
# 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, j ) )
# 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, j ) )
# 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 and attributeName!="reference_name":
if attributeValue in uniqueDict["Attribute_"+attributeName]:
logging.error( "Found {!r} data repeated in {!r} field on {} element in record {}".format( attributeValue, attributeName, element.tag, j ) )
uniqueDict["Attribute_"+attributeName].append( attributeValue )
else:
logging.warning( "Unexpected element: {} in record {}".format( element.tag, j ) )
示例8: __validateAndExtractChapter
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoTail [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 chapter attributes first
chapterNumber = numVerses = None
for attrib,value in chapter.items():
if attrib=="cnumber":
chapterNumber = value
else: logging.warning( "Unprocessed {!r} attribute ({}) in chapter element".format( attrib, value ) )
if chapterNumber:
#print( BBB, 'c', chapterNumber )
thisBook.addLine( 'c', chapterNumber )
else: logging.error( "Missing 'n' attribute in chapter element for {}".format( BBB ) )
for element in chapter:
if element.tag == HaggaiXMLBible.paragraphTag:
location = "paragraph in {} {}".format( BBB, chapterNumber )
self.__validateAndExtractParagraph( BBB, chapterNumber, thisBook, element )
elif element.tag == HaggaiXMLBible.verseTag+'disabled':
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 ) )
示例9: loadFigure
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoTail [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 '' ) )
示例10: __load
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoTail [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 ) )
示例11: loadTable
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoTail [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 ) )
示例12: __validateAndExtractParagraph
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoTail [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 ) )
示例13: load
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoTail [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
# Find the main (bible) container
if self.tree.tag == OpenSongXMLBible.treeTag:
location = "XML file"
BibleOrgSysGlobals.checkXMLNoText( self.tree, location, '4f6h' )
BibleOrgSysGlobals.checkXMLNoTail( self.tree, location, '1wk8' )
name = shortName = None
for attrib,value in self.tree.items():
if attrib=="n":
name = value
elif attrib=="sn":
shortName = value
else: logging.warning( "Unprocessed {!r} attribute ({}) in main element".format( attrib, value ) )
# Find the submain (book) containers
for element in self.tree:
if element.tag == OpenSongXMLBible.bookTag:
sublocation = "book in " + location
BibleOrgSysGlobals.checkXMLNoText( element, sublocation, 'g3g5' )
BibleOrgSysGlobals.checkXMLNoTail( element, sublocation, 'd3f6' )
self.__validateAndExtractBook( element )
elif element.tag == 'OT':
pass
elif element.tag == 'NT':
pass
else: logging.error( "Expected to find {!r} but got {!r}".format( OpenSongXMLBible.bookTag, element.tag ) )
else: logging.error( "Expected to load {!r} but got {!r}".format( OpenSongXMLBible.treeTag, self.tree.tag ) )
self.doPostLoadProcessing()
示例14: validateEntry
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoTail [as 别名]
def validateEntry( self, entry ):
"""
Check/validate the given Strongs Greek lexicon entry.
"""
if BibleOrgSysGlobals.debugFlag: assert entry.tag == "entry"
BibleOrgSysGlobals.checkXMLNoText( entry, entry.tag, "na19" )
BibleOrgSysGlobals.checkXMLNoTail( entry, entry.tag, "kaq9" )
# Process the entry attributes first
strongs5 = None
for attrib,value in entry.items():
if attrib == "strongs":
strongs5 = value
if BibleOrgSysGlobals.verbosityLevel > 2: print( "Validating {} entry…".format( strongs5 ) )
else: logging.warning( "Unprocessed {!r} attribute ({}) in main entry element".format( attrib, value ) )
if BibleOrgSysGlobals.debugFlag: assert len(strongs5)==5 and strongs5.isdigit()
entryResults = {}
entryString = ""
gettingEssentials = True
for j, element in enumerate( entry ):
#print( strongs5, j, element.tag, repr(entryString) )
if element.tag == "strongs":
if BibleOrgSysGlobals.debugFlag: assert gettingEssentials and j==0 and element.text
BibleOrgSysGlobals.checkXMLNoAttributes( element, element.tag, "md3d" )
if strongs5!='02717' and (3203 > int(strongs5) > 3302):
BibleOrgSysGlobals.checkXMLNoTail( element, element.tag, "f3g7" )
BibleOrgSysGlobals.checkXMLNoSubelements( element, element.tag, "m56g" )
strongs = element.text
if BibleOrgSysGlobals.debugFlag: assert strongs5.endswith( strongs )
if element.tail and element.tail.strip(): entryString += element.tail.strip()
elif element.tag == "greek":
location = "greek in Strongs " + strongs5
BibleOrgSysGlobals.checkXMLNoText( element, location, "jke0" )
#BibleOrgSysGlobals.checkXMLNoTail( element, location, "ks24" )
BibleOrgSysGlobals.checkXMLNoSubelements( element, location, "df35" )
# Process the attributes
translit = greek = beta = None
for attrib,value in element.items():
if attrib=="translit": translit = value
elif attrib=="unicode": greek = value
elif attrib=="BETA": beta = value
else: logging.warning( "scs4 Unprocessed {!r} attribute ({}) in {}".format( attrib, value, location ) )
if BibleOrgSysGlobals.debugFlag: assert greek and translit and beta
if 'word' not in entryResults: # This is the first/main entry
if BibleOrgSysGlobals.debugFlag: assert gettingEssentials and j==1
BibleOrgSysGlobals.checkXMLNoTail( element, location, "ks24" )
entryResults['word'] = (greek, translit, beta)
else:
#print( "Have multiple greek entries in " + strongs5 )
if BibleOrgSysGlobals.debugFlag: assert j > 2
gettingEssentials = False
entryString += ' ' + BibleOrgSysGlobals.getFlattenedXML( element, strongs5 ) #.replace( '\n', '' )
elif element.tag == "pronunciation":
location = "pronunciation in Strongs " + strongs5
BibleOrgSysGlobals.checkXMLNoText( element, location, "iw9k" )
BibleOrgSysGlobals.checkXMLNoSubelements( element, location, "0s20" )
# Process the attributes
pronunciation = None
for attrib,value in element.items():
if attrib=="strongs": pronunciation = value
else: logging.warning( "scs4 Unprocessed {!r} attribute ({}) in {}".format( attrib, value, location ) )
if gettingEssentials:
#BibleOrgSysGlobals.checkXMLNoTail( element, location, "kd02" )
if BibleOrgSysGlobals.debugFlag:
assert j == 2
assert pronunciation
assert 'pronunciation' not in entryResults
entryResults['pronunciation'] = pronunciation
else:
if BibleOrgSysGlobals.debugFlag: assert j>2 and not gettingEssentials
if element.tail and element.tail.strip(): entryString += element.tail.strip().replace( '\n', '' )
elif element.tag == "strongs_derivation":
location = "strongs_derivation in Strongs " + strongs5
BibleOrgSysGlobals.checkXMLNoAttributes( element, location, "jke0" )
BibleOrgSysGlobals.checkXMLNoTail( element, location, "ks24" )
derivation = BibleOrgSysGlobals.getFlattenedXML( element, strongs5 ).replace( '\n', '' )
#print( strongs5, "derivation", repr(derivation) )
if BibleOrgSysGlobals.debugFlag:
assert derivation and '\t' not in derivation and '\n' not in derivation
entryString += derivation
elif element.tag == "strongs_def":
location = "strongs_def in Strongs " + strongs5
BibleOrgSysGlobals.checkXMLNoAttributes( element, location, "jke0" )
BibleOrgSysGlobals.checkXMLNoTail( element, location, "jd28" )
definition = BibleOrgSysGlobals.getFlattenedXML( element, strongs5 ).replace( '\n', '' )
#print( strongs5, "definition", repr(definition) )
if BibleOrgSysGlobals.debugFlag:
assert definition and '\t' not in definition and '\n' not in definition
entryString += definition
elif element.tag == "kjv_def":
location = "kjv_def in Strongs " + strongs5
BibleOrgSysGlobals.checkXMLNoAttributes( element, location, "jke0" )
#BibleOrgSysGlobals.checkXMLNoTail( element, location, "8s2s" )
#BibleOrgSysGlobals.checkXMLNoSubelements( element, location, "dvb2" )
KJVdefinition = BibleOrgSysGlobals.getFlattenedXML( element, strongs5 ).replace( '\n', '' )
#print( strongs5, "KJVdefinition", repr(KJVdefinition), repr(entryString) )
if BibleOrgSysGlobals.debugFlag: assert KJVdefinition and '\t' not in KJVdefinition and '\n' not in KJVdefinition
entryString += KJVdefinition
elif element.tag == "strongsref":
#.........这里部分代码省略.........
示例15: _validateSystem
# 需要导入模块: import BibleOrgSysGlobals [as 别名]
# 或者: from BibleOrgSysGlobals import checkXMLNoTail [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 ) )