예제 #1
0
 def __eq__(self, other):
     if isinstance(other, TokenSpan) and self.tokens.equals(other.tokens):
         return (self.begin_token == other.begin_token
                 and self.end_token == other.end_token)
     else:
         # Different tokens, or no tokens, or not a span ==> Fall back on superclass
         return Span.__eq__(self, other)
예제 #2
0
 def SpanOnEndChange(change, span, text, column_name, index):
     new_span = Span(
         widget._df.get(column_name)[index].target_text, span.begin,
         change["new"])
     widget._df.get(column_name)[index] = new_span
     text.value = str(new_span)
     widget._update_document()
예제 #3
0
 def __lt__(self, other):
     """
     span1 < span2 if span1.end <= span2.begin
     """
     if isinstance(other, TokenSpan):
         # Use token offsets when available
         return self.end_token <= other.begin_token
     else:
         return Span.__lt__(self, other)
예제 #4
0
 def test_left_to_right(self):
     test_text = "Is it weird in here, or is it just me?"
     spans = [
         Span(test_text, 0, 3),
         Span(test_text, 2, 3),
         Span(test_text, 3, 3),
         Span(test_text, 1, 3),
         Span(test_text, 0, 4),  # index 4
         Span(test_text, 5, 7),  # index 5
         Span(test_text, 6, 9),
         Span(test_text, 8, 9),  # index 7
     ]
     df = pd.DataFrame({
         "s": SpanArray._from_sequence(spans),
         "ix": range(len(spans))
     })
     c_df = consolidate(df, on="s", how="left_to_right")
     self._assertArrayEquals(list(c_df.index), [4, 5, 7])
예제 #5
0
 def __hash__(self):
     # Use superclass hash function so that hash and __eq__ are consistent
     return Span.__hash__(self)