Skip to content

Commit

Permalink
Implement disjointWith parsing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
minottic committed Jul 31, 2024
1 parent 19b2f90 commit 2d95561
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/__tests__/fixtures/MockStubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const xmlContent = `<?xml version="1.0"?>
<owl:Class rdf:about="class3">
<rdfs:subClassOf rdf:resource="http://class2/label2"/>
<owl:disjointWith rdf:resource="aDescription5"/>
<rdfs:label rdf:datatype="aLabel">label3</rdfs:label>
<owl:equivalentClass rdf:resource="class6"/>
<owl:equivalentClass rdf:resource="class7"/>
Expand Down
20 changes: 13 additions & 7 deletions src/__tests__/unit/technique-getter.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down Expand Up @@ -406,7 +402,6 @@ describe('GitHubOwlTechnique', () => {
prefLabel: 'label3',
parents: [
'http://class2/label2',
'aDescription5',
'aDescription6',
'class1',
'class5',
Expand All @@ -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']),
},
Expand Down Expand Up @@ -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();
});
});
});
31 changes: 27 additions & 4 deletions src/misc/technique-getter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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']);
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -281,6 +296,14 @@ export class GitHubOwlTechnique extends OntologyTechnique {
o['leaves'] = o['leaves'].concat(this.filterLeaves(e));
});
}

async build(): Promise<this> {
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 {
Expand Down

0 comments on commit 2d95561

Please sign in to comment.