repairframe.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,767 行 · 第 1/5 页
JAVA
1,767 行
// toolBar.add(settingsBtn);
toolBar.add(updatePlanChk);
toolBar.add(new JLabel(""));
toolBar.add(new JLabel(""));
toolBar.add(new JLabel(""));
JPanel topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
topPanel.add(axiomAnalysisPane, "Center");
topPanel.add(toolBar, "South");
mainPane.setTopComponent(topPanel);
planTabs = new JTabbedPaneWithCloseIcons();
planPane = new JEditorPane();
planPane.setContentType("text/html");
planPane.setEditable(false);
planPane.addHyperlinkListener(this);
planTabs.addTab("Main Plan", new JScrollPane(planPane));
JPanel planPanel = new JPanel();
planPanel.setLayout(new BorderLayout());
planPanel.add(planTabs, "Center");
clearBtn = createButton("Clear");
saveBtn = createButton("Save");
previewBtn = createButton("Preview");
execBtn = createButton("Execute");
JToolBar btnPanel = new JToolBar();
btnPanel.add(clearBtn);
btnPanel.add(saveBtn);
btnPanel.add(previewBtn);
btnPanel.add(execBtn);
planPanel.add(btnPanel, "South");
mainPane.setBottomComponent(planPanel);
content.add(mainPane);
this.setSize(1024, 740);
this.setLocation(1, 1);
this.setTitle("Repairing Ontology "+swoopModel.shortForm(ontology.getURI()));
this.show();
// set divider positions after displaying UI
axiomAnalysisPane.setDividerLocation(150);
mainPane.setDividerLocation(460);
axiomTablePane.setDividerLocation(0);
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private JButton createButton(String lbl) {
JButton btn = new JButton(lbl);
btn.setFont(tahoma);
btn.addActionListener(this);
return btn;
}
/*
* Used to prune explanation set obtained from Pellet
*/
public boolean checkSatisfiability(Set axioms, OWLDescription clazz) {
// create a new ontology with axioms
// and check satisfiability of clazz
boolean sat = false;
try {
OWLOntBuilder ontBuilder = new OWLOntBuilder();
// create new ontology using axioms
// use OWLOntBuilder to build a new ontology given axioms
for (Iterator iter = axioms.iterator(); iter.hasNext();) {
OWLObject obj = (OWLObject) iter.next();
obj.accept(ontBuilder);
}
// if clazz is not in ontology, return true
OWLOntology newOnt = ontBuilder.currentOnt;
if (clazz!=null && clazz instanceof OWLClass && newOnt.getClass(((OWLClass) clazz).getURI())==null) return true;
else if (clazz!=null) {
// get clazz in newOnt
clazz = ontBuilder.visitDescription(clazz);
}
// create new instance of pellet and check sat. of clazz
PelletReasoner newPellet = new PelletReasoner();
newPellet.setOntology(newOnt, false);
if (clazz!=null) sat = newPellet.isConsistent(clazz);
else sat = newPellet.isConsistent();
}
catch (Exception ex) {
System.out.println(ex.getMessage()); // clazz (description) may not be in ontology!
// ex.printStackTrace();
return true;
}
return sat;
}
private String insFont() {
return("<FONT FACE=\""+swoopModel.getFontFace()+"\" SIZE="+swoopModel.getFontSize()+">");
}
/* (non-Javadoc)
* @see javax.swing.event.HyperlinkListener#hyperlinkUpdate(javax.swing.event.HyperlinkEvent)
*/
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
// if (e.getSource() == repTable || e.getSource() == planPane) {
String hLink = e.getDescription();
if (isURI(hLink)) {
try {
if (DEBUG) logFile += NEWLINE + "Clicking URI: "+hLink+" "+swoopModel.getTimeStamp();
URI uri = new URI(hLink);
// popup entity
// if entity already displayed, return
if (uri.equals(swoopModel.selectedOWLObject.getURI())) return;
if (swoopModel.getOntologyURIs().contains(uri)) {
swoopHandler.ontDisplay.selectOntology(swoopModel.getOntology(uri));
}
else {
swoopHandler.termDisplay.selectEntity(hLink);
// popup entity
ConciseFormatEntityRenderer cfRend = new ConciseFormatEntityRenderer();
boolean temp = swoopModel.getEditorEnabled();
swoopModel.setEditorEnabled(false);
cfRend.setSwoopModel(swoopModel);
cfRend.createVisitor();
StringWriter st = new StringWriter();
cfRend.render(swoopModel.getSelectedEntity(), swoopModel, st);
displayPopup(st.toString(), swoopModel.shortForm(swoopModel.getSelectedEntity().getURI()));
swoopModel.setEditorEnabled(temp);
}
}
catch (Exception e1) {
e1.printStackTrace();
}
}
else if (hLink.startsWith(":DISP_UNION")) {
if (DEBUG) logFile += NEWLINE + "Switched MUPS Union: "+String.valueOf(!this.displayMUPSUnion)+ " "+swoopModel.getTimeStamp();
this.displayMUPSUnion = !this.displayMUPSUnion;
this.refreshClaListSelection();
}
else
if (hLink.startsWith(":FORCE")) {
// (un)force axiom into solution set
if (DEBUG) logFile += NEWLINE + "REMOVED Axiom "+swoopModel.getTimeStamp();
String hcode = hLink.substring(hLink.lastIndexOf(":")+1, hLink.length());
OWLObject axiom = (OWLObject) hcodeAxiomMap.get(hcode);
if (removedAxiomSet.contains(axiom)) {
removedAxiomSet.remove(axiom);
// solnAxiomSet.remove(axiom); ??
}
else
if (!keptAxiomSet.contains(axiom)) {
removedAxiomSet.add(axiom);
}
removedBtn.setText("Removed Axioms ("+removedAxiomSet.size()+")");
this.refreshRemovedFrame();
if (this.updatePlanChk.isSelected()) {
this.genPlan();
}
this.sortAndDisplayAxioms(CURR_METRIC);
this.refreshPlan();
planTabs.setSelectedIndex(0);
}
else
if (hLink.startsWith(":BLOCK")) {
if (DEBUG) logFile += NEWLINE + "KEPT Axiom "+swoopModel.getTimeStamp();
// toggle axiom blocked status (i.e. if blocked, it cannot be part of the solution)
String hcode = hLink.substring(hLink.lastIndexOf(":")+1, hLink.length());
OWLObject axiom = (OWLObject) hcodeAxiomMap.get(hcode);
if (!keptAxiomSet.contains(axiom)) {
keptAxiomSet.add(axiom);
// also remove axiom from forced set and soln set
Set mainSolnSet = planSolnAxioms[0];
if (removedAxiomSet.contains(axiom) || mainSolnSet.contains(axiom)) {
removedAxiomSet.remove(axiom);
mainSolnSet.remove(axiom);
}
}
else keptAxiomSet.remove(axiom);
keptBtn.setText("Kept Axioms ("+keptAxiomSet.size()+")");
this.refreshKeptFrame();
if (this.updatePlanChk.isSelected()) {
this.genPlan();
}
this.sortAndDisplayAxioms(CURR_METRIC);
this.refreshPlan();
planTabs.setSelectedIndex(0);
}
else
if (hLink.startsWith(":REMOVE")) {
if (DEBUG) logFile += NEWLINE + "DISCARDED Axiom "+swoopModel.getTimeStamp();
// remove axiom from soln set
String hcode = hLink.substring(hLink.lastIndexOf(":")+1, hLink.length());
OWLObject remAxiom = (OWLObject) hcodeAxiomMap.get(hcode);
int num = 0;
String title = planTabs.getTitleAt(planTabs.getSelectedIndex());
if (title.indexOf("Main")==-1) num = Integer.parseInt(title.substring(title.lastIndexOf(" ")+1), title.length())-1;
Set soln = planSolnAxioms[num];
soln.remove(remAxiom);
// manualAxiomSet.remove(axiom); ??
if (planTabs.getSelectedIndex()!=0) {
JEditorPane copyPane = (JEditorPane) planTabs.getSelectedComponent();
this.setCopyPaneText(copyPane, soln);
}
else {
this.refreshPlan();
}
}
else
if (hLink.equals(":ARITY")) {
if (DEBUG) logFile += NEWLINE + "Sorting by ARITY "+swoopModel.getTimeStamp();
// sort axioms by arity
CURR_METRIC = ARITY;
this.sortAndDisplayAxioms(ARITY);
}
else if (hLink.equals(":IMPACT")) {
if (DEBUG) logFile += NEWLINE + "Sorting by IMPACT "+swoopModel.getTimeStamp();
// sort axioms by impact
CURR_METRIC = IMPACT;
this.sortAndDisplayAxioms(IMPACT);
}
else if (hLink.equals(":USAGE")) {
if (DEBUG) logFile += NEWLINE + "Sorting by USAGE "+swoopModel.getTimeStamp();
// sort axioms by usage
CURR_METRIC = USAGE;
this.sortAndDisplayAxioms(USAGE);
}
else if (hLink.equals(":RANK")) {
if (DEBUG) logFile += NEWLINE + "Sorting by RANK "+swoopModel.getTimeStamp();
// sort axioms by rank
CURR_METRIC = RANK;
this.sortAndDisplayAxioms(RANK);
}
else if (hLink.startsWith(":REWRITE")) {
String hashCode = hLink.substring(hLink.lastIndexOf(":")+1, hLink.length());
OWLObject axiom = (OWLObject) hcodeAxiomMap.get(hashCode);
if (DEBUG) {
if (rewriteAxiomSet.contains(axiom)) logFile += NEWLINE + "Chose to UNDO REWRITE "+swoopModel.getTimeStamp();
else logFile += NEWLINE + "Chose to REWRITE "+swoopModel.getTimeStamp();
}
if (rewriteAxiomSet.contains(axiom)) rewriteAxiomSet.remove(axiom);
else rewriteAxiomSet.add(axiom);
// TODO
// if (this.updatePlanChk.isSelected()) {
// this.genPlan();
// }
this.refreshPlan();
}
else if (hLink.startsWith(":HASH")) {
// display arity/impact in popup
String param = hLink.substring(6, hLink.lastIndexOf(":"));
if (DEBUG) logFile += NEWLINE + "Viewing Parameter: "+param+" "+swoopModel.getTimeStamp();
String hashCode = hLink.substring(hLink.lastIndexOf(":")+1, hLink.length());
Set disp = (HashSet) objectMap.get(hashCode);
String html = "<html><body>";
int ctr = 1;
for (Iterator iter = disp.iterator(); iter.hasNext();) {
OWLObject obj = (OWLObject) iter.next();
swoopModel.repairColor = true;
swoopModel.repairSet = new HashSet(currUnsat);
html += insFont() + String.valueOf(ctr++) + ". "+this.getOWLObjectHTML(obj);
swoopModel.repairColor = false;
swoopModel.repairSet = new HashSet();
// also add why? link if present
if (whyMap.containsKey(obj)) {
this.hcodeAxiomMap.put(String.valueOf(obj.hashCode()), obj);
html += " (<a href=\":WHY:"+obj.hashCode()+"\">Why?</a>)";
}
html += "<br>";
}
displayPopup(html, param+" Details");
}
else if (hLink.startsWith(":WHY")) {
// display explanation for impact related to unsat. classes
try {
String param = hLink.substring(hLink.lastIndexOf(":")+1, hLink.length());
if (DEBUG) logFile += NEWLINE + "Viewing Entailment Explanation: "+param+" "+swoopModel.getTimeStamp();
OWLObject entailment = (OWLObject) this.hcodeAxiomMap.get(param);
Set expl = (HashSet) whyMap.get(entailment);
String html = "<html><body>";
html += "<font face=\"Verdana\" size=3><b>Explanation for "+ this.getOWLObjectHTML(entailment) +"</b><hr>";
// get indented explanation
ConciseFormatEntityRenderer cfRend = new ConciseFormatEntityRenderer();
cfRend.setSwoopModel(swoopModel);
cfRend.visitor = cfRend.createVisitor();
StringWriter st = new StringWriter();
PrintWriter buffer = new PrintWriter(st);
cfRend.setWriter(buffer);
OWLClass thing = ontology.getOWLDataFactory().getOWLThing();
OWLObjectContainer cont = new OWLObjectContainer(thing);
cont.visit(entailment);
OWLClass any = null;
if (cont.getLHS().size()>0) any = (OWLClass) cont.getLHS().iterator().next();
else any = (OWLClass) cont.getRHS().iterator().next();
if (any==null) any = thing;
cfRend.printRepairSOS(expl, any, this);
String sosStr = st.toString().replaceAll("problem", "entailment");
html += "<font face=\"Verdana\" size=3>" + sosStr;
displayPopup(html, "Why?", 600, 200);
}
catch (OWLException ex) {
ex.printStackTrace();
}
}
// }
}
}
private void refreshKeptFrame() {
// print forced axioms first
String planStr = "<html><head></head><body>";
if (!keptAxiomSet.isEmpty()) {
planStr += insFont(); //+"<b>Axioms to be KEPT in Ontology</b><br>";
for (Iterator iter = keptAxiomSet.iterator(); iter.hasNext();) {
OWLObject axiom = (OWLObject) iter.next();
hcodeAxiomMap.put(String.valueOf(axiom.hashCode()), axiom);
planStr += "<font color=\"green\">[<a href=\":BLOCK:"+axiom.hashCode()+"\">Undo Keep</a>]</font> ";
planStr += this.getOWLObjectHTMLWithAttribs(axiom) + "<br>";
}
planStr += "<br>";
}
planStr += "</body></html>";
keptPane.setText(planStr);
}
private void refreshRemovedFrame() {
// print blocked axioms
String planStr = "<html><head></head><body>";
if (!removedAxiomSet.isEmpty()) {
planStr += insFont(); //+"<b>Axioms to be REMOVED from Ontology</b><br>";
for (Iterator iter = removedAxiomSet.iterator(); iter.hasNext();) {
OWLObject axiom = (OWLObject) iter.next();
hcodeAxiomMap.put(String.valueOf(axiom.hashCode()), axiom);
planStr += "<font color=\"red\">[<a href=\":FORCE:"+axiom.hashCode()+"\">Undo Remove</a>]</font> ";
planStr += this.getOWLObjectHTMLWithAttribs(axiom) + "<br>";
}
planStr += "<br>";
}
planStr += "</body></html>";
removedPane.setText(planStr);
}
private void displayPopup(String html, String title) {
this.displayPopup(html, title, 400, 300);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?