Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include co-authors in search query #49

Merged
merged 2 commits into from
Dec 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions adstex.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
r"\\(?:bibentry|[cC]ite[a-zA]{0,7})\*?(?:(?!\n{2,})\s)*(?:(?<!\\)[\[<](?:(?!\n{2,}).)*?(?<!\\)[\]>](?:(?!\n{2,})\s)*)*{((?:(?!\n{2,})[^{}])+)}",
re.S,
)
_re_fayear = re.compile(r"([A-Za-z-]+)(?:(?=[\W_])[^\s\d,]+)?((?:\d{2})?\d{2})")
_re_fayear = re.compile(r"([A-Za-z-:]+)(?:(?=[\W_])[^\s\d,]+)?((?:\d{2})?\d{2})")
_re_id = {}
_re_id["doi"] = re.compile(r"\b10\.\d{4,}(?:\.\d+)*\/(?:(?!['\"&<>])\S)+\b")
_re_id["bibcode"] = re.compile(r"\b\d{4}\D\S{13}[A-Z.:]\b")
Expand Down Expand Up @@ -101,6 +101,13 @@ def _y2toy4(y2):
k = int(y2 > _this_year)
return str((_this_cent - k) * 100 + y2)

def _fa_split(fa):
fa = fa.strip(':')
fa = fa.split(':')
if len(fa) == 1:
return fa[0], []
return fa[0], fa[1:]


def _is_like_string(s):
try:
Expand Down Expand Up @@ -175,8 +182,9 @@ def id2bibcode(id_this, possible_id_types=("bibcode", "doi", "arxiv")):
pass


def authoryear2bibcode(author, year, key):
q = 'first_author:"{}" year:{} database:{}'.format(author, year, _database)
def authoryear2bibcode(author, year, key, coauthors=[]):
coauthors = ' '.join([f'author:"{_a}"' for _a in coauthors])
q = 'first_author:"{}" {} year:{} database:{}'.format(author, coauthors, year, _database)
entries = list(
fixedAdsSearchQuery(
q=q,
Expand Down Expand Up @@ -232,9 +240,10 @@ def find_bibcode_interactive(key):
m = _re_fayear.match(key)
if m:
fa, y = m.groups()
fa, ca = _fa_split(fa)
if len(y) == 2:
y = _y2toy4(y)
bibcode = authoryear2bibcode(fa, y, key)
bibcode = authoryear2bibcode(fa, y, key, coauthors=ca)
if bibcode:
return bibcode

Expand Down
Loading