diff --git a/src/__tests__/fixtures/MockStubs.ts b/src/__tests__/fixtures/MockStubs.ts index 1adf209..9e5eae0 100644 --- a/src/__tests__/fixtures/MockStubs.ts +++ b/src/__tests__/fixtures/MockStubs.ts @@ -29,6 +29,7 @@ export const xmlContent = ` + label3 diff --git a/src/__tests__/unit/technique-getter.unit.ts b/src/__tests__/unit/technique-getter.unit.ts index 919dbe0..c76ea02 100644 --- a/src/__tests__/unit/technique-getter.unit.ts +++ b/src/__tests__/unit/technique-getter.unit.ts @@ -348,11 +348,7 @@ describe('GitHubOwlTechnique', () => { describe('parents', () => { it('checks the parents from the xml queried file', done => { const item = querySelectorXml[2]; - const parents = [ - 'http://class2/label2', - 'aDescription5', - 'aDescription6', - ]; + const parents = ['http://class2/label2', 'aDescription6']; expect(GitHubOwlTechnique.parents(item)).to.be.eql(parents); done(); }); @@ -406,7 +402,6 @@ describe('GitHubOwlTechnique', () => { prefLabel: 'label3', parents: [ 'http://class2/label2', - 'aDescription5', 'aDescription6', 'class1', 'class5', @@ -419,7 +414,6 @@ describe('GitHubOwlTechnique', () => { class1: new Set(['class1', 'class3']), 'http://class2/label2': new Set(['http://class2/label2', 'class3']), class3: new Set(['class3']), - aDescription5: new Set(['aDescription5', 'class3']), aDescription6: new Set(['aDescription6', 'class3']), class5: new Set(['class5', 'class3']), }, @@ -527,4 +521,16 @@ describe('GitHubOwlTechnique', () => { done(); }); }); + + describe('disjointWith', () => { + it('checks the equivalentClass from the xml queried file', done => { + expect(GitHubOwlTechnique.disjointWith(querySelectorXml[2])).to.be.eql([ + 'aDescription5', + ]); + expect(GitHubOwlTechnique.disjointClasses).to.be.eql({ + class3: ['aDescription5'], + }); + done(); + }); + }); }); diff --git a/src/misc/technique-getter.ts b/src/misc/technique-getter.ts index d565c90..13f21c6 100644 --- a/src/misc/technique-getter.ts +++ b/src/misc/technique-getter.ts @@ -122,6 +122,7 @@ export class GitHubOwlTechnique extends OntologyTechnique { url: string; collection: OwlTechniqueCollection[]; equivalentClasses: {[key: string]: string[]}; + disjointClasses: {[key: string]: string[]}; constructor(config: GitHubGetter) { super(); @@ -134,6 +135,7 @@ export class GitHubOwlTechnique extends OntologyTechnique { : 'latest/download'; this.file = config.file ?? 'PaNET.owl'; this.equivalentClasses = {}; + this.disjointClasses = {}; this.keys.push(...['prefLabel', 'synonym']); } @@ -222,10 +224,9 @@ export class GitHubOwlTechnique extends OntologyTechnique { parentsList.push(parent); i++; } - const parents = [ - ...new Set([...parentsList, ...this.equivalentClass(item)]), - ]; - return parents; + const parents = new Set([...parentsList, ...this.equivalentClass(item)]); + this.disjointWith(item).forEach(disjoint => parents.delete(disjoint)); + return [...parents]; } buildNodes( @@ -264,6 +265,20 @@ export class GitHubOwlTechnique extends OntologyTechnique { ]; } + disjointWith(item: Element) { + const pid = this.pid(item); + const disjointClasses = item.getElementsByTagName('owl:disjointWith'); + let i = 0; + const disjoints = []; + while (i < disjointClasses.length) { + const klass = this.pid(disjointClasses[i], 'rdf:resource'); + if (klass) disjoints.push(klass); + i++; + } + this.disjointClasses[pid] = disjoints; + return disjoints; + } + processInCollectionLoop( node: OwlTechniqueCollection, o: GitHubTechniqueNodes, @@ -281,6 +296,14 @@ export class GitHubOwlTechnique extends OntologyTechnique { o['leaves'] = o['leaves'].concat(this.filterLeaves(e)); }); } + + async build(): Promise { + await super.build(); + Object.entries(this.disjointClasses).map(([key, value]) => + value.forEach(v => this.relatives[key].delete(v)), + ); + return this; + } } export class BioPortalTechniques extends OntologyTechnique {