From a202eb720ce29d3a165edb85bef391fcf0c20dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Thu, 2 Dec 2021 23:21:03 +0100 Subject: [PATCH] [ui] update identification logic --- ui/src/components/Address.svelte | 2 +- ui/src/lib/entity.ts | 53 +++++--------------------------- 2 files changed, 8 insertions(+), 47 deletions(-) diff --git a/ui/src/components/Address.svelte b/ui/src/components/Address.svelte index 31fc999..beb38d9 100644 --- a/ui/src/components/Address.svelte +++ b/ui/src/components/Address.svelte @@ -27,7 +27,7 @@ if (resolve) { resolving = true; identify($attributes, $backlinks).then((inferredEntries) => { - inferredIds = inferredEntries.map((eid) => eid.value); + inferredIds = inferredEntries; resolving = false; }); } diff --git a/ui/src/lib/entity.ts b/ui/src/lib/entity.ts index 885cfd9..61ad3e0 100644 --- a/ui/src/lib/entity.ts +++ b/ui/src/lib/entity.ts @@ -4,6 +4,7 @@ import { derived, Readable, readable, writable } from "svelte/store"; import type { IEntry, ListingResult, OrderedListing } from "upend/types"; import { listingAsOrdered } from "upend"; import LRU from "lru-cache"; +import { attr } from "svelte/internal"; export function useEntity( address: string | (() => string), @@ -80,15 +81,10 @@ export async function queryOnce(query: string): Promise { } } -interface EntityIdentification { - type: string; - value: string; -} - export async function identify( attributes: OrderedListing, backlinks: OrderedListing -): Promise { +): Promise { // Get all entries where the object is linked const hasEntries = backlinks .filter(([_, entry]) => entry.attribute === "HAS") @@ -105,44 +101,9 @@ export async function identify( return entry.value.c; }); - // Get all identities of the object - const isEntries = attributes - .filter(([_, entry]) => entry.attribute === "IS") - .map(([_, entry]) => entry.value.c); - - // Out of those, retrieve their TYPE_ID entries - const typeIdListing = isEntries.length - ? await queryOnce( - `(matches (in ${isEntries.map((e) => `"${e}"`).join(" ")}) "TYPE_ID" ?)` - ) - : []; - - const typeIdAttributes = typeIdListing.map(([_, entry]) => { - return [entry.entity, entry.value.c]; - }); - - // Finally, filter own object's attributes according to TYPE_IDs - // For each identity/TYPE_ID pair - return typeIdAttributes - .map(([type, attrName]) => { - // And each associated TYPE_ID attribute... - // return own matchin attributes - return attributes - .filter(([_, e]) => e.attribute === attrName) - .map(([_, attr]) => { - return { - type, - value: attr.value.c, - }; - }); - }) - .flat() - .concat( - aliasValues.map((value) => { - return { - type: "ALIAS", - value, - }; - }) - ); + // Return all LBLs concatenated with named aliases + return attributes + .filter(([_, attr]) => attr.attribute === "LBL") + .map(([_, attr]) => attr.value.c) + .concat(aliasValues); }