Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion backend/cli/src/science/connectors/literature/europepmc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ interface Result {
authorString?: string
abstractText?: string
pubYear?: string
// `resultType=core` records (this connector hardcodes core) nest the journal
// name under journalInfo.journal.title. Older/lite shapes put it top-level as
// journalTitle — keep both so either shape resolves.
journalTitle?: string
journalInfo?: { journal?: { title?: string } }
citedByCount?: number
}

/** The publication venue, from whichever shape the record uses. */
export function journalName(r: Result): string | undefined {
return r.journalInfo?.journal?.title ?? r.journalTitle
}

interface SearchResponse {
hitCount?: number
resultList?: { result?: Result[] }
Expand All @@ -38,7 +47,7 @@ function url(r: Result): string | undefined {
}

function toHit(r: Result): ConnectorHit {
const meta = [r.authorString, r.journalTitle, r.pubYear].filter(Boolean).join(". ")
const meta = [r.authorString, journalName(r), r.pubYear].filter(Boolean).join(". ")
return {
id: r.source && r.id ? `${r.source}/${r.id}` : (r.id ?? ""),
title: snippet(r.title, 300) ?? r.id ?? "Untitled",
Expand Down
22 changes: 22 additions & 0 deletions backend/cli/test/science/europepmc.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect, test } from "bun:test"
import { journalName } from "../../src/science/connectors/literature/europepmc"

describe("europepmc journalName", () => {
test("reads the nested journalInfo.journal.title from a resultType=core record", () => {
expect(journalName({ journalInfo: { journal: { title: "Nature" } } })).toBe("Nature")
})

test("falls back to the top-level journalTitle for lite-shaped records", () => {
expect(journalName({ journalTitle: "Cell" })).toBe("Cell")
})

test("prefers the nested title when both are present", () => {
expect(journalName({ journalTitle: "Old", journalInfo: { journal: { title: "New" } } })).toBe("New")
})

test("returns undefined when no journal is present", () => {
expect(journalName({})).toBeUndefined()
expect(journalName({ journalInfo: {} })).toBeUndefined()
expect(journalName({ journalInfo: { journal: {} } })).toBeUndefined()
})
})
Loading