Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
Rnet_WebService
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hxw
Rnet_WebService
Commits
2f0f71cf
Commit
2f0f71cf
authored
Apr 13, 2018
by
hxw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改答案为空
parent
a2e08666
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
0 deletions
+88
-0
ChangeNoAnswer.py
ChangeNoAnswer.py
+88
-0
No files found.
ChangeNoAnswer.py
0 → 100755
View file @
2f0f71cf
# coding:utf-8
import
json
from
collections
import
OrderedDict
from
tqdm
import
tqdm
def
JsonConvert
(
InputFile
,
OutputFile
):
root
=
{}
data
=
[]
id_count
=
0
with
open
(
InputFile
,
'r'
)
as
fh
:
source
=
json
.
load
(
fh
)
for
article
in
tqdm
(
source
[
"data"
]):
for
para
in
article
[
"paragraphs"
]:
context
=
'# '
+
para
[
"context"
]
.
replace
(
# 替代''为“
"''"
,
'" '
)
.
replace
(
"``"
,
'" '
)
for
qa
in
para
[
"qas"
]:
qas
=
list
(
dict
()
for
i
in
range
(
1
))
paragraphs
=
list
(
dict
()
for
i
in
range
(
1
))
article
=
OrderedDict
()
question
=
qa
[
"question"
]
.
replace
(
# 替代''为“
"''"
,
'" '
)
.
replace
(
"``"
,
'" '
)
answers
=
qa
[
"answers"
]
if
(
'train'
in
OutputFile
):
answers
=
answers4train
(
context
,
answers
)
else
:
answers
=
answers4test
(
context
,
answers
)
qas
[
0
][
"answers"
]
=
answers
qas
[
0
][
"question"
]
=
question
qas
[
0
][
"id"
]
=
qa
[
'id'
]
paragraphs
[
0
][
"context"
]
=
context
paragraphs
[
0
][
"qas"
]
=
qas
article
[
"title"
]
=
" "
article
[
"paragraphs"
]
=
paragraphs
data
.
append
(
article
)
root
[
"data"
]
=
data
json
.
dump
(
root
,
open
(
OutputFile
,
'w'
))
def
answers4train
(
context
,
answers
):
answer
=
OrderedDict
()
if
(
answers
==
[]):
answer
[
"text"
]
=
"#"
answer
[
"answer_start"
]
=
context
.
find
(
'#'
)
answers
.
append
(
answer
)
else
:
answers
[
0
][
"answer_start"
]
+=
len
(
'# '
)
return
answers
def
answers4test
(
context
,
answers
):
if
(
answers
==
[]):
answers
=
list
(
OrderedDict
()
for
i
in
range
(
3
))
answers
[
0
][
"text"
]
=
answers
[
1
][
"text"
]
=
answers
[
2
][
"text"
]
=
'#'
answers
[
0
][
"answer_start"
]
=
answers
[
1
][
"answer_start"
]
=
answers
[
2
][
"answer_start"
]
=
0
else
:
for
i
in
range
(
len
(
answers
)):
answers
[
i
][
"answer_start"
]
+=
len
(
'# '
)
return
answers
JsonConvert
(
'd0/train-v1.1.json'
,
'd0/a-train-v1.1.json'
)
JsonConvert
(
'd0/dev-v1.1.json'
,
'd0/a-dev-v1.1.json'
)
JsonConvert
(
'd1/train-v1.1.json'
,
'd1/a-train-v1.1.json'
)
JsonConvert
(
'd1/dev-v1.1.json'
,
'd1/a-dev-v1.1.json'
)
JsonConvert
(
'd2/train-v1.1.json'
,
'd2/a-train-v1.1.json'
)
JsonConvert
(
'd2/dev-v1.1.json'
,
'd2/a-dev-v1.1.json'
)
JsonConvert
(
'd3/train-v1.1.json'
,
'd3/a-train-v1.1.json'
)
JsonConvert
(
'd3/dev-v1.1.json'
,
'd3/a-dev-v1.1.json'
)
Write
Preview
Markdown
is supported
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