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
3d3e41b8
Commit
3d3e41b8
authored
Oct 30, 2018
by
Thomas Huetter
Browse files
db service option for statistic script
parent
cbba5a23
Changes
1
Hide whitespace changes
Inline
Side-by-side
statistics/statistics.py
View file @
3d3e41b8
...
@@ -19,9 +19,9 @@ import psycopg2
...
@@ -19,9 +19,9 @@ import psycopg2
from
psycopg2
import
sql
from
psycopg2
import
sql
# http://initd.org/psycopg/docs/sql.html#module-psycopg2.sql
# http://initd.org/psycopg/docs/sql.html#module-psycopg2.sql
def
store_result
(
table_name
,
values_dict
):
def
store_result
(
service
,
table_name
,
values_dict
):
# Connect to database.
# Connect to database.
db
=
psycopg2
.
connect
(
"service=
ted-join"
)
db
=
psycopg2
.
connect
(
"service=
"
+
service
)
# Open a cursor to perform database operations
# Open a cursor to perform database operations
cur
=
db
.
cursor
()
cur
=
db
.
cursor
()
attributes
=
values_dict
.
keys
()
attributes
=
values_dict
.
keys
()
...
@@ -41,14 +41,14 @@ def store_result(table_name, values_dict):
...
@@ -41,14 +41,14 @@ def store_result(table_name, values_dict):
# parse input argurments
# parse input argurments
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"--inputfile"
,
type
=
str
,
parser
.
add_argument
(
"--inputfile"
,
type
=
str
,
required
=
True
,
help
=
"path to input files containing line seperated trees in bracket notation"
)
help
=
"path to input files containing line seperated trees in bracket notation"
)
parser
.
add_argument
(
"--shortdesc"
,
type
=
str
,
default
=
"no description"
,
parser
.
add_argument
(
"--shortdesc"
,
type
=
str
,
default
=
"no description"
,
help
=
"short description about the dataset"
)
help
=
"short description about the dataset"
)
parser
.
add_argument
(
"--printlabels"
,
action
=
'store_true'
,
dest
=
'printlabels'
,
parser
.
add_argument
(
"--printlabels"
,
action
=
'store_true'
,
dest
=
'printlabels'
,
help
=
"print label distribution"
)
help
=
"print label distribution"
)
parser
.
add_argument
(
"
--s
toreindb"
,
action
=
'store_true'
,
dest
=
'storeindb'
,
parser
.
add_argument
(
'
--s
ervice'
,
type
=
str
,
help
=
"
store the information about the dataset
in a database"
)
help
=
"
Service name for db connection. Specify this parameter to store the results
in a database
.
"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
...
@@ -99,8 +99,8 @@ dataset_info += "}"
...
@@ -99,8 +99,8 @@ dataset_info += "}"
print
(
dataset_info
)
print
(
dataset_info
)
# store dataset in db
# store dataset in db
if
args
.
s
toreindb
:
if
args
.
s
ervice
:
store_result
(
db_table_name
,
json
.
loads
(
dataset_info
))
store_result
(
args
.
service
,
db_table_name
,
json
.
loads
(
dataset_info
))
# print label distribution
# print label distribution
if
args
.
printlabels
:
if
args
.
printlabels
:
...
...
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