A float with a magic "assessments" property, which is the set of all n-grams contributing to the weight.
| 351 | return [tuple(s[i:i+n]) for i in range(len(s)-n+1)] |
| 352 | |
| 353 | class Weight(float): |
| 354 | """ A float with a magic "assessments" property, |
| 355 | which is the set of all n-grams contributing to the weight. |
| 356 | """ |
| 357 | def __new__(self, value=0.0, assessments=[]): |
| 358 | return float.__new__(self, value) |
| 359 | def __init__(self, value=0.0, assessments=[]): |
| 360 | self.assessments = set(assessments) |
| 361 | def __iadd__(self, value): |
| 362 | return Weight(self + value, self.assessments) |
| 363 | def __isub__(self, value): |
| 364 | return Weight(self - value, self.assessments) |
| 365 | def __imul__(self, value): |
| 366 | return Weight(self * value, self.assessments) |
| 367 | def __idiv__(self, value): |
| 368 | return Weight(self / value, self.assessments) |
| 369 | |
| 370 | def intertextuality(texts=[], n=5, continuous=False, weight=lambda ngram: 1): |
| 371 | """ Returns a dictionary of (i, j) => float. |
no outgoing calls
no test coverage detected
searching dependent graphs…