adambuttrick commited on
Commit
03d5390
·
verified ·
1 Parent(s): 82876b2

Upload folder using huggingface_hub

Browse files
README.md CHANGED
@@ -46,14 +46,21 @@ Each record contains:
46
  |-------|------|-------------|
47
  | `arxiv_doi` | string | The DOI for the arXiv work (format: `10.48550/arXiv.{id}`) |
48
  | `arxiv_id` | string | The arXiv identifier (e.g., `1412.6980`) |
49
- | `citation_count` | integer | Number of citing works |
50
- | `cited_by` | array | List of citation objects |
 
51
 
52
- Each citation object in `cited_by` contains:
53
 
54
  | Field | Type | Description |
55
  |-------|------|-------------|
56
  | `doi` | string | DOI of the citing work |
 
 
 
 
 
 
57
  | `raw_match` | string | The original text that matched the arXiv reference |
58
  | `reference` | string | The full reference object from the citing work's metadata (JSON-encoded) |
59
 
@@ -63,12 +70,17 @@ Each citation object in `cited_by` contains:
63
  {
64
  "arxiv_doi": "10.48550/arXiv.1412.6980",
65
  "arxiv_id": "1412.6980",
 
66
  "citation_count": 40040,
67
  "cited_by": [
68
  {
69
  "doi": "10.1016/j.jhydrol.2025.134709",
70
- "raw_match": "arXiv.1412.6980",
71
- "reference": "{\"key\": \"10.1016/j.jhydrol.2025.134709_b0175\", \"unstructured\": \"Kingma, D.P., & Ba, J. (2014), Adam: A Method for Stochastic Optimization...\"}"
 
 
 
 
72
  }
73
  ]
74
  }
@@ -77,7 +89,7 @@ Each citation object in `cited_by` contains:
77
  To parse the reference field in Python:
78
  ```python
79
  import json
80
- reference = json.loads(record['cited_by'][0]['reference'])
81
  ```
82
 
83
  ## Extraction Process
 
46
  |-------|------|-------------|
47
  | `arxiv_doi` | string | The DOI for the arXiv work (format: `10.48550/arXiv.{id}`) |
48
  | `arxiv_id` | string | The arXiv identifier (e.g., `1412.6980`) |
49
+ | `reference_count` | integer | Total number of reference instances |
50
+ | `citation_count` | integer | Number of unique citing works |
51
+ | `cited_by` | array | List of citing work objects |
52
 
53
+ Each citing work object in `cited_by` contains:
54
 
55
  | Field | Type | Description |
56
  |-------|------|-------------|
57
  | `doi` | string | DOI of the citing work |
58
+ | `matches` | array | List of reference matches from this citing work |
59
+
60
+ Each match object in `matches` contains:
61
+
62
+ | Field | Type | Description |
63
+ |-------|------|-------------|
64
  | `raw_match` | string | The original text that matched the arXiv reference |
65
  | `reference` | string | The full reference object from the citing work's metadata (JSON-encoded) |
66
 
 
70
  {
71
  "arxiv_doi": "10.48550/arXiv.1412.6980",
72
  "arxiv_id": "1412.6980",
73
+ "reference_count": 40040,
74
  "citation_count": 40040,
75
  "cited_by": [
76
  {
77
  "doi": "10.1016/j.jhydrol.2025.134709",
78
+ "matches": [
79
+ {
80
+ "raw_match": "arXiv.1412.6980",
81
+ "reference": "{\"key\": \"10.1016/j.jhydrol.2025.134709_b0175\", \"unstructured\": \"Kingma, D.P., & Ba, J. (2014), Adam: A Method for Stochastic Optimization...\"}"
82
+ }
83
+ ]
84
  }
85
  ]
86
  }
 
89
  To parse the reference field in Python:
90
  ```python
91
  import json
92
+ reference = json.loads(record['cited_by'][0]['matches'][0]['reference'])
93
  ```
94
 
95
  ## Extraction Process
data/arxiv_citations_valid.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:9a585b3818eef324918e238004fbd4b9efc7d5ff3f4e7e9d8d4809e89fd4a2fb
3
- size 464962508
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e8b0fb3b96b64ed854d860ccfda676426c8a52c32c361c2f938b810e362479d8
3
+ size 458932570
transform_schema.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Transform existing arxiv_citations parquet to new grouped schema.
4
+
5
+ Old schema:
6
+ cited_by: [{doi, raw_match, reference}, ...]
7
+
8
+ New schema:
9
+ reference_count: total reference instances
10
+ citation_count: unique citing works
11
+ cited_by: [{doi, matches: [{raw_match, reference}, ...]}, ...]
12
+ """
13
+
14
+ import json
15
+ from collections import defaultdict
16
+ from pathlib import Path
17
+
18
+ import pyarrow as pa
19
+ import pyarrow.parquet as pq
20
+
21
+
22
+ def transform_record(record: dict) -> dict:
23
+ """Transform a single record to the new grouped schema."""
24
+ # Group citations by citing DOI
25
+ citing_works = defaultdict(list)
26
+
27
+ for citation in record.get('cited_by', []):
28
+ doi = citation.get('doi', '')
29
+ match_entry = {
30
+ 'raw_match': citation.get('raw_match', ''),
31
+ 'reference': citation.get('reference', ''), # Already JSON string
32
+ }
33
+ citing_works[doi].append(match_entry)
34
+
35
+ # Convert to new format
36
+ cited_by = [
37
+ {'doi': doi, 'matches': matches}
38
+ for doi, matches in citing_works.items()
39
+ ]
40
+
41
+ return {
42
+ 'arxiv_doi': record.get('arxiv_doi', ''),
43
+ 'arxiv_id': record.get('arxiv_id', ''),
44
+ 'reference_count': sum(len(cw['matches']) for cw in cited_by),
45
+ 'citation_count': len(cited_by),
46
+ 'cited_by': cited_by,
47
+ }
48
+
49
+
50
+ def main():
51
+ input_path = Path('data/arxiv_citations_valid.parquet')
52
+ output_path = Path('data/arxiv_citations_valid_v2.parquet')
53
+
54
+ print(f"Reading {input_path}...")
55
+ table = pq.read_table(input_path)
56
+ records = table.to_pylist()
57
+ print(f"Loaded {len(records)} records")
58
+
59
+ print("Transforming to new schema...")
60
+ transformed = []
61
+ total_refs = 0
62
+ total_citations = 0
63
+
64
+ for i, record in enumerate(records):
65
+ new_record = transform_record(record)
66
+ transformed.append(new_record)
67
+ total_refs += new_record['reference_count']
68
+ total_citations += new_record['citation_count']
69
+
70
+ if (i + 1) % 100000 == 0:
71
+ print(f" Processed {i + 1} records...")
72
+
73
+ print(f"Transformation complete:")
74
+ print(f" Total arXiv works: {len(transformed)}")
75
+ print(f" Total references: {total_refs}")
76
+ print(f" Unique citing works: {total_citations}")
77
+
78
+ # Define new schema
79
+ schema = pa.schema([
80
+ ('arxiv_doi', pa.string()),
81
+ ('arxiv_id', pa.string()),
82
+ ('reference_count', pa.int64()),
83
+ ('citation_count', pa.int64()),
84
+ ('cited_by', pa.list_(pa.struct([
85
+ ('doi', pa.string()),
86
+ ('matches', pa.list_(pa.struct([
87
+ ('raw_match', pa.string()),
88
+ ('reference', pa.string()),
89
+ ]))),
90
+ ]))),
91
+ ])
92
+
93
+ print(f"Writing {output_path}...")
94
+
95
+ # Convert to Arrow format
96
+ arxiv_dois = [r['arxiv_doi'] for r in transformed]
97
+ arxiv_ids = [r['arxiv_id'] for r in transformed]
98
+ reference_counts = [r['reference_count'] for r in transformed]
99
+ citation_counts = [r['citation_count'] for r in transformed]
100
+ cited_by_lists = [r['cited_by'] for r in transformed]
101
+
102
+ table = pa.table({
103
+ 'arxiv_doi': arxiv_dois,
104
+ 'arxiv_id': arxiv_ids,
105
+ 'reference_count': reference_counts,
106
+ 'citation_count': citation_counts,
107
+ 'cited_by': cited_by_lists,
108
+ }, schema=schema)
109
+
110
+ pq.write_table(table, output_path, compression='snappy')
111
+
112
+ output_size = output_path.stat().st_size / (1024 * 1024)
113
+ print(f"Done! Output size: {output_size:.1f} MB")
114
+
115
+ # Verify by reading back
116
+ print("\nVerifying output...")
117
+ verify_table = pq.read_table(output_path)
118
+ print(f" Rows: {verify_table.num_rows}")
119
+ print(f" Schema: {verify_table.schema}")
120
+
121
+ # Show sample record
122
+ sample = verify_table.to_pylist()[0]
123
+ print(f"\nSample record:")
124
+ print(f" arxiv_doi: {sample['arxiv_doi']}")
125
+ print(f" arxiv_id: {sample['arxiv_id']}")
126
+ print(f" reference_count: {sample['reference_count']}")
127
+ print(f" citation_count: {sample['citation_count']}")
128
+ print(f" First citing work: {sample['cited_by'][0]['doi']}")
129
+ print(f" Matches in first citing work: {len(sample['cited_by'][0]['matches'])}")
130
+
131
+
132
+ if __name__ == '__main__':
133
+ main()