Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
ner
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
ner
Commits
94e1ce5f
Commit
94e1ce5f
authored
Apr 20, 2018
by
hxw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
390bc184
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
14 deletions
+14
-14
get_ner.py
get_ner.py
+14
-14
No files found.
get_ner.py
View file @
94e1ce5f
...
@@ -8,17 +8,17 @@ Trie = pickle.load(open('Trie.data','rb'))
...
@@ -8,17 +8,17 @@ Trie = pickle.load(open('Trie.data','rb'))
@click.command
()
@click.command
()
@click.option
(
'--file_name'
,
default
=
'baike_sents_full.jsonl'
)
@click.option
(
'--file_name'
,
default
=
'baike_sents_full.jsonl'
)
def
get_ner
(
file_name
):
@click.option
(
"--outputfile"
,
default
=
'test.jsonl'
)
def
get_ner
(
file_name
,
outputfile
):
wf
=
open
(
"test.jsonl"
,
'w'
)
wf
=
open
(
outputfile
,
'w'
)
with
open
(
file_name
,
'r'
)
as
data
:
with
open
(
file_name
,
'r'
)
as
data
:
for
line
in
data
:
for
line
in
data
:
content
=
json
.
loads
(
line
)
content
=
json
.
loads
(
line
)
sentence
=
''
.
join
(
content
[
"sentence"
]
.
strip
()
.
split
())
sentence
=
''
.
join
(
content
[
"sentence"
]
.
strip
()
.
split
())
sentId
=
content
[
"sentId"
]
sentId
=
content
[
"sentId"
]
sent_len
=
len
(
sentence
)
sent_len
=
len
(
sentence
)
ner_list
=
[]
used_idx
=
set
()
used_idx
=
set
()
used_list
=
[]
used_list
=
[]
wordtype
=
{}
wordtype
=
{}
...
@@ -26,27 +26,27 @@ def get_ner(file_name):
...
@@ -26,27 +26,27 @@ def get_ner(file_name):
for
Type
in
[
"PER"
,
"LOC"
,
"ORG"
]:
for
Type
in
[
"PER"
,
"LOC"
,
"ORG"
]:
idx
=
0
;
rev_idx
=
sent_len
-
1
idx
=
0
;
rev_idx
=
sent_len
-
1
i_
w
_list
=
[]
i_
e
_list
=
[]
while
(
idx
<
sent_len
):
while
(
idx
<
sent_len
):
[
idx
,
word_used_idx
]
=
get_entity
(
sentence
,
idx
,
sent_len
,
Type
)
[
idx
,
entity_span
]
=
get_entity
(
sentence
,
idx
,
sent_len
,
Type
)
i_
w_list
.
append
([
idx
,
word_used_idx
])
i_
e_list
.
append
([
idx
,
entity_span
])
while
(
rev_idx
>=
0
):
while
(
rev_idx
>=
0
):
[
rev_idx
,
word_used_idx
]
=
rev_get_entity
(
sentence
,
rev_idx
,
sent_len
,
Type
)
[
rev_idx
,
entity_span
]
=
rev_get_entity
(
sentence
,
rev_idx
,
sent_len
,
Type
)
i_
w_list
.
append
([
idx
,
word_used_idx
])
i_
e_list
.
append
([
idx
,
entity_span
])
for
idx
,
word_used_idx
in
i_w
_list
:
for
idx
,
entity_span
in
i_e
_list
:
flag
=
1
flag
=
1
if
(
len
(
word_used_idx
)
>
1
):
if
(
len
(
entity_span
)
>
1
):
for
s
in
used_list
:
for
s
in
used_list
:
jiaoji
=
word_used_idx
.
intersection
(
s
)
jiaoji
=
entity_span
.
intersection
(
s
)
if
(
jiaoji
!=
set
()):
if
(
jiaoji
!=
set
()):
if
(
len
(
word_used_idx
)
<
len
(
s
)
or
jiaoji
==
s
):
if
(
len
(
entity_span
)
<
len
(
s
)
or
jiaoji
==
s
):
flag
=
0
flag
=
0
else
:
else
:
used_list
.
remove
(
s
)
used_list
.
remove
(
s
)
if
(
flag
):
if
(
flag
):
used_list
.
append
(
word_used_idx
)
used_list
.
append
(
entity_span
)
wordtype
[
tuple
(
word_used_idx
)]
=
Type
wordtype
[
tuple
(
entity_span
)]
=
Type
...
...
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