repairframe.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,767 行 · 第 1/5 页
JAVA
1,767 行
private void displayPopup(String html, String title, int width, int height) {
JFrame popup = new JFrame();
JEditorPane pane = new JEditorPane();
pane.setContentType("text/html");
pane.setEditable(false);
pane.addHyperlinkListener(this);
pane.setText(html);
pane.setCaretPosition(0);
popup.getContentPane().add(new JScrollPane(pane));
popup.setSize(width, height);
popup.setLocation(100, 100);
popup.setTitle(title);
popup.show();
}
private void setCopyPaneText(JEditorPane copyPane, Set soln) {
String html = "<html><body>";
for (Iterator iter = soln.iterator(); iter.hasNext();) {
OWLObject axiom = (OWLObject) iter.next();
hcodeAxiomMap.put(String.valueOf(axiom.hashCode()), axiom);
html += insFont()+"<font color=\"blue\">[<a href=\":REMOVE:"+axiom.hashCode()+"\">X</a>]</font> ";
String rem = "Remove";
if (removedAxiomSet.contains(axiom)) rem = "Undo-Remove";
html += "<font color=\"red\">[<a href=\":FORCE:"+axiom.hashCode()+"\">"+rem+"</a>]</font> ";
html += "<font color=\"green\">[<a href=\":BLOCK:"+axiom.hashCode()+"\">Keep</a>]</font> ";
if (removedAxiomSet.contains(axiom)) html += "<font color = \"red\">";
html += this.getOWLObjectHTMLWithAttribs(axiom) + "<br>";
if (removedAxiomSet.contains(axiom)) html += "</font>";
}
html += "</body></html>";
copyPane.setText(html);
}
/*
* sort axioms in table based on specified parameter
*/
private void sortAndDisplayAxioms(int param) {
int numAxioms = currAxioms.size();
OWLObject[] sorted = new OWLObject[numAxioms];
HashMap sourceMap = null;
boolean increase = false;
switch (param) {
case ARITY:
sourceMap = axiomUnsatClaMap;
increase = false;
break;
case IMPACT:
increase = true;
sourceMap = axiomSOSMap;
break;
case USAGE:
increase = true;
sourceMap = axiomUsageMap;
break;
case RANK:
increase = true;
sourceMap = axiomRanksMap;
}
// sort based on sourceMap selected
for (Iterator iter = currAxioms.iterator(); iter.hasNext();) {
OWLObject axiom = (OWLObject) iter.next();
double metric = 0;
if (sourceMap.containsKey(axiom)) {
if (!sourceMap.equals(axiomRanksMap)) metric = ((HashSet) sourceMap.get(axiom)).size();
else {
String m = sourceMap.get(axiom).toString();
metric = Double.parseDouble(m);
}
}
for (int ctr=0; ctr<numAxioms; ctr++) {
OWLObject ax = sorted[ctr];
if (ax!=null) {
double metric2 = 0;
if (sourceMap.containsKey(ax)) {
if (!sourceMap.equals(axiomRanksMap)) metric2 = ((HashSet) sourceMap.get(ax)).size();
else {
metric2 = Double.parseDouble(sourceMap.get(ax).toString());
}
}
if ((increase && metric<metric2) || (!increase && metric>metric2)) {
insert(sorted, axiom, ctr);
break;
}
}
else {
insert(sorted, axiom, ctr);
break;
}
}
}
// refresh repair table after sorting
List order = new ArrayList();
for (int ctr=0; ctr<numAxioms; ctr++) order.add(sorted[ctr]);
this.refreshTable(order);
}
private void insert(Object[] array, Object obj, int pos) {
int len = array.length;
// System.out.println(array+" "+obj+" "+pos);
for (int i=len-2; i>=pos; i--) {
array[i+1] = array[i];
}
array[pos] = obj;
}
/*
* for each axiom, compute its relevance to the ontology based on usage
*/
private void computeUsage(OWLObject axiom) {
try {
OWLClass thing = ontology.getOWLDataFactory().getOWLThing();
OWLObjectContainer owlCont = new OWLObjectContainer(thing);
owlCont.visit(axiom);
List axiomElements = new ArrayList();
axiomElements.addAll(owlCont.getLHS());
axiomElements.addAll(owlCont.getRHS());
// get usage for each entity in axiom-elements
Set usage = new HashSet();
for (Iterator iter2=axiomElements.iterator(); iter2.hasNext();) {
Object obj = iter2.next();
if (obj instanceof OWLEntity) {
usage.addAll(OntologyHelper.entityUsage(ontology, (OWLEntity) obj));
}
}
for (Iterator iter2 = new HashSet(usage).iterator(); iter2.hasNext();) {
OWLObject obj = (OWLObject) iter2.next();
if (!(obj instanceof OWLEntity)) usage.remove(obj);
}
if (!turnOffUsage) axiomUsageMap.put(axiom, usage);
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private String getOWLObjectHTMLWithAttribs(OWLObject axiom) {
String html = "";
html += this.getOWLObjectHTML(axiom) + " (";
int arity = -1;
if (axiomUnsatClaMap.containsKey(axiom)) arity = ((HashSet) this.axiomUnsatClaMap.get(axiom)).size();
if (arity!=-1) {
String hash = String.valueOf(this.axiomUnsatClaMap.get(axiom).hashCode());
html += "Arity:<a href=\":HASH:Arity:"+hash+"\">"+String.valueOf(arity) + "</a>";
objectMap.put(hash, (HashSet) this.axiomUnsatClaMap.get(axiom));
}
int impact = -1;
Set impactSet = new HashSet();
if (axiomSOSMap.containsKey(axiom)) impactSet = (HashSet) this.axiomSOSMap.get(axiom);
impact = impactSet.size();
if (impact!=-1) {
String hash = String.valueOf(impactSet.hashCode());
objectMap.put(hash, impactSet);
html += " Impact: <a href=\":HASH:Impact:"+hash+"\">" + String.valueOf(impact)+"</a>";
}
int usage = -1;
if (axiomUsageMap.containsKey(axiom)) usage = ((HashSet) this.axiomUsageMap.get(axiom)).size();
if (usage!=-1) {
String hash = String.valueOf(this.axiomUsageMap.get(axiom).hashCode());
objectMap.put(hash, this.axiomUsageMap.get(axiom));
html += " Usage: <a href=\":HASH:Usage:"+hash+"\">" + String.valueOf(usage)+"</a>";
}
html += ")";
return html;
}
public void refreshPlan() {
refreshPlan(false);
int pos = indentPane.getCaretPosition();
this.refreshIndentPane();
try {
indentPane.setCaretPosition(pos);
}
catch (Exception ex) {
indentPane.setCaretPosition(0);
}
}
// refresh plan
// plan axioms are present in planSolnAxioms[0]
private void refreshPlan(boolean genPlans) {
String planStr = "<html><body>"+insFont();
// print solution axioms
Set mainSolnSet = planSolnAxioms[0];
if (!mainSolnSet.isEmpty()) {
// planStr += "<b><u>GENERATED REPAIR PLAN:" + " to "+ granularityCombo.getSelectedItem().toString()+"</u></b><br>";
for (Iterator iter = mainSolnSet.iterator(); iter.hasNext();) {
OWLObject axiom = (OWLObject) iter.next();
hcodeAxiomMap.put(String.valueOf(axiom.hashCode()), axiom);
planStr += insFont()+"<font color=\"blue\">[<a href=\":REMOVE:"+axiom.hashCode()+"\">X</a>]</font> ";
String rem = "Remove";
if (removedAxiomSet.contains(axiom)) rem = "Undo-Remove";
planStr += "<font color=\"red\">[<a href=\":FORCE:"+axiom.hashCode()+"\">"+rem+"</a>]</font> ";
planStr += "<font color=\"green\">[<a href=\":BLOCK:"+axiom.hashCode()+"\">Keep</a>]</font> ";
if (removedAxiomSet.contains(axiom)) planStr += "<font color = \"red\">";
planStr += this.getOWLObjectHTMLWithAttribs(axiom);
if (removedAxiomSet.contains(axiom)) planStr += "</font>";
// suggestions for rewrites?
if (rewriteEnabled) planStr += suggestRewrites(axiom);
planStr += "<br>";
}
// also add preview information directly
planStr += "<br>"+previewEffect(true);
}
else if (genPlans) {
planStr += "<br><b>No Plan Found.</b> Try changing one or more of the KEPT or REMOVED axioms.<br>";
}
planStr += "</body></html>";
planPane.setText(planStr);
planPane.setCaretPosition(0);
}
private String suggestRewrites(OWLObject axiom) {
String html = "";
try {
if (axiom instanceof OWLEquivalentClassesAxiom) {
// weaken equivalent to subclass
OWLEquivalentClassesAxiom equ = (OWLEquivalentClassesAxiom) axiom;
OWLClass cla = null;
for (Iterator iter = equ.getEquivalentClasses().iterator(); iter.hasNext();) {
OWLDescription desc = (OWLDescription) iter.next();
if (desc instanceof OWLClass) {
cla = (OWLClass) desc;
break;
}
}
Set copy = new HashSet(equ.getEquivalentClasses());
copy.remove(cla);
for (Iterator iter = copy.iterator(); iter.hasNext();) {
OWLDescription desc = (OWLDescription) iter.next();
OWLSubClassAxiom sub = ontology.getOWLDataFactory().getOWLSubClassAxiom(cla, desc);
hcodeAxiomMap.put(String.valueOf(sub.hashCode()), sub);
String rewrite = "Undo Rewrite";
// rewriteAxiomSet.add(sub);
if (!rewriteAxiomSet.contains(sub)) rewrite = "Rewrite?";
html += "<br>"+"<font face=\"Verdana\" size=2> |_[<a href=\":REWRITE:"+sub.hashCode()+"\">" + rewrite + "</a>] "+this.getOWLObjectHTML(sub)+"</font>";
}
}
else if (axiom instanceof OWLPropertyDomainAxiom) {
// rewrite domain into local property restriction
OWLPropertyDomainAxiom opd = (OWLPropertyDomainAxiom) axiom;
OWLProperty prop = opd.getProperty();
OWLDescription dom = opd.getDomain();
OWLDescription all = null;
if (prop instanceof OWLObjectProperty) {
OWLObject ran = ontology.getOWLDataFactory().getOWLThing();
if (prop.getRanges(ontology).size()>0) ran = (OWLObject) prop.getRanges(ontology).iterator().next();
all = ontology.getOWLDataFactory().getOWLObjectAllRestriction((OWLObjectProperty) prop, (OWLDescription) ran);
}
else {
OWLObject ran = ontology.getOWLDataFactory().getOWLConcreteDataType(new URI("http://www.w3.org/2001/XMLSchema#string"));
if (prop.getRanges(ontology).size()>0) ran = (OWLObject) prop.getRanges(ontology).iterator().next();
all = ontology.getOWLDataFactory().getOWLDataAllRestriction((OWLDataProperty) prop, (OWLDataType) ran);
}
OWLSubClassAxiom sub = ontology.getOWLDataFactory().getOWLSubClassAxiom(dom, all);
hcodeAxiomMap.put(String.valueOf(sub.hashCode()), sub);
String rewrite = "Undo Rewrite";
// rewriteAxiomSet.add(sub);
if (!rewriteAxiomSet.contains(sub)) rewrite = "Rewrite?";
html += "<br>"+"<font face=\"Verdana\" size=2> |_[<a href=\":REWRITE:"+sub.hashCode()+"\">" + rewrite + "</a>] "+this.getOWLObjectHTML(sub)+"</font>";
}
}
catch (Exception ex) {
ex.printStackTrace();
}
return html;
}
public void valueChanged(ListSelectionEvent e) {
if (e.getSource() == classList) {
refreshClaListSelection();
}
}
/*
* refresh table based on class list selection
* either display union or intersection of MUPS
*/
private void refreshClaListSelection() {
if (classList.getSelectedValue()!=null) {
// init the axiom set that is to be displayed
// based on selected classes and union/intersection
Set displayAxioms = new HashSet();
for (int i = 0; i < classList.getSelectedValues().length; i++) {
OWLClass cla = (OWLClass) classList.getSelectedValues()[i];
if (!claMUPSMap.containsKey(cla)) this.findMUPS(cla);
Set mups = new HashSet((Set) claMUPSMap.get(cla));
if (this.displayMUPSUnion) displayAxioms.addAll(mups);
else {
// display intersection
if (displayAxioms.isEmpty()) displayAxioms = mups;
else displayAxioms.retainAll(mups);
}
}
this.refreshTable(new ArrayList(displayAxioms));
this.sortAndDisplayAxioms(CURR_METRIC);
int pos = indentPane.getCaretPosition();
this.refreshIndentPane();
try {
indentPane.setCaretPosition(pos);
}
catch (Exception ex) {
indentPane.setCaretPosition(0);
}
}
else this.refreshTable(new ArrayList());
}
/*
* display indented sos for selected classes
*/
private void refreshIndentPane() {
try {
ConciseFormatEntityRenderer cfRend = new ConciseFormatEntityRenderer();
cfRend.setSwoopModel(swoopModel);
cfRend.visitor = cfRend.createVisitor();
Set claSet = new HashSet();
for (int i = 0; i < classList.getSelectedValues().length; i++) {
claSet.add(classList.getSelectedValues()[i]);
}
List claList = new ArrayList();
while (claSet.size()>0) {
// take any one class out of set
OWLClass cla = (OWLClass) claSet.iterator().next();
claList.add(cla);
claSet.remove(cla);
// find all other classes that share atleast one axiom
if (!claMUPSMap.containsKey(cla)) this.findMUPS(cla);
Set mups = new HashSet((Set) claMUPSMap.get(cla));
for (Iterator iter = mups.iterator(); iter.hasNext();) {
OWLObject axiom = (OWLObject) iter.next();
for (Iterator iter2 = ((Set) axiomUnsatClaMap.get(axiom)).iterator(); iter2.hasNext(); ) {
OWLClass sharedCla = (OWLClass) iter2.next();
if (claSet.contains(sharedCla)) {
claList.add(sharedCla);
claSet.remove(sharedCla);
}
}
}
}
String html = "<html><body>";
for (int i = 0; i < claList.size(); i++) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?