Skip to content

Commit

Permalink
More robust citation lookups (#210)
Browse files Browse the repository at this point in the history
* Added ; to allowed delimiters for citations
* Add check now that it is a citation, since things like (in year 2020) were triggering
  • Loading branch information
whitead authored Nov 20, 2023
1 parent def3640 commit 30e9989
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 7 additions & 1 deletion paperqa/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,19 @@ def markdown(self) -> Tuple[str, str]:
index = 1
for citation in iter_citations(self.answer):
compound = ""
for c in citation.split(","):
for c in citation.split(",;"):
c = c.strip("() ")
if c == "Extra background information":
continue
if c in refs:
compound += f"[^{refs[c]}]"
continue
# check if it is a citation
try:
self.get_citation(c)
except ValueError:
# not a citation
continue
refs[c] = index
compound += f"[^{index}]"
index += 1
Expand Down
2 changes: 1 addition & 1 deletion paperqa/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.13.0"
__version__ = "3.13.1"
7 changes: 4 additions & 3 deletions tests/test_paperqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ def test_iter_citations():
"time. For instance, the effectiveness of COVID-19 vaccines against severe "
"COVID-19 declined to 64% after 121 days, compared to around 90% initially "
"(Chemaitelly2022WaningEO, Foo2019Bar). Despite this, vaccines still provide "
"significant protection against severe outcomes."
"significant protection against severe outcomes (Bar2000Foo pg 1-3; Far2000 pg 2-5)."
)
ref = [
"(Dorabawila2022EffectivenessOT)",
"(Bernal2021EffectivenessOC pg. 1-3)",
"(Thompson2021EffectivenessOC pg. 3-5, Goo2031Foo pg. 3-4)",
"(Marfé2021EffectivenessOC)",
"(Chemaitelly2022WaningEO, Foo2019Bar)",
"(Bar2000Foo pg 1-3; Far2000 pg 2-5)",
]
assert list(iter_citations(text)) == ref

Expand Down Expand Up @@ -130,13 +131,13 @@ def test_markdown():
answer = Answer(
question="What was Fredic's greatest accomplishment?",
answer="Frederick Bates's greatest accomplishment was his role in resolving land disputes "
"and his service as governor of Missouri (Wiki2023 chunk 1).",
"and his service as governor of Missouri (Wiki2023 chunk 1). It is said (in 2010) that foo.",
contexts=[
Context(
context="",
text=Text(
text="Frederick Bates's greatest accomplishment was his role in resolving land disputes "
"and his service as governor of Missouri (Wiki2023 chunk 1).",
"and his service as governor of Missouri.",
name="Wiki2023 chunk 1",
doc=Doc(
name="Wiki2023",
Expand Down

0 comments on commit 30e9989

Please sign in to comment.