Commit 94e1ce5f by hxw

update

parent 390bc184
...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment