Runs the 4-stage pipeline: Parse -> Identify -> Enrich -> Format.
| 122 | |
| 123 | |
| 124 | class PipelineController: |
| 125 | """Runs the 4-stage pipeline: Parse -> Identify -> Enrich -> Format.""" |
| 126 | |
| 127 | def __init__(self, use_google_scholar: bool = False): |
| 128 | """Initialize the pipeline controller. |
| 129 | |
| 130 | Args: |
| 131 | use_google_scholar: If ``True``, enable Google Scholar as an |
| 132 | additional data source for identification and enrichment. |
| 133 | Requires the optional ``scholarly`` package. Defaults to |
| 134 | ``False``. |
| 135 | """ |
| 136 | self.logger = logging.getLogger(__name__) |
| 137 | from .pipeline import ParserModule, IdentifierModule, EnricherModule, FormatterModule |
| 138 | |
| 139 | self.template_loader = TemplateLoader() |
| 140 | self.parser = ParserModule() |
| 141 | self.identifier = IdentifierModule(use_google_scholar=use_google_scholar) |
| 142 | self.enricher = EnricherModule(use_google_scholar=use_google_scholar) |
| 143 | self.formatter = FormatterModule() |
| 144 | |
| 145 | def process(self, input_content: str, input_type: str, template_name: str, |
| 146 | output_format: str, interactive_callback: Callable[[List[Dict]], int]) -> Dict[str, Any]: |
| 147 | """Run all four pipeline stages and return results with a report. |
| 148 | |
| 149 | Args: |
| 150 | input_content: The raw text or BibTeX content to process. |
| 151 | input_type: Format of *input_content* — ``"txt"`` for |
| 152 | plain-text references or ``"bib"`` for BibTeX. |
| 153 | template_name: Name of the YAML template that controls |
| 154 | which fields are collected (e.g. |
| 155 | ``"journal_article_full"``). |
| 156 | output_format: Output format. Only ``"bibtex"`` is |
| 157 | supported; any other value raises ``FormatError``. |
| 158 | interactive_callback: A callable that receives a list of |
| 159 | candidate dictionaries and returns the index of the |
| 160 | selected candidate. |
| 161 | |
| 162 | Returns: |
| 163 | A dictionary with two keys: |
| 164 | |
| 165 | * ``results`` — a list of formatted citation strings. |
| 166 | * ``report`` — a dict containing ``total``, ``succeeded``, |
| 167 | and ``failed_entries``. |
| 168 | """ |
| 169 | self.logger.info("Starting OneCite processing pipeline") |
| 170 | |
| 171 | try: |
| 172 | template = self.template_loader.load_template(template_name) |
| 173 | raw_entries = self.parser.parse(input_content, input_type) |
| 174 | identified_entries = self.identifier.identify(raw_entries, interactive_callback) |
| 175 | completed_entries = self.enricher.enrich(identified_entries, template, raw_entries) |
| 176 | result = self.formatter.format(completed_entries, output_format) |
| 177 | |
| 178 | self.logger.info("OneCite processing pipeline completed") |
| 179 | return result |
| 180 | |
| 181 | except Exception as e: |
no outgoing calls
no test coverage detected