History of google_local
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] Remove superfluous details of the upstream distribution from the descriptions dc07aa0
The descriptions mentioned incidental details of how the upstream data are made available: the file formats (CSV, JSON, XML, GEXF, SBML, HIF, Pajek, UCINET, ...), file names, where the files were published or obtained from (Zenodo, figshare, Kaggle, the Pajek datasets page, the Internet Archive), and that some networks are only available in the gt format. These are left out; caveats about the data themselves are kept, referring to "the data" instead of "the file". The description of sp_baboons now lists its properties instead of the upstream columns, and says that events without a recipient are left out.
diff --git a/entries/google_local/__init__.py b/entries/google_local/__init__.py
index 611e79b..6c70d41 100644
--- a/entries/google_local/__init__.py
+++ b/entries/google_local/__init__.py
@@ -29,11 +29,11 @@ from .. import *
title = "Google Maps business reviews (Google Local, 2018 and 2021)"
description = """Bipartite networks of the users of Google Maps and the businesses they reviewed, collected by researchers of the group of J. McAuley at UC San Diego.
-- `reviews`: the reviews of businesses in the United States written up to September 2021 (Google Local 2021, collected by T. Zhang and J. Li), with the rating and the time of each review. Each edge is a review, and a user is connected to a business as many times as they reviewed it. The reviews are those of the "ratings only" files of the source (one per US state, which list the business, the user, the rating and the time; the review texts, pictures and the responses of the businesses are left out). The user ids of the source (the Google account ids) are not included.
+- `reviews`: the reviews of businesses in the United States written up to September 2021 (Google Local 2021, collected by T. Zhang and J. Li), with the rating and the time of each review. Each edge is a review, and a user is connected to a business as many times as they reviewed it. The reviews are those of the "ratings only" version of the data (with the business, the user, the rating and the time; the review texts, pictures and the responses of the businesses are left out). The user ids of the source (the Google account ids) are not included.
- `related`: a directed network of the businesses of `reviews`, in which an edge from business A to business B means that B is among the "relative results" listed by Google Maps on the page of A (businesses that people also search for).
- `reviews_2018`: an earlier, smaller collection of reviews (Google Local 2018, collected from Google+ by R. He, W.-C. Kang and J. McAuley), from businesses all over the world, with the rating and the time of each review. The user names and the profiles of the users are left out.
-All the businesses of the metadata files of the source are included, also those without reviews; the businesses without metadata (listed in reviews or relative results but not in the metadata files) are included too, with empty properties.
+All the businesses of the metadata of the source are included, also those without reviews; the businesses without metadata (listed in reviews or relative results but not in the metadata) are included too, with empty properties.
The networks have the following properties:
@@ -43,7 +43,7 @@ The networks have the following properties:
- (Node) `name`, `address`, `latitude`, `longitude`, `price`: the name, address, coordinates and price (e.g. "$$") of the business; empty for users.
- (Node) `category` (`reviews` and `related`): the list of categories of the business; empty for users.
- (Node) `avg_rating`, `num_of_reviews` (`reviews` and `related`): on Google Maps, at the time of the collection (-1 if unknown); empty for users.
-- (Node) `state` (`reviews` and `related`): the name of the metadata file in which the business is listed (a US state, or "other"); empty for users.
+- (Node) `state` (`reviews` and `related`): the US state under which the business is listed in the metadata (or "other"); empty for users.
- (Node) `closed` (`reviews_2018`): whether the business was marked as closed; empty for users.
- (Edge) `rating` (`reviews` and `reviews_2018`): the rating, from 1 to 5 (0 if missing).
- (Edge) `time` (`reviews` and `reviews_2018`): the time of the review (Unix time; -1 if missing)."""
[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/google_local/__init__.py b/entries/google_local/__init__.py
index 7777265..611e79b 100644
--- a/entries/google_local/__init__.py
+++ b/entries/google_local/__init__.py
@@ -54,7 +54,7 @@ citation = [('J. Li, J. Shang, J. McAuley, "UCTopic: Unsupervised Contrastive Le
('A. Yan, Z. He, J. Li, T. Zhang, J. McAuley, "Personalized Showcases: Generating Multi-Modal Explanations for Recommendations." Proceedings of the 46th International ACM SIGIR Conference on Research and Development in Information Retrieval (SIGIR), 2251-2255 (2023)', 'https://doi.org/10.1145/3539618.3592036'),
('R. He, W.-C. Kang, J. McAuley, "Translation-based Recommendation." Proceedings of the 11th ACM Conference on Recommender Systems (RecSys), 161-169 (2017)', 'https://doi.org/10.1145/3109859.3109882'),
('R. Pasricha, J. McAuley, "Translation-based factorization machines for sequential recommendation." Proceedings of the 12th ACM Conference on Recommender Systems (RecSys), 63-71 (2018)', 'https://doi.org/10.1145/3240323.3240356')]
-icon_hash = None
+date_added = '2026-10-27'
upstream_license = None
# networks of more than about 300 million edges: only stored and served in the
# gt format
[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/google_local/__init__.py b/entries/google_local/__init__.py
index 43abe68..7777265 100644
--- a/entries/google_local/__init__.py
+++ b/entries/google_local/__init__.py
@@ -37,10 +37,16 @@ All the businesses of the metadata files of the source are included, also those
The networks have the following properties:
-- `reviews` and `reviews_2018`: `is_user`, whether the node is a user (otherwise a business).
-- `reviews` and `related`: `gmap_id`, the Google Maps id of the business; `name`, `address`, `latitude` and `longitude`, `category` (the list of categories), `avg_rating` and `num_of_reviews` (on Google Maps, at the time of the collection; -1 if unknown), `price` (e.g. "$$"), and `state`, the name of the metadata file in which it is listed (a US state, or "other"); empty for users.
-- `reviews_2018`: `gplus_id`, the Google+ id of the business; `name`, `address`, `latitude` and `longitude`, `price` and `closed`, whether it was marked as closed; empty for users.
-- Edges of `reviews` and `reviews_2018`: `rating`, the rating, from 1 to 5 (0 if missing); `time`, the time of the review (Unix time; -1 if missing)."""
+- (Node) `is_user` (`reviews` and `reviews_2018`): whether the node is a user (otherwise a business).
+- (Node) `gmap_id` (`reviews` and `related`): the Google Maps id of the business; empty for users.
+- (Node) `gplus_id` (`reviews_2018`): the Google+ id of the business; empty for users.
+- (Node) `name`, `address`, `latitude`, `longitude`, `price`: the name, address, coordinates and price (e.g. "$$") of the business; empty for users.
+- (Node) `category` (`reviews` and `related`): the list of categories of the business; empty for users.
+- (Node) `avg_rating`, `num_of_reviews` (`reviews` and `related`): on Google Maps, at the time of the collection (-1 if unknown); empty for users.
+- (Node) `state` (`reviews` and `related`): the name of the metadata file in which the business is listed (a US state, or "other"); empty for users.
+- (Node) `closed` (`reviews_2018`): whether the business was marked as closed; empty for users.
+- (Edge) `rating` (`reviews` and `reviews_2018`): the rating, from 1 to 5 (0 if missing).
+- (Edge) `time` (`reviews` and `reviews_2018`): the time of the review (Unix time; -1 if missing)."""
tags = ['Social', 'Online', 'Commerce', 'Preferences', 'Unweighted', 'Multigraph', 'Timestamps', 'Metadata']
url = ['https://mcauleylab.ucsd.edu/public_datasets/gdrive/googlelocal/',
'https://cseweb.ucsd.edu/~jmcauley/datasets.html#google_local']
[entries] Remove unneeded code from the entries 2c69f19
Unneeded "global files" statements, unused imports and variables, f-strings without placeholders, duplicate keys in foodweb_little_rock (keeping the order and the values used), and the second definition of get_lines() in twitter_higgs. Nothing changes in the networks or descriptions. Changed: none
diff --git a/entries/google_local/__init__.py b/entries/google_local/__init__.py
index 1c75148..43abe68 100644
--- a/entries/google_local/__init__.py
+++ b/entries/google_local/__init__.py
@@ -191,7 +191,6 @@ def _literal(line, keys):
@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:
[entries] Store the networks of more than 300 million edges of the new large entries only in the gt format 68260af
The networks of the large datasets added recently with more than about 300 million edges (published counts, or estimates where the networks have not been parsed yet) are listed in `skip_conversion`, so that they are not converted to GraphML, GML and CSV, which would take about 5 TB.
diff --git a/entries/google_local/__init__.py b/entries/google_local/__init__.py
index 6d0fcaf..1c75148 100644
--- a/entries/google_local/__init__.py
+++ b/entries/google_local/__init__.py
@@ -50,6 +50,9 @@ citation = [('J. Li, J. Shang, J. McAuley, "UCTopic: Unsupervised Contrastive Le
('R. Pasricha, J. McAuley, "Translation-based factorization machines for sequential recommendation." Proceedings of the 12th ACM Conference on Recommender Systems (RecSys), 63-71 (2018)', 'https://doi.org/10.1145/3240323.3240356')]
icon_hash = None
upstream_license = None
+# networks of more than about 300 million edges: only stored and served in the
+# gt format
+skip_conversion = ['reviews']
upstream_prefix = 'https://mcauleylab.ucsd.edu/public_datasets'
# Huge: about 666 million reviews of 114 million users; the parse of
# `reviews` is estimated to need about 35-40 GB of memory
[entries] New entry: google_local 04a22e9
diff --git a/entries/google_local/__init__.py b/entries/google_local/__init__.py
new file mode 100644
index 0000000..6d0fcaf
--- /dev/null
+++ b/entries/google_local/__init__.py
@@ -0,0 +1,323 @@
+#! /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 ast
+import re
+
+import pyarrow
+import pyarrow.compute as pc
+import pyarrow.csv
+import pyarrow.json
+
+from .. import *
+
+
+title = "Google Maps business reviews (Google Local, 2018 and 2021)"
+description = """Bipartite networks of the users of Google Maps and the businesses they reviewed, collected by researchers of the group of J. McAuley at UC San Diego.
+
+- `reviews`: the reviews of businesses in the United States written up to September 2021 (Google Local 2021, collected by T. Zhang and J. Li), with the rating and the time of each review. Each edge is a review, and a user is connected to a business as many times as they reviewed it. The reviews are those of the "ratings only" files of the source (one per US state, which list the business, the user, the rating and the time; the review texts, pictures and the responses of the businesses are left out). The user ids of the source (the Google account ids) are not included.
+- `related`: a directed network of the businesses of `reviews`, in which an edge from business A to business B means that B is among the "relative results" listed by Google Maps on the page of A (businesses that people also search for).
+- `reviews_2018`: an earlier, smaller collection of reviews (Google Local 2018, collected from Google+ by R. He, W.-C. Kang and J. McAuley), from businesses all over the world, with the rating and the time of each review. The user names and the profiles of the users are left out.
+
+All the businesses of the metadata files of the source are included, also those without reviews; the businesses without metadata (listed in reviews or relative results but not in the metadata files) are included too, with empty properties.
+
+The networks have the following properties:
+
+- `reviews` and `reviews_2018`: `is_user`, whether the node is a user (otherwise a business).
+- `reviews` and `related`: `gmap_id`, the Google Maps id of the business; `name`, `address`, `latitude` and `longitude`, `category` (the list of categories), `avg_rating` and `num_of_reviews` (on Google Maps, at the time of the collection; -1 if unknown), `price` (e.g. "$$"), and `state`, the name of the metadata file in which it is listed (a US state, or "other"); empty for users.
+- `reviews_2018`: `gplus_id`, the Google+ id of the business; `name`, `address`, `latitude` and `longitude`, `price` and `closed`, whether it was marked as closed; empty for users.
+- Edges of `reviews` and `reviews_2018`: `rating`, the rating, from 1 to 5 (0 if missing); `time`, the time of the review (Unix time; -1 if missing)."""
+tags = ['Social', 'Online', 'Commerce', 'Preferences', 'Unweighted', 'Multigraph', 'Timestamps', 'Metadata']
+url = ['https://mcauleylab.ucsd.edu/public_datasets/gdrive/googlelocal/',
+ 'https://cseweb.ucsd.edu/~jmcauley/datasets.html#google_local']
+citation = [('J. Li, J. Shang, J. McAuley, "UCTopic: Unsupervised Contrastive Learning for Phrase Representations and Topic Mining." Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (ACL), 6159-6169 (2022)', 'https://doi.org/10.18653/v1/2022.acl-long.426'),
+ ('A. Yan, Z. He, J. Li, T. Zhang, J. McAuley, "Personalized Showcases: Generating Multi-Modal Explanations for Recommendations." Proceedings of the 46th International ACM SIGIR Conference on Research and Development in Information Retrieval (SIGIR), 2251-2255 (2023)', 'https://doi.org/10.1145/3539618.3592036'),
+ ('R. He, W.-C. Kang, J. McAuley, "Translation-based Recommendation." Proceedings of the 11th ACM Conference on Recommender Systems (RecSys), 161-169 (2017)', 'https://doi.org/10.1145/3109859.3109882'),
+ ('R. Pasricha, J. McAuley, "Translation-based factorization machines for sequential recommendation." Proceedings of the 12th ACM Conference on Recommender Systems (RecSys), 63-71 (2018)', 'https://doi.org/10.1145/3240323.3240356')]
+icon_hash = None
+upstream_license = None
+upstream_prefix = 'https://mcauleylab.ucsd.edu/public_datasets'
+# Huge: about 666 million reviews of 114 million users; the parse of
+# `reviews` is estimated to need about 35-40 GB of memory
+huge = True
+states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado',
+ 'Connecticut', 'Delaware', 'District_of_Columbia', 'Florida',
+ 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas',
+ 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts',
+ 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana',
+ 'Nebraska', 'Nevada', 'New_Hampshire', 'New_Jersey', 'New_Mexico',
+ 'New_York', 'North_Carolina', 'North_Dakota', 'Ohio', 'Oklahoma',
+ 'Oregon', 'Pennsylvania', 'Rhode_Island', 'South_Carolina',
+ 'South_Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia',
+ 'Washington', 'West_Virginia', 'Wisconsin', 'Wyoming']
+_meta = [f'gdrive/googlelocal/meta-{s}.json.gz' for s in states + ['other']]
+_ratings = [f'gdrive/googlelocal/rating-{s}.csv.gz' for s in states]
+files = [(tuple(_ratings + _meta), 'reviews', None),
+ (tuple(_meta), 'related', None),
+ (('data/googlelocal/reviews.clean.json.gz',
+ 'data/googlelocal/places.clean.json.gz'), 'reviews_2018', None)]
+
+def fetch_upstream(force=False):
+ return fetch_upstream_files(__name__.split(".")[-1], upstream_prefix, files,
+ force)
+
+# For checks only: if set, only (about) this many reviews are read from each
+# file
+_check_rows = None
+
+_meta_fields = [("gmap_id", pyarrow.string()), ("name", pyarrow.string()),
+ ("address", pyarrow.string()), ("latitude", pyarrow.float64()),
+ ("longitude", pyarrow.float64()),
+ ("category", pyarrow.list_(pyarrow.string())),
+ ("avg_rating", pyarrow.float64()),
+ ("num_of_reviews", pyarrow.int64()),
+ ("price", pyarrow.string()),
+ ("relative_results", pyarrow.list_(pyarrow.string()))]
+
+def read_meta(name, fnames):
+ """The metadata of the businesses, from all the metadata files (a
+ table, with the first occurrence of each business, and its state)."""
+ tables = []
+ for fname in fnames:
+ state = fname.split("meta-")[1].removesuffix(".json.gz")
+ with open_upstream_file(name, fname, "rb") as f:
+ t = pyarrow.json.read_json(
+ f, parse_options=pyarrow.json.ParseOptions(
+ explicit_schema=pyarrow.schema(_meta_fields),
+ unexpected_field_behavior="ignore"))
+ t = t.append_column("state", pyarrow.array([state] * t.num_rows))
+ tables.append(t)
+ meta = pyarrow.concat_tables(tables)
+ del tables
+ ids = meta["gmap_id"].to_pylist()
+ first = {}
+ for i, b in enumerate(ids):
+ first.setdefault(b, i)
+ if len(first) < len(ids):
+ meta = meta.take(pyarrow.array(sorted(first.values())))
+ return meta
+
+def add_business_props(g, meta, extra):
+ """Store the metadata of the businesses as properties of the first
+ vertices: those of `meta`, followed by the businesses without metadata,
+ whose ids are in the list `extra`."""
+ B = meta.num_rows
+ for p in ["gmap_id", "name", "address", "price", "state"]:
+ g.vp[p] = g.new_vp("string")
+ vals = meta[p].to_pylist()
+ if p == "gmap_id":
+ vals += extra
+ for v, x in enumerate(vals):
+ if x:
+ g.vp[p][v] = x
+ for p in ["latitude", "longitude"]:
+ g.vp[p] = g.new_vp("double", val=numpy.nan)
+ g.vp[p].a[:B] = pc.fill_null(meta[p], numpy.nan).to_numpy()
+ g.vp.avg_rating = g.new_vp("double", val=-1)
+ g.vp.avg_rating.a[:B] = pc.fill_null(meta["avg_rating"], -1).to_numpy()
+ g.vp.num_of_reviews = g.new_vp("int64_t", val=-1)
+ g.vp.num_of_reviews.a[:B] = pc.fill_null(meta["num_of_reviews"], -1).to_numpy()
+ g.vp.category = g.new_vp("vector<string>")
+ for v, x in enumerate(meta["category"].to_pylist()):
+ if x:
+ g.vp.category[v] = x
+
+def user_keys(a):
+ """Google account ids (21-digit decimal strings starting with 1) as
+ unsigned 64-bit integers (the id minus 10^20)."""
+ assert pc.all(pc.equal(pc.utf8_length(a), 21)).as_py()
+ hi = pc.cast(pc.utf8_slice_codeunits(a, 0, 11), pyarrow.uint64()).to_numpy()
+ lo = pc.cast(pc.utf8_slice_codeunits(a, 11, 21), pyarrow.uint64()).to_numpy()
+ hi = hi - numpy.uint64(10 ** 10)
+ # the result must fit in 64 bits
+ assert (hi <= numpy.uint64(1844674407)).all()
+ k = hi * numpy.uint64(10 ** 10) + lo
+ assert (k >= hi).all()
+ return k
+
+def read_ratings(name, fname):
+ """The ratings of a file, in blocks of (business, user, rating, time)
+ arrays: business ids as a pyarrow array, users as keys (see
+ user_keys()), the times in seconds."""
+ n = 0
+ with open_upstream_file(name, fname, "rb") as f:
+ reader = pyarrow.csv.open_csv(
+ f, read_options=pyarrow.csv.ReadOptions(block_size=1 << 26),
+ convert_options=pyarrow.csv.ConvertOptions(
+ column_types={"business": pyarrow.string(),
+ "user": pyarrow.string(),
+ "rating": pyarrow.int64(),
+ "timestamp": pyarrow.int64()}))
+ for batch in reader:
+ if _check_rows is not None and n >= _check_rows:
+ break
+ n += batch.num_rows
+ assert batch.schema.names == ["business", "user", "rating", "timestamp"]
+ yield (batch.column(0), user_keys(batch.column(1)),
+ pc.fill_null(batch.column(2), 0).to_numpy(),
+ batch.column(3).to_numpy() // 1000)
+
+def _literal(line, keys):
+ """The values of the given keys of a line of the 2018 files (a Python
+ dict literal), found with regular expressions, or by evaluating the
+ line if they are ambiguous."""
+ vals = {}
+ for k, pat in keys.items():
+ m = re.findall(r"[{,] '%s': %s" % (k, pat), line)
+ if len(m) != 1:
+ d = ast.literal_eval(line)
+ return {k: d.get(k) for k in keys}
+ vals[k] = m[0]
+ return vals
+
+@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 alt == "reviews_2018":
+ yield alt, parse_2018(name, fnames)
+ continue
+ meta = read_meta(name, [f for f in fnames if "/meta-" in f])
+ bindex = {b: i for i, b in enumerate(meta["gmap_id"].to_pylist())}
+ B = len(bindex)
+ extra = []
+ def business_index(ids):
+ ids = ids.to_pylist()
+ for b in ids:
+ if b not in bindex:
+ bindex[b] = len(bindex)
+ extra.append(b)
+ return numpy.array([bindex[b] for b in ids], dtype="int64")
+
+ if alt == "related":
+ rel = meta["relative_results"]
+ src = numpy.repeat(numpy.arange(B), pc.fill_null(pc.list_value_length(rel), 0).to_numpy())
+ tgt = business_index(pc.list_flatten(rel))
+ g = Graph(directed=True)
+ g.add_vertex(len(bindex))
+ g.add_edge_list(numpy.column_stack([src, tgt]))
+ add_business_props(g, meta, extra)
+ yield alt, g
+ continue
+ meta = meta.drop_columns(["relative_results"])
+
+ # First pass: the users (sorted keys)
+ ratings = [f for f in fnames if "/rating-" in f]
+ ukeys = []
+ for fname in ratings:
+ ks = [numpy.unique(u) for b, u, r, t in read_ratings(name, fname)]
+ ukeys.append(numpy.unique(numpy.concatenate(ks)))
+ del ks
+ ukeys = numpy.unique(numpy.concatenate(ukeys))
+ U = len(ukeys)
+
+ # Second pass: the reviews; the vertices are the businesses (with
+ # metadata), the users, then the businesses without metadata
+ g = Graph(directed=False)
+ g.add_vertex(B + U)
+ g.ep.rating = g.new_ep("int16_t")
+ g.ep.time = g.new_ep("int64_t")
+ for fname in ratings:
+ for b, u, r, t in read_ratings(name, fname):
+ # businesses: by their distinct ids in the block
+ d = pc.dictionary_encode(b)
+ bi = business_index(d.dictionary)[d.indices.to_numpy()]
+ bi = numpy.where(bi < B, bi, bi + U)
+ ui = B + numpy.searchsorted(ukeys, u)
+ g.add_edge_list(numpy.column_stack([bi, ui, r, t]),
+ eprops=[g.ep.rating, g.ep.time])
+ del b, u, r, t, d, bi, ui
+ g.vp.is_user = g.new_vp("bool")
+ g.vp.is_user.a[B:B + U] = True
+ # the businesses without metadata come after the users: their
+ # properties are set on a reordered copy of the ids
+ add_business_props(g, meta, [])
+ for i, b in enumerate(extra):
+ g.vp.gmap_id[B + U + i] = b
+ yield alt, g
+
+def parse_2018(name, fnames):
+ places = {} # Google+ id -> vertex
+ pmeta = []
+ with open_upstream_file(name, fnames[1], "r") as f:
+ for line in f:
+ d = ast.literal_eval(line)
+ pid = d["gPlusPlaceId"]
+ if pid in places:
+ continue
+ places[pid] = len(places)
+ gps = d.get("gps") or (numpy.nan, numpy.nan)
+ pmeta.append((d.get("name") or "",
+ ", ".join(d.get("address") or []),
+ d.get("price") or "", bool(d.get("closed")),
+ gps[0], gps[1]))
+ del d
+ users = {}
+ edges = []
+ keys = {"rating": r"([0-9.]+|None)", "gPlusPlaceId": r"u?'([0-9]+)'",
+ "unixReviewTime": r"([0-9]+|None)", "gPlusUserId": r"u?'([0-9]+)'"}
+ extra = []
+ n = 0
+ with open_upstream_file(name, fnames[0], "r") as f:
+ for line in f:
+ if _check_rows is not None and n >= _check_rows:
+ break
+ n += 1
+ d = _literal(line, keys)
+ pid = d["gPlusPlaceId"]
+ if pid not in places:
+ places[pid] = len(places)
+ extra.append(pid)
+ u = users.setdefault(d["gPlusUserId"], len(users))
+ r = d["rating"]
+ t = d["unixReviewTime"]
+ edges.append((places[pid], u,
+ 0 if r in (None, "None") else int(float(r)),
+ -1 if t in (None, "None") else int(t)))
+ edges = numpy.array(edges, dtype="int64")
+ X = len(places) # places, with those without metadata
+ edges[:, 1] += X
+ g = Graph(directed=False)
+ g.add_vertex(X + len(users))
+ g.ep.rating = g.new_ep("int16_t")
+ g.ep.time = g.new_ep("int64_t")
+ g.add_edge_list(edges, eprops=[g.ep.rating, g.ep.time])
+ del edges
+ g.vp.is_user = g.new_vp("bool")
+ g.vp.is_user.a[X:] = True
+ g.vp.gplus_id = g.new_vp("string")
+ for pid, v in places.items():
+ g.vp.gplus_id[v] = pid
+ g.vp.name = g.new_vp("string")
+ g.vp.address = g.new_vp("string")
+ g.vp.price = g.new_vp("string")
+ g.vp.closed = g.new_vp("bool")
+ g.vp.latitude = g.new_vp("double", val=numpy.nan)
+ g.vp.longitude = g.new_vp("double", val=numpy.nan)
+ for v, (pname, addr, price, closed, lat, lon) in enumerate(pmeta):
+ g.vp.name[v] = pname
+ g.vp.address[v] = addr
+ g.vp.price[v] = price
+ g.vp.closed[v] = closed
+ g.vp.latitude[v] = lat
+ g.vp.longitude[v] = lon
+ return g