result.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from pathlib import Path
  15. from ...common.result import BaseCVResult, MarkdownMixin
  16. class MarkdownResult(BaseCVResult, MarkdownMixin):
  17. def __init__(self, data) -> None:
  18. """Initializes a new instance of the class with the specified data."""
  19. super().__init__(data)
  20. MarkdownMixin.__init__(self)
  21. def _get_input_fn(self):
  22. fn = super()._get_input_fn()
  23. if (page_idx := self.get("page_index", None)) is not None:
  24. fp = Path(fn)
  25. stem, suffix = fp.stem, fp.suffix
  26. fn = f"{stem}_{page_idx}{suffix}"
  27. if (language := self.get("language", None)) is not None:
  28. fp = Path(fn)
  29. stem, suffix = fp.stem, fp.suffix
  30. fn = f"{stem}_{language}{suffix}"
  31. return fn
  32. def _to_markdown(self, pretty=True, show_formula_number=False) -> dict:
  33. return self