Skip to content

Commit

Permalink
Merge pull request #155 from andras-simonyi/Fix_term_lookup
Browse files Browse the repository at this point in the history
Fix term lookup
  • Loading branch information
andras-simonyi authored Mar 6, 2024
2 parents c61c98b + 1ff4457 commit 9ef8ccc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
36 changes: 15 additions & 21 deletions citeproc-context.el
Original file line number Diff line number Diff line change
Expand Up @@ -168,34 +168,28 @@ TYPED RTS is a list of (RICH-TEXT . TYPE) pairs"
"Return the first text associated with TERM in CONTEXT."
(citeproc-term-text-from-terms term (citeproc-context-terms context)))

(defun citeproc-term-inflected-text (term form number context)
"Return the text associated with TERM having FORM and NUMBER."
(let ((matches
(--select (string= term (citeproc-term-name it))
(citeproc-context-terms context))))
(cond ((not matches) nil)
((= (length matches) 1)
(citeproc-term-text (car matches)))
(t (citeproc-term--inflected-text-1 matches form number)))))

(defconst citeproc--term-form-fallback-alist
'((verb-short . verb)
(symbol . short)
(verb . long)
(short . long))
"Alist containing the fallback form for each term form.")

(defun citeproc-term--inflected-text-1 (matches form number)
(let ((match (--first (and (eq form (citeproc-term-form it))
(or (not (citeproc-term-number it))
(eq number (citeproc-term-number it))))
matches)))
(if match
(citeproc-term-text match)
(citeproc-term--inflected-text-1
matches
(alist-get form citeproc--term-form-fallback-alist)
number))))
(defun citeproc-term-inflected-text (term form number context)
"Return the text associated with TERM having FORM and NUMBER."
(let ((matches
(--select (string= term (citeproc-term-name it))
(citeproc-context-terms context))))
(if (not matches) nil
(let (match)
(while (and (not match) form)
(setq match (--first (and (eq form (citeproc-term-form it))
(or (not (citeproc-term-number it))
(eq number (citeproc-term-number it))))
matches))
(unless match
(setq form (alist-get form citeproc--term-form-fallback-alist))))
(when match (citeproc-term-text match))))))

(defun citeproc-term-get-gender (term context)
"Return the gender of TERM or nil if none is given."
Expand Down
4 changes: 4 additions & 0 deletions test/expected_fails.lst
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,7 @@ citeproc-suite-textcase-stop-word-before-hyphen
citeproc-suite-variables-container-title-short
citeproc-suite-variables-container-title-short2
citeproc-suite-variables-title-short-on-short-title-no-title-condition
citeproc-suite-fullstyles-chicago-article-title-question
citeproc-suite-label-missing-returns-empty
citeproc-suite-sort-chicago-year-suffix1
citeproc-suite-sort-chicago-year-suffix2
2 changes: 1 addition & 1 deletion test/human/citation_BibEntry.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ citation
<macro name="contributors">
<names variable="author">
<name and="text" delimiter=", " delimiter-precedes-last="always" name-as-sort-order="first" sort-separator=", " />
<label form="verb-short" prefix=", " suffix="." text-case="lowercase" />
<label form="short" prefix=", " suffix="." text-case="lowercase" />
<substitute>
<text macro="editor" />
<text macro="translator" />
Expand Down

0 comments on commit 9ef8ccc

Please sign in to comment.