11import { useState , useEffect , useMemo , useRef , useCallback } from 'react' ;
22import { authHeaders } from '../api.js' ;
33import { useMemoryGraphEvents } from './useNodeEvents.js' ;
4+ import { MEMORY_LABEL_PREDICATES } from '../lib/memoryLabels.js' ;
45
56export type TrustLevel = 'working' | 'shared' | 'verified' ;
67export type MemoryLayerKey = 'wm' | 'swm' | 'vm' ;
@@ -48,13 +49,6 @@ export interface MemoryData {
4849}
4950
5051const RDF_TYPE = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' ;
51- const NAME_PREDS = [
52- 'http://schema.org/name' ,
53- 'http://www.w3.org/2000/01/rdf-schema#label' ,
54- 'http://purl.org/dc/terms/title' ,
55- 'http://purl.org/dc/elements/1.1/title' ,
56- 'http://xmlns.com/foaf/0.1/name' ,
57- ] ;
5852
5953function bv ( v : unknown ) : string | undefined {
6054 if ( v == null ) return undefined ;
@@ -106,6 +100,10 @@ function isRawExtractionLabel(label: string, uri: string): boolean {
106100 return label === uri && / ^ u r n : d k g : e x t r a c t i o n : [ ^ \s ] + $ / i. test ( uri ) ;
107101}
108102
103+ function isUnreadableDefaultUriLabel ( label : string , uri : string ) : boolean {
104+ return label === uri && ( uri . startsWith ( 'urn:' ) || uri . startsWith ( 'did:' ) ) ;
105+ }
106+
109107function readableFallbackLabel ( entity : MemoryEntity ) : string {
110108 const tail = readableTail ( entity . uri ) ;
111109 const type = entity . types
@@ -119,13 +117,18 @@ function readableFallbackLabel(entity: MemoryEntity): string {
119117}
120118
121119function deriveEntityLabel ( entity : MemoryEntity ) : string {
122- for ( const pred of NAME_PREDS ) {
120+ for ( const pred of MEMORY_LABEL_PREDICATES ) {
123121 const vals = entity . properties . get ( pred ) ;
124122 const name = vals ?. find ( v => v . trim ( ) . length > 0 ) ;
125123 if ( name ) return name ;
126124 }
127125
128- if ( entity . label && ! isRawExtractionLabel ( entity . label , entity . uri ) ) {
126+ const defaultUriLabel = shortLabel ( entity . uri ) ;
127+ if (
128+ entity . label &&
129+ ( entity . label !== defaultUriLabel || ! isUnreadableDefaultUriLabel ( entity . label , entity . uri ) ) &&
130+ ! isRawExtractionLabel ( entity . label , entity . uri )
131+ ) {
129132 return entity . label ;
130133 }
131134
0 commit comments