support for addressing an instance by descendants of its concept type
This commit is contained in:
parent
28d913f370
commit
1cd45aa352
@ -65,7 +65,7 @@ class CENode {
|
||||
|
||||
getInstanceByName(name, concept) {
|
||||
if (!name) { return null; }
|
||||
const possibleConcepts = concept ? concept.ancestors.map(ancestor => ancestor.id).concat(concept.id) : [];
|
||||
const possibleConcepts = concept ? [concept.id].concat(concept.ancestors.map(ancestor => ancestor.id)).concat(concept.descendants.map(descendant => descendant.id)) : [];
|
||||
for (const instance of this.instances) {
|
||||
if (instance && (concept ? possibleConcepts.indexOf(instance.concept.id) > -1 : true)) {
|
||||
if (instance.name.toLowerCase() === name.toLowerCase()) {
|
||||
|
@ -207,6 +207,7 @@ class CEParser {
|
||||
const relConceptName = match[2];
|
||||
const relInstanceName = match[3].replace(/'/g, '');
|
||||
const relConcept = this.node.getConceptByName(relConceptName);
|
||||
|
||||
if (relConcept) {
|
||||
let relInstance = this.node.getInstanceByName(relInstanceName, relConcept);
|
||||
if (!relInstance) {
|
||||
|
@ -64,16 +64,15 @@ class RuleEngine {
|
||||
if (typeof objectInstance === 'string') {
|
||||
return;
|
||||
}
|
||||
const rules = this.node.getInstances('rule');
|
||||
for (let i = 0; i < rules.length; i += 1) {
|
||||
const rule = RuleEngine.parseRule(rules[i].instruction);
|
||||
for (const ruleInstance of this.node.getInstances('rule')) {
|
||||
const rule = RuleEngine.parseRule(ruleInstance.instruction);
|
||||
if (!rule) { return; }
|
||||
if (rule.if.concept === subjectInstance.type.name) {
|
||||
if ((propertyType === 'relationship' && rule.if.relationship) || (propertyType === 'value' && rule.if.value)) {
|
||||
const ancestorConcepts = objectInstance.type.ancestors;
|
||||
ancestorConcepts.push(objectInstance.type);
|
||||
for (let j = 0; j < ancestorConcepts.length; j += 1) {
|
||||
if (ancestorConcepts[j].name.toLowerCase() === rule.if[propertyType].type.toLowerCase()) {
|
||||
const ancestorConcepts = objectInstance.concept.ancestors;
|
||||
ancestorConcepts.push(objectInstance.concept);
|
||||
for (const ancestorConcept of ancestorConcepts) {
|
||||
if (ancestorConcept.name.toLowerCase() === rule.if[propertyType].type.toLowerCase()) {
|
||||
if (rule.then.relationship && rule.then.relationship.type === subjectInstance.type.name) {
|
||||
objectInstance.addRelationship(rule.then.relationship.label, subjectInstance, false, source);
|
||||
} else if (rule.then.value && rule.then.value.type === subjectInstance.type.name) {
|
||||
|
Loading…
Reference in New Issue
Block a user