Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mateusz Pawlik
ted-datasets
Commits
183b6142
Commit
183b6142
authored
Oct 23, 2018
by
Mateusz Pawlik
Browse files
Working on Python.
parent
f5ccdceb
Changes
3
Hide whitespace changes
Inline
Side-by-side
python/README.md
View file @
183b6142
...
...
@@ -24,13 +24,17 @@ https://www.sri.inf.ethz.ch/py150
-
**sort**
-
**cut**
## RAM requirements
The current way of processing DBLP dataset requires
**??GB**
of RAM memory.
## Steps
Execute t
o download all necessary files, convert them into bracket notation and sort them
.
Execute t
he following to download and prepare the dataset
.
```
bash
./download_prepare.sh
```
## Estimated time
To be measured.
\ No newline at end of file
On an Intel Xeon 2.40GHz CPU, it takes around
**??min**
.
\ No newline at end of file
python/download_prepare.sh
View file @
183b6142
#!/bin/bash
# file: download_prepare.sh
#
# Program: Downloads and prepares data containing abstract syntax trees
# from python programs. (https://www.sri.inf.ethz.ch/py150)
#
# Author: Thomas Huetter
# download abstract syntax trees
# The MIT License (MIT)
# Copyright (c) 2017 Thomas Hütter, Mateusz Pawlik.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Download the raw dataset.
wget http://files.srl.inf.ethz.ch/data/py150.tar.gz
#
e
xtract
abstract syntax trees
#
E
xtract
the dataset.
tar
-xzf
py150.tar.gz
#
c
onvert ast to bracket notation
python3 parse_json.py
--inputfile
python100k_train.json
>
python
_ast
.bracket
#
C
onvert
the training dat
as
e
t to bracket notation
.
python3 parse_json.py
--inputfile
python100k_train.json
>
python.bracket
#
c
onvert ast to bracket notation
python3 parse_json.py
--inputfile
python50k_eval.json
>>
python
_ast
.bracket
#
C
onvert
the evaluation dat
as
e
t to bracket notation
and append to training.
python3 parse_json.py
--inputfile
python50k_eval.json
>>
python.bracket
#
s
ort the trees
ascending by their
size
./sort_dataset.sh python
_ast
.bracket
#
S
ort the trees
by
size
.
./
../utilities/
sort_dataset.sh python
.bracket
>
python_sorted
.bracket
python/parse_json.py
View file @
183b6142
#!/usr/bin/env python
'''
File name: parse_json.py
Author: Thomas Huetter
Program: Reads Python and Javascript Abstract Syntax Trees
and converts them into bracket notation.
(https://www.sri.inf.ethz.ch/py150)
'''
#!/usr/bin/env python3
# The MIT License (MIT)
# Copyright (c) 2017 Thomas Hütter.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import
argparse
import
json
# recursively traverses the tree and converts it step by step
# into bracket notation
# Reads Python and Javascript Abstract Syntax Trees and converts them into
# bracket notation.
# Recursively traverse the tree and convert it into bracket notation.
def
print_tree
(
json_tree
,
index
):
print
(
'{'
+
json_tree
[
index
][
'type'
],
end
=
''
)
if
'value'
in
json_tree
[
index
]:
...
...
@@ -25,7 +42,7 @@ def print_tree(json_tree, index):
print_tree
(
json_tree
,
child
)
print
(
'}'
,
end
=
''
)
#
p
arse input argurments
#
P
arse input argurments
.
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"--inputfile"
,
type
=
str
,
help
=
"path to input files containing line seperated JSON ASTs"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment