A Guess is a dictionary which has an associated confidence for each of its values.
As it is a subclass of dict, you can use it everywhere you expect a simple dict.
Return the metadata associated with the given property name
If no property name is given, get the global_metadata
Return a string with the property names and their values, that also displays the associated confidence to each property.
FIXME: doc with param
Return the guess as a dict containing only base types, ie: where dates, languages, countries, etc. are converted to strings.
if advanced is True, return the data as a json string containing also the raw information of the properties.
Update this guess with the values from the given one. In case there is property present in both, only the one with the highest one is kept.
Function used by merge_similar_guesses to choose between 2 possible properties when they are integers.
Function used by merge_similar_guesses to choose between 2 possible properties when they are strings.
If the 2 strings are similar, or one is contained in the other, the latter is returned with an increased confidence.
If the 2 strings are dissimilar, the one with the higher confidence is returned, with a weaker confidence.
Note that here, ‘similar’ means that 2 strings are either equal, or that they differ very little, such as one string being the other one with the ‘the’ word prepended to it.
>>> s(choose_string(('Hello', 0.75), ('World', 0.5)))
('Hello', 0.25)
>>> s(choose_string(('Hello', 0.5), ('hello', 0.5)))
('Hello', 0.75)
>>> s(choose_string(('Hello', 0.4), ('Hello World', 0.4)))
('Hello', 0.64)
>>> s(choose_string(('simpsons', 0.5), ('The Simpsons', 0.5)))
('The Simpsons', 0.75)
Take a list of guesses and merge those which have the same properties, increasing or decreasing the confidence depending on whether their values are similar.
Merge all the guesses in a single result, remove very unlikely values, and return it. You can specify a list of properties that should be appended into a list instead of being merged.
>>> s(merge_all([ Guess({'season': 2}, confidence=0.6),
... Guess({'episodeNumber': 13}, confidence=0.8) ])
... ) == {'season': 2, 'episodeNumber': 13}
True
>>> s(merge_all([ Guess({'episodeNumber': 27}, confidence=0.02),
... Guess({'season': 1}, confidence=0.2) ])
... ) == {'season': 1}
True
>>> s(merge_all([ Guess({'other': 'PROPER'}, confidence=0.8),
... Guess({'releaseGroup': '2HD'}, confidence=0.8) ],
... append=['other'])
... ) == {'releaseGroup': '2HD', 'other': ['PROPER']}
True