54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
from citegeist import BibliographyStore, parse_bibtex
|
|
|
|
|
|
SAMPLE_BIB = """
|
|
@article{smith2024graphs,
|
|
author = {Smith, Jane and Doe, Alex},
|
|
title = {Graph-first bibliography augmentation},
|
|
year = {2024},
|
|
doi = {10.1000/graph.2024.1},
|
|
abstract = {We study citation graphs for literature discovery.},
|
|
references = {miller2023search}
|
|
}
|
|
|
|
@inproceedings{miller2023search,
|
|
author = {Miller, Sam},
|
|
title = {Semantic search for research corpora},
|
|
year = {2023},
|
|
abstract = {Dense retrieval improves recall for academic search.}
|
|
}
|
|
"""
|
|
|
|
|
|
def test_parse_bibtex_extracts_entries_and_fields():
|
|
entries = parse_bibtex(SAMPLE_BIB)
|
|
|
|
assert [entry.citation_key for entry in entries] == ["smith2024graphs", "miller2023search"]
|
|
assert entries[0].fields["title"] == "Graph-first bibliography augmentation"
|
|
assert entries[0].fields["references"] == "miller2023search"
|
|
|
|
|
|
def test_store_ingests_entries_relations_and_search_text():
|
|
store = BibliographyStore()
|
|
try:
|
|
store.ingest_bibtex(
|
|
SAMPLE_BIB,
|
|
fulltext_by_key={
|
|
"smith2024graphs": "This paper links citation graphs with semantic search over abstracts."
|
|
},
|
|
)
|
|
|
|
entry = store.get_entry("smith2024graphs")
|
|
assert entry is not None
|
|
assert entry["doi"] == "10.1000/graph.2024.1"
|
|
|
|
assert store.get_relations("smith2024graphs") == ["miller2023search"]
|
|
|
|
results = store.search_text("semantic")
|
|
assert [row["citation_key"] for row in results][:2] == [
|
|
"miller2023search",
|
|
"smith2024graphs",
|
|
]
|
|
finally:
|
|
store.close()
|