m
This commit is contained in:
parent
01454162bb
commit
4240ad38e2
2 changed files with 39 additions and 7 deletions
|
|
@ -106,15 +106,13 @@ def parse_cluster_id_from_href(href: str | None) -> str | None:
|
||||||
if citation_for_view:
|
if citation_for_view:
|
||||||
token = citation_for_view[0].strip()
|
token = citation_for_view[0].strip()
|
||||||
if token:
|
if token:
|
||||||
if ":" in token:
|
return f"cfv:{token}"
|
||||||
return token.rsplit(":", 1)[-1] or None
|
|
||||||
return token
|
|
||||||
|
|
||||||
cluster = query.get("cluster")
|
cluster = query.get("cluster")
|
||||||
if cluster:
|
if cluster:
|
||||||
token = cluster[0].strip()
|
token = cluster[0].strip()
|
||||||
if token:
|
if token:
|
||||||
return token
|
return f"cluster:{token}"
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -133,10 +131,10 @@ def parse_citation_count(parts: list[str]) -> int | None:
|
||||||
text = normalize_space(" ".join(parts))
|
text = normalize_space(" ".join(parts))
|
||||||
if not text:
|
if not text:
|
||||||
return 0
|
return 0
|
||||||
match = re.search(r"\d+", text)
|
digits = re.sub(r"\D+", "", text)
|
||||||
if not match:
|
if not digits:
|
||||||
return None
|
return None
|
||||||
return int(match.group(0))
|
return int(digits)
|
||||||
|
|
||||||
|
|
||||||
def _parse_publication_row(row_html: str) -> tuple[PublicationCandidate | None, list[str]]:
|
def _parse_publication_row(row_html: str) -> tuple[PublicationCandidate | None, list[str]]:
|
||||||
|
|
|
||||||
|
|
@ -97,10 +97,44 @@ def test_parse_profile_page_handles_missing_optional_metadata() -> None:
|
||||||
assert parsed.state_reason == "publications_extracted"
|
assert parsed.state_reason == "publications_extracted"
|
||||||
assert len(parsed.publications) == 1
|
assert len(parsed.publications) == 1
|
||||||
publication = parsed.publications[0]
|
publication = parsed.publications[0]
|
||||||
|
assert publication.cluster_id == "cfv:abc:def123"
|
||||||
assert publication.year is None
|
assert publication.year is None
|
||||||
assert publication.venue_text is None
|
assert publication.venue_text is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_profile_page_parses_comma_formatted_citation_counts() -> None:
|
||||||
|
html = """
|
||||||
|
<html>
|
||||||
|
<div id="gsc_prf_in">Citation Formatting Test</div>
|
||||||
|
<span id="gsc_a_nn">Articles 1-1</span>
|
||||||
|
<table>
|
||||||
|
<tbody id="gsc_a_b">
|
||||||
|
<tr class="gsc_a_tr">
|
||||||
|
<td class="gsc_a_t">
|
||||||
|
<a class="gsc_a_at" href="/citations?view_op=view_citation&citation_for_view=abc:def123">Paper</a>
|
||||||
|
</td>
|
||||||
|
<td class="gsc_a_c"><a class="gsc_a_ac">Cited by 1,234</a></td>
|
||||||
|
<td class="gsc_a_y"><span class="gsc_a_h">2024</span></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
fetch_result = FetchResult(
|
||||||
|
requested_url="https://scholar.google.com/citations?hl=en&user=abcDEF123456",
|
||||||
|
status_code=200,
|
||||||
|
final_url="https://scholar.google.com/citations?hl=en&user=abcDEF123456",
|
||||||
|
body=html,
|
||||||
|
error=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
parsed = parse_profile_page(fetch_result)
|
||||||
|
|
||||||
|
assert parsed.state == ParseState.OK
|
||||||
|
assert len(parsed.publications) == 1
|
||||||
|
assert parsed.publications[0].citation_count == 1234
|
||||||
|
|
||||||
|
|
||||||
def test_parse_profile_page_ignores_direct_pdf_link_markup() -> None:
|
def test_parse_profile_page_ignores_direct_pdf_link_markup() -> None:
|
||||||
html = """
|
html = """
|
||||||
<html>
|
<html>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue