示例#1
0
    def apply(self, doc: Document) -> Iterator[TemporaryCaptionMention]:
        """
        Generate MentionCaptions from a Document by parsing all of its Captions.

        :param doc: The ``Document`` to parse.
        :raises TypeError: If the input doc is not of type ``Document``.
        """
        if not isinstance(doc, Document):
            raise TypeError(
                "Input Contexts to MentionCaptions.apply() must be of type Document"
            )

        for caption in doc.captions:
            yield TemporaryCaptionMention(caption)
示例#2
0
    def apply(self, session, doc):
        """
        Generate MentionCaptions from a Document by parsing all of its Captions.

        :param session: The database session
        :param doc: The ``Document`` to parse.
        :type doc: ``Document``
        :raises TypeError: If the input doc is not of type ``Document``.
        """
        if not isinstance(doc, Document):
            raise TypeError(
                "Input Contexts to MentionCaptions.apply() must be of type Document"
            )

        doc = session.query(Document).filter(Document.id == doc.id).one()
        for caption in doc.captions:
            yield TemporaryCaptionMention(caption)