import java.io.*;
import java.util.*;
import edu.stanford.smi.protege.model.*;
/*
* This application just prints out all of the classes in a knowledge base
* and the direct instances of those classes.
*/
public class KnowledgeBasePrinter {
private static final String PROJECT_FILE_NAME = "c:\\temp\\newspaper\\newspaper.pprj";
public static void main(String[] args ){
Collection errors = new ArrayList();
Project project = new Project(PROJECT_FILE_NAME, errors);
if (errors.size() == 0) {
KnowledgeBase kb = project.getKnowledgeBase();
Iterator i = kb.getClses().iterator();
while (i.hasNext()) {
Cls cls = (Cls) i.next();
System.out.println("Class: " + cls.getName());
Iterator j = cls.getDirectInstances().iterator();
while (j.hasNext()) {
Instance instance = (Instance) j.next();
System.out.println(" Instance: " + instance.getName());
}
}
} else {
displayErrors(errors);
}
waitForContinue();
}
private static void displayErrors(Collection errors) {
Iterator i = errors.iterator();
while (i.hasNext()) {
System.out.println("Error: " + i.next());
}
}
private static void waitForContinue() {
System.out.println("Press <Enter> to continue");
try {
System.in.read();
} catch (Exception e) {}
}
}