emanuelaboros commited on
Commit
f9d6dfb
·
1 Parent(s): 4b21d68
Files changed (1) hide show
  1. generic_ner.py +8 -15
generic_ner.py CHANGED
@@ -274,15 +274,7 @@ class MultitaskTokenClassificationPipeline(Pipeline):
274
  """Check if entity1 is fully within the bounds of entity2."""
275
  return entity1["start"] >= entity2["start"] and entity1["end"] <= entity2["end"]
276
 
277
- def postprocess_entities(self, all_entities, text_sentence):
278
- # Collect all entities in one list for processing
279
-
280
- # for entity in ner_results[key]:
281
- # print(
282
- # text_sentence[entity["start"] : entity["end"]],
283
- # "--",
284
- # entity["word"],
285
- # )
286
 
287
  # Sort entities by start position, then by end position (to handle nested structures)
288
  all_entities.sort(key=lambda x: (x["start"], -x["end"]))
@@ -363,12 +355,13 @@ class MultitaskTokenClassificationPipeline(Pipeline):
363
  if key not in ["NE-COARSE-LIT"]:
364
  all_entities.extend(entities[key])
365
 
366
- postprocessed_entities = self.postprocess_entities(all_entities, text_sentence)
367
- print("After 1:")
368
- pprint(postprocessed_entities)
 
369
  # Attach "comp.function" entities to the closest non-"comp.function" entity
370
- postprocessed_entities = attach_comp_to_closest(postprocessed_entities)
371
  print("After 2:")
372
- pprint(postprocessed_entities)
373
  print("\n")
374
- return postprocessed_entities
 
274
  """Check if entity1 is fully within the bounds of entity2."""
275
  return entity1["start"] >= entity2["start"] and entity1["end"] <= entity2["end"]
276
 
277
+ def postprocess_entities(self, all_entities):
 
 
 
 
 
 
 
 
278
 
279
  # Sort entities by start position, then by end position (to handle nested structures)
280
  all_entities.sort(key=lambda x: (x["start"], -x["end"]))
 
355
  if key not in ["NE-COARSE-LIT"]:
356
  all_entities.extend(entities[key])
357
 
358
+ print("Skipping 1")
359
+ # all_entities = self.postprocess_entities(all_entities, text_sentence)
360
+ # print("After 1:")
361
+ # pprint(all_entities)
362
  # Attach "comp.function" entities to the closest non-"comp.function" entity
363
+ all_entities = attach_comp_to_closest(all_entities)
364
  print("After 2:")
365
+ pprint(all_entities)
366
  print("\n")
367
+ return all_entities