Skip to content

Commit 584e835

Browse files
committed
Add proper parsing of nmr methods
1 parent 6d7aba4 commit 584e835

File tree

7 files changed

+35
-395
lines changed

7 files changed

+35
-395
lines changed

package-lock.json

Lines changed: 4 additions & 363 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"@radix-ui/react-slot": "^1.1.0",
4141
"@storybook/addon-docs": "^8.5.0",
4242
"@types/luxon": "^3.4.2",
43-
"@types/sparql-http-client": "^3.0.5",
4443
"@xyflow/react": "^12.3.6",
4544
"class-variance-authority": "^0.7.1",
4645
"clsx": "^2.1.1",
@@ -52,7 +51,6 @@
5251
"prettier": "^3.4.2",
5352
"react": "^18.3.1",
5453
"react-dom": "^18.3.1",
55-
"sparql-http-client": "^3.0.1",
5654
"swr": "^2.3.0",
5755
"tailwind-merge": "^2.5.5",
5856
"tailwindcss-animate": "^1.0.7",

src/components/result/PidDisplay.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { PidResolver, pidResolver } from "@/lib/pidResolver"
22
import { memo, useCallback } from "react"
33
import useSWR from "swr"
4+
import { ontobeeResolver } from "@/lib/OntobeeResolver"
45

56
/**
67
* Resolves a PID and displays the name of the received record
@@ -9,11 +10,13 @@ import useSWR from "swr"
910
*/
1011
export const PidDisplay = memo(function PidDisplay({ pid }: { pid: string }) {
1112
const resolveContent = useCallback(async (pid: string) => {
12-
if (!PidResolver.isPID(pid)) {
13-
return pid
14-
} else {
13+
if (PidResolver.isPID(pid)) {
1514
const content = await pidResolver.resolve(pid)
1615
return content.name
16+
} else if (pid.startsWith("http://purl.obolibrary.org")) {
17+
return ontobeeResolver.parse(pid)
18+
} else {
19+
return pid
1720
}
1821
}, [])
1922

src/components/search/DefaultFacetOption.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import { Label } from "@/components/ui/label"
33
import { PidDisplay } from "@/components/result/PidDisplay"
44
import { FacetValue } from "@elastic/search-ui"
55
import { FairDOFacetConfig } from "@/config/FairDOConfig"
6-
import { useEffect, useMemo } from "react"
6+
import { useMemo } from "react"
77
import { tryURLPrettyPrint } from "@/lib/utils"
8-
import { ontobeeResolver } from "@/lib/OntobeeResolver"
98

109
export function DefaultFacetOption({
1110
option,
@@ -28,16 +27,10 @@ export function DefaultFacetOption({
2827
} else return value
2928
}, [facetConfig.prettyPrintURLs, value])
3029

31-
useEffect(() => {
32-
if (value.startsWith("http://purl.obolibrary.org")) {
33-
ontobeeResolver.parse(value)
34-
}
35-
}, [value])
36-
3730
return (
3831
<div key={value} className="flex max-w-full items-center gap-2 break-words p-1 pb-2">
3932
<Checkbox id={value} checked={option.selected} onCheckedChange={(v) => (v ? onSelect(value) : onRemove(value))} />
40-
<Label htmlFor={value} className="min-w-0 grow break-words [&:not(:hover)]:truncate">
33+
<Label htmlFor={value} className="min-w-0 grow break-words">
4134
{value ? (
4235
facetConfig.usePidResolver ? (
4336
<PidDisplay pid={value} />

src/config/FairDOConfigBuilder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ export class FairDOConfigBuilder {
102102
return {
103103
index_names,
104104
search_fields: allSearchFields,
105-
result_fields: allResultFields
105+
result_fields: allResultFields,
106+
disjunctiveFacets: this.getConfig().disjunctiveFacets
106107
}
107108
}
108109

src/lib/OntobeeResolver.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
import { ParsingClient } from "sparql-http-client"
1+
import { z } from "zod"
22

3-
export class OntobeeResolver {
4-
private client: ParsingClient
5-
6-
constructor() {
7-
this.client = new ParsingClient({ endpointUrl: "https://sparql.hegroup.org/sparql" })
8-
}
3+
const TS4TIBResponse = z.object({
4+
response: z.object({
5+
docs: z.object({ label: z.string(), iri: z.string() }).array()
6+
})
7+
})
98

9+
export class OntobeeResolver {
1010
async parse(url: string) {
1111
try {
12-
const result = await this.client.query.select(`
13-
DEFINE sql:describe-mode "CBD"
14-
DESCRIBE <${url}>
15-
FROM <http://purl.obolibrary.org/obo/merged/CHMO>
16-
`)
17-
18-
console.log(result)
12+
const result = await fetch(`https://service.tib.eu/ts4tib/api/select?q=${url}`)
13+
const data = await result.json()
14+
const parsed = TS4TIBResponse.parse(data)
15+
const entry = parsed.response.docs.find((entry) => entry.iri === url)
16+
if (entry) return entry.label
17+
else {
18+
console.log("Found no matching entry", parsed.response.docs)
19+
return url
20+
}
1921
} catch (e) {
2022
console.error(e)
23+
return url
2124
}
2225
}
2326
}

src/stories/FairDOElasticSearch.stories.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const demoConfig: FairDOConfig = {
4444
{
4545
key: "NMR_Method.keyword",
4646
label: "NMR Method",
47-
prettyPrintURLs: true
47+
usePidResolver: true
4848
}
4949
],
5050
resultFields: [], // Leave empty to get all fields
@@ -85,13 +85,14 @@ const demoConfig2: FairDOConfig = {
8585
{
8686
key: "NMR_Method.keyword",
8787
label: "NMR Method",
88-
prettyPrintURLs: true
88+
usePidResolver: true
8989
}
9090
],
9191
resultFields: [], // Leave empty to get all fields
9292
searchFields: ["name", "pid", "hasMetadata", "isMetadataFor", "NMR_Method"]
9393
}
94-
]
94+
],
95+
disjunctiveFacets: ["NMR_Method.keyword"]
9596
}
9697

9798
export const DemoElastic: Story = {

0 commit comments

Comments
 (0)