From a6742b92b331240a68576dff5e0eb557007a9ead Mon Sep 17 00:00:00 2001 From: Daven Quinn Date: Sat, 21 Sep 2024 17:13:43 -0500 Subject: [PATCH 01/10] Remove unused function --- pages/dev/legend-affinity/+Page.client.ts | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/pages/dev/legend-affinity/+Page.client.ts b/pages/dev/legend-affinity/+Page.client.ts index 16dd4b8b..d69f1c9a 100644 --- a/pages/dev/legend-affinity/+Page.client.ts +++ b/pages/dev/legend-affinity/+Page.client.ts @@ -1,10 +1,6 @@ import h from "./main.module.sass"; import { mapboxAccessToken, tileserverDomain } from "@macrostrat-web/settings"; -import { - buildQueryString, - useDarkMode, - useStoredState, -} from "@macrostrat/ui-components"; +import { useDarkMode } from "@macrostrat/ui-components"; import { Select, SelectProps } from "@blueprintjs/select"; import mapboxgl from "mapbox-gl"; import { useCallback, useState, useEffect, useMemo } from "react"; @@ -158,14 +154,6 @@ export function Page() { ); } -function isValidMapPosition(data: any): boolean { - if (data == null) return false; - if (typeof data !== "object") return false; - if (data?.camera?.lng == null) return false; - if (data?.camera?.lat == null) return false; - return true; -} - interface StyleParams { inDarkMode: boolean; term: string | null; @@ -360,6 +348,7 @@ function useMapPosition(startPos) { setMapPosition_(position); let params = getQueryString(window.location.search) ?? {}; applyMapPositionToHash(params, position); + console.log(params); setQueryString(params); }, []); From 46d44795dcfa27239d7633d3887b90a6af3de89e Mon Sep 17 00:00:00 2001 From: Daven Quinn Date: Sat, 21 Sep 2024 17:47:48 -0500 Subject: [PATCH 02/10] Improved rendering of citations --- pages/integrations/xdd/extractions/+Page.ts | 44 +++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/pages/integrations/xdd/extractions/+Page.ts b/pages/integrations/xdd/extractions/+Page.ts index 1cafd56c..2fe03f9e 100644 --- a/pages/integrations/xdd/extractions/+Page.ts +++ b/pages/integrations/xdd/extractions/+Page.ts @@ -6,7 +6,11 @@ import { ContentPage } from "~/layouts"; import { PageHeaderV2 } from "~/components"; import { postgrestPrefix } from "@macrostrat-web/settings"; import { useEffect, useState } from "react"; -import { InfiniteScroll, LoadingPlaceholder } from "@macrostrat/ui-components"; +import { + AuthorList, + InfiniteScroll, + LoadingPlaceholder, +} from "@macrostrat/ui-components"; import { create } from "zustand"; const postgrest = new PostgrestClient(postgrestPrefix); @@ -114,6 +118,40 @@ function pruneEmptyCitationElements(citation): any { function xDDCitation({ citation, href }) { const newCitation = pruneEmptyCitationElements(citation); - const { title } = newCitation; - return h("div", [h("h2.title", h("a", { href }, title))]); + const { title, author, journal, identifier } = newCitation; + console.log(newCitation); + const names = author?.map((d) => d.name); + console.log(names); + return h("div", [ + h("h2.title", h("a", { href }, title)), + h("h3.journal", null, journal), + h(AuthorList, { names }), + h(IdentLink, { identifier: getBestIdentifier(identifier) }), + ]); +} + +function IdentLink({ identifier }) { + const { type, id } = identifier; + + let ident = h("code.identifier", id); + if (type == "doi") { + ident = h("a", { href: "https://dx.doi.org/doi/" + id }, ident); + } + + return h("p", [h("span.label", type), " ", ident]); +} + +type Identifier = { + id: string; + type: string; +}; + +function getBestIdentifier(identifier: Identifier[] | null): Identifier | null { + if (identifier == null || identifier.length == 0) return null; + for (const ident of identifier) { + if (ident.type == "doi") { + return ident; + } + } + return identifier[0]; } From eed44f324f278925095e6548dfbd26e06977d59e Mon Sep 17 00:00:00 2001 From: Daven Quinn Date: Sat, 21 Sep 2024 18:00:23 -0500 Subject: [PATCH 03/10] Fixed paper citations --- pages/integrations/xdd/extractions/+Page.ts | 23 ++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/pages/integrations/xdd/extractions/+Page.ts b/pages/integrations/xdd/extractions/+Page.ts index 2fe03f9e..7b593b35 100644 --- a/pages/integrations/xdd/extractions/+Page.ts +++ b/pages/integrations/xdd/extractions/+Page.ts @@ -37,8 +37,8 @@ const useStore = create((set, get) => ({ let req = postgrest .from("kg_publication_entities") - .select("citation,paper_id") - .order("paper_id", { ascending: true }); + .select("*") + .order("n_matches", { ascending: false }); if (lastID != null) { req = req.gt("paper_id", lastID); @@ -77,11 +77,21 @@ function ExtractionIndex() { ]); } +function NameMatch({ type, count, pluralSuffix = "s" }) { + let pluralType = type; + if (count > 1) { + pluralType += pluralSuffix; + } + + return `${count} ${pluralType}`; +} + function PaperList({ data }) { const ctx = usePageContext(); const pageLink = ctx.urlPathname; return h("div.paper-list", [ data.map((d) => { + console.log(d); return h("div", [ h(xDDCitation, { citation: d.citation, @@ -89,7 +99,11 @@ function PaperList({ data }) { }), h.if(d.n_matches != null)( "p", - `${d.n_matches} stratigraphic name matches` + h(NameMatch, { + type: "stratigraphic name match", + count: d.n_matches, + pluralSuffix: "es", + }) ), ]); }), @@ -119,9 +133,7 @@ function pruneEmptyCitationElements(citation): any { function xDDCitation({ citation, href }) { const newCitation = pruneEmptyCitationElements(citation); const { title, author, journal, identifier } = newCitation; - console.log(newCitation); const names = author?.map((d) => d.name); - console.log(names); return h("div", [ h("h2.title", h("a", { href }, title)), h("h3.journal", null, journal), @@ -131,6 +143,7 @@ function xDDCitation({ citation, href }) { } function IdentLink({ identifier }) { + if (identifier == null) return null; const { type, id } = identifier; let ident = h("code.identifier", id); From 376689a7e29a65bf84d941720f2c2f513a5f67b5 Mon Sep 17 00:00:00 2001 From: Daven Quinn Date: Sat, 21 Sep 2024 18:32:18 -0500 Subject: [PATCH 04/10] Started working on text ranges --- pages/integrations/xdd/extractions/@paperId/+Page.ts | 3 +-- .../+Page.ts => integrations/xdd/feedback/+Page.client.ts} | 0 2 files changed, 1 insertion(+), 2 deletions(-) rename pages/{dev/feedback/+Page.ts => integrations/xdd/feedback/+Page.client.ts} (100%) diff --git a/pages/integrations/xdd/extractions/@paperId/+Page.ts b/pages/integrations/xdd/extractions/@paperId/+Page.ts index 41c34721..1ac15f37 100644 --- a/pages/integrations/xdd/extractions/@paperId/+Page.ts +++ b/pages/integrations/xdd/extractions/@paperId/+Page.ts @@ -40,6 +40,7 @@ function ExtractionIndex() { const { paperId } = routeParams; const data = usePostgresQuery("kg_context_entities", { paperId }); + console.log(data); if (data == null) { return h("div", "Loading..."); } @@ -73,8 +74,6 @@ function ExtractionInfo({ data }: { data: Entity }) { const match = data.match ?? null; - console.log(data); - return h("li.entity", { className: data.type }, [ h("span.name", data.name), h(Match, { data: match }), diff --git a/pages/dev/feedback/+Page.ts b/pages/integrations/xdd/feedback/+Page.client.ts similarity index 100% rename from pages/dev/feedback/+Page.ts rename to pages/integrations/xdd/feedback/+Page.client.ts From 39e803eff79fc61ea0f33514619a8f7000de5593 Mon Sep 17 00:00:00 2001 From: Daven Quinn Date: Sat, 21 Sep 2024 19:23:15 -0500 Subject: [PATCH 05/10] Added model ID --- .../xdd/extractions/@paperId/+Page.ts | 61 +++++++++++++++---- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/pages/integrations/xdd/extractions/@paperId/+Page.ts b/pages/integrations/xdd/extractions/@paperId/+Page.ts index 1ac15f37..c38bc8dc 100644 --- a/pages/integrations/xdd/extractions/@paperId/+Page.ts +++ b/pages/integrations/xdd/extractions/@paperId/+Page.ts @@ -10,20 +10,37 @@ import { JSONView } from "@macrostrat/ui-components"; const postgrest = new PostgrestClient(postgrestPrefix); -function usePostgresQuery(query, { paperId }) { +interface FilterDef { + subject: string; + op?: string; + predicate: any; +} + +function usePostgresQuery(query: string, filter: FilterDef | null = null) { const [data, setData] = useState(null); useEffect(() => { - postgrest - .from(query) - .select() - .filter("paper_id", "eq", paperId) - .then((res) => { - setData(res.data); - }); - }, [query]); + let q = postgrest.from(query).select(); + + if (filter != null) { + const { subject, op = "eq", predicate } = filter; + + q = q.filter(subject, op, predicate); + } + + q.then((res) => { + setData(res.data); + }); + }, [query, filter]); return data; } +function useModelIndex() { + const models = usePostgresQuery("kg_model"); + if (models == null) return null; + + return new Map(models.map((d) => [d.id, d])); +} + export function Page() { return h(ContentPage, [h(PageBreadcrumbs), h(PageMain)]); } @@ -39,18 +56,36 @@ function ExtractionIndex() { const { routeParams } = usePageContext(); const { paperId } = routeParams; - const data = usePostgresQuery("kg_context_entities", { paperId }); - console.log(data); - if (data == null) { + const models = useModelIndex(); + + const data = usePostgresQuery("kg_context_entities", { + subject: "paper_id", + predicate: paperId, + }); + if (data == null || models == null) { return h("div", "Loading..."); } - return h(data.map((d) => h(ExtractionContext, { data: d }))); + return h( + data.map((d) => { + return h(ExtractionContext, { data: enhanceData(d, models) }); + }) + ); +} + +function enhanceData(extractionData, models) { + return { + ...extractionData, + model: models.get(extractionData.model_id), + }; } function ExtractionContext({ data }) { + console.log(data); + const { name } = data.model; return h("div", [ h("p", data.paragraph_text), + h("p.model-name", h("code", name)), h( "ul.entities", data.entities.map((d) => h(ExtractionInfo, { data: d })) From 56da13f5c603ba65f081dfa7460d5d273cd06a1e Mon Sep 17 00:00:00 2001 From: Daven Quinn Date: Sun, 22 Sep 2024 11:05:23 -0700 Subject: [PATCH 06/10] Fixed entities --- .../xdd/extractions/@paperId/+Page.ts | 54 +++++++++++++++---- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/pages/integrations/xdd/extractions/@paperId/+Page.ts b/pages/integrations/xdd/extractions/@paperId/+Page.ts index c38bc8dc..fbd0f6b9 100644 --- a/pages/integrations/xdd/extractions/@paperId/+Page.ts +++ b/pages/integrations/xdd/extractions/@paperId/+Page.ts @@ -4,9 +4,9 @@ import { PostgrestClient } from "@supabase/postgrest-js"; import { ContentPage } from "~/layouts"; import { PageBreadcrumbs } from "~/components"; import { postgrestPrefix } from "@macrostrat-web/settings"; -import { useEffect, useState } from "react"; +import { useEffect, memo, useState } from "react"; import { usePageContext } from "vike-react/usePageContext"; -import { JSONView } from "@macrostrat/ui-components"; +import { Tag } from "@blueprintjs/core"; const postgrest = new PostgrestClient(postgrestPrefix); @@ -18,6 +18,7 @@ interface FilterDef { function usePostgresQuery(query: string, filter: FilterDef | null = null) { const [data, setData] = useState(null); + useEffect(() => { let q = postgrest.from(query).select(); @@ -30,15 +31,25 @@ function usePostgresQuery(query: string, filter: FilterDef | null = null) { q.then((res) => { setData(res.data); }); - }, [query, filter]); + }, [query]); return data; } -function useModelIndex() { - const models = usePostgresQuery("kg_model"); +function useIndex(model, idField = "id") { + const models = usePostgresQuery(model); if (models == null) return null; + return new Map(models.map((d) => [d[idField], d])); +} + +function useModelIndex() { + return useIndex("kg_model"); +} + +function useEntityTypeIndex() { + const ix = useIndex("kg_entity_type"); + // Add a "color" field - return new Map(models.map((d) => [d.id, d])); + return ix; } export function Page() { @@ -57,6 +68,7 @@ function ExtractionIndex() { const { paperId } = routeParams; const models = useModelIndex(); + const entityTypes = useEntityTypeIndex(); const data = usePostgresQuery("kg_context_entities", { subject: "paper_id", @@ -68,15 +80,29 @@ function ExtractionIndex() { return h( data.map((d) => { - return h(ExtractionContext, { data: enhanceData(d, models) }); + return h(ExtractionContext, { + data: enhanceData(d, models, entityTypes), + }); }) ); } -function enhanceData(extractionData, models) { +function enhanceData(extractionData, models, entityTypes) { + console.log(entityTypes); return { ...extractionData, model: models.get(extractionData.model_id), + entities: extractionData.entities?.map((d) => + enhanceEntity(d, entityTypes) + ), + }; +} + +function enhanceEntity(entity, entityTypes) { + return { + ...entity, + type: entityTypes.get(entity.type), + children: entity.children?.map((d) => enhanceEntity(d, entityTypes)), }; } @@ -85,7 +111,7 @@ function ExtractionContext({ data }) { const { name } = data.model; return h("div", [ h("p", data.paragraph_text), - h("p.model-name", h("code", name)), + h("p.model-name", h("code.bp5-code", name)), h( "ul.entities", data.entities.map((d) => h(ExtractionInfo, { data: d })) @@ -98,7 +124,7 @@ type Match = any; interface Entity { id: number; name: string; - type: "strat_name" | "lith" | "lith_att"; + type?: number; indices: [number, number]; children: Entity[]; match?: Match; @@ -109,8 +135,14 @@ function ExtractionInfo({ data }: { data: Entity }) { const match = data.match ?? null; + console.log(data.type); + return h("li.entity", { className: data.type }, [ - h("span.name", data.name), + h(Tag, { style: { backgroundColor: "#ddd", color: "#222" } }, [ + h("span.name", data.name), + " ", + h("code.type", null, data.type.name), + ]), h(Match, { data: match }), h.if(children.length > 0)([ h( From 28fc4b9534f277f4b9725c286eebd5af0ef23206 Mon Sep 17 00:00:00 2001 From: Daven Quinn Date: Sun, 22 Sep 2024 11:13:35 -0700 Subject: [PATCH 07/10] Fixed entities 2 --- .../xdd/extractions/@paperId/+Page.ts | 27 ++++++++++--------- .../xdd/extractions/@paperId/main.module.sass | 5 ++++ 2 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 pages/integrations/xdd/extractions/@paperId/main.module.sass diff --git a/pages/integrations/xdd/extractions/@paperId/+Page.ts b/pages/integrations/xdd/extractions/@paperId/+Page.ts index fbd0f6b9..bbf1e686 100644 --- a/pages/integrations/xdd/extractions/@paperId/+Page.ts +++ b/pages/integrations/xdd/extractions/@paperId/+Page.ts @@ -1,4 +1,4 @@ -import h from "@macrostrat/hyper"; +import h from "./main.module.sass"; import { PostgrestClient } from "@supabase/postgrest-js"; import { ContentPage } from "~/layouts"; @@ -7,6 +7,7 @@ import { postgrestPrefix } from "@macrostrat-web/settings"; import { useEffect, memo, useState } from "react"; import { usePageContext } from "vike-react/usePageContext"; import { Tag } from "@blueprintjs/core"; +import classNames from "classnames"; const postgrest = new PostgrestClient(postgrestPrefix); @@ -57,10 +58,7 @@ export function Page() { } function PageMain() { - return h("div", [ - h("h1", "xDD stratigraphic name extractions"), - h(ExtractionIndex), - ]); + return h("div", [h(ExtractionIndex)]); } function ExtractionIndex() { @@ -74,17 +72,21 @@ function ExtractionIndex() { subject: "paper_id", predicate: paperId, }); + + console.log(data); + if (data == null || models == null) { return h("div", "Loading..."); } - return h( + return h([ + h("h1", data.citation?.title ?? "Model extractions"), data.map((d) => { return h(ExtractionContext, { data: enhanceData(d, models, entityTypes), }); - }) - ); + }), + ]); } function enhanceData(extractionData, models, entityTypes) { @@ -107,7 +109,6 @@ function enhanceEntity(entity, entityTypes) { } function ExtractionContext({ data }) { - console.log(data); const { name } = data.model; return h("div", [ h("p", data.paragraph_text), @@ -134,10 +135,12 @@ function ExtractionInfo({ data }: { data: Entity }) { const children = data.children ?? []; const match = data.match ?? null; + const className = classNames({ + matched: match != null, + type: data.type.name, + }); - console.log(data.type); - - return h("li.entity", { className: data.type }, [ + return h("li.entity", { className }, [ h(Tag, { style: { backgroundColor: "#ddd", color: "#222" } }, [ h("span.name", data.name), " ", diff --git a/pages/integrations/xdd/extractions/@paperId/main.module.sass b/pages/integrations/xdd/extractions/@paperId/main.module.sass new file mode 100644 index 00000000..81e68947 --- /dev/null +++ b/pages/integrations/xdd/extractions/@paperId/main.module.sass @@ -0,0 +1,5 @@ +.entities + list-style: none + +.entity + margin: 0.2em 0 0.5em From 63d1b5af30ec44a4a105d8babee88bed237a8225 Mon Sep 17 00:00:00 2001 From: Daven Quinn Date: Sun, 22 Sep 2024 12:00:32 -0700 Subject: [PATCH 08/10] Highlights --- .../xdd/extractions/@paperId/+Page.ts | 73 +++++++++++++++++-- .../xdd/extractions/@paperId/main.module.sass | 3 + 2 files changed, 69 insertions(+), 7 deletions(-) diff --git a/pages/integrations/xdd/extractions/@paperId/+Page.ts b/pages/integrations/xdd/extractions/@paperId/+Page.ts index bbf1e686..e0674c30 100644 --- a/pages/integrations/xdd/extractions/@paperId/+Page.ts +++ b/pages/integrations/xdd/extractions/@paperId/+Page.ts @@ -73,8 +73,6 @@ function ExtractionIndex() { predicate: paperId, }); - console.log(data); - if (data == null || models == null) { return h("div", "Loading..."); } @@ -84,11 +82,26 @@ function ExtractionIndex() { data.map((d) => { return h(ExtractionContext, { data: enhanceData(d, models, entityTypes), + entityTypes, }); }), ]); } +function buildHighlights(entities, entityTypes): Highlight[] { + let highlights = []; + for (const entity of entities) { + console.log(entity); + highlights.push({ + start: entity.indices[0], + end: entity.indices[1], + backgroundColor: entity.type.color ?? "#ccc", + }); + highlights.push(...buildHighlights(entity.children ?? [], entityTypes)); + } + return highlights; +} + function enhanceData(extractionData, models, entityTypes) { console.log(entityTypes); return { @@ -101,6 +114,7 @@ function enhanceData(extractionData, models, entityTypes) { } function enhanceEntity(entity, entityTypes) { + console.log(entity); return { ...entity, type: entityTypes.get(entity.type), @@ -108,10 +122,12 @@ function enhanceEntity(entity, entityTypes) { }; } -function ExtractionContext({ data }) { +function ExtractionContext({ data, entityTypes }) { const { name } = data.model; + const highlights = buildHighlights(data.entities, entityTypes); + return h("div", [ - h("p", data.paragraph_text), + h("p", h(HighlightedText, { text: data.paragraph_text, highlights })), h("p.model-name", h("code.bp5-code", name)), h( "ul.entities", @@ -143,10 +159,10 @@ function ExtractionInfo({ data }: { data: Entity }) { return h("li.entity", { className }, [ h(Tag, { style: { backgroundColor: "#ddd", color: "#222" } }, [ h("span.name", data.name), - " ", + ": ", h("code.type", null, data.type.name), + h(Match, { data: match }), ]), - h(Match, { data: match }), h.if(children.length > 0)([ h( "ul.children", @@ -159,7 +175,7 @@ function ExtractionInfo({ data }: { data: Entity }) { function Match({ data }) { if (data == null) return null; const href = buildHref(data); - return h([" ", h("a.match", { href }, data.name)]); + return h([" ", h("a.match", { href }, `#${matchID(data)}`)]); } function buildHref(match) { @@ -180,3 +196,46 @@ function buildHref(match) { return null; } + +function matchID(match) { + if (match == null) return null; + + for (const id of ["strat_name_id", "lith_id", "lith_att_id"]) { + if (match[id]) { + return match[id]; + } + } + return null; +} + +type Highlight = { + start: number; + end: number; + backgroundColor?: string; + borderColor?: string; +}; + +function HighlightedText(props: { text: string; highlights: Highlight[] }) { + const { text, highlights = [] } = props; + const parts = []; + let start = 0; + + const sortedHighlights = highlights.sort((a, b) => a.start - b.start); + const deconflictedHighlights = sortedHighlights.map((highlight, i) => { + if (i === 0) return highlight; + const prev = sortedHighlights[i - 1]; + if (highlight.start < prev.end) { + highlight.start = prev.end; + } + return highlight; + }); + + for (const highlight of deconflictedHighlights) { + const { start: s, end, ...rest } = highlight; + parts.push(text.slice(start, s)); + parts.push(h("span.highlight", { style: rest }, text.slice(s, end))); + start = end; + } + parts.push(text.slice(start)); + return h("span", parts); +} diff --git a/pages/integrations/xdd/extractions/@paperId/main.module.sass b/pages/integrations/xdd/extractions/@paperId/main.module.sass index 81e68947..d378eb6a 100644 --- a/pages/integrations/xdd/extractions/@paperId/main.module.sass +++ b/pages/integrations/xdd/extractions/@paperId/main.module.sass @@ -1,5 +1,8 @@ .entities list-style: none + padding-left: 0 + .entities ul + list-style: none .entity margin: 0.2em 0 0.5em From 3a07f0d08f2b3b097aab96c86b742ba4f9ff6f8c Mon Sep 17 00:00:00 2001 From: Daven Quinn Date: Sun, 22 Sep 2024 12:45:10 -0700 Subject: [PATCH 09/10] Colors --- .../xdd/extractions/@paperId/+Page.ts | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/pages/integrations/xdd/extractions/@paperId/+Page.ts b/pages/integrations/xdd/extractions/@paperId/+Page.ts index e0674c30..64c56ec5 100644 --- a/pages/integrations/xdd/extractions/@paperId/+Page.ts +++ b/pages/integrations/xdd/extractions/@paperId/+Page.ts @@ -8,6 +8,7 @@ import { useEffect, memo, useState } from "react"; import { usePageContext } from "vike-react/usePageContext"; import { Tag } from "@blueprintjs/core"; import classNames from "classnames"; +import { asChromaColor } from "@macrostrat/color-utils"; const postgrest = new PostgrestClient(postgrestPrefix); @@ -48,8 +49,6 @@ function useModelIndex() { function useEntityTypeIndex() { const ix = useIndex("kg_entity_type"); - // Add a "color" field - return ix; } @@ -95,7 +94,7 @@ function buildHighlights(entities, entityTypes): Highlight[] { highlights.push({ start: entity.indices[0], end: entity.indices[1], - backgroundColor: entity.type.color ?? "#ccc", + backgroundColor: entity.type.color ?? "#ddd", }); highlights.push(...buildHighlights(entity.children ?? [], entityTypes)); } @@ -117,18 +116,34 @@ function enhanceEntity(entity, entityTypes) { console.log(entity); return { ...entity, - type: entityTypes.get(entity.type), + type: addColor(entityTypes.get(entity.type), entity.match != null), children: entity.children?.map((d) => enhanceEntity(d, entityTypes)), }; } +function addColor(entityType, match = false) { + let color = "#ddd"; + const name = entityType.name; + if (name == "strat_name") color = "#be75c6"; + + if (name == "lith") color = "#74ea41"; + + if (name == "strat_noun") color = "#be75c6"; + + if (name == "lith_att") color = "#e8e534"; + + color = asChromaColor(color).brighten(match ? 1 : 2); + + return { ...entityType, color: color.css() }; +} + function ExtractionContext({ data, entityTypes }) { const { name } = data.model; const highlights = buildHighlights(data.entities, entityTypes); return h("div", [ h("p", h(HighlightedText, { text: data.paragraph_text, highlights })), - h("p.model-name", h("code.bp5-code", name)), + h("p.model-name", ["Model: ", h("code.bp5-code", name)]), h( "ul.entities", data.entities.map((d) => h(ExtractionInfo, { data: d })) @@ -157,12 +172,16 @@ function ExtractionInfo({ data }: { data: Entity }) { }); return h("li.entity", { className }, [ - h(Tag, { style: { backgroundColor: "#ddd", color: "#222" } }, [ - h("span.name", data.name), - ": ", - h("code.type", null, data.type.name), - h(Match, { data: match }), - ]), + h( + Tag, + { style: { backgroundColor: data.type.color ?? "#ddd", color: "#222" } }, + [ + h("span.name", data.name), + ": ", + h("code.type", null, data.type.name), + h(Match, { data: match }), + ] + ), h.if(children.length > 0)([ h( "ul.children", From d47ff16658b2f78d4786b58c502eb40f333d3b53 Mon Sep 17 00:00:00 2001 From: Daven Quinn Date: Thu, 26 Sep 2024 02:25:59 -0700 Subject: [PATCH 10/10] Update title view --- pages/integrations/xdd/extractions/@paperId/+Page.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pages/integrations/xdd/extractions/@paperId/+Page.ts b/pages/integrations/xdd/extractions/@paperId/+Page.ts index 64c56ec5..f8e8c3bc 100644 --- a/pages/integrations/xdd/extractions/@paperId/+Page.ts +++ b/pages/integrations/xdd/extractions/@paperId/+Page.ts @@ -67,17 +67,22 @@ function ExtractionIndex() { const models = useModelIndex(); const entityTypes = useEntityTypeIndex(); + const paper = usePostgresQuery("kg_publication_entities", { + subject: "paper_id", + predicate: paperId, + })?.[0]; + const data = usePostgresQuery("kg_context_entities", { subject: "paper_id", predicate: paperId, }); - if (data == null || models == null) { + if (data == null || models == null || paper == null || entityTypes == null) { return h("div", "Loading..."); } return h([ - h("h1", data.citation?.title ?? "Model extractions"), + h("h1", paper.citation?.title ?? "Model extractions"), data.map((d) => { return h(ExtractionContext, { data: enhanceData(d, models, entityTypes),