repairframe.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,767 行 · 第 1/5 页
JAVA
1,767 行
}
}
}
disjoints.add(obj);
}
}
}
}
else if (axiom instanceof OWLPropertyDomainAxiom) {
OWLPropertyDomainAxiom pd = (OWLPropertyDomainAxiom) axiom;
Set onts = new HashSet();
onts.add(ontology);
if (pd.getDomain() instanceof OWLClass) {
OWLClass dom = (OWLClass) pd.getDomain();
Set sup = OWLDescriptionFinder.getSuperClasses(dom, onts);
for (Iterator iter2 = sup.iterator(); iter2.hasNext();) {
OWLDescription supCla = (OWLDescription) iter2.next();
OWLPropertyDomainAxiomImpl ax = new OWLPropertyDomainAxiomImpl((OWLDataFactoryImpl) ontology.getOWLDataFactory(), pd.getProperty(), supCla);
this.addAxiom(axiomSOSMap, axiom, ax);
}
}
}
else if (axiom instanceof OWLObjectPropertyRangeAxiom) {
OWLObjectPropertyRangeAxiom pd = (OWLObjectPropertyRangeAxiom) axiom;
Set onts = new HashSet();
onts.add(ontology);
if (pd.getRange() instanceof OWLClass) {
OWLClass ran = (OWLClass) pd.getRange();
Set sup = OWLDescriptionFinder.getSuperClasses(ran, onts);
for (Iterator iter2 = sup.iterator(); iter2.hasNext();) {
OWLClass supCla = (OWLClass) iter2.next();
OWLObjectPropertyRangeAxiomImpl ax = new OWLObjectPropertyRangeAxiomImpl((OWLDataFactoryImpl) ontology.getOWLDataFactory(), pd.getProperty(), supCla);
this.addAxiom(axiomSOSMap, axiom, ax);
}
}
}
}
catch (OWLException ex) {
ex.printStackTrace();
}
if (axiomSOSMap.containsKey(axiom)) impact = ((HashSet) this.axiomSOSMap.get(axiom)).size();
// get usage
int usage = ((HashSet) this.axiomUsageMap.get(axiom)).size();
double rank = this.calculateRank(arity, impact, usage);
String rankStr = String.valueOf(rank);
if (rankStr.length()>4) rankStr = rankStr.substring(0, 4);
axiomRanksMap.put(axiom, rankStr);
}
}
/*
* Populate class list with unsat classes
*/
private void populateClassList() {
Set claSet = new TreeSet(EntityComparator.INSTANCE);
claSet.addAll(currUnsat);
// claSet.add("<All Unsatisfiable>");
// claSet.add("<All Roots>");
classList.setListData(claSet.toArray());
// select root classes
int[] indices = new int[currRoots.size()];
int i = 0;
for (int ctr=0; ctr<classList.getModel().getSize(); ctr++) {
if (currRoots.contains(classList.getModel().getElementAt(ctr)))
indices[i++] = ctr;
}
classList.setSelectedIndices(indices);
this.refreshClaListSelection();
}
/*
* refresh axiom results
*/
private void refreshTable(List order) {
// set current Axioms displayed
this.currAxioms = order;
String html = "<html><body>";
String dispUnion = "Union (<a href=\":DISP_UNION\">Toggle</a>)";
if (!this.displayMUPSUnion) dispUnion = "Intersection (<a href=\":DISP_UNION\">Toggle</a>)";
html += insFont()+"Displaying Axioms in " + dispUnion + " of MUPS of Selected Classes <br>";
// html += insFont() + "<b>Root Classes: ";
// for (Iterator iter = currRoots.iterator(); iter.hasNext();) {
// OWLClass root = (OWLClass) iter.next();
// html += this.getOWLObjectHTML(root) + " ";
// }
html += "</b><hr><table border=\"1\">";
html += "<tr><td>"+insFont()+"<b>Erroneous Axioms</b></td><td>"+insFont()+"<b><a href=\":ARITY\">Arity</a></b></td><td>"+insFont()+"<b><a href=\":IMPACT\">Impact</a></b></td><td>"+insFont()+"<b><a href=\":USAGE\">Usage</a></b></td><td>"+insFont()+"<b><a href=\":RANK\">Rank</a></b></td><td>"+insFont()+"<b>Status</b></td></tr>";
for (Iterator iter = order.iterator(); iter.hasNext();) {
OWLObject axiom = (OWLObject) iter.next();
if (keptAxiomSet.contains(axiom)) html += "<tr bgcolor=\"C3FDB8\"><td>";
else if (removedAxiomSet.contains(axiom)) html += "<tr bgcolor=\"FFDDDD\"><td>";
else html += "<tr><td>";
html += insFont();
hcodeAxiomMap.put(String.valueOf(axiom.hashCode()), axiom);
html += this.getOWLObjectHTML(axiom);
html += "</td>";
int arity = ((HashSet) this.axiomUnsatClaMap.get(axiom)).size();
String hash = String.valueOf(this.axiomUnsatClaMap.get(axiom).hashCode());
objectMap.put(hash, this.axiomUnsatClaMap.get(axiom));
html += "<td>" + insFont()+ "<a href=\":HASH:Arity:"+hash+"\">"+String.valueOf(arity) + "</a></td>";
int impact = 0;
Set impactSet = new HashSet();
if (axiomSOSMap.containsKey(axiom)) impactSet = (HashSet) this.axiomSOSMap.get(axiom);
impact = impactSet.size();
hash = String.valueOf(impactSet.hashCode());
objectMap.put(hash, impactSet);
html += "<td>" + insFont()+ "<a href=\":HASH:Impact:"+hash+"\">" + String.valueOf(impact) + "</td>";
int usage = ((HashSet) this.axiomUsageMap.get(axiom)).size();
hash = String.valueOf(this.axiomUsageMap.get(axiom).hashCode());
objectMap.put(hash, this.axiomUsageMap.get(axiom));
html += "<td>" + insFont()+ "<a href=\":HASH:Usage:"+hash+"\">" + String.valueOf(usage) + "</td>";
String rank = "-";
if (axiomRanksMap.containsKey(axiom)) rank = this.axiomRanksMap.get(axiom).toString();
html += "<td>" + insFont()+ rank + "</td>";
String rem = "Remove";
if (removedAxiomSet.contains(axiom)) rem="Undo";
html += "<td>"+insFont()+"<font color = \"red\">[<a href=\":FORCE:"+axiom.hashCode()+"\">"+rem+"</a>] </font>";
String keep = "Keep";
if (keptAxiomSet.contains(axiom)) keep = "Undo";
html += insFont()+"<font color = \"green\">[<a href =\":BLOCK:"+axiom.hashCode()+"\">"+keep+"</a>] </font>";
html += "</td>";
html += "</tr>";
}
html += "</table>";
html += "</body></html>";
repTable.setText(html);
repTable.setCaretPosition(0);
}
/*
* Use ConciseFormatEntityRender to get HTML for a particular OWLObject
*/
private String getOWLObjectHTML(OWLObject object) {
ConciseFormatEntityRenderer cfRend = new ConciseFormatEntityRenderer();
cfRend.setSwoopModel(swoopModel);
cfRend.visitor = cfRend.createVisitor();
StringWriter st = new StringWriter();
PrintWriter buffer = new PrintWriter(st);
cfRend.setWriter(buffer);
try {
cfRend.printObject(object);
} catch (OWLException e) {
e.printStackTrace();
}
return st.toString();
}
/*
* Refresh the reasoner (debugger) over the ontology
*/
private void refreshPelletDebuggerOntology(OWLOntology ont) {
pelletDebug = new Reasoner();
try {
pelletDebug.setOntology(ont);
} catch (OWLException e) {
e.printStackTrace();
}
pelletDebug.getKB().setDoExplanation(true);
pelletDebug.getKB().doDependencyTracking = true;
}
private void findMUPS(OWLDescription desc) {
this.findMUPS(desc, null);
}
/*
* Find MUPS of a single unsat. concept
* *** Store info in appropriate HashMaps: arity and usage ***
*/
private void findMUPS(OWLDescription desc, OWLObject entailment) {
try {
pelletDebug.isConsistent(desc);
Set explSet = pelletDebug.getKB().getExplanationSet();
// prune the axioms in case there are additional axioms
Set mups = new HashSet(explSet);
for (Iterator iter2 = explSet.iterator(); iter2.hasNext();) {
OWLObject axiom = (OWLObject) iter2.next();
mups.remove(axiom);
boolean sat = false;
sat = this.checkSatisfiability(mups, desc);
if (sat) {
mups.add(axiom);
// add axiom-cla relationship to hashmap
if (desc instanceof OWLClass) this.addAxiom(axiomUnsatClaMap, axiom, (OWLClass) desc);
if (entailment!=null) this.addAxiom(axiomSOSMap, axiom, entailment);
// compute usage of axiom when MUPS is found
this.computeUsage(axiom);
}
}
// also cross-references class with MUPS
if (desc instanceof OWLClass) this.claMUPSMap.put((OWLClass) desc, mups);
if (entailment!=null) this.whyMap.put(entailment, new HashSet(mups));
}
catch (OWLException ex) {
ex.printStackTrace();
}
}
/*
* return set of all MUPS of all root classes
*/
private Set findRootsMUPS() {
try {
Set rootMUPS = new HashSet();
for (Iterator iter = currRoots.iterator(); iter.hasNext();) {
OWLClass root = (OWLClass) iter.next();
if (!claMUPSMap.containsKey(root)) this.findMUPS(root);
rootMUPS.add(claMUPSMap.get(root));
}
return rootMUPS;
}
catch (Exception ex) {
ex.printStackTrace();
}
return new HashSet();
}
/*
* Add a pair of (axiom, ..) to the corresponding hashmap
*/
private void addAxiom(HashMap map, OWLObject axiom, Object desc) {
Set elems = new HashSet();
elems.add(desc);
if (map.containsKey(axiom)) elems.addAll((HashSet) map.get(axiom));
map.put(axiom, elems);
}
private void setupUI() {
try {
Container content = this.getContentPane();
JSplitPane mainPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
classList = new JList();
classList.setFont(tahoma);
classList.addListSelectionListener(this);
repTable = new JEditorPane();
repTable.setContentType("text/html");
repTable.setEditable(false);
repTable.addHyperlinkListener(this);
JPanel toprightPane = new JPanel();
toprightPane.setLayout(new BorderLayout());
JLabel wlbl = new JLabel("Weights: (Note: Rank = -W1 * arity + W2 * impact + W3 * usage)");
wlbl.setFont(tahoma);
w_arityFld = new JTextField("0.9");
w_impactFld = new JTextField("0.7");
w_usageFld = new JTextField("0.1");
JLabel ariLbl = new JLabel(" W1: ");
ariLbl.setFont(tahoma);
JLabel impLbl = new JLabel(" W2: ");
impLbl.setFont(tahoma);
JLabel usaLbl = new JLabel(" W3: ");
usaLbl.setFont(tahoma);
Box box1 = Box.createHorizontalBox();
box1.add(ariLbl);
box1.add(w_arityFld);
Box box2 = Box.createHorizontalBox();
box2.add(impLbl);
box2.add(w_impactFld);
Box box3 = Box.createHorizontalBox();
box3.add(usaLbl);
box3.add(w_usageFld);
rankBtn = new JButton("Recompute Ranks");
rankBtn.setFont(tahoma);
rankBtn.addActionListener(this);
JToolBar bar = new JToolBar();
bar.add(wlbl);
bar.add(box1);
bar.add(box2);
bar.add(box3);
bar.add(rankBtn);
viewGlobalChk = new JCheckBox("View Axioms Globally");
viewGlobalChk.setSelected(false);
viewGlobalChk.addActionListener(this);
bar.add(viewGlobalChk);
toprightPane.add(bar, "North");
indentPane = new JEditorPane();
indentPane.setContentType("text/html");
indentPane.setEditable(false);
indentPane.addHyperlinkListener(this);
axiomTablePane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
toprightPane.add(axiomTablePane, "Center");
axiomTablePane.setLeftComponent(new JScrollPane(repTable));
axiomTablePane.setRightComponent(new JScrollPane(indentPane));
JSplitPane axiomAnalysisPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
axiomAnalysisPane.setRightComponent(toprightPane);
axiomAnalysisPane.setLeftComponent(new JScrollPane(classList));
keptBtn = this.createButton("Kept Axioms (0)");
keptPane = new JEditorPane();
keptPane.setContentType("text/html");
keptPane.addHyperlinkListener(this);
keptPane.setEditable(false);
keptFrame = new JFrame("Axioms to be KEPT in Ontology");
keptFrame.getContentPane().add(new JScrollPane(keptPane));
keptFrame.setLocation(100, 100);
keptFrame.setSize(500, 300);
removedBtn = this.createButton("Removed Axioms (0)");
removedPane = new JEditorPane();
removedPane.setContentType("text/html");
removedPane.addHyperlinkListener(this);
removedPane.setEditable(false);
removedFrame = new JFrame("Axioms to be REMOVED from Ontology");
removedFrame.getContentPane().add(new JScrollPane(removedPane));
removedFrame.setLocation(100, 200);
removedFrame.setSize(500, 300);
impactUnsatChk = new JCheckBox("Extended Impact");
impactUnsatChk.setSelected(true);
impactUnsatChk.setFont(tahoma);
impactUnsatChk.addActionListener(this);
generateBtn = this.createButton("Generate Plan");
granularityCombo = new JComboBox();
granularityCombo.setFont(tahoma);
granularityCombo.addActionListener(this);
granularityCombo.addItem("Repair All Unsatisfiable");
granularityCombo.addItem("Repair All Roots");
granularityCombo.addItem("Repair Selected (above)");
granularityCombo.setSelectedIndex(1); // DEFAULT
granularityCombo.addItemListener(this);
rewriteChk = new JCheckBox("Include Rewrites");
rewriteChk.setFont(tahoma);
rewriteChk.addActionListener(this);
updatePlanChk = new JCheckBox("Auto Recompute Plan"); // (when changes are made)");
updatePlanChk.setFont(tahoma);
updatePlanChk.addActionListener(this);
updatePlanChk.setSelected(true);
settingsBtn = this.createButton("Settings");
JPanel toolBar = new JPanel();
toolBar.setLayout(new GridLayout(2,7));
toolBar.add(keptBtn);
toolBar.add(removedBtn);
toolBar.add(impactUnsatChk);
toolBar.add(new JLabel(""));
toolBar.add(new JLabel(""));
toolBar.add(new JLabel(""));
toolBar.add(new JLabel(""));
toolBar.add(generateBtn);
toolBar.add(granularityCombo);
toolBar.add(rewriteChk);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?