我正在查看reddit数据集,以及older question查看使用BigQuery查找bi-gram的情况 - 但是这个问题的答案不适用于URL,引号等。是否有更好的方法,并将其推广到三元组而不是二元组?
答案 0 :(得分:4)
这样做:
SELECT word, nextword, nextword2, COUNT(*) c
FROM (
SELECT pos, id, word, LEAD(word) OVER(PARTITION BY id ORDER BY pos) nextword, LEAD(word, 2) OVER(PARTITION BY id ORDER BY pos) nextword2 FROM (
SELECT id, word, pos FROM FLATTEN(
(SELECT id, REGEXP_REPLACE(word, 'QUOTE', "'") word, POSITION(word) pos FROM
(SELECT id, SPLIT(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(LOWER(body), "'", 'QUOTE'), r'http.?://[^ ]*', r'URL'), r'\b', ' '), ' ') word
FROM [fh-bigquery:reddit_comments.2016_01]
WHERE score>200
HAVING REGEXP_MATCH(word, '[a-zA-Z0-9]')
)
), word)
))
WHERE nextword IS NOT null
GROUP EACH BY 1, 2, 3
ORDER BY c DESC
LIMIT 100
(请注意,我正在过滤评分为> 200得分以获得更快的结果 - 您可以整整一个月移动该过滤器)