Skip to content

Commit

Permalink
Merge branch 'kingdoms-multi-root-codes'
Browse files Browse the repository at this point in the history
  • Loading branch information
phfaist committed Oct 25, 2023
2 parents b486b3e + 7802afe commit b7dcb13
Show file tree
Hide file tree
Showing 23 changed files with 855 additions and 643 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"env": {
"browser": true,
"es2021": true
"es2021": true,
"commonjs": true
},
"extends": "eslint:recommended",
"parserOptions": {
Expand Down
2 changes: 1 addition & 1 deletion _zoodb_citations_cache/cache_compiled_citations.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _zoodb_citations_cache/cache_downloaded_info.json

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions eczoodb/eczoodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,19 @@ export class EcZooDb extends ZooDb

code_parent_domains(code, {find_domain_id} = {})
{
let domains_by_kingdom_code_id = Object.fromEntries(
Object.entries(this.objects.kingdom).map(
([kingdom_id, kingdom]) =>
[kingdom.kingdom_code.code_id, kingdom.parent_domain]
)
);
let domains_by_kingdom_root_code_id = {};
for (const kingdom of Object.values(this.objects.kingdom)) {
for (const kingdomRootCodeRel of kingdom.root_codes) {
domains_by_kingdom_root_code_id[ kingdomRootCodeRel.code_id ] =
kingdom.parent_domain;
}
}

let domains = [];
this.code_visit_relations(code, {
relation_properties: ['parents'],
callback: (code_visit) => {
const domain = domains_by_kingdom_code_id[code_visit.code_id];
const domain = domains_by_kingdom_root_code_id[code_visit.code_id];
if (domain !== undefined) {
domains.push(domain);
if (find_domain_id != null && domain.domain_id === find_domain_id) {
Expand Down Expand Up @@ -315,7 +317,7 @@ export class EcZooDb extends ZooDb
num_incoming_edges[child.code_id] += 1;
}
}
};
}

// find "root nodes" w/o any parents
let root_nodes = codes.filter( (c) => (num_incoming_edges[c.code_id] === 0) );
Expand Down Expand Up @@ -357,13 +359,13 @@ export class EcZooDb extends ZooDb
const clean_all_child_nodes = () => {
// Remove any listed children that are not themselves listed
// as having children.
while (true) {
for (;;) {
let remove_cids = new Set();
all_child_nodes = Object.fromEntries(
Object.entries(all_child_nodes).map( ([c_id, children]) => {
let new_children = (children ?? []).filter( (child) => {
const child_id = child.code_id;
if ( !all_child_nodes.hasOwnProperty(child_id)
if ( !Object.hasOwn(all_child_nodes, child_id)
|| (all_child_nodes[child_id] == null)
|| (all_child_nodes[child_id].length == 0) ) {
return false; // filter this child out
Expand Down
24 changes: 13 additions & 11 deletions eczoodb/render_code.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import debug_mod from 'debug';
const debug = debug_mod("eczoodbjs.render_code");
//import debug_mod from 'debug';
//const debug = debug_mod("eczoodbjs.render_code");

import { getfield } from '@phfaist/zoodb/util';

import * as zooflm from '@phfaist/zoodb/zooflm';
const { $$kw, repr } = zooflm;
//const { $$kw, repr } = zooflm;
import { sqzhtml } from '@phfaist/zoodb/util/sqzhtml';

import {
Expand Down Expand Up @@ -66,19 +66,21 @@ export function render_code_page(
`
}

const kingdom = code.relations?.defines_kingdom?.[0]?.kingdom ?? null;
if (kingdom != null) {
html += sqzhtml`
<div class="sectioncontent code-defines-kingdom-name">
const kingdomRelList = code.relations?.root_for_kingdom;
if (kingdomRelList != null && kingdomRelList.length >= 1) {
for (const { kingdom } of kingdomRelList) {
html += sqzhtml`
<div class="sectioncontent code-root-code-kingdom-name">
<span class="kingdom-name-label">
This code defines the
Root code for the
</span> <!-- space -->${
ref('kingdom', kingdom.kingdom_id)
}</div>
<div class="kingdom-description">${ rdr(kingdom.description) }</div>`;
<div class="kingdom-description">${ rdr(kingdom.description) }</div>
`;
}
}


if (code._meta?.stub) {
html += sqzhtml`
<div class="sectioncontent code-is-stub">
Expand Down Expand Up @@ -213,6 +215,6 @@ export function render_code_page(
annotations: ['sectioncontent'],
}
});
};
}


2 changes: 1 addition & 1 deletion eczoodb/schemas/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ properties:
# including 'code_id', no need to specify them here)


defines_kingdom:
root_for_kingdom:
_auto_populated: true


Expand Down
31 changes: 15 additions & 16 deletions eczoodb/schemas/kingdom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $id: "https://errorcorrectionzoo.org/schemas/kingdom"
_zoo_primarykey: 'kingdom_id'
type: object
additionalProperties: false
required: ['kingdom_id', 'name', 'parent_domain', 'kingdom_code']
required: ['kingdom_id', 'name', 'parent_domain', 'root_codes']
properties:

kingdom_id:
Expand All @@ -31,22 +31,21 @@ properties:
properties:
domain_id:
type: string
pattern: '^[a-z0-9_.-]+$'
_single_line_string: True

kingdom_code:
type: object
additionalProperties: false
requried: ['code_id']
properties:
code_id:
type: string
_single_line_string: True
pattern: '^[a-z0-9_.-]+$'
root_codes:
type: array
items:
additionalProperties: false
requried: ['code_id']
properties:
code_id:
type: string
_single_line_string: True

# automatically populated fields, don't specify manually
code:
_auto_populated: true
# automatically populated fields, don't specify manually
code:
_auto_populated: true



Expand All @@ -58,9 +57,9 @@ _zoo_relations:
backreference:
field: 'kingdoms'

- object_field: 'kingdom_code'
- object_field: 'root_codes'
to_object_type: 'code'
relation_primary_key_field: 'code_id'
relation_add_object_field: 'code'
backreference:
field: 'relations.defines_kingdom'
field: 'relations.root_for_kingdom'
18 changes: 4 additions & 14 deletions eczoodb/test_data/codetree/kingdoms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,12 @@ kingdoms_by_domain_id:
classical_domain:
- kingdom_id: bits_into_bits
name: 'Bits Kingdom (binary linear)'
kingdom_code:
code_id: binary_linear
root_codes:
- code_id: binary_linear

quantum_domain:
- kingdom_id: qubits_into_qubits
name: 'Qubit Kingdom'
kingdom_code:
code_id: qubits_into_qubits
root_codes:
- code_id: qubits_into_qubits

# - kingdom_id: qudits_into_qudits
# name: 'Qu\emph{d}it Kingdom'
# kingdom_code: {'code_id': 'qudits_into_qudits'}
# - kingdom_id: oscillators
# name: 'Oscillator Kingdom'
# kingdom_code: {'code_id': 'oscillators'}
# - kingdom_id: group_quantum
# name: 'Group Kingdom'
# kingdom_code: {'code_id': 'group_quantum'}

Loading

0 comments on commit b7dcb13

Please sign in to comment.