musicbrainz-sparql

BNF / MusicBrainz links statistics

Count links in either direction between MusicBrainz and BNF

from pprint import pprint
%run -i ../startup.py
endpoint = 'http://data.bnf.fr/sparql'
Last notebook update: 2021-01-31
Importing libs
Defining database parameters
Defining *sql* helper function
Last database update: 2021-01-13

Defining *sparql* helper function
links_from_mb = {}
for entity_type in MB_ENTITIES:
    links_from_mb[entity_type] = mb_entity_count(entity_type, url_pattern='bnf.fr')

pprint(links_from_mb)
{'area': 0,
 'artist': 34252,
 'event': 0,
 'instrument': 0,
 'label': 102,
 'place': 125,
 'recording': 2,
 'release': 457,
 'release_group': 0,
 'series': 2,
 'work': 1002}
links_from_bnf = {}
for entity_type in MB_ENTITIES:
    links_from_bnf[entity_type] = bnf_entity_count(entity_type)
   
pprint(links_from_bnf)
{'area': 0,
 'artist': 56759,
 'event': 0,
 'instrument': 0,
 'label': 0,
 'place': 0,
 'recording': 0,
 'release': 0,
 'release_group': 205,
 'series': 0,
 'work': 2839}
link_count = pd.DataFrame({'from_mb': links_from_mb, 'from_bnf': links_from_bnf})
link_count
from_mb from_bnf
area 0 0
artist 34252 56759
event 0 0
instrument 0 0
label 102 0
place 125 0
recording 2 0
release 457 0
release_group 0 205
series 2 0
work 1002 2839
import jinja2

template = jinja2.Template("""
<!doctype html>

<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Alignment of MusicBrainz and BNF entities</title>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  </head>

  <body style="margin: 20px;">
    <h1>Alignment of MusicBrainz and BNF entities</h1>

    <p>Latest MB database update: </p>
    <p>Latest update: </p>

    <h2>Count links in either direction between MusicBrainz and BNF</h2>
    
  </body>
</html>
""")

with open('../docs/bnf-statistics-report.html', 'w') as f:
    f.write(template.render(**globals())
            .replace('&lt;', '<').replace('&gt;', '>')
            .replace('class="dataframe"', 'class="table table-striped table-hover table-sm"')
            .replace('thead', 'thead class="thead-light"'))