fix: display all academic degrees
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.7.8
|
||||||
|
|
||||||
|
- В колонке учёной степени отображаются все найденные степени без лишнего текста.
|
||||||
|
|
||||||
## 0.7.7
|
## 0.7.7
|
||||||
|
|
||||||
- Удалена неиспользуемая интеграция обмена данными и связанная документация и тесты.
|
- Удалена неиспользуемая интеграция обмена данными и связанная документация и тесты.
|
||||||
|
|||||||
@@ -2,13 +2,16 @@ import re
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
_PATTERN = re.compile(r"\b(?:кандидат|доктор)\s+[\w\s-]{0,80}?\s+наук\b|\bph\.?\s*d\.?\b", re.IGNORECASE)
|
_PATTERN = re.compile(r"\b(?:кандидат|доктор)(?:\s+[\w-]+){0,12}\s+наук\b|\bph\.?\s*d\.?(?!\w)", re.IGNORECASE)
|
||||||
|
|
||||||
|
|
||||||
def academic_degrees(data: dict[str, Any] | None) -> list[str]:
|
def academic_degrees(data: dict[str, Any] | None) -> list[str]:
|
||||||
degrees = []
|
degrees = []
|
||||||
|
seen = set()
|
||||||
for section in (data or {}).get("sections") or []:
|
for section in (data or {}).get("sections") or []:
|
||||||
if not isinstance(section, dict) or not re.search(r"уч[её]н.*степен|academic degree", str(section.get("title") or ""), re.IGNORECASE):
|
if not isinstance(section, dict) or not re.search(
|
||||||
|
r"образован|степен|academic degree|education", str(section.get("title") or ""), re.IGNORECASE
|
||||||
|
):
|
||||||
continue
|
continue
|
||||||
values = [
|
values = [
|
||||||
*(entry.get("text") for entry in section.get("year_entries") or [] if isinstance(entry, dict)),
|
*(entry.get("text") for entry in section.get("year_entries") or [] if isinstance(entry, dict)),
|
||||||
@@ -16,8 +19,15 @@ def academic_degrees(data: dict[str, Any] | None) -> list[str]:
|
|||||||
*(section.get("items") or []),
|
*(section.get("items") or []),
|
||||||
section.get("raw_text"),
|
section.get("raw_text"),
|
||||||
]
|
]
|
||||||
|
table = section.get("table") or {}
|
||||||
|
for row in table.get("rows") or []:
|
||||||
|
if isinstance(row, dict):
|
||||||
|
values.extend(row.get("cells") or [])
|
||||||
for value in values:
|
for value in values:
|
||||||
text = str(value or "").strip()
|
text = str(value or "").strip()
|
||||||
if text and _PATTERN.search(text) and text not in degrees:
|
for match in _PATTERN.finditer(text):
|
||||||
degrees.append(text)
|
degree = match.group(0).strip()
|
||||||
|
if degree.casefold() not in seen:
|
||||||
|
seen.add(degree.casefold())
|
||||||
|
degrees.append(degree)
|
||||||
return degrees
|
return degrees
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
APP_VERSION = "0.7.7"
|
APP_VERSION = "0.7.8"
|
||||||
FRONTEND_VERSION = "0.7.7"
|
FRONTEND_VERSION = "0.7.8"
|
||||||
BACKEND_VERSION = "0.7.7"
|
BACKEND_VERSION = "0.7.8"
|
||||||
|
|||||||
26
tests/test_academic_degrees.py
Normal file
26
tests/test_academic_degrees.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
from app.services.academic_degrees import academic_degrees
|
||||||
|
|
||||||
|
|
||||||
|
def test_academic_degrees_extracts_all_degree_names_without_surrounding_text():
|
||||||
|
data = {
|
||||||
|
"sections": [
|
||||||
|
{
|
||||||
|
"title": "Образование",
|
||||||
|
"year_entries": [
|
||||||
|
{"text": "2008 — кандидат технических наук, доцент"},
|
||||||
|
{"text": "2018 — Доктор физико-математических наук"},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Учёные степени",
|
||||||
|
"table": {"rows": [{"cells": ["Ph.D.", "Доктор физико-математических наук"]}]},
|
||||||
|
},
|
||||||
|
{"title": "Публикации", "items": ["Доктор медицинских наук выступил автором статьи"]},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
assert academic_degrees(data) == [
|
||||||
|
"кандидат технических наук",
|
||||||
|
"Доктор физико-математических наук",
|
||||||
|
"Ph.D.",
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user