-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathowljs-refilter.js
executable file
·78 lines (65 loc) · 2.36 KB
/
owljs-refilter.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var Parser = require('ringo/args').Parser;
var system = require('system');
var {OWL} = require("owljs");
function main(args) {
var script = args.shift();
var parser = new Parser(system.args);
var re = null;
parser.addOption('h', 'help', null, 'Display help');
parser.addOption('v', 'invertMatch', null, 'Invert (negate) match');
parser.addOption('o', 'outputFile', 'File', 'output file (defaults to stdout)');
parser.addOption('t', 'toOutputFormat', 'OWLOntologyFormat', 'output format (defaults to RDFXML)');
parser.addOption('j', 'jsFrames', null, 'writes output as js frames');
var options = parser.parse(args);
if (options.help) {
print("Usage: owljs-cgrep OPTIONS [PATTERN] OWLFILE\n");
print("Filters class from an ontology using a regexp. Compare with owljs-grep, which greps axioms");
print("\nOptions:");
print(parser.help());
print("\nExample:");
print("owljs-cgrep /epithelium/ foo.owl");
system.exit('-1');
}
var owl = new OWL();
if (options.toOutputFormat != null) {
console.log("Setting format to "+options.toOutputFormat);
owl.setDefaultFormat(options.toOutputFormat);
}
var reStr = args.shift();
if (reStr.indexOf("/") != 0) {
reStr = "/" + reStr + "/";
}
var re = eval(reStr);
args.forEach(function(fn) { owl.loadFile(fn) } );
if (options.load != null) {
owl.log("Loading "+options.load);
}
var clist = owl.mfind(re);
owl.log("#filteredClasses = " + clist.length);
if (options.jsFrames) {
var repl = require("owljs/repl");
repl.owlinit(owl);
//repl.owl = owl;
for (var ci in clist) {
var c = clist[ci];
var fr = owl.getFrame(c);
print(repl.render(fr));
}
}
else {
var filteredAxioms = [];
for (var ci in clist) {
var c = clist[ci];
var axioms = owl.getAllAxioms(c);
console.log(c+" #axioms = "+axioms.length);
filteredAxioms = filteredAxioms.concat(axioms);
}
owl.log("#filteredAxioms = " + filteredAxioms.length);
owl.log("Saving to " + options.outputFile);
owl.saveAxioms(filteredAxioms, null, options.outputFile);
}
}
// call the main method; ringo specific
if (require.main == module.id) {
main(system.args);
}