Skip to content

Commit d83dc78

Browse files
committed
Update README sections
1 parent 1260382 commit d83dc78

File tree

1 file changed

+32
-36
lines changed

1 file changed

+32
-36
lines changed

README.md

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,60 @@
1-
# FuzzyMap <img src="https://github.com/pysnippet.png" align="right" height="64" />
1+
# Fuzzy Map <img src="https://github.com/pysnippet.png" align="right" height="64" />
22

33
[![PyPI](https://img.shields.io/pypi/v/fuzzymap.svg)](https://pypi.org/project/fuzzymap/)
4-
[![License](https://img.shields.io/pypi/l/fuzzymap.svg)](https://github.com/pysnippet/fuzzymap/blob/master/LICENSE)
4+
[![License](https://img.shields.io/pypi/l/fuzzymap.svg?color=blue)](https://github.com/pysnippet/fuzzymap/blob/master/LICENSE)
55
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fpysnippet%2Ffuzzymap.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fpysnippet%2Ffuzzymap?ref=badge_shield)
6+
[![Tests](https://github.com/pysnippet/fuzzymap/actions/workflows/tests.yml/badge.svg)](https://github.com/pysnippet/fuzzymap/actions/workflows/tests.yml)
67

7-
## What is FuzzyMap?
8+
## What is the Fuzzy Map?
89

9-
`FuzzyMap` is a polymorph Python dictionary. This kind of dictionary returns the value of the exact key if there is such
10-
a key. Otherwise, it will return the value of the most similar key satisfying the given ratio. The same mechanism works
11-
when setting a new or replacing an old key in the dictionary. If the key is not found and does not match any of the keys
12-
by the given ratio, it returns `None`.
10+
The Fuzzy Map is a polymorph Python dictionary that always returns the value of the closest similar key. This kind of
11+
dictionary returns the value of the exact key if there is such a key. Otherwise, it will return the value of the most
12+
similar key satisfying the given ratio. The exact mechanism works when setting a new or replacing an old key in the
13+
dictionary. If the key is not found and does not match any of the keys by the given ratio, it returns none.
1314

14-
## How does it work?
15+
## Usage with a real-world example
1516

16-
Suppose you have scraped data from multiple sources that do not have a unique identifier, and you want to compare the
17-
values of the items having the same identifiers. Sure there will be found a field that mostly has an equivalent value
18-
at each source. And you can use that field to identify the corresponding items of other sources' data.
19-
20-
## Let's look at the following example
21-
22-
There is a live data parser that collects the coefficients of football matches from different bookmakers at once, then
23-
calculates and logs the existing forks. Many bookmakers change the name of the teams to be incomparable with names on
24-
other sites.
17+
A live data parser collects the coefficients of sports games from different bookmakers at once, and then an analyzer
18+
tries to find the existing forks. Different bookmakers use different names for the same games. Some of them use the full
19+
names, and others use names with a partial abbreviation that makes the analyzer's job harder to find and compare the
20+
coefficients of the same game. Rather this could be hard without `FuzzyMap` that can find the game using the name used
21+
in one of the sources.
2522

2623
```python
2724
from fuzzymap import FuzzyMap
2825

29-
src1 = {
26+
source_1 = {
3027
'Rapid Wien - First Vienna': {'w1': 1.93, 'x': 2.32, 'w2': 7.44},
3128
'Al Bourj - Al Nejmeh': {'w1': 26, 'x': 11.5, 'w2': 1.05},
32-
# hundreds of other teams' data
29+
# hundreds of other games' data
3330
}
3431

35-
src2 = FuzzyMap({
32+
source_2 = FuzzyMap({
3633
'Bourj FC - Nejmeh SC Beirut': {'w1': 32, 'x': 12, 'w2': 1.05},
3734
'SK Rapid Wien - First Vienna FC': {'w1': 1.97, 'x': 2.3, 'w2': 8.2},
38-
# hundreds of other teams' data
35+
# hundreds of other games' data
3936
})
4037

41-
for team, coefs1 in src1.items():
42-
coefs2 = src2[team]
38+
for game, odds1 in source_1.items():
39+
odds2 = source_2[game]
4340

44-
# coefs1 = {"w1": 1.93, "x": 2.32, "w2": 7.44}
45-
# coefs2 = {"w1": 1.97, "x": 2.3, "w2": 8.2}
46-
handle_fork(coefs1, coefs2)
41+
# odds1 = {"w1": 1.93, "x": 2.32, "w2": 7.44}
42+
# odds2 = {"w1": 1.97, "x": 2.3, "w2": 8.2}
43+
handle_fork(odds1, odds2)
4744
```
4845

49-
With a human brain, it is not difficult to identify that "Rapid Wien - First Vienna" and "SK Rapid Wien - First Vienna
50-
FC" matches are the same. In the above example, the `src2` is defined as `FuzzyMap`, it makes its keys fuzzy-matchable,
51-
and we can get an item corresponding to the key of `src1`. See the below graph demonstrating the associations of
52-
`FuzzyMap` keys.
46+
In this code example, `source_1` and `source_2` are the dictionary of game and coefficients key-value pairs parsed from
47+
different sources. And converting the `source_2` dictionary to the `FuzzyMap` dictionary makes it able to find the
48+
corresponding game using the game's key used in the `source_1` dictionary.
5349

5450
```mermaid
5551
graph LR
56-
src1team1[Rapid Wien - First Vienna]-->src1coefs1["{'w1': 1.93, 'x': 2.32, 'w2': 7.44}"]
57-
src1team2[Al Bourj - Al Nejmeh]-->src1coefs2["{'w1': 26, 'x': 11.5, 'w2': 1.05}"]
58-
src2team1[SK Rapid Wien - First Vienna FC]-->src2coefs1["{'w1': 1.97, 'x': 2.3, 'w2': 8.2}"]
59-
src2team2[Bourj FC - Nejmeh SC Beirut]-->src2coefs2["{'w1': 32, 'x': 12, 'w2': 1.05}"]
60-
src1team1-->src2coefs1
61-
src1team2-->src2coefs2
52+
src1team1[Rapid Wien - First Vienna] --> src1coefs1["{'w1': 1.93, 'x': 2.32, 'w2': 7.44}"]
53+
src1team2[Al Bourj - Al Nejmeh] --> src1coefs2["{'w1': 26, 'x': 11.5, 'w2': 1.05}"]
54+
src2team1[SK Rapid Wien - First Vienna FC] --> src2coefs1["{'w1': 1.97, 'x': 2.3, 'w2': 8.2}"]
55+
src2team2[Bourj FC - Nejmeh SC Beirut] --> src2coefs2["{'w1': 32, 'x': 12, 'w2': 1.05}"]
56+
src1team1 --> src2coefs1
57+
src1team2 --> src2coefs2
6258
```
6359

6460
## License

0 commit comments

Comments
 (0)