From 24d067cdebe590292d32359334d6c20f9d64fe88 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Mon, 4 Dec 2023 02:15:46 +0300 Subject: [PATCH] $mol_view_tree2 refactor, https://github.com/hyoo-ru/mam_mol/pull/646 --- rdf.view.tree | 30 +++++++++++++++--------------- rdf.view.ts | 23 +++++++++++++---------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/rdf.view.tree b/rdf.view.tree index a34257c..0c4f0b6 100644 --- a/rdf.view.tree +++ b/rdf.view.tree @@ -4,7 +4,7 @@ $hyoo_rdf $mol_page title @ \RDF graph browser head / <= Uri $mol_string - value?val <=> uri?val \http://dbpedia.org/ontology/ + value? <=> uri? \http://dbpedia.org/ontology/ hint <= uri_hint \URI <= Tools tools / @@ -12,17 +12,17 @@ $hyoo_rdf $mol_page <= Source_link $mol_link_source uri \https://github.com/hyoo-ru/rdf.hyoo.ru body / <= Subjects $mol_list rows <= subject_rows / - Subject_row!uri $mol_view sub / - <= Subject!uri $mol_link - title <= subject_title!uri \ - uri <= subject_uri!uri \ - <= Predicates!uri $mol_list rows <= predicate_rows!uri / - Predicate_row!id $mol_view sub / - <= Predicate!id $mol_link - title <= predicate_title!id \ - uri <= predicate_uri!id \ - <= Objects!id $mol_list rows <= object_rows!id / - Resource!id $mol_link - title <= resource_title!id \ - uri <= resource_uri!id \ - Value!id $mol_view sub / <= value!id \ + Subject_row* $mol_view sub / + <= Subject* $mol_link + title <= subject_title* \ + uri <= subject_uri* \ + <= Predicates* $mol_list rows <= predicate_rows* / + Predicate_row* $mol_view sub / + <= Predicate* $mol_link + title <= predicate_title* \ + uri <= predicate_uri* \ + <= Objects* $mol_list rows <= object_rows* / + Resource* $mol_link + title <= resource_title* \ + uri <= resource_uri* \ + Value* $mol_view sub / <= value* \ diff --git a/rdf.view.ts b/rdf.view.ts index 863c4f0..6f3912b 100644 --- a/rdf.view.ts +++ b/rdf.view.ts @@ -1,5 +1,7 @@ namespace $.$$ { + export type $hyoo_rdf_resource_key = { subject : string , predicate : string , index : number } + export class $hyoo_rdf extends $.$hyoo_rdf { uri( next? : string ) { @@ -78,24 +80,25 @@ namespace $.$$ { @ $mol_mem_key object_rows( { subject , predicate } : { subject : string , predicate : string } ) { const data = this.data()[ subject ][ predicate ] - return Object.keys( data ).map( object => { - if( data[ object ].resource ) return this.Resource({ subject , predicate , object }) - return this.Value({ subject , predicate , object }) - } ) + + return data.map((val, index) => { + if( val.resource ) return this.Resource({ subject , predicate , index }) + return this.Value({ subject , predicate , index }) + }) } - resource_title( { subject , predicate , object } : { subject : string , predicate : string , object : string } ) { - const data = this.data()[ subject ][ predicate ][ object ] + resource_title( { subject , predicate , index } : $hyoo_rdf_resource_key ) { + const data = this.data()[ subject ][ predicate ][ index ] return decodeURIComponent( data.resource.replace( /.*[\/#]/ , '' ) ) || '#' } - resource_uri( { subject , predicate , object } : { subject : string , predicate : string , object : string } ) { - const data = this.data()[ subject ][ predicate ][ object ] + resource_uri( { subject , predicate , index } : $hyoo_rdf_resource_key ) { + const data = this.data()[ subject ][ predicate ][ index ] return this.$.$mol_state_arg.link({ uri : data.resource }) } - value( { subject , predicate , object } : { subject : string , predicate : string , object : string } ) { - return this.data()[ subject ][ predicate ][ object ].value + value( { subject , predicate , index } : $hyoo_rdf_resource_key ) { + return this.data()[ subject ][ predicate ][ index ].value } }