@@ -1188,6 +1188,8 @@ class DataHarmonizer {
1188
1188
tables [ dh . template_name ] = dh . hot . getData ( ) ;
1189
1189
}
1190
1190
1191
+ this . checkForAnnotations ( tables , 'class' , schema ) ;
1192
+
1191
1193
// Technical notes: Handsontable appears to get overloaded by inserting data via
1192
1194
// setDataAtCell() after loading of subsequent schemas.
1193
1195
// Now using getData() and setData() as these avoid slowness or crashes
@@ -1270,9 +1272,11 @@ class DataHarmonizer {
1270
1272
title : obj . title ,
1271
1273
description : obj . description ,
1272
1274
meaning : obj . meaning ,
1275
+ exact_mappings : this . getDelimitedString ( obj . exact_mappings ) ,
1273
1276
is_a : obj . is_a ,
1274
1277
notes : obj . notes // ??= ''
1275
1278
} ) ;
1279
+
1276
1280
} ;
1277
1281
}
1278
1282
break ;
@@ -1284,9 +1288,7 @@ class DataHarmonizer {
1284
1288
// Setting up empty class name as empty string since human edits to
1285
1289
// create new generic slots will create same.
1286
1290
this . addSlotRecord ( dh , tables , loaded_schema_name , '' , 'slot' , item_name , value ) ;
1287
-
1288
- dh_annotation
1289
-
1291
+ this . checkForAnnotations ( tables , 'slot' , value ) ;
1290
1292
break ;
1291
1293
1292
1294
case 'Class' :
@@ -1324,22 +1326,7 @@ class DataHarmonizer {
1324
1326
this . addSlotRecord ( dh_slot , tables , loaded_schema_name , class_name , 'attribute' , slot_name , obj ) ;
1325
1327
} ;
1326
1328
}
1327
-
1328
- if ( value . annotations ) {
1329
- for ( let [ key_name , obj ] of Object . entries ( value . annotations ) ) {
1330
-
1331
- this . addRowRecord ( dh_annotation , tables , {
1332
- schema_id : loaded_schema_name ,
1333
- slot_type : 'Class' ,
1334
- class_name : class_name ,
1335
- name : key_name ,
1336
- unique_key_slots : obj . unique_key_slots . join ( ";" ) ,
1337
- description : obj . description
1338
- } ) ;
1339
-
1340
- } ;
1341
- }
1342
-
1329
+ this . checkForAnnotations ( tables , 'class' , value ) ;
1343
1330
break ;
1344
1331
}
1345
1332
} ;
@@ -1350,6 +1337,7 @@ class DataHarmonizer {
1350
1337
for ( let class_name of Object . keys ( this . context . relations [ 'Schema' ] . child ) ) {
1351
1338
let dh = this . context . dhs [ class_name ] ;
1352
1339
dh . hot . loadData ( Object . values ( tables [ dh . template_name ] ) ) ;
1340
+ // Special call to initialize highlight of schema library slots having 'slot_type' = 'field'
1353
1341
if ( class_name === 'Slot' ) {
1354
1342
dh . rowHighlightColValue ( dh , 'slot_type' , 'slot' ) ;
1355
1343
}
@@ -1361,6 +1349,53 @@ class DataHarmonizer {
1361
1349
1362
1350
} ;
1363
1351
1352
+
1353
+ /**
1354
+ * Annotations are currently possible on schema, class, slot, slot_usage and attribute.
1355
+ *
1356
+ *
1357
+ */
1358
+ checkForAnnotations ( tables , annotation_type , source_obj ) {
1359
+
1360
+ // For now DH annotations only apply to slots, slot_usages, and class.attributes
1361
+ if ( source_obj . annotations ) {
1362
+ let dh_annotation = this . context . dhs . Annotation ;
1363
+ let base_record = {
1364
+ schema_id : schema_name ,
1365
+ slot_type : annotation_type ,
1366
+ }
1367
+ switch ( annotation_type ) {
1368
+ case 'schema' :
1369
+ break ;
1370
+ case 'class' :
1371
+ base_record . class_name = source_obj . class_name ;
1372
+ break ;
1373
+ case 'slot' :
1374
+ base_record . slot_name = source_obj . slot_name ;
1375
+ break ;
1376
+ case 'slot_usage' :
1377
+ case 'attribute' :
1378
+ base_record . class_name = source_obj . class_name ;
1379
+ base_record . slot_name = source_obj . slot_name ;
1380
+ break ;
1381
+ }
1382
+ for ( let [ tag , obj ] of Object . entries ( source_obj . annotations ) ) {
1383
+ let record = Object . assign ( base_record , {
1384
+ annotation_type : annotation_type ,
1385
+ name : tag , // FUTURE tag: ...
1386
+ value : obj . value
1387
+ } ) ;
1388
+ // NORMALLY name: would be key: but current problem is that header in
1389
+ // schema_editor tables is using [text] as slot_group for a field
1390
+ // yields that if that [text] is a slot name, then title is being
1391
+ // looked up as a SLOT rather than as an enumeration - because DH code
1392
+ // doesn’t have enumeration yet...
1393
+
1394
+ this . addRowRecord ( dh_annotation , tables , record ) ;
1395
+ } ;
1396
+ }
1397
+ }
1398
+
1364
1399
/** The slot object, and the Class.slot_usage object (which gets to enhance
1365
1400
* add attributes to a slot but not override existing slot attributes) are
1366
1401
* identical in potential attributes, so construct the same object for both
@@ -1398,37 +1433,14 @@ class DataHarmonizer {
1398
1433
maximum_cardinality : slot_obj . maximum_cardinality ,
1399
1434
pattern : slot_obj . pattern ,
1400
1435
equals_expression : slot_obj . equals_expression ,
1436
+ todos : this . getDelimitedString ( slot_obj . todos ) ,
1401
1437
exact_mappings : this . getDelimitedString ( slot_obj . exact_mappings ) ,
1402
1438
comments : this . getDelimitedString ( slot_obj . comments ) ,
1403
1439
examples : this . getDelimitedString ( slot_obj . examples , 'value' ) , //extract value from list of objects
1404
1440
version : slot_obj . version ,
1405
1441
notes : slot_obj . notes
1406
1442
} ;
1407
1443
this . addRowRecord ( dh , tables , slot_record ) ;
1408
-
1409
- // For now DH annotations only apply to slots, slot_usages, and class.attributes
1410
- if ( slot_obj . annotations ) {
1411
- let dh_annotation = this . context . dhs . Annotation
1412
- for ( let [ annotation_name , obj ] of Object . entries ( slot_obj . annotations ) ) {
1413
- let record = {
1414
- schema_id : schema_name ,
1415
- slot_type : slot_type ,
1416
- class_name : class_name , // in the case of annotation on .slot_usage
1417
- slot_name : slot_key ,
1418
- name : annotation_name , // or obj.tag
1419
- value : obj . value
1420
- }
1421
- // NORMALLY name: would be key: but current problem is that header in
1422
- // schema_editor tables is using [text] as slot_group for a field
1423
- // yields that if that [text] is a slot name, then title is being
1424
- // looked up as a SLOT rather than as an enumeration - because DH code
1425
- // doesn’t have enumeration yet...
1426
-
1427
- this . addRowRecord ( dh_annotation , tables , record ) ;
1428
- } ;
1429
-
1430
- }
1431
-
1432
1444
} ;
1433
1445
1434
1446
/**
@@ -1555,7 +1567,6 @@ class DataHarmonizer {
1555
1567
let schema_key_slot = ( tab_name === 'Schema' ? 'name' : 'schema_id' ) ;
1556
1568
let rows = this . context . crudFindAllRowsByKeyVals ( tab_name , { [ schema_key_slot ] : schema_name } )
1557
1569
let dependent_dh = this . context . dhs [ tab_name ] ;
1558
- console . log ( "getting rows for" , tab_name , schema_key_slot , "=" , schema_name , "result" , rows )
1559
1570
1560
1571
// Schema | Prefix | Class | UniqueKey | Slot | Annotation | Enum | PermissibleValue | Setting | Extension
1561
1572
for ( let dep_row of rows ) {
@@ -1577,7 +1588,8 @@ class DataHarmonizer {
1577
1588
value = parseFloat ( value ) ;
1578
1589
break ;
1579
1590
case 'xsd:boolean' :
1580
- value = value . toLowerCase ( ) in [ 't' , 'true' , '1' , 'yes' , 'y' ] ;
1591
+ value = [ 't' , 'true' , '1' , 'yes' , 'y' ] . includes ( value . toLowerCase ( ) ) ;
1592
+ console . log ( 'after' , value )
1581
1593
break ;
1582
1594
}
1583
1595
@@ -1629,25 +1641,34 @@ class DataHarmonizer {
1629
1641
1630
1642
switch ( record . slot_type ) {
1631
1643
case 'slot' :
1632
- target_obj = new_schema . slots [ slot_name ] ??= { } ;
1644
+ target_obj = new_schema . slots [ slot_name ] ??= { name : slot_name } ;
1633
1645
break ;
1634
1646
1635
1647
// slot_usage and attribute cases are connected to a class
1636
1648
case 'slot_usage' :
1637
- su_class_obj . slots ??= [ ] ;
1638
- su_class_obj . slots . push ( slot_name ) ;
1639
1649
// Note no break here, 'slot_usage' case uses code below too.
1640
1650
case 'attribute' :
1641
1651
// Error case if no record.class_id.
1642
1652
const su_class_obj = new_schema . classes [ record . class_id ] ??= { } ;
1643
1653
1654
+ // Issue: attributes don't show in class.slots list
1655
+ // so how to determine rank automatically?
1656
+ // order by length of
1657
+ let calculated_rank = Object . keys ( su_class_obj . slot_usage || { } ) . length + Object . keys ( su_class_obj . attributes || { } ) . length ;
1658
+
1644
1659
if ( record . slot_type == 'slot_usage' ) {
1660
+ su_class_obj . slots ??= [ ] ;
1661
+ su_class_obj . slots . push ( slot_name ) ;
1645
1662
su_class_obj . slot_usage ??= { } ;
1646
- target_obj = su_class_obj . slot_usage [ slot_name ] ??= { } ;
1663
+ // No need to add name in case below
1664
+ target_obj = su_class_obj . slot_usage [ slot_name ] ??= { rank : calculated_rank } ;
1647
1665
}
1648
1666
else {
1649
- su_class_obj . attributes ??= { } ;
1650
- target_obj = su_class_obj . attributes [ slot_name ] ??= { } ; // plural attributes
1667
+ su_class_obj . attributes ??= { } ; // plural attributes
1668
+ target_obj = su_class_obj . attributes [ slot_name ] ??= {
1669
+ name : slot_name ,
1670
+ rank : calculated_rank
1671
+ } ;
1651
1672
}
1652
1673
break ;
1653
1674
}
@@ -1656,30 +1677,40 @@ class DataHarmonizer {
1656
1677
if ( ranges . length > 0 ) {
1657
1678
if ( ranges . length == 1 )
1658
1679
target_obj . range = record . range ;
1659
- else
1680
+ else // more than one range here
1660
1681
//array of { range: ...}
1661
- target_obj . any_of = ranges . map ( ( x ) => { range : x } ) ;
1662
- }
1682
+ target_obj . any_of = ranges . map ( x => { return { range : x } } ) ;
1683
+ } ;
1684
+
1663
1685
if ( record . aliases )
1664
1686
record . aliases = this . getArrayFromDelimited ( record . aliases ) ;
1687
+ if ( record . todos )
1688
+ record . todos = this . getArrayFromDelimited ( record . todos ) ;
1665
1689
if ( record . exact_mappings )
1666
1690
record . exact_mappings = this . getArrayFromDelimited ( record . exact_mappings ) ;
1667
1691
if ( record . comments )
1668
1692
record . comments = this . getArrayFromDelimited ( record . comments ) ;
1669
1693
if ( record . examples )
1670
1694
record . examples = this . getArrayFromDelimited ( record . examples , 'value' ) ;
1671
1695
1672
- this . copySlots ( tab_name , record , target_obj , [ 'name' , 'rank' , 'slot_group' , 'inlined' , 'inlined_as_list' , 'slot_uri' , 'title' , 'required' , 'recommended' , 'description' , 'aliases' , 'identifier' , 'multivalued' , 'minimum_value' , 'maximum_value' , 'minimum_cardinality' , 'maximum_cardinality' , 'equals_expression' , 'exact_mappings' , 'comments' , 'examples' ] ) ;
1696
+ // slot_usage case doesn't need name, so name handled above.
1697
+ this . copySlots ( tab_name , record , target_obj , [ 'slot_group' , 'inlined' , 'inlined_as_list' , 'slot_uri' , 'title' , 'required' , 'recommended' , 'description' , 'aliases' , 'identifier' , 'multivalued' , 'minimum_value' , 'maximum_value' , 'minimum_cardinality' , 'maximum_cardinality' , 'equals_expression' , 'exact_mappings' , 'comments' , 'examples' ] ) ;
1673
1698
}
1674
1699
break ;
1675
1700
1676
1701
case 'Annotation' :
1677
1702
target_obj = new_schema ;
1678
1703
// If slot type is more specific then switch target to appropriate reference.
1679
- switch ( record . slot_type ) {
1704
+ switch ( record . annotation_type ) {
1705
+ case 'schema' :
1706
+ target_obj = new_schema ;
1707
+ break
1708
+ case 'class' :
1709
+ target_obj = new_schema . classes [ record . class_name ] ;
1680
1710
case 'slot' :
1681
1711
target_obj = new_schema . slots [ record . slot_name ] ;
1682
1712
break ;
1713
+
1683
1714
case 'slot_usage' :
1684
1715
target_obj = new_schema . classes [ record . class_name ] . slot_usage [ record . slot_name ] ??= { } ;
1685
1716
break ;
@@ -1690,7 +1721,7 @@ class DataHarmonizer {
1690
1721
target_obj = target_obj . annotations ??= { } ;
1691
1722
1692
1723
target_obj [ record . name ] = {
1693
- key : record . name ,
1724
+ key : record . name , // convert name to 'key'
1694
1725
value : record . value
1695
1726
}
1696
1727
@@ -1706,7 +1737,13 @@ class DataHarmonizer {
1706
1737
case 'PermissibleValue' : // LOOP?????? 'text shouldn't be overwritten.
1707
1738
let permissible_values = new_schema . enums [ record . enum_id ] . permissible_values ??= { } ;
1708
1739
target_obj = permissible_values [ record . text ] ??= { } ;
1709
- this . copySlots ( tab_name , record , target_obj , [ 'text' , 'title' , 'description' , 'meaning' , 'is_a' , 'notes' ] ) ;
1740
+ if ( record . exact_mappings ) {
1741
+ record . exact_mappings = this . getArrayFromDelimited ( record . exact_mappings ) ;
1742
+ }
1743
+ this . copySlots ( tab_name , record , target_obj , [ 'text' , 'title' , 'description' , 'meaning' , 'is_a' , 'exact_mappings' , 'notes' ] ) ;
1744
+
1745
+
1746
+
1710
1747
break ;
1711
1748
1712
1749
case 'Type' :
0 commit comments