1818#
1919#===============================================================================
2020
21- __version__ = "1.3.0 "
21+ __version__ = "1.3.1 "
2222
2323#===============================================================================
2424
4646
4747SCHEMA_VERSION = '1.4'
4848
49+ ## Have auto update to remove any ``-npo`` suffix on ``source`` column values.
50+
51+ ## select count(*) from knowledge where substr(source, -4, 4) = '-npo'
52+
53+
54+ ## update knowledge set source=substr(source, 1, length(source)-4) where substr(source, -4, 4)='-npo';
55+
56+
57+ ## Server needs to then trim any ``-npo`` from ``source`` sent by viewer
58+
59+ ## Better for viewer to trim ``source``.
60+
61+
62+
4963KNOWLEDGE_SCHEMA = f"""
5064 create table metadata (name text primary key, value text);
5165
93107
94108#===============================================================================
95109
110+ ## Add node "aliases" to knowledge store??
111+ ##
112+ ## This conflates anatomical terms and connectivity nodes...
113+ ##
114+ alias_entry = {
115+ "id" : ["ILX:0738432" , []],
116+ "aliases" : [
117+ ["ILX:0793804" , []],
118+ ["ILX:0793877" , []]
119+ ]
120+ }
121+ ## What is being stored? Why? How is it used??
122+ ##
123+ ## $ curl https://mapcore-demo.org/fccb/flatmap/knowledge/label/ILX:0738432
124+ ## {"entity":"ILX:0738432","label":"Sixth lumbar spinal cord segment"}
125+ ## $ curl https://mapcore-demo.org/fccb/flatmap/knowledge/label/ILX:0793804
126+ ## {"entity":"ILX:0793804","label":"L6 parasympathetic nucleus"}
127+ ## $ curl https://mapcore-demo.org/fccb/flatmap/knowledge/label/ILX:0793877
128+ ## {"entity":"ILX:0793877","label":"Intermediolateral nucleus of sixth lumbar segment"}
129+
130+
96131class KnowledgeBase (object ):
97132 def __init__ (self , store_directory , read_only = False , create = False , knowledge_base = KNOWLEDGE_BASE ):
98133 self .__db = None
@@ -296,6 +331,7 @@ def clean_connectivity(self, knowledge_source: Optional[str]):
296331 self .db .execute (f'delete from connectivity_nodes where source=? or source is null' , (knowledge_source ,))
297332 self .db .commit ()
298333
334+ ### Is this still relevanty???
299335 def connectivity_models (self ) -> list [str ]:
300336 #==========================================
301337 """
@@ -342,6 +378,8 @@ def entity_knowledge(self, entity: str, source: Optional[str]=None) -> dict:
342378 #===========================================================================
343379 use_source = self .__source if source is None else source
344380
381+ ## Trim ``-npo`` from ``use_source``
382+
345383 # Check local cache
346384 if (knowledge := self .__entity_knowledge .get ((use_source , entity ))) is not None :
347385 KnowledgeStore .__log_errors (entity , knowledge )
@@ -424,6 +462,8 @@ def entity_knowledge(self, entity: str, source: Optional[str]=None) -> dict:
424462
425463 def knowledge_sources (self ) -> list [str ]:
426464 #========================================
465+ ## Trim ``-npo`` ??
466+ ## No, since auto update will have done so...
427467 return ([row [0 ]
428468 for row in self .db .execute (
429469 'select distinct source from knowledge order by source desc' ).fetchall ()] if self .db
@@ -442,6 +482,7 @@ def stored_knowledge(self, source: Optional[str]=None) -> list[dict]:
442482 #====================================================================
443483 stored_knowledge = []
444484 source = self .__source if source is None else source
485+ ## Trim ``-npo``
445486 if self .db is not None :
446487 if source is not None :
447488 rows = self .db .execute (
0 commit comments