forked from cmungall/owljs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
owljs-dlquery.js
executable file
·57 lines (49 loc) · 1.98 KB
/
owljs-dlquery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var Parser = require('ringo/args').Parser;
var system = require('system');
var {OWL} = require("owljs");
var owl;
function main(args) {
var script = args.shift();
var parser = new Parser(system.args);
var grepFunc = null;
parser.addOption('h', 'help', null, 'Display help');
parser.addOption('q', 'query', 'ManchesterString', 'class expression in owltools manchester syntax (all labels enclosed in single quotes)');
parser.addOption('r', 'reasoner', 'Reasoner', 'set reasoner factory. Default is elk.');
parser.addOption('a', 'ancestors', null, 'TODO');
parser.addOption('d', 'direct', null, 'direct only (defaults to direct plus indirect)');
parser.addOption('p', 'property', 'ObjectProperty', 'ancestors over specified relation. queries SELECT ?x WHERE {CLASSEXPR SubClassOf ?p some ?x}');
var options = parser.parse(args);
if (options.help) {
print("Usage: owljs-dlquery OPTIONS OWLFILE\n");
print("DL-query");
print("\nOptions:");
print(parser.help());
print("\nExample (what are the things that are parts of some cell):");
print("$ owljs-dlquery -r elk \"'part_of' some 'cell'\" foo.owl");
print("\nExample (what does this cell type have as parts)?:");
print("$ owljs-dlquery -p has_part -q \"'small pre-B-II cell'\" cl-edit.owl");
system.exit('-1');
}
owl = new OWL();
owl.addCatalog();
args.forEach(function(fn) { owl.loadFile(fn) } );
var cx = owl.parseManchesterExpression(options.query);
owl.log("Query="+cx);
var subs;
if (options.property == null) {
subs = owl.getInferredSubClasses(cx);
}
else {
var objprop = owl.find(options.property);
owl.log("Prop="+objprop);
subs = owl.getAncestorsOver(cx, objprop, false, options.direct != null);
}
subs.forEach(show);
}
function show(c) {
print(c + " " + owl.getLabel(c));
}
// call the main method; ringo specific
if (require.main == module.id) {
main(system.args);
}