Skip to content

Commit

Permalink
AI map entities classes
Browse files Browse the repository at this point in the history
This PR introduces logic which labels entities with their DBpedia
ontological classes. Using this logic, it creates a file which tags
every unique entity found for the AI map dataset with their respective
classes.

closes #120
  • Loading branch information
doogyb committed Jun 20, 2022
1 parent c066dbc commit 5e409be
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 10 deletions.
47 changes: 47 additions & 0 deletions src/bin/dbpedia/getClasses.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { promises as fs } from 'fs';

import { Command, InvalidArgumentError } from 'commander';
import * as _ from 'lamb';

import { arxliveCopy } from 'conf/config.mjs';
import { getClasses } from 'dbpedia/requests.mjs';
import { getEntities } from 'es/entities.mjs';

const program = new Command();
program.option(
'-d, --domain <domain>',
'ES domain on which to aggregate',
arxliveCopy
);
program.option('-i, --index <index>', 'ES index from which to get titles');
program.option('-f, --path <path>', 'Path to file containing DBpedia titles');
program.requiredOption('-o, --out <output>', 'Path of output file');

program.parse();
const options = program.opts();

const main = async () => {
if (!options.index && !options.path) {
throw new InvalidArgumentError(`
You must specify either the index containing the DBpedia entities
or a path to the file containing the entities\' titles`
);
}
if (options.index && options.path) {
throw new InvalidArgumentError(`
Ambigous input. Do you want to use the index or the file as input?`
);
}

// previous checks garauntee the following:
const titles = options.index
? await getEntities(options.index)
: JSON.parse(await fs.readFile(options.path));

const sample=titles.slice(100, 110);
console.log(sample);
console.log(await getClasses(sample, { depth: 10, squash: true, fullURI:true }));

};

main();
22 changes: 22 additions & 0 deletions src/node_modules/dbpedia/ontology.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 46 additions & 2 deletions src/node_modules/dbpedia/requests.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions src/node_modules/es/entities.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions src/node_modules/util/array.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5e409be

Please sign in to comment.