def __init__(self, *elements):
"""Initialize a Document manually by passing one or more Document elements (Paragraph, Heading, Table, etc.)
Strings that are passed to this constructor are automatically wrapped into Paragraph elements.
:param list[chemdataextractor.doc.element.BaseElement|string] elements: Elements in this Document.
"""
self._elements = []
for element in elements:
# Convert raw text to Paragraph elements
if isinstance(element, six.text_type):
element = Paragraph(element)
elif isinstance(element, six.binary_type):
# Try guess encoding if byte string
encoding = get_encoding(element)
log.warning('Guessed bytestring encoding as %s. Use unicode strings to avoid this warning.', encoding)
element = Paragraph(element.decode(encoding))
element.document = self
self._elements.append(element)
log.debug('%s: Initializing with %s elements' % (self.__class__.__name__, len(self.elements)))
评论列表
文章目录