Skip to content

Commit 1d7b294

Browse files
committed
bug fixes and attributes work
1 parent 578c86c commit 1d7b294

File tree

1 file changed

+95
-58
lines changed

1 file changed

+95
-58
lines changed

lib/DataHarmonizer.js

Lines changed: 95 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,8 @@ class DataHarmonizer {
11881188
tables[dh.template_name] = dh.hot.getData();
11891189
}
11901190

1191+
this.checkForAnnotations(tables, 'class', schema);
1192+
11911193
// Technical notes: Handsontable appears to get overloaded by inserting data via
11921194
// setDataAtCell() after loading of subsequent schemas.
11931195
// Now using getData() and setData() as these avoid slowness or crashes
@@ -1270,9 +1272,11 @@ class DataHarmonizer {
12701272
title: obj.title,
12711273
description: obj.description,
12721274
meaning: obj.meaning,
1275+
exact_mappings: this.getDelimitedString(obj.exact_mappings),
12731276
is_a: obj.is_a,
12741277
notes: obj.notes // ??= ''
12751278
});
1279+
12761280
};
12771281
}
12781282
break;
@@ -1284,9 +1288,7 @@ class DataHarmonizer {
12841288
// Setting up empty class name as empty string since human edits to
12851289
// create new generic slots will create same.
12861290
this.addSlotRecord(dh, tables, loaded_schema_name, '', 'slot', item_name, value);
1287-
1288-
dh_annotation
1289-
1291+
this.checkForAnnotations(tables, 'slot', value);
12901292
break;
12911293

12921294
case 'Class':
@@ -1324,22 +1326,7 @@ class DataHarmonizer {
13241326
this.addSlotRecord(dh_slot, tables, loaded_schema_name, class_name, 'attribute', slot_name, obj);
13251327
};
13261328
}
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);
13431330
break;
13441331
}
13451332
};
@@ -1350,6 +1337,7 @@ class DataHarmonizer {
13501337
for (let class_name of Object.keys(this.context.relations['Schema'].child)) {
13511338
let dh = this.context.dhs[class_name];
13521339
dh.hot.loadData(Object.values(tables[dh.template_name]));
1340+
// Special call to initialize highlight of schema library slots having 'slot_type' = 'field'
13531341
if (class_name === 'Slot') {
13541342
dh.rowHighlightColValue(dh, 'slot_type', 'slot');
13551343
}
@@ -1361,6 +1349,53 @@ class DataHarmonizer {
13611349

13621350
};
13631351

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+
13641399
/** The slot object, and the Class.slot_usage object (which gets to enhance
13651400
* add attributes to a slot but not override existing slot attributes) are
13661401
* identical in potential attributes, so construct the same object for both
@@ -1398,37 +1433,14 @@ class DataHarmonizer {
13981433
maximum_cardinality: slot_obj.maximum_cardinality,
13991434
pattern: slot_obj.pattern,
14001435
equals_expression: slot_obj.equals_expression,
1436+
todos: this.getDelimitedString(slot_obj.todos),
14011437
exact_mappings: this.getDelimitedString(slot_obj.exact_mappings),
14021438
comments: this.getDelimitedString(slot_obj.comments),
14031439
examples: this.getDelimitedString(slot_obj.examples, 'value'), //extract value from list of objects
14041440
version: slot_obj.version,
14051441
notes: slot_obj.notes
14061442
};
14071443
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-
14321444
};
14331445

14341446
/**
@@ -1555,7 +1567,6 @@ class DataHarmonizer {
15551567
let schema_key_slot = (tab_name === 'Schema' ? 'name' : 'schema_id');
15561568
let rows = this.context.crudFindAllRowsByKeyVals(tab_name, {[schema_key_slot]: schema_name})
15571569
let dependent_dh = this.context.dhs[tab_name];
1558-
console.log("getting rows for", tab_name, schema_key_slot, "=", schema_name, "result", rows)
15591570

15601571
// Schema | Prefix | Class | UniqueKey | Slot | Annotation | Enum | PermissibleValue | Setting | Extension
15611572
for (let dep_row of rows) {
@@ -1577,7 +1588,8 @@ class DataHarmonizer {
15771588
value = parseFloat(value);
15781589
break;
15791590
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)
15811593
break;
15821594
}
15831595

@@ -1629,25 +1641,34 @@ class DataHarmonizer {
16291641

16301642
switch (record.slot_type) {
16311643
case 'slot':
1632-
target_obj = new_schema.slots[slot_name] ??= {};
1644+
target_obj = new_schema.slots[slot_name] ??= {name: slot_name};
16331645
break;
16341646

16351647
// slot_usage and attribute cases are connected to a class
16361648
case 'slot_usage':
1637-
su_class_obj.slots ??= [];
1638-
su_class_obj.slots.push(slot_name);
16391649
// Note no break here, 'slot_usage' case uses code below too.
16401650
case 'attribute':
16411651
// Error case if no record.class_id.
16421652
const su_class_obj = new_schema.classes[record.class_id] ??= {};
16431653

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+
16441659
if (record.slot_type == 'slot_usage') {
1660+
su_class_obj.slots ??= [];
1661+
su_class_obj.slots.push(slot_name);
16451662
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};
16471665
}
16481666
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+
};
16511672
}
16521673
break;
16531674
}
@@ -1656,30 +1677,40 @@ class DataHarmonizer {
16561677
if (ranges.length > 0) {
16571678
if (ranges.length == 1)
16581679
target_obj.range = record.range;
1659-
else
1680+
else // more than one range here
16601681
//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+
16631685
if (record.aliases)
16641686
record.aliases = this.getArrayFromDelimited(record.aliases);
1687+
if (record.todos)
1688+
record.todos = this.getArrayFromDelimited(record.todos);
16651689
if (record.exact_mappings)
16661690
record.exact_mappings = this.getArrayFromDelimited(record.exact_mappings);
16671691
if (record.comments)
16681692
record.comments = this.getArrayFromDelimited(record.comments);
16691693
if (record.examples)
16701694
record.examples = this.getArrayFromDelimited(record.examples, 'value');
16711695

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']);
16731698
}
16741699
break;
16751700

16761701
case 'Annotation':
16771702
target_obj = new_schema;
16781703
// 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];
16801710
case 'slot':
16811711
target_obj = new_schema.slots[record.slot_name];
16821712
break;
1713+
16831714
case 'slot_usage':
16841715
target_obj = new_schema.classes[record.class_name].slot_usage[record.slot_name] ??= {};
16851716
break;
@@ -1690,7 +1721,7 @@ class DataHarmonizer {
16901721
target_obj = target_obj.annotations??= {};
16911722

16921723
target_obj[record.name] = {
1693-
key: record.name,
1724+
key: record.name, // convert name to 'key'
16941725
value: record.value
16951726
}
16961727

@@ -1706,7 +1737,13 @@ class DataHarmonizer {
17061737
case 'PermissibleValue': // LOOP?????? 'text shouldn't be overwritten.
17071738
let permissible_values = new_schema.enums[record.enum_id].permissible_values ??= {};
17081739
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+
17101747
break;
17111748

17121749
case 'Type':

0 commit comments

Comments
 (0)