logo Netzschleuder network catalog, repository, and centrifuge

History of tkgl_smallpedia

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] New entry: tkgl_smallpedia by Tiago de Paula Peixoto a946b00
diff --git a/entries/tkgl_smallpedia/__init__.py b/entries/tkgl_smallpedia/__init__.py
new file mode 100644
index 0000000..b2de147
--- /dev/null
+++ b/entries/tkgl_smallpedia/__init__.py
@@ -0,0 +1,77 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 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
+# 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 Affero General Public License for more
+# details.
+#
+# 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/>.
+
+
+
+import pandas
+
+from .. import *
+
+
+title = "Wikidata temporal knowledge graph, small subset (tkgl-smallpedia, TGB 2.0)"
+description = """A temporal knowledge graph extracted from Wikidata, from the `tkgl-smallpedia` dataset of the Temporal Graph Benchmark (TGB 2.0): the statements between the Wikidata entities with identifiers below one million (i.e. Q1 to Q999999) that are paired with Wikipedia pages. Each node is an entity of Wikidata, and a directed edge from entity A to entity B is a statement (A, relation, B), with a Wikidata property as relation (e.g. `P166`, "award received", or `P54`, "member of sports team"). Pairs of entities may be connected by several edges.
+
+- `temporal`: the statements with a time (a point in time, or the start of a period), as a year from 1900 to 2024.
+- `static`: the statements of the same entities without a time; the statements that are also temporal ones were removed by TGB.
+
+The data do not include the labels of the entities and relations, which can be looked up in Wikidata.
+
+The networks have the following properties:
+
+- `wikidata_id`: the Wikidata identifier of the entity, e.g. `Q648`.
+- Edge `relation`: the Wikidata property of the statement, e.g. `P166`.
+- Edge `year` (`temporal` only): the year of the statement."""
+tags = ['Informational', 'Relatedness', 'Unweighted', 'Multigraph', 'Timestamps', 'Metadata']
+url = ['https://tgb.complexdatalab.com/docs/tkg/',
+       'https://github.com/shenyangHuang/TGB']
+citation = [('J. Gastinger, S. Huang, M. Galkin, E. Loghmani, A. Parviz, F. Poursafaei, J. Danovitch, E. Rossi, I. Koutis, H. Stuckenschmidt, R. Rabbany, G. Rabusseau, "TGB 2.0: A Benchmark for Learning on Temporal Knowledge Graphs and Heterogeneous Graphs." Advances in Neural Information Processing Systems 37 (Datasets and Benchmarks Track) (2024)', 'https://doi.org/10.48550/arXiv.2406.09639'),
+            ('D. Vrandečić, M. Krötzsch, "Wikidata: a free collaborative knowledgebase." Communications of the ACM 57(10), 78-85 (2014)', 'https://doi.org/10.1145/2629489')]
+icon_hash = None
+upstream_license = ('CC0 1.0 (Wikidata)', 'https://www.wikidata.org/wiki/Wikidata:Licensing')
+upstream_prefix = 'https://object-arbutus.alliancecan.ca/swift/v1/14c95234f6cd4a21a47deafe20cce2a7/tgb'
+files = [('tkgl-smallpedia.zip:tkgl-smallpedia_edgelist.csv', 'temporal', None),
+         ('tkgl-smallpedia.zip:tkgl-smallpedia_static_edgelist.csv', 'static', None)]
+
+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 fname, alt, fmt in files:
+        if alts is not None and alt not in alts:
+            continue
+        # "ts,head,tail,relation_type" or "head,tail,relation_type"
+        with open_upstream_file(name, fname, "rb") as f:
+            df = pandas.read_csv(f, dtype=str)
+        cols = ["head", "tail", "relation_type"]
+        eprops = [("relation", "string")]
+        if alt == "temporal":
+            cols.append("ts")
+            eprops.append(("year", "int"))
+            df["ts"] = df["ts"].astype("int64")
+        g = Graph(directed=True)
+        g.vp.wikidata_id = g.add_edge_list(df[cols].itertuples(index=False),
+                                           hashed=True, eprops=list(eprops))
+        for k, t in eprops:
+            g.ep[k] = g.ep[k]
+        yield alt, g