densenet commited on
Commit
7febd01
·
verified ·
1 Parent(s): afe7dc8

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ multilinguality:
6
+ - monolingual
7
+ tags:
8
+ - text
9
+ - qa
10
+ - code
11
+ - lua
12
+ - roblox
13
+ size_categories:
14
+ - 1K<n<10K
15
+ task_categories:
16
+ - question-answering
17
+ task_ids:
18
+ - closed-domain-qa
19
+ pretty_name: "scriptinghelpers archive"
20
+ configs:
21
+ - config_name: raw_data
22
+ data_files:
23
+ - split: train
24
+ path: "questions_raw.snappy.parquet"
25
+ - config_name: parsed_data
26
+ data_files:
27
+ - split: train
28
+ path: "data.snappy.parquet"
29
+ dataset_info:
30
+ - config_name: raw_data
31
+ features:
32
+ - name: path
33
+ dtype: string
34
+ - name: content
35
+ dtype: string
36
+ splits:
37
+ - name: train
38
+ num_examples: 5733
39
+ - config_name: parsed_data
40
+ features:
41
+ - name: question_score
42
+ dtype: string
43
+ - name: title
44
+ dtype: string
45
+ - name: question_userid
46
+ dtype: string
47
+ - name: question_user
48
+ dtype: string
49
+ - name: question_user_score
50
+ dtype: string
51
+ - name: question_datetime
52
+ dtype: string
53
+ - name: question
54
+ dtype: string
55
+ - name: question_id
56
+ dtype: string
57
+ - name: answer_count
58
+ dtype: string
59
+ - name: answer_id
60
+ dtype: string
61
+ - name: answer_score
62
+ dtype: string
63
+ - name: answer_userid
64
+ dtype: string
65
+ - name: answer_user
66
+ dtype: string
67
+ - name: answer_user_score
68
+ dtype: string
69
+ - name: answer_datetime
70
+ dtype: string
71
+ - name: answer
72
+ dtype: string
73
+ splits:
74
+ - name: train
75
+ num_examples: 5129
76
+ ---
77
+
78
+ This is a small dataset containing question/answer articles on (now defunct) scriptinghelpers.org, which was a StackExchange-like website for Roblox developers. It was scraped from archive.org about a year ago and parsed with regex.
79
+
80
+ ## Trivia
81
+
82
+ - There are 2097 archived articles with accepted answers out of 5129.
83
+ - The earliest question archived was posted on `Sat Feb 1 23:57:31 2014` with question_id `1` by TheGuyWithAShortName entitled `HttpService - PostAsync `. It had an accepted answer posted on `2014-02-17 03:11:33` by MarkOtaris.
84
+ - The last question archived was posted on `Sun Apr 2 01:40:15 2023` with question_id `133258` by RedWirePlatinum entitled `Help with making a bouncy character script *without* creating instances?`.
85
+ - The last question archived with an accepted answer was posted on `Thu Mar 30 18:53:16 2023` with question_id `133254` by krLuCiEzkr entitled `LocalScript that checks if a player has this badge doesn't work? [CLOSED]`. Its answer was posted on `2023-03-30 19:29:01` by MaleficentMaestro.
86
+
87
+ ## Other Notes
88
+
89
+ The `question` and `answer` columns have an endogenous HTML schema that has not been transformed into Markdown. For instance, in question id `129668`:
90
+
91
+ ```html
92
+ <!-- question -->
93
+ <p>I was trying to remove the HopperBin in user's inventory using the following script:</p>
94
+ <pre class="brush: lua">game.Players.PlayerAdded:Connect(function(player)
95
+ for i,v in pairs(player.Backpack:GetChildren())
96
+ if v:IsA("HopperBin") then
97
+ v:Destroy()
98
+ end
99
+ end
100
+ end)
101
+ </pre>
102
+ <p>Instead of removing, it does nothing.
103
+ Any help would be great!</p>
104
+
105
+ <!-- answer -->
106
+ <p>1st of all, you should try it when the <strong>Character</strong> is added. Tools and such do not go straight to the backpack, it <strong>waits until the character is added and then adds tools to the backpack</strong>.</p>
107
+ <p>2nd of all, I wouldn't use HopperBins to begin with, as they're <strong>deprecated</strong> (use tools).</p>
108
+
109
+ ```
110
+
111
+ Parsing was done only with the single-pass regular expression and minimal post-processing to remove recurring anomalies.
112
+ Comments and unaccepted answers were not included in the parsed data, but can be found in the raw data.
113
+
114
+ ## Requirements
115
+
116
+ - `brute.py` requires an installation of [ripgrep](https://github.com/burntsushi/ripgrep#installation) on your machine.
117
+ - `data_to_parquet.py` requires pyarrow.
brute.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ from re import Match
3
+ import subprocess
4
+ from tqdm import tqdm
5
+ from questions_tar_extract import extract_articles
6
+ import shutil
7
+ import os
8
+ from pathlib import Path
9
+ import stat
10
+
11
+ blockregex = re.compile(r'<<<(.*?)<<<', flags=re.MULTILINE | re.DOTALL)
12
+ tr = str.maketrans({
13
+ "\"": "\\\"",
14
+ "\\": "\\\\",
15
+ "\n": "\\n"
16
+ })
17
+
18
+ def render_block(mo: Match) -> str:
19
+ block = mo.group(1)
20
+ block = block.translate(tr)
21
+ return f'"{block}"'
22
+
23
+ def prepare_with_ripgrep() -> list[str]:
24
+ articles = extract_articles()
25
+
26
+ pbar = tqdm(total=5129, desc="Extracting and formatting scriptinghelpers posts")
27
+
28
+ rg_exec: str | None = None
29
+ if 'RIPGREP_PATH' in os.environ:
30
+ rg_exec_p = Path(os.path.normpath(os.environ['RIPGREP_PATH'].strip()))
31
+ if rg_exec_p.is_dir():
32
+ rg_exec = shutil.which("rg", path=rg_exec_p)
33
+ else:
34
+ rg_exec_mode = rg_exec_p.stat().st_mode
35
+ if bool(rg_exec_mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)):
36
+ rg_exec = str(rg_exec_p)
37
+ else:
38
+ rg_exec = shutil.which("rg")
39
+
40
+ if rg_exec is None:
41
+ raise RuntimeError(f"ripgrep executable `{rg_exec}` is not installed or not visible in this environment")
42
+
43
+ process = subprocess.Popen([rg_exec, "-U", "-uuu", "-o", "--multiline-dotall", "-N", "--color=never", "-I", "-f", "qa_regex4.txt", str(articles),
44
+ "-r", """{"qscore": "$1", "title": "$2", "quserid": "$3", "quser": "$4", "quserscore": "$5", "qdatetime": "$6", "question": <<<$7<<<, "qid": "$8", "answercount": "$9", "aid": "$10", "ascore": "$11", "auserid": "$12", "auser": "$13", "auserscore": "$14", "adatetime": "$15", "answer": <<<$16<<<}"""], stdout=subprocess.PIPE, text=True, bufsize=1)
45
+ chunk_array = []
46
+ latest_chunk_part = []
47
+ while True:
48
+ line = process.stdout.readline()
49
+ if not line:
50
+ break
51
+ line = line.rstrip()
52
+ if line[-4:] == '<<<}':
53
+ latest_chunk = line if len(latest_chunk_part) == 0 else "\n".join(latest_chunk_part) + f"\n{line}"
54
+ latest_chunk = blockregex.sub(render_block, latest_chunk)
55
+ chunk_array.append(latest_chunk)
56
+ latest_chunk_part.clear()
57
+ pbar.update(1)
58
+ else:
59
+ latest_chunk_part.append(line)
60
+ pbar.total = len(chunk_array)
61
+ pbar.refresh()
62
+ pbar.close()
63
+
64
+ return chunk_array
65
+
66
+ if __name__=='__main__':
67
+ chunk_array = "\n".join(prepare_with_ripgrep())
68
+ with open('data.jsonl', 'w') as f:
69
+ f.write(chunk_array)
70
+ # with open('extract5.txt', 'w') as f:
71
+ # f.write(f'[{",\n".join(chunk_array)}]')
data.snappy.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:11f7eda26f0d1001b03f6da3cbd9e0fbaf44f2b678931fbd63e31d619c97e5ba
3
+ size 3491342
data_to_parquet.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ import pyarrow as pa
3
+ import pyarrow.parquet as pq
4
+ import sys
5
+ import json
6
+ import time
7
+
8
+ from questions_tar_extract import extract_articles
9
+ from brute import prepare_with_ripgrep
10
+
11
+ file_structure_schema = pa.schema([
12
+ ('path', pa.string()),
13
+ ('content', pa.large_string())
14
+ ])
15
+
16
+ extracted_schema = pa.schema([
17
+ ('question_score', pa.string()),
18
+ ('title', pa.string()),
19
+ ('question_userid', pa.string()),
20
+ ('question_user', pa.string()),
21
+ ('question_user_score', pa.string()),
22
+ ('question_datetime', pa.string()),
23
+ ('question', pa.string()),
24
+ ('question_id', pa.string()),
25
+ ('answer_count', pa.string()),
26
+ ('answer_id', pa.string()),
27
+ ('answer_score', pa.string()),
28
+ ('answer_userid', pa.string()),
29
+ ('answer_user', pa.string()),
30
+ ('answer_user_score', pa.string()),
31
+ ('answer_datetime', pa.string()),
32
+ ('answer', pa.string())
33
+ ])
34
+
35
+ extracted_src_key_order = ["qscore","title","quserid","quser","quserscore","qdatetime","question","qid","answercount","aid","ascore","auserid","auser","auserscore","adatetime","answer"]
36
+
37
+ script_dir = Path(__file__).resolve().parent
38
+
39
+ if __name__ == '__main__':
40
+ articles = extract_articles()
41
+
42
+ scraped_files_root = articles.name + "_raw"
43
+
44
+ article_pq_inputs = [[],[]]
45
+ for a in articles.iterdir():
46
+ a = next(next(a.iterdir()).iterdir())
47
+ with open(a, "r") as f:
48
+ content = f.read()
49
+ article_pq_inputs[0].append(str(a))
50
+ article_pq_inputs[1].append(content)
51
+
52
+ article_table = pa.Table.from_arrays(article_pq_inputs, schema=file_structure_schema)
53
+
54
+ pq.write_table(article_table, f"{scraped_files_root}.snappy.parquet", compression='Snappy')
55
+
56
+ article_pq_file = Path(f"{scraped_files_root}.snappy.parquet")
57
+
58
+ print(f"wrote to cwd: {scraped_files_root}.snappy.parquet ({article_pq_file.stat().st_size / (1024 * 1024):.2f} MiB)")
59
+
60
+ extract_file_path = script_dir / "data.jsonl"
61
+ extract_pq_inputs: list[dict[str, str]] | list[list[str]] | None = None
62
+ if not extract_file_path.is_file():
63
+ try:
64
+ rem_attempts = 2
65
+ while rem_attempts > 0:
66
+ user_input = input(f"extracted data not found at {extract_file_path}. run extraction (need ripgrep)? [y/N] ").strip().lower()
67
+
68
+ if not user_input or user_input in ['n', 'no']:
69
+ print("warning: parquet conversion only partially completed because extracted data could not be prepared.")
70
+ sys.exit(0)
71
+ elif user_input in ['y', 'yes']:
72
+ chunk_array = prepare_with_ripgrep()
73
+ with open(script_dir / "data.jsonl", 'w', encoding='utf-8') as f:
74
+ f.write("\n".join(chunk_array))
75
+ extract_pq_inputs = list(map(json.loads, chunk_array))
76
+ break
77
+ else:
78
+ print(f"warning: unknown response '{user_input if len(user_input) < 4 else f"{user_input[:3]}..."}'. remaining attempts: {rem_attempts}")
79
+ time.sleep(0.5)
80
+ rem_attempts -= 1
81
+ if rem_attempts == 0:
82
+ print("fatal: failed to move on after a few attempts")
83
+ sys.exit(1)
84
+ except KeyboardInterrupt:
85
+ print("fatal: received KeyboardInterrupt")
86
+ sys.exit(1)
87
+ else:
88
+ with open(extract_file_path, 'r', encoding='utf-8') as f:
89
+ extract_pq_inputs = list(map(json.loads, f))
90
+
91
+ assert extract_pq_inputs is not None
92
+
93
+ _extract_pq_inputs = [[] for k in extracted_src_key_order]
94
+ for j, k_j in enumerate(extracted_src_key_order):
95
+ for i in range(len(extract_pq_inputs)):
96
+ _extract_pq_inputs[j].append(extract_pq_inputs[i][k_j])
97
+ extract_pq_inputs = _extract_pq_inputs
98
+
99
+ extract_table = pa.Table.from_arrays(extract_pq_inputs, schema=extracted_schema)
100
+
101
+ pq.write_table(extract_table, "data.snappy.parquet", compression='Snappy')
102
+
103
+ extract_pq_file = Path("data.snappy.parquet")
104
+
105
+ print(f"wrote to cwd: data.snappy.parquet ({extract_pq_file.stat().st_size / (1024 * 1024):.2f} MiB)")
106
+
format.md ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Format of Scripting Helpers Q&A posts
2
+
3
+ ## QA Regex
4
+
5
+ ### Prototype
6
+
7
+ ```regex
8
+ points-number">(?P<qscore>\d+)[^h]+<h1 class="question-title">\r?\n\s*(?P<title>[^<]+)(?:\s*<span class="muted">\[closed\]</span>)?</h1>\s*<div class="question-poster sans-serif">\r?\n\s*<span class="muted">Asked by</span>\r?\n\s*<div class="question-poster-username">\r?\n\s*<img src="resources/avatar/(?P<quserid>\d+)" alt(?:="[^"]*")? class="loggedin-avatar" /><a href="/user/(?P<quser>\w+)" class="loggedin-name">[^<]+</a> <span class="muted small">(?P<quserscore>\d+)</span>[^f]+float-right" title="(?P<qdatetime>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})[^q]+question-markdown">(?P<question>(?:<p>(?:[^<]|<code>[^<]+</code>)*</p>|<pre class=[\x27"]brush: lua[\x27"]>[^<]*</pre>)*)[^I]+Id = \x27q(?P<qid>\d+)(?:.*?h3 class="wide-line-title">(?P<answercount>\d+) answers?</h3>\r?\n\s*<div class="question" id="(?P<aid>\d+)">[^b]+ber">(?P<ascore>\d+)[^A]+Accepted answer[^A]Answered by</span>\r?\n\s*<div class="question-poster-username">\r?\n\s*<img src="/resources/avatar/(?P<auserid>\d+)" alt(?:="[^"]*")? class="loggedin-avatar" /><a href="/user/(?P<auser>\w+)" class="loggedin-name">\w+</a> <span class="muted small">(?P<auserscore>\d+)[^f]float right" title="(?P<adatetime>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})[^q]question-markdown">(?P<answer>(?:<p>(?:[^<]|<code>[^<]+</code>)*</p>|<pre class=[\x27"]brush: lua[\x27"]>[^<]*</pre>)*))?
9
+ ```
10
+
11
+ Unusable. Use [./qa_regex4.txt/](qa_regex4.txt)
12
+
13
+ ### Command
14
+
15
+ Requires [ripgrep](https://github.com/burntsushi/ripgrep).
16
+
17
+ ```
18
+ rg -U -uuu -o --multiline-dotall -N --color never -I -f qa_regex4.txt questions \
19
+ -r '{"qscore": "$1", "title": "$2", "quserid": "$3", "quser": "$4", "quserscore": "$5", "qdatetime": "$6", "question": <<<$7<<<, "qid": "$8", "answercount": "$9", "aid": "$10", "ascore": "$11", "auserid": "$12", "auser": "$13", "auserscore": "$14", "adatetime": "$15", "answer": >>>$16>>>}' \
20
+ ```
21
+
22
+ Must replace `<<<` blocks with long, programmatically escaped content strings. Some post content includes single backslashes. All post content has many newlines.
23
+
24
+ ### Entry Specification
25
+
26
+ There is one entry for every asked question, so there may be no accepted answer associated with it. In that case, all of the answer's properties (from and including `"answercount"`) will be empty strings.
qa_regex4.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ points-number">(?P<qscore>\d+)[^h]+h1 class="question-title">\r?\n\s*(?P<title>[^<]+)(?:\s*<span class="muted">\[closed\]</span>)?</h1>\s*<div class="question-poster sans-serif">\r?\n\s*<span class="muted">Asked by</span>\r?\n\s*<div class="question-poster-username">\r?\n\s*<img src="/resources/avatar/(?P<quserid>\d+)" alt(?:="[^"]*")? class="loggedin-avatar" /><a href="/user/(?P<quser>\w+)" class="loggedin-name">[^<]+</a> <span class="muted small">(?P<quserscore>\d+)</span>[^f]+float-right" title="(?P<qdatetime>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})[^q]+question-markdown">(?:<div id="markdown-[a-z0-9]+">)?(?P<question>(?:(?:<(?:p|h[1-6]|blockquote)>(?:[^<]|<(?:code|strong|em|blockquote|p|a(?: target="[^"]*")? href="[^"]+"(?: rev="footnote")?(?: class="[^"]+")?)>(?:[^<]|<(?:code|strong|em|a(?: target="[^.]+") href="[^"]+")>[^<]+</(?:code|strong|em|a)>)*</(?:code|strong|em|blockquote|p|a)>|<sup id="fnref:\d+"><a href="#fn:\d+" class="footnote-ref">\d+</a></sup>|<br />)*</(?:p|h[1-6]|blockquote)>|<(?:ul|ol)>(?:\s|<li>.*?</li>)+</(?:ul|ol)>|<div class="footnotes">\n<hr />\n<ol>\n\n(?:<li id="fn:\d+">.*?</li>\n\n)*</ol>\n</div>|<pre class=[\x27"]brush: lua[\x27"]>(?:<br />)?[^<]*</pre>|<hr ?/>)(?:\r?\n)+)*).*?Id = [\x27]q(?P<qid>\d+)(?:.*?h3 class="wide-line-title">(?P<answercount>\d+) answers?</h3>\r?\n\s*<div class="question" id="(?P<aid>\d+)">[^b]+ber">(?P<ascore>\d+)[^A]+Accepted answer[^A]+Answered by</span>\r?\n\s*<div class="question-poster-username">\r?\n\s*<img src="/resources/avatar/(?P<auserid>\d+)" alt(?:="[^"]*")? class="loggedin-avatar" /><a href="/user/(?P<auser>\w+)" class="loggedin-name">\w+</a> <span class="muted small">(?P<auserscore>\d+)[^f]+float-right" title="(?P<adatetime>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})[^q]+question-markdown">(?:<div id="markdown-[a-z0-9]+">)?(?P<answer>(?:(?:<(?:p|h[1-6]|blockquote)>(?:[^<]|<(?:code|strong|em|blockquote|p|a(?: target="[^"]*")? href="[^"]+"(?: rev="footnote")?(?: class="[^"]+")?)>(?:[^<]|<(?:code|strong|em|a(?: target="[^.]+") href="[^"]+")>[^<]+</(?:code|strong|em|a)>)*</(?:code|strong|em|blockquote|p|a)>|<sup id="fnref:\d+"><a href="#fn:\d+" class="footnote-ref">\d+</a></sup>|<br />)*</(?:p|h[1-6]|blockquote)>|<(?:ul|ol)>(?:\s|<li>.*?</li>)+</(?:ul|ol)>|<div class="footnotes">\n<hr />\n<ol>\n\n(?:<li id="fn:\d+">.*?</li>\n\n)*</ol>\n</div>|<pre class=[\x27"]brush: lua[\x27"]>(?:<br />)?[^<]*</pre>|<hr ?/>)(?:\r?\n)+)*))?
questions.tar.xz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2a5a79ac3cada431dc6aed57550c8905ef12de36b80f50df6aeb5eb0e889fa43
3
+ size 4715488
questions_raw.snappy.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:52d0ef1044e938d9a37fee956cec4d303fb195c09616d8e29fcc57b89f3c1438
3
+ size 22622502
questions_tar_extract.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tarfile
2
+ from pathlib import Path
3
+
4
+ script_dir = Path(__file__).resolve().parent
5
+ scraped_files_root = "questions"
6
+
7
+ def extract_articles() -> Path:
8
+ articles = script_dir / scraped_files_root
9
+ if not articles.is_dir():
10
+ articles_archive = script_dir / f"{scraped_files_root}.tar.xz"
11
+ if not articles_archive.is_file():
12
+ raise RuntimeError(f"{scraped_files_root} directory / {scraped_files_root}.tar.xz archive not present in cwd")
13
+ with tarfile.open(articles_archive, "r:*") as tar:
14
+ tar.extractall()
15
+ articles = script_dir / scraped_files_root
16
+ if not articles.is_dir():
17
+ raise RuntimeError(f"tarfile extraction failed to produce {scraped_files_root} directory")
18
+ return articles
scrape_log.jsonl ADDED
The diff for this file is too large to render. See raw diff