History of discogs_genre
The changes to the source code of this entry in the repository, newest first, each with the differences it made to the entry's files. They are also listed on GitLab.
[entries] Add the date when each entry was added, and remove icon_hash beff7c9
The dates are those of the commits that first added the entries' files (2020-08-11 for the entries of the initial commit); renamed entries keep the date of their first name. Changed: none
diff --git a/entries/discogs_genre/__init__.py b/entries/discogs_genre/__init__.py
index c2a2bbf..800b69e 100644
--- a/entries/discogs_genre/__init__.py
+++ b/entries/discogs_genre/__init__.py
@@ -38,7 +38,7 @@ The networks have the following properties:
tags = ['Informational', 'Relatedness', 'Affiliation', 'Weighted', 'Metadata']
url = 'https://data.discogs.com/'
citation = [('Discogs, "Discogs data dumps: releases, 1 October 2015."', 'https://data.discogs.com/')]
-icon_hash = '5758b60cbd3e93b53c6955be'
+date_added = '2020-08-11'
upstream_license = ("Creative Commons CC0 1.0 Universal (Public Domain Dedication)",
"https://creativecommons.org/publicdomain/zero/1.0/")
dump = 'discogs_20151001_releases.xml.gz'
[entries] Prefix the properties in the descriptions with (Node), (Edge) or (Graph) bc3dbbd
The lists of properties at the end of the descriptions marked edge properties with "Edge" but left node properties unmarked, or grouped them in "Nodes: `a`, ...; `b`, ..." items, so the kind of a property was often unclear. Every item now starts with (Node), (Edge) or (Graph), followed by the property names, a colon and the explanation, one item per property or group of properties; qualifications (kinds of nodes, networks) follow the names in parentheses. Properties that were only named got a short explanation, and a few items that named the wrong kind of property were corrected.
diff --git a/entries/discogs_genre/__init__.py b/entries/discogs_genre/__init__.py
index 7d5b752..c2a2bbf 100644
--- a/entries/discogs_genre/__init__.py
+++ b/entries/discogs_genre/__init__.py
@@ -30,10 +30,11 @@ Artists are identified by their Discogs id, and their names are the Discogs name
The networks have the following properties:
-- `is_artist`: whether the node is an artist (otherwise it is a genre or style).
-- `name`: the name of the artist, genre or style.
-- `discogs_id`: the Discogs id of the artist (-1 for genres and styles).
-- Edges: `count`, the number of releases of that genre or style in which the artist is credited; `first_year` and `last_year`, the earliest and latest release years among them (-1 if none of them has a known year; the years are as entered in Discogs, and a few are evidently mistyped)."""
+- (Node) `is_artist`: whether the node is an artist (otherwise it is a genre or style).
+- (Node) `name`: the name of the artist, genre or style.
+- (Node) `discogs_id`: the Discogs id of the artist (-1 for genres and styles).
+- (Edge) `count`: the number of releases of that genre or style in which the artist is credited.
+- (Edge) `first_year` and `last_year`: the earliest and latest release years among them (-1 if none of them has a known year; the years are as entered in Discogs, and a few are evidently mistyped)."""
tags = ['Informational', 'Relatedness', 'Affiliation', 'Weighted', 'Metadata']
url = 'https://data.discogs.com/'
citation = [('Discogs, "Discogs data dumps: releases, 1 October 2015."', 'https://data.discogs.com/')]
[entries] Use American spelling in the descriptions 802d564
British spellings in the titles and descriptions of 69 entries (e.g. labelled, organisation, millimetres, centres, anonymised, neighbours, analysed, modelled, colour, licence) are replaced by the American ones. Proper names keep their spelling (Otago Harbour, the Centre for Water Systems, the Centre jeunesse de Montréal, the Dutch Ministry of Defence), as do quoted upstream terms, citations, and property names.
diff --git a/entries/discogs_genre/__init__.py b/entries/discogs_genre/__init__.py
index a33de2e..7d5b752 100644
--- a/entries/discogs_genre/__init__.py
+++ b/entries/discogs_genre/__init__.py
@@ -21,7 +21,7 @@ import array
from lxml import etree
title = "Discogs artist-genre and artist-style affiliations (2015)"
-description = """Two bipartite networks of musical artists and the genres or styles of their releases, from the Discogs database. Discogs (discogs.com) is a user-built online database of music recordings, whose contributors catalogue releases (albums, singles, compilations, etc.) together with their credits, and classify each release into one or more of 15 broad genres (e.g. Rock, Electronic, Jazz) and, optionally, into finer styles (e.g. Deep House, Free Jazz, Punk); its content is published as monthly XML dumps. These networks are built from the releases dump of 1 October 2015, which contains the 6,379,659 releases accepted in the database at that time (drafts and the few rejected or deleted releases of the dump are excluded). Nodes are artists and genres (`genre`) or styles (`style`), and an undirected edge connects an artist to a genre or style if the artist is credited in at least one release of that genre or style, weighted by the number of such releases. An artist is credited in a release either as one of its main artists or with a release-wide credit (e.g. producer, mixer, or performer on all tracks); credits limited to individual tracks are not included.
+description = """Two bipartite networks of musical artists and the genres or styles of their releases, from the Discogs database. Discogs (discogs.com) is a user-built online database of music recordings, whose contributors catalog releases (albums, singles, compilations, etc.) together with their credits, and classify each release into one or more of 15 broad genres (e.g. Rock, Electronic, Jazz) and, optionally, into finer styles (e.g. Deep House, Free Jazz, Punk); its content is published as monthly XML dumps. These networks are built from the releases dump of 1 October 2015, which contains the 6,379,659 releases accepted in the database at that time (drafts and the few rejected or deleted releases of the dump are excluded). Nodes are artists and genres (`genre`) or styles (`style`), and an undirected edge connects an artist to a genre or style if the artist is credited in at least one release of that genre or style, weighted by the number of such releases. An artist is credited in a release either as one of its main artists or with a release-wide credit (e.g. producer, mixer, or performer on all tracks); credits limited to individual tracks are not included.
- `genre`: artists and genres.
- `style`: artists and styles.
[entries] Move more KONECT-derived entries to their original sources bf9dc0e
The entries now download the data from where KONECT obtained them (live, or via the Wayback Machine), using the same release as KONECT where it is still available, and gain the metadata KONECT dropped; descriptions and citations are rewritten from the original sources: - Linton Freeman's UCINET data page: bible_nouns, bison, cattle, hens, highschool, kangaroo, macaques, moreno_sheep, physician_trust (the three relations and the physicians' attributes), rhesus_monkey, train_terrorists, windsurfers (now the networks `interaction` and `closeness`), college_freshmen, crime, interactome_yeast (from the primary source), moreno_taro (undirected), residence_hall, zebras - other pages, archived: contiguous_usa, advogato, google, github, digg_reply, twitter, bookcrossing, dbtropes_feature (without KONECT's spurious "ItemName" tropes) - movielens_100k (in fact the MovieLens 10M tag assignments) - dblp release 2017-05-02: dblp_author_paper, dblp_cite, dblp_coauthor - DBpedia 3.9: dbpedia_country, dbpedia_genre, dbpedia_location, dbpedia_occupation, dbpedia_producer, dbpedia_recordlabel, dbpedia_starring, dbpedia_team, dbpedia_writer, dbpedia_all, dbpedia_link - Discogs releases dump of October 2015: discogs_affiliation, discogs_genre and discogs_label (now with genre and style networks)
diff --git a/entries/discogs_genre/__init__.py b/entries/discogs_genre/__init__.py
index bd7c78e..a33de2e 100644
--- a/entries/discogs_genre/__init__.py
+++ b/entries/discogs_genre/__init__.py
@@ -17,33 +17,134 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
from .. import *
+import array
+from lxml import etree
-title = "Discogs artist affiliations"
-description = """Two bipartite networks of the affiliations between musical artists and either musical genres or musical \"styles,\" as given in the discogs.com database. An edge indicates that a given artist was involved in a production of a particular genre or style. The date of this snapshot is uncertain.[^icon]
-[^icon]: Description obtained from the [ICON](https://icon.colorado.edu) project."""
-tags = ['Informational', 'Relatedness', 'Unweighted']
-url = 'http://konect.cc/networks/discogs_genre'
-citation = [('J. Kunegis, "Discogs network dataset." KONECT (2016)', 'https://doi.org/10.1145/2487788.2488173')]
+title = "Discogs artist-genre and artist-style affiliations (2015)"
+description = """Two bipartite networks of musical artists and the genres or styles of their releases, from the Discogs database. Discogs (discogs.com) is a user-built online database of music recordings, whose contributors catalogue releases (albums, singles, compilations, etc.) together with their credits, and classify each release into one or more of 15 broad genres (e.g. Rock, Electronic, Jazz) and, optionally, into finer styles (e.g. Deep House, Free Jazz, Punk); its content is published as monthly XML dumps. These networks are built from the releases dump of 1 October 2015, which contains the 6,379,659 releases accepted in the database at that time (drafts and the few rejected or deleted releases of the dump are excluded). Nodes are artists and genres (`genre`) or styles (`style`), and an undirected edge connects an artist to a genre or style if the artist is credited in at least one release of that genre or style, weighted by the number of such releases. An artist is credited in a release either as one of its main artists or with a release-wide credit (e.g. producer, mixer, or performer on all tracks); credits limited to individual tracks are not included.
+
+- `genre`: artists and genres.
+- `style`: artists and styles.
+
+Artists are identified by their Discogs id, and their names are the Discogs names, which include a numeric suffix (e.g. "John Smith (2)") to distinguish artists with the same name. Discogs uses placeholder artists such as "Various" (for compilations) and "Unknown Artist", which are kept as nodes. Artists without any release with a genre (or style) are not included in the corresponding network.
+
+The networks have the following properties:
+
+- `is_artist`: whether the node is an artist (otherwise it is a genre or style).
+- `name`: the name of the artist, genre or style.
+- `discogs_id`: the Discogs id of the artist (-1 for genres and styles).
+- Edges: `count`, the number of releases of that genre or style in which the artist is credited; `first_year` and `last_year`, the earliest and latest release years among them (-1 if none of them has a known year; the years are as entered in Discogs, and a few are evidently mistyped)."""
+tags = ['Informational', 'Relatedness', 'Affiliation', 'Weighted', 'Metadata']
+url = 'https://data.discogs.com/'
+citation = [('Discogs, "Discogs data dumps: releases, 1 October 2015."', 'https://data.discogs.com/')]
icon_hash = '5758b60cbd3e93b53c6955be'
-upstream_prefix = 'http://konect.cc/files'
-files = [('download.tsv.discogs_genre.tar.bz2', None, 'konect')]
+upstream_license = ("Creative Commons CC0 1.0 Universal (Public Domain Dedication)",
+ "https://creativecommons.org/publicdomain/zero/1.0/")
+dump = 'discogs_20151001_releases.xml.gz'
+upstream_prefix = 'https://data.discogs.com/?download=data%2F2015%2F'
+files = [(dump, 'genre', None), (dump, 'style', None)]
def fetch_upstream(force=False):
- return fetch_upstream_files(__name__.split(".")[-1], upstream_prefix, files,
- force)
+ # The files are served under a query string, so they are downloaded
+ # here, streaming to disk (the dump has 3.4 GB)
+ name = __name__.split(".")[-1]
+ fname = f"cache/upstream/{name}/{dump}"
+ if os.path.exists(fname) and not force:
+ return
+ os.makedirs(os.path.dirname(fname), exist_ok=True)
+ with open_url(upstream_prefix + dump) as f, open(fname + ".part", "wb") as out:
+ shutil.copyfileobj(f, out, 1 << 24)
+ os.replace(fname + ".part", fname)
+
+def read_releases(f):
+ """Iterate over the accepted releases of a Discogs releases XML dump, yielding
+ (id, year, labels, artists, extra_artists, genres, styles), where artists
+ are (id, name) pairs, and labels, genres and styles are lists of distinct
+ names."""
+ def year(s):
+ s = (s or "")[:4]
+ return int(s) if s.isdigit() and int(s) > 0 else -1
+ def distinct(xs):
+ return list(dict.fromkeys(x for x in xs if x))
+ def artists(el, path):
+ return [(int(a.findtext("id")), a.findtext("name") or "")
+ for a in el.iterfind(path) if (a.findtext("id") or "").isdigit()]
+ for ev, el in etree.iterparse(f, events=("end",), tag="release"):
+ # A few releases are drafts, or were rejected or deleted
+ if el.get("status") == "Accepted":
+ yield (int(el.get("id")), year(el.findtext("released")),
+ distinct(l.get("name") for l in el.iterfind("labels/label")),
+ artists(el, "artists/artist"),
+ artists(el, "extraartists/artist"),
+ distinct(x.text for x in el.iterfind("genres/genre")),
+ distinct(x.text for x in el.iterfind("styles/style")))
+ el.clear()
+ while el.getprevious() is not None:
+ del el.getparent()[0]
+
+def aggregate(src, tgt, year):
+ """Collapse the (source, target, year) records into distinct (source,
+ target) pairs, with the number of records and the earliest and latest
+ known years."""
+ src = numpy.frombuffer(src, dtype="int64")
+ tgt = numpy.frombuffer(tgt, dtype="int64")
+ year = numpy.frombuffer(year, dtype="int64")
+ idx = numpy.lexsort((tgt, src))
+ src, tgt, year = src[idx], tgt[idx], year[idx]
+ start = numpy.flatnonzero(numpy.r_[True, (src[1:] != src[:-1]) |
+ (tgt[1:] != tgt[:-1])])
+ count = numpy.diff(numpy.r_[start, len(src)])
+ big = numpy.iinfo("int64").max
+ first = numpy.minimum.reduceat(numpy.where(year < 0, big, year), start)
+ first[first == big] = -1
+ last = numpy.maximum.reduceat(year, start)
+ return src[start], tgt[start], count, first, last
@cache_network()
-@coerce_props()
+@coerce_props(vforce={"name": "string"})
@annotate()
def parse(alts=None):
- global files
name = __name__.split(".")[-1]
- for fnames, alt, fmt in files:
- if alts is not None and alt not in alts:
- continue
- if isinstance(fnames, str):
- fnames = [fnames]
- with ExitStack() as stack:
- fs = [stack.enter_context(open_upstream_file(name, fn, "rb")) for fn in fnames]
- g = parse_graph(fs, fmt, directed=False)
+ alts = [alt for fn, alt, fmt in files if alts is None or alt in alts]
+ nodes = {} # key -> (index, name)
+ cats = {alt: {} for alt in alts} # genre/style name -> index
+ recs = {alt: (array.array("l"), array.array("l"), array.array("l"))
+ for alt in alts}
+ with open_upstream_file(name, dump, "rb") as f:
+ for rid, year, ls, main, xtra, genres, styles in read_releases(f):
+ us = list(dict(main + xtra).items())
+ for alt, cs in (("genre", genres), ("style", styles)):
+ if alt not in recs or not cs:
+ continue
+ src, tgt, yr = recs[alt]
+ cidx = [cats[alt].setdefault(c, len(cats[alt])) for c in cs]
+ for key, uname in us:
+ u = nodes.setdefault(key, (len(nodes), uname))[0]
+ for c in cidx:
+ src.append(u)
+ tgt.append(c)
+ yr.append(year)
+ for alt in alts:
+ src, tgt, count, first, last = aggregate(*recs[alt])
+ recs[alt] = None
+ # Only the nodes with some edge in this network
+ used, src = numpy.unique(src, return_inverse=True)
+ N = len(used)
+ g = Graph(directed=False)
+ g.add_vertex(N + len(cats[alt]))
+ g.add_edge_list(numpy.column_stack((src, tgt + N)))
+ g.ep.count = g.new_ep("int32_t", vals=count)
+ g.ep.first_year = g.new_ep("int16_t", vals=first)
+ g.ep.last_year = g.new_ep("int16_t", vals=last)
+ g.vp.is_artist = g.new_vp("bool")
+ g.vp.is_artist.a[:N] = True
+ g.vp.name = g.new_vp("string")
+ g.vp.discogs_id = g.new_vp("int32_t", val=-1)
+ keys = {i: (k, n) for k, (i, n) in nodes.items()}
+ for v, i in enumerate(used):
+ k, n = keys[i]
+ g.vp.name[v] = n
+ g.vp.discogs_id[v] = k
+ for c, i in cats[alt].items():
+ g.vp.name[N + i] = c
yield alt, g
Update copyright information 73a4f0d
diff --git a/entries/discogs_genre/__init__.py b/entries/discogs_genre/__init__.py
index e791c8b..bd7c78e 100644
--- a/entries/discogs_genre/__init__.py
+++ b/entries/discogs_genre/__init__.py
@@ -1,7 +1,7 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
-# Copyright (C) 2020-2024 Tiago de Paula Peixoto <tiago@skewed.de>
+# Copyright (C) 2020-2026 Tiago de Paula Peixoto <tiago@skewed.de>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
Update copyright information 3d288ea
diff --git a/entries/discogs_genre/__init__.py b/entries/discogs_genre/__init__.py
index 02374c1..e791c8b 100644
--- a/entries/discogs_genre/__init__.py
+++ b/entries/discogs_genre/__init__.py
@@ -1,7 +1,7 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
-# Copyright (C) 2020-2023 Tiago de Paula Peixoto <tiago@skewed.de>
+# Copyright (C) 2020-2024 Tiago de Paula Peixoto <tiago@skewed.de>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
Update copyright information 8d005ae
diff --git a/entries/discogs_genre/__init__.py b/entries/discogs_genre/__init__.py
index 25d9aca..02374c1 100644
--- a/entries/discogs_genre/__init__.py
+++ b/entries/discogs_genre/__init__.py
@@ -1,7 +1,7 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
-# Copyright (C) 2021 Tiago de Paula Peixoto <tiago@skewed.de>
+# Copyright (C) 2020-2023 Tiago de Paula Peixoto <tiago@skewed.de>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
Update copyright info db2efcc
diff --git a/entries/discogs_genre/__init__.py b/entries/discogs_genre/__init__.py
index 69e3217..25d9aca 100644
--- a/entries/discogs_genre/__init__.py
+++ b/entries/discogs_genre/__init__.py
@@ -1,7 +1,7 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
-# Copyright (C) 2020 Tiago de Paula Peixoto <tiago@skewed.de>
+# Copyright (C) 2021 Tiago de Paula Peixoto <tiago@skewed.de>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
Un-orphan KONECT datasets 894eba5
KONECT has been brought back from the dead for the time being.
diff --git a/entries/discogs_genre/__init__.py b/entries/discogs_genre/__init__.py
index c88d1ab..69e3217 100644
--- a/entries/discogs_genre/__init__.py
+++ b/entries/discogs_genre/__init__.py
@@ -26,7 +26,6 @@ url = 'http://konect.cc/networks/discogs_genre'
citation = [('J. Kunegis, "Discogs network dataset." KONECT (2016)', 'https://doi.org/10.1145/2487788.2488173')]
icon_hash = '5758b60cbd3e93b53c6955be'
upstream_prefix = 'http://konect.cc/files'
-orphan = True
files = [('download.tsv.discogs_genre.tar.bz2', None, 'konect')]
def fetch_upstream(force=False):
Update citations to use DOIs e878874
diff --git a/entries/discogs_genre/__init__.py b/entries/discogs_genre/__init__.py
index c44edbf..c88d1ab 100644
--- a/entries/discogs_genre/__init__.py
+++ b/entries/discogs_genre/__init__.py
@@ -23,7 +23,7 @@ description = """Two bipartite networks of the affiliations between musical arti
[^icon]: Description obtained from the [ICON](https://icon.colorado.edu) project."""
tags = ['Informational', 'Relatedness', 'Unweighted']
url = 'http://konect.cc/networks/discogs_genre'
-citation = [('J. Kunegis, "Discogs network dataset." KONECT (2016)', 'http://konect.cc/networks/')]
+citation = [('J. Kunegis, "Discogs network dataset." KONECT (2016)', 'https://doi.org/10.1145/2487788.2488173')]
icon_hash = '5758b60cbd3e93b53c6955be'
upstream_prefix = 'http://konect.cc/files'
orphan = True
Add support for 'orphan' datasets and tag konect entries e330b80
diff --git a/entries/discogs_genre/__init__.py b/entries/discogs_genre/__init__.py
index 1e60e8c..c44edbf 100644
--- a/entries/discogs_genre/__init__.py
+++ b/entries/discogs_genre/__init__.py
@@ -26,6 +26,7 @@ url = 'http://konect.cc/networks/discogs_genre'
citation = [('J. Kunegis, "Discogs network dataset." KONECT (2016)', 'http://konect.cc/networks/')]
icon_hash = '5758b60cbd3e93b53c6955be'
upstream_prefix = 'http://konect.cc/files'
+orphan = True
files = [('download.tsv.discogs_genre.tar.bz2', None, 'konect')]
def fetch_upstream(force=False):
Change license from GPLv3 to AGPLv3 d754be5
diff --git a/entries/discogs_genre/__init__.py b/entries/discogs_genre/__init__.py
index ea67969..1e60e8c 100644
--- a/entries/discogs_genre/__init__.py
+++ b/entries/discogs_genre/__init__.py
@@ -3,18 +3,18 @@
#
# Copyright (C) 2020 Tiago de Paula Peixoto <tiago@skewed.de>
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Affero General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+# details.
#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Affero General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
from .. import *
Add explicit attribution to descriptions obtained from ICON 1645314
diff --git a/entries/discogs_genre/__init__.py b/entries/discogs_genre/__init__.py
index 235c3c5..ea67969 100644
--- a/entries/discogs_genre/__init__.py
+++ b/entries/discogs_genre/__init__.py
@@ -19,7 +19,8 @@
from .. import *
title = "Discogs artist affiliations"
-description = "Two bipartite networks of the affiliations between musical artists and either musical genres or musical \"styles,\" as given in the discogs.com database. An edge indicates that a given artist was involved in a production of a particular genre or style. The date of this snapshot is uncertain."
+description = """Two bipartite networks of the affiliations between musical artists and either musical genres or musical \"styles,\" as given in the discogs.com database. An edge indicates that a given artist was involved in a production of a particular genre or style. The date of this snapshot is uncertain.[^icon]
+[^icon]: Description obtained from the [ICON](https://icon.colorado.edu) project."""
tags = ['Informational', 'Relatedness', 'Unweighted']
url = 'http://konect.cc/networks/discogs_genre'
citation = [('J. Kunegis, "Discogs network dataset." KONECT (2016)', 'http://konect.cc/networks/')]
Initial commit cc85872
diff --git a/entries/discogs_genre/__init__.py b/entries/discogs_genre/__init__.py
new file mode 100644
index 0000000..235c3c5
--- /dev/null
+++ b/entries/discogs_genre/__init__.py
@@ -0,0 +1,48 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2020 Tiago de Paula Peixoto <tiago@skewed.de>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from .. import *
+
+title = "Discogs artist affiliations"
+description = "Two bipartite networks of the affiliations between musical artists and either musical genres or musical \"styles,\" as given in the discogs.com database. An edge indicates that a given artist was involved in a production of a particular genre or style. The date of this snapshot is uncertain."
+tags = ['Informational', 'Relatedness', 'Unweighted']
+url = 'http://konect.cc/networks/discogs_genre'
+citation = [('J. Kunegis, "Discogs network dataset." KONECT (2016)', 'http://konect.cc/networks/')]
+icon_hash = '5758b60cbd3e93b53c6955be'
+upstream_prefix = 'http://konect.cc/files'
+files = [('download.tsv.discogs_genre.tar.bz2', None, 'konect')]
+
+def fetch_upstream(force=False):
+ return fetch_upstream_files(__name__.split(".")[-1], upstream_prefix, files,
+ force)
+
+@cache_network()
+@coerce_props()
+@annotate()
+def parse(alts=None):
+ global files
+ name = __name__.split(".")[-1]
+ for fnames, alt, fmt in files:
+ if alts is not None and alt not in alts:
+ continue
+ if isinstance(fnames, str):
+ fnames = [fnames]
+ with ExitStack() as stack:
+ fs = [stack.enter_context(open_upstream_file(name, fn, "rb")) for fn in fnames]
+ g = parse_graph(fs, fmt, directed=False)
+ yield alt, g