Exemple #1
0
    def _get_ctxt(self, start, end, idx_sent, sentence):
        """
        Retrieves context surrounding a given mention up to 100 words from both sides.

        :return: left and right context
        """

        # Iteratively add words up until we have 100
        left_ctxt = split_in_words(sentence[:start])
        if idx_sent > 0:
            i = idx_sent - 1
            while (i >= 0) and (len(left_ctxt) <= 100):
                left_ctxt = split_in_words(self.sentences_doc[i]) + left_ctxt
                i -= 1
        left_ctxt = left_ctxt[-100:]
        left_ctxt = " ".join(left_ctxt)

        right_ctxt = split_in_words(sentence[end:])
        if idx_sent < len(self.sentences_doc):
            i = idx_sent + 1
            while (i < len(self.sentences_doc)) and (len(right_ctxt) <= 100):
                right_ctxt = right_ctxt + split_in_words(self.sentences_doc[i])
                i += 1
        right_ctxt = right_ctxt[:100]
        right_ctxt = " ".join(right_ctxt)

        return left_ctxt, right_ctxt
Exemple #2
0
def _get_ctxt(self, start, end, idx_sent, sentence):
    """
    Retrieves context surrounding a given mention up to 100 words from both sides.

    :return: left and right context
    """

    # Iteratively add words up until we have 100
    left_ctxt = split_in_words(sentence[:start])
    left_ctxt = " ".join(left_ctxt)

    right_ctxt = split_in_words(sentence[end:])
    right_ctxt = " ".join(right_ctxt)

    return left_ctxt, right_ctxt