Combined NER processor that merges quantity and material annotations. Runs both :class:`GrobidQuantitiesProcessor` and :class:`GrobidMaterialsProcessor`, then prunes overlapping spans so that the output is clean and non-overlapping. Args: grobid_quantities_client: Optional
| 721 | |
| 722 | |
| 723 | class GrobidAggregationProcessor(GrobidQuantitiesProcessor, GrobidMaterialsProcessor): |
| 724 | """Combined NER processor that merges quantity and material annotations. |
| 725 | |
| 726 | Runs both :class:`GrobidQuantitiesProcessor` and |
| 727 | :class:`GrobidMaterialsProcessor`, then prunes overlapping spans so |
| 728 | that the output is clean and non-overlapping. |
| 729 | |
| 730 | Args: |
| 731 | grobid_quantities_client: Optional quantities API client. |
| 732 | grobid_superconductors_client: Optional materials NER client. |
| 733 | |
| 734 | Either or both clients may be ``None``; only the provided services |
| 735 | will be called. |
| 736 | """ |
| 737 | |
| 738 | def __init__(self, grobid_quantities_client=None, grobid_superconductors_client=None): |
| 739 | if grobid_quantities_client: |
| 740 | self.gqp = GrobidQuantitiesProcessor(grobid_quantities_client) |
| 741 | if grobid_superconductors_client: |
| 742 | self.gmp = GrobidMaterialsProcessor(grobid_superconductors_client) |
| 743 | |
| 744 | def process_single_text(self, text): |
| 745 | """Run both NER services on *text* and return merged, deduplicated spans. |
| 746 | |
| 747 | Args: |
| 748 | text: Plain text to process. |
| 749 | |
| 750 | Returns: |
| 751 | list[dict]: Non-overlapping span dicts sorted by offset. |
| 752 | """ |
| 753 | extracted_quantities_spans = self.process_properties(text) |
| 754 | extracted_materials_spans = self.process_materials(text) |
| 755 | all_entities = extracted_quantities_spans + extracted_materials_spans |
| 756 | entities = self.prune_overlapping_annotations(all_entities) |
| 757 | return entities |
| 758 | |
| 759 | def process_properties(self, text): |
| 760 | if self.gqp: |
| 761 | return self.gqp.process(text) |
| 762 | else: |
| 763 | return [] |
| 764 | |
| 765 | def process_materials(self, text): |
| 766 | if self.gmp: |
| 767 | return self.gmp.process(text) |
| 768 | else: |
| 769 | return [] |
| 770 | |
| 771 | @staticmethod |
| 772 | def box_to_dict(box, color=None, type=None, border=None): |
| 773 | """Convert a GROBID coordinate list into an annotation dict. |
| 774 | |
| 775 | Args: |
| 776 | box: List or tuple of ``[page, x, y, width, height]``. |
| 777 | color: Optional hex colour string for the annotation. |
| 778 | type: Optional annotation type label. |
| 779 | border: Optional border style (e.g. ``"dotted"``). |
| 780 |