File size: 2,313 Bytes
a3898b5
 
 
a82e3ba
 
 
 
a3898b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a82e3ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3898b5
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
---
configs:
- config_name: default
  data_files:
  - split: train
    path: "stackoverflow/train_clean.csv"
- config_name: raw
  data_files:
  - split: train
    path: "stackoverflow/train.csv"
---

# StackExchange Dataset

Working doc: https://docs.google.com/document/d/1h585bH5sYcQW4pkHzqWyQqA4ape2Bq6o1Cya0TkMOQc/edit?usp=sharing

<!-- 1. We run the following query on StackExchange Data Explorer (note that this can be done programmatically using BigQuery for the StackOverflow site, but not the other sites)
```
SELECT *
FROM Posts p
WHERE p.PostTypeId = 2
AND LOWER(p.Body) LIKE '%arxiv%'
```

2. Download the csv results

3. 

```
CREATE TEMPORARY TABLE answers AS
SELECT *
FROM Posts
WHERE PostTypeId = 2
AND LOWER(a.Body) LIKE '%arxiv%'

CREATE TEMPORARY TABLE questions AS
SELECT *
FROM Posts
WHERE PostTypeId = 1;

SELECT *
FROM answers a
JOIN questions q ON q.Id = a.ParentId
``` -->

BigQuery query (see [so_bigquery.ipynb](so_bigquery.ipynb)):
```
CREATE TEMP TABLE answers AS
SELECT *
FROM bigquery-public-data.stackoverflow.posts_answers
WHERE LOWER(Body) LIKE '%arxiv%';

CREATE TEMPORARY TABLE questions AS
SELECT *
FROM bigquery-public-data.stackoverflow.posts_questions;

SELECT *
FROM answers
JOIN questions ON questions.id = answers.parent_id;
```

NOTE: BigQuery only has the StackOverflow site data, not the other sites.
So if we want to query the other sites, we would probably want to download the data dump to a cluster and run a SQL server.

Columns in the raw query output:
```
'id', 
'title', 
'body', 
'accepted_answer_id', 
'answer_count', 
'comment_count', 
'community_owned_date', # present only if post is community wiki'd
'creation_date',
'favorite_count',
'last_activity_date', 
'last_edit_date',
'last_editor_display_name', 
'last_editor_user_id',
'owner_display_name', 
'owner_user_id',
'parent_id', # if post is answer, then this is the question id; if post is question, this is None
'post_type_id', # 1 = QUESTION, 2 = ANSWER
'score',
'tags',
'view_count',
```

(Official database schema)[https://meta.stackexchange.com/questions/2677/database-schema-documentation-for-the-public-data-dump-and-sede/2678#2678]

## File structure

Each folder represents the different StackExchange [sites](https://stackexchange.com/sites#oldest) (~182). The largest one is StackOverflow.