Spaces:
Sleeping
Sleeping
Commit ·
6125895
1
Parent(s): c479870
Update entities
Browse filesFiles changed (2)
- IBO_to_XML.py+52-52
- app.py+2-2
74 unmodified lines7576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413574 unmodified linesreturn xml_output.strip()def sortTags(entities):temp_counter = 0# For each entity, this loop will sort each tag of entitiy, first it will check if the# previous tags has same count of this tag, second will sort the tags and check if this tags is correctfor temp_entities in entities:for entity in temp_entities[1]:tags = entity.split()for tag in tags:# if the counter is not 0 then, will completeif temp_counter != 0:# Check if this tag is equal I-, if yes then it will count how many tag in this tags and# count how many tag in previous tagsif "I-" == tag[0:2]:counter_of_this_tag = 0counter_of_previous_tag = 0for word in tags:if tag.split("-")[1] in word:counter_of_this_tag+=1for word in entity[temp_counter-1][1].split():if tag.split("-")[1] in word:counter_of_previous_tag+=1# if the counter of previous tag is bigger than counter of this tag, then we# need to add I-tag in this tagsif counter_of_previous_tag > counter_of_this_tag:tags.append("I-"+tag.split("-")[1])# Sort the tagstags.sort()# Need to revers the tags because it should begins with Itags.reverse()# If the counter is not 0 then we can completeif temp_counter != 0:this_tags = tagsprevious_tags = entity[temp_counter - 1][1].split()sorted_tags = list()# Check if the this tag is not O and previous tags is not O, then will complete,# if not then it will ignor this tagif "O" not in this_tags and "O" not in previous_tags:index = 0#For each previous tags, need sort this tag by previous tags if its I, B we can ignorfor i in previous_tags:j = 0while this_tags and j < len(this_tags):if this_tags[j][0:2] == "I-" and this_tags[j][2:] == i[2:]:sorted_tags.insert(index, this_tags.pop(j))breakelif this_tags[j][0:2] == "B-":breakj += 1index += 1sorted_tags += this_tagstags = sorted_tagsstr_tag = " "str_tag = str_tag.join(tags)str_tag = str_tag.strip()temp_entities[temp_counter][1] = str_tagtemp_counter += 1return temp_entities74 unmodified lines7576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413574 unmodified linesreturn xml_output.strip()def sortTags(entities):temp_entities = entitiestemp_counter = 0# For each entity, this loop will sort each tag of entitiy, first it will check if the# previous tags has same count of this tag, second will sort the tags and check if this tags is correctfor entity in temp_entities:tags = entity[1].split()for tag in tags:# if the counter is not 0 then, will completeif temp_counter != 0:# Check if this tag is equal I-, if yes then it will count how many tag in this tags and# count how many tag in previous tagsif "I-" == tag[0:2]:counter_of_this_tag = 0counter_of_previous_tag = 0for word in tags:if tag.split("-")[1] in word:counter_of_this_tag+=1for word in temp_entities[temp_counter-1][1].split():if tag.split("-")[1] in word:counter_of_previous_tag+=1# if the counter of previous tag is bigger than counter of this tag, then we# need to add I-tag in this tagsif counter_of_previous_tag > counter_of_this_tag:tags.append("I-"+tag.split("-")[1])# Sort the tagstags.sort()# Need to revers the tags because it should begins with Itags.reverse()# If the counter is not 0 then we can completeif temp_counter != 0:this_tags = tagsprevious_tags = temp_entities[temp_counter - 1][1].split()sorted_tags = list()# Check if the this tag is not O and previous tags is not O, then will complete,# if not then it will ignor this tagif "O" not in this_tags and "O" not in previous_tags:index = 0#For each previous tags, need sort this tag by previous tags if its I, B we can ignorfor i in previous_tags:j = 0while this_tags and j < len(this_tags):if this_tags[j][0:2] == "I-" and this_tags[j][2:] == i[2:]:sorted_tags.insert(index, this_tags.pop(j))breakelif this_tags[j][0:2] == "B-":breakj += 1index += 1sorted_tags += this_tagstags = sorted_tagsstr_tag = " "str_tag = str_tag.join(tags)str_tag = str_tag.strip()temp_entities[temp_counter][1] = str_tagtemp_counter += 1return temp_entities
147 unmodified lines148149150151152153154155156147 unmodified lineslist_of_tags = [i for i in list_of_tags if i not in ("O", " ", "")]if not list_of_tags:item["tags"] = ["O"]else:item["tags"] = list_of_tagslists.append(item)return lists147 unmodified lines148149150151152153154155156147 unmodified lineslist_of_tags = [i for i in list_of_tags if i not in ("O", " ", "")]if not list_of_tags:item["tags"] = "O"else:item["tags"] = " ".join(list_of_tags)lists.append(item)return lists
IBO_to_XML.py+52-52
app.py+2-2