Datasets:

License:
SaifHassanOnim commited on
Commit
73deef2
·
verified ·
1 Parent(s): a9ec1a1

fixed no content error

Browse files
Files changed (2) hide show
  1. monim.json.gz +2 -2
  2. monim.py +81 -0
monim.json.gz CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:9cfe90e5844bd072bb5a651feb3d7843da050dec92be3d8590b7532615d939e4
3
- size 1111142
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:09be11eea1f7b434670e036f97dbbf0ebd5b073a9c9bae6ec8027db59d7e9d83
3
+ size 1437166
monim.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Fri Nov 1 23:06:17 2024
4
+
5
+ @author: monim
6
+ """
7
+
8
+
9
+ import json, re
10
+ import requests
11
+ from urlextract import URLExtract
12
+ import sys, gzip
13
+ from tqdm import tqdm
14
+
15
+ utid = 'monim'
16
+ base= { 'model':'https://huggingface.co/', 'data': 'https://huggingface.co/datasets/', 'source': 'https://' }
17
+ post = '/raw/main/README.md'
18
+ postGH = 'blob/master/README.md'
19
+ postGH_1 = 'blob/main/README.md' #handling the case for main/master
20
+
21
+ extU = URLExtract()
22
+ DOIpattern = r'\b(10\.\d{4,9}\/[-._;()/:A-Z0-9]+)\b/i'
23
+ bibPattern = r'@(\w+)\{[^}]+\}' #bonus problem
24
+
25
+ def extractURLs (c):
26
+ res = extU.find_urls (c)
27
+ return res
28
+
29
+ def extractDOIs (c):
30
+ res = re.findall (DOIpattern, c)
31
+ return res
32
+
33
+ def extractBibs (c):
34
+ res = re.findall (bibPattern, c)
35
+ return res
36
+
37
+ fo = gzip.open(f"output/{utid}.json.gz", 'w+')
38
+
39
+ def run (tp):
40
+ post0 = post
41
+ with open(f"input/{utid}_{tp}", 'r') as f:
42
+ for line in tqdm(f):
43
+ line = line.strip ()
44
+ if tp == 'source':
45
+ (npapers,line) = line.split(';');
46
+ post0 = postGH
47
+ print(line)
48
+ url = base[tp] + f"{line}{post0}"
49
+ try:
50
+ r = requests.get (url)
51
+ except:
52
+ continue
53
+ if r.status_code != 200:
54
+ if tp != 'source':
55
+ continue
56
+ else:
57
+ url_1 = url.replace(postGH, postGH_1)
58
+ r = requests.get(url_1)
59
+ if r.status_code != 200:
60
+ continue
61
+ else:
62
+ url = url_1
63
+
64
+ content = r.text
65
+ #github returns repos that do not exist, need to detect that here
66
+ #github when you give master instead of main, that might cause issues as well
67
+ #fixed both
68
+ urls = extractURLs(content)
69
+ dois = extractDOIs(content)
70
+ bibs = extractBibs(content)
71
+ res = { 'ID': line, 'type': tp, 'url': url, 'content': content, 'links': urls, 'dois': dois, 'bibs': bibs }
72
+ out = json.dumps(res, ensure_ascii=False)
73
+ fo.write((out+"\n").encode())
74
+
75
+ run('model')
76
+
77
+ run('data')
78
+
79
+ run('source')
80
+
81
+ fo.close()