📄 jracer.java
字号:
if(index != -1)
name = name.substring(0, index);
index = name.lastIndexOf( '/' );
if(index != -1)
name = name.substring(index + 1);
System.out.print( "Reading " + name + "..." );
Timer t = timers.startTimer( "reading" );
racer.RACERreadFile( file );
t.stop();
System.out.print( "done. (" + t.getTotal() + ") ");
}
void reset() throws RacerException, IOException {
racer.deleteAllTBoxes();
racer.deleteAllABoxes();
timers.resetAll();
}
void info() throws IOException, RacerException {
System.out.print("Classes: " + racer.allAtomicConcepts().length + " " );
System.out.print("Properties: " + racer.allRoles().length + " " );
System.out.print("Individuals: " + racer.allIndividuals().length );
System.out.println();
}
void consistency() throws IOException, RacerException {
System.out.print( "ABox Consistency..." );
t = timers.startTimer( "consistency" );
racer.aboxConsistentP();
t.stop();
System.out.println( "done. (" + t.getTotal() + ")");
}
void classify() throws IOException, RacerException {
System.out.print( "Classifying..." );
t = timers.startTimer( "classify" );
racer.classifyTBox();
t.stop();
System.out.println( "done. (" + t.getTotal() + ") ");
}
void realize() throws IOException, RacerException {
System.out.print( "Realizing..." );
t = timers.startTimer( "realize" );
racer.realizeABox();
t.stop();
System.out.println( "done. (" + t.getTotal() + ") " );
}
void query(String name, String qry) throws IOException, RacerException {
System.out.print( "Realizing..." );
t = timers.startTimer( name );
racer.send( qry );
t.stop();
System.out.println( "done. (" + t.getTotal() + ") " );
}
void createTree() throws Exception {
JTree tree = new JTree(new DefaultTreeModel(createNode("TOP")));
JFrame frame = new JFrame();
frame.getContentPane().add(new JScrollPane(tree));
frame.setVisible(true);
}
DefaultMutableTreeNode createNode(String concept) throws Exception {
DefaultMutableTreeNode node = new DefaultMutableTreeNode();
String label = concept;
String[] eqs = racer.conceptSynonyms( concept );
for(int i = 0; i < eqs.length; i++) {
if( !eqs[i].equals( concept ) )
label += " = " + eqs[i];
}
node.setUserObject( label );
String[] subs = racer.conceptChildren( concept );
for(int i = 0; i < subs.length; i++) {
if( subs[i].equals( "BOTTOM" ) ) continue;
node.add( createNode( subs[i] ) );
}
return node;
}
void printTree(String concept, String indent) throws Exception {
if( concept.equals( "BOTTOM" ) ) return;
System.out.print( indent + concept );
String[] eqs = racer.conceptSynonyms( concept );
for(int i = 0; i < eqs.length; i++) {
if( !eqs[i].equals( concept ) )
System.out.print( " = " + eqs[i] );
}
if( racer.aboxRealizedP() ) {
String[] instances = racer.conceptInstances( concept );
if( instances.length > 0 ) System.out.print( " (" );
for(int i = 0; i < instances.length; i++) {
if( i > 0 ) System.out.print( ", " );
System.out.print( instances[i] );
}
if( instances.length > 0 ) System.out.print( ")" );
}
System.out.println();
indent += " ";
String[] subs = racer.conceptChildren( concept );
for(int i = 0; i < subs.length; i++) {
printTree( subs[i], indent );
}
}
void print(String[] data, String header) throws Exception {
System.out.println( header + " (" + data.length + ")");
for(int i = 0; i < data.length; i++) {
System.out.println( data[i] );
}
}
void printTBox() throws Exception {
concepts = racer.allAtomicConcepts();
conceptSet = new HashSet( Arrays.asList(concepts));
for(int i = 0; i < concepts.length; i++) {
String concept = concepts[i];
printTBox(concept);
}
}
void printTBox(String concept) throws Exception {
if( concept.equals( "BOTTOM" ) || conceptSet.contains( concept ) ) return;
System.out.print("(");
printConcept(concept);
System.out.print(" ");
String[] supers = racer.conceptParents( concept );
if(supers.length == 0) {
System.out.print("NIL");
}
else {
System.out.print("(");
for(int i = 0; i < supers.length; i++) {
if( i > 0 ) System.out.print( " " );
printConcept( supers[i] );
}
System.out.print(")");
}
System.out.print(" ");
String[] subs = racer.conceptChildren( concept );
if(subs.length == 0) {
System.out.print("NIL");
}
else {
System.out.print("(");
for(int i = 0; i < subs.length; i++) {
if( i > 0 ) System.out.print( " " );
printConcept( subs[i] );
}
System.out.print(")");
}
System.out.println(")");
}
void printABox() throws Exception {
for(int i = 0; i < concepts.length; i++) {
String concept = concepts[i];
printTBox(concept);
}
}
void printABox(String concept) throws Exception {
if( concept.equals( "BOTTOM" ) ) return;
System.out.print("(");
printConcept(concept);
System.out.print(" ");
String[] instances = racer.conceptInstances( concept );
if(instances.length == 0) {
System.out.print("NIL");
}
else {
System.out.print("(");
for(int i = 0; i < instances.length; i++) {
if( i > 0 ) System.out.print( " " );
System.out.print( instances[i] );
}
System.out.print(")");
}
System.out.println(")");
}
void printConcept(String concept) throws Exception {
String[] eqs = filter( racer.conceptSynonyms( concept ) );
if(eqs.length>1) System.out.print("(");
for(int i = 0; i < eqs.length; i++) {
if( i > 0 ) System.out.print( " " );
System.out.print( eqs[i] );
}
if(eqs.length>1) System.out.print(")");
}
String[] filter(String[] array) {
List list = new ArrayList(Arrays.asList(array));
list.remove("*TOP*");
list.remove("*BOTTOM*");
return (String[]) list.toArray(new String[list.size()]);
}
public int findMatchingP( String qry ) throws Exception {
int openBracket = 0;
for(int i = 0; i < qry.length(); i++) {
char c = qry.charAt(i);
if( c == '(' )
openBracket++;
else if( c == ')' ) {
openBracket--;
if( openBracket == 0 )
return i;
}
}
return -1;
}
void close() throws IOException {
racer.closeConnection();
}
public static void main(String[] args) throws Exception{
JRacer test = new JRacer();
try {
test.run();
// test.runDLBenchmark();
// test.runLUBM(Integer.parseInt(args[0]));
}
catch( Exception e ) {
// TODO Auto-generated catch block
e.printStackTrace();
}
test.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -