Commit 218763b4 authored by Romana Pernischova's avatar Romana Pernischova
Browse files

new impact measures

parent e3a8f107
chimp.plugin
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="openjdk-15" project-jdk-type="JavaSDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -101,6 +101,7 @@
<excludes>
<!-- Exclude performance tests-->
<exclude>**/*PerformanceTest.java</exclude>
<exclude>**/*Test.java</exclude>
</excludes>
</configuration>
</plugin>
......
......@@ -17,10 +17,14 @@ public class ChangeImpact extends Metric implements ImpactMetric {
private final ChimpReasoner customReasoner;
public ChangeImpact(ChimpReasoner customReasoner) {
super("Change Impact",
"This measure signals the amount of changed axioms (added and removed) in the materialization " +
"in comparison to the number of changes in the ontology.",
"\\gamma = \\frac{\\Delta_i^+ + \\Delta_i^-}{\\delta_i^+ + \\delta_i^-}");
super("Change-based Impact",
"This measure signals the amount of changed axioms (added and removed) in the materialization" +
" with \\Delta_i^+ and \\Delta_i^- " +
" in comparison to the number of changed axioms in the ontology, which are denoted with \\delta_i^+" +
" and \\delta_i^-." +
" The changes to the materialization do not include the changes to the ontology, therefore," +
" \\Delta_i \backslash \\delta_i = {}",
"\\gamma = \\frac{|\\Delta_i^+| + |\\Delta_i^-|}{|\\delta_i^+| + |\\delta_i^-|}");
this.customReasoner = customReasoner;
}
......@@ -30,6 +34,7 @@ public class ChangeImpact extends Metric implements ImpactMetric {
Set<OWLAxiom> currentMaterialization = customReasoner.getCurrentMaterialization();
Set<OWLAxiom> firstMaterialization = customReasoner.getFirstMaterialization();
Set<OWLAxiom> firstOntology = customReasoner.getFirstOntology();
Set<OWLOntology> activeOntologies = customReasoner.getCurrentOntology();
Set<OWLAxiom> currentOntology = new TreeSet<>();
for (OWLOntology ont : activeOntologies){
......@@ -37,10 +42,14 @@ public class ChangeImpact extends Metric implements ImpactMetric {
}
if (currentMaterialization != null) {
updateMetric(calculateMetricWithMaterializations(firstMaterialization, currentMaterialization,firstOntology,currentOntology));
updateMetric(calculateMetricWithMaterializations(firstMaterialization, currentMaterialization,
firstOntology,currentOntology));
} else {
log.debug(getDisplayName() + " could not be calculated because there were no previous materializations");
}
}
public double calculateMetricWithMaterializations(Set<OWLAxiom> oldMaterialization, Set<OWLAxiom> newMaterialization,
......@@ -56,8 +65,11 @@ public class ChangeImpact extends Metric implements ImpactMetric {
ontologyRemovals.removeAll(newOntology);
double sizeOfMaterializedChanges = materializedAdditions.size() + materializedRemovals.size();
double sizeOfOntologyChanges = ontologyAdditions.size() + ontologyRemovals.size();
log.info("Ontology changes: " + sizeOfOntologyChanges);
log.info("Mat changes: " + sizeOfMaterializedChanges);
return sizeOfOntologyChanges > 0 ? sizeOfMaterializedChanges / sizeOfOntologyChanges : 0;
}
......
......@@ -20,9 +20,13 @@ public class ChangeSubclassImpact extends Metric implements ImpactMetric {
public ChangeSubclassImpact(ChimpReasoner customReasoner) {
super("Change Hierarchy Impact",
"This measure signals the amount of changed axioms (added and removed) in the materialization " +
"in comparison to the number of changes in the ontology.",
"\\gamma_\\sqsubseteq = \\frac{h_\\Delta_i^+ + h_\\Delta_i^-}{h_\\delta_i^+ + h_\\delta_i^-}");
"This measure signals the amount of changed subclass axioms (added and removed) in the materialization" +
" with h_{\\Delta_i^+} and h_{\\Delta_i^-} " +
"in comparison to the number of changed subclass axioms in the ontology, which are denoted with h_{\\delta_i^+}" +
"and h_{\\delta_i^-}." +
"The changes to the materialization do not include the changes to the ontology, therefore," +
" \\Delta_i \backslash \\delta_i = {}",
"\\gamma = \\frac{h_{\\Delta_i^+} + h_{\\Delta_i^-}}{h_{\\delta_i^+} + h_{\\delta_i^-}}");
this.customReasoner = customReasoner;
}
......
......@@ -15,14 +15,16 @@ public class SizeImpact extends Metric implements ImpactMetric {
private final ChimpReasoner customReasoner;
public SizeImpact(ChimpReasoner customReasoner) {
super("Size Impact",
"This measure signals the amount of changed axioms (added and removed) in the materialization " +
"in comparison to the unchanged part of the materialization, when " +
"comparing the materialization now and to the one calculated " +
"as the reasoner was started. If this number is larger than 1, " +
"it means that the amount of changed axioms in the materialization " +
"exceed the amount of shared axioms between the two materializations.",
"\\sigma = \\frac{\\Delta_i^+ + \\Delta_i^-}{m_{i,i+1}}");
super("Size-based Impact",
"This measure signals the amount of changed axioms (added and removed) in the materialization," +
" denoted with \\Delta_i^+ and \\Delta_i^-" +
"in comparison to the unchanged part of the materialization." +
"A materialization is denoted with M, therefore the intersection between the two versions " +
"of the materialization with M_{i} \\cap M_{i+1}." +
"This comparison occurs between the first materialization, when the reasoner was started " +
"and the last materialization when the reasoner was synchronized." +
"The materialization does not include the ontology itself.",
"\\sigma = \\frac{|\\Delta_i^+| + |\\Delta_i^-|}{|M_{i} \\cap M_{i+1}|}");
this.customReasoner = customReasoner;
}
......
......@@ -18,13 +18,15 @@ public class SizeSubclassImpact extends Metric implements ImpactMetric {
public SizeSubclassImpact(ChimpReasoner customReasoner) {
super("Size Hierarchy Impact",
"This measure signals the amount of changed SubclassOf axioms (added and removed) in the materialization " +
"in comparison to the unchanged part of the materialization, when " +
"comparing the materialization now and to the one calculated " +
"as the reasoner was started. If this number is larger than 1, " +
"it means that the amount of changes to the hierarchy in the materialization " +
"exceed the amount of shared axioms between the two materializations.",
"\\sigma_{\\sqsubseteq} = \\frac{h_{\\Delta_i}}{h_{m_{i,i+1}}}");
"This measure signals the amount of changed subclass axioms (added and removed) in the materialization," +
" denoted with h_{\\Delta_i^+} and h_{\\Delta_i^-}" +
"in comparison to the unchanged hierarchy part of the materialization." +
"A materialization is denoted with M, therefore the intersection between the two versions " +
"of the materialization with M_{i} \\cap M_{i+1}, however we only count the subclass axioms." +
"This comparison occurs between the first materialization, when the reasoner was started " +
"and the last materialization when the reasoner was synchronized." +
"The materialization does not include the ontology itself.",
"\\sigma_{\\sqsubseteq} = \\frac{h_{\\Delta_i^+}+h_{\\Delta_i^-}}{h_{M_{i} \\cap M_{i+1}}}");
this.customReasoner = customReasoner;
}
......
package metrics.primitive;
import metrics.Metric;
import metrics.PrimitiveMetric;
import org.semanticweb.owlapi.model.OWLOntology;
import java.util.Set;
import java.util.stream.Collectors;
public class NumberOfAxioms extends Metric implements PrimitiveMetric {
private final Set<OWLOntology> ontologies;
public NumberOfAxioms(Set<OWLOntology> ontologies) {
super("Number of Axioms", "Counts the number of axioms in the active ontologies.");
this.ontologies = ontologies;
}
@Override
public void calculateMetric() {
updateMetric(ontologies.stream()
.flatMap(o -> o.getAxioms().stream())
.collect(Collectors.toSet())
.size()
);
}
}
package metrics.primitive;
import metrics.Metric;
import metrics.PrimitiveMetric;
import org.semanticweb.owlapi.model.OWLOntology;
public class NumberOfPropertyUsage extends Metric implements PrimitiveMetric {
NumberOfPropertyUsage numberOfPropertyUsageMetric;
public NumberOfPropertyUsage(OWLOntology ontology) {
super("Number of Property Usage",
"Counts the number of property usage in the ontology. ");
this.numberOfPropertyUsageMetric = new NumberOfPropertyUsage(ontology);
}
@Override
public void calculateMetric() {
//TODO implementation missing
// this.numberOfPropertyUsageMetric.calculateMetric();
//
// int usageProperties = (int) this.ontology.getProperties();
// updateMetric(usageProperties);
}
}
......@@ -33,12 +33,15 @@ public class ChimpReasoner {
public ChimpReasoner(OWLReasoner reasoner, Set<OWLOntology> activeOntologies) {
this.reasoner = reasoner;
this.currentOntologies = activeOntologies;
this.firstOntology = new TreeSet<>();
Set<OWLAxiom> firstOntology = new TreeSet<>();
for (OWLOntology ont : activeOntologies) {
firstOntology.addAll(ont.getAxioms());
}
updateOntology(activeOntologies);
// this.firstOntology = new TreeSet<>();
//
// Set<OWLAxiom> firstOntology = new TreeSet<>();
// for (OWLOntology ont : activeOntologies) {
// firstOntology.addAll(ont.getAxioms());
// }
// log.info("I was here");
}
public void inferAxioms() {
......@@ -78,7 +81,7 @@ public class ChimpReasoner {
public void updateOntology(Set<OWLOntology> ontologies) {
if (firstOntology == null) {
Set<OWLAxiom> firstOntology = new TreeSet<>();
firstOntology = new TreeSet<>();
for (OWLOntology ont : ontologies) {
firstOntology.addAll(ont.getAxioms());
}
......@@ -89,6 +92,7 @@ public class ChimpReasoner {
private void updateMaterialization(Set<OWLAxiom> materialization) {
if (firstMaterialization == null) {
firstMaterialization = materialization;
} else {
......
......@@ -50,8 +50,9 @@ public class ChimpPlugin extends AbstractOWLViewComponent implements ChimpLayout
impactMetricsPanel = new ImpactMetricsPanel(getOWLWorkspace());
standardMetricsPanel = new StandardMetricsPanel(getOWLModelManager());
JSplitPane innerSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
new ChimpScrollPane(lastChangePanel),
lastChangePanel,
new ChimpScrollPane(impactMetricsPanel)
);
innerSplitPane.setDividerLocation(100);
......
......@@ -51,7 +51,6 @@ public class ImpactMetricsPanel extends JPanel implements ChimpLayout {
add(reasonerStatusLabel);
add(displayPanel, "grow");
initReasoner();
updatePanel();
log.debug("ImpactMetricsPanel initialized");
......@@ -74,10 +73,10 @@ public class ImpactMetricsPanel extends JPanel implements ChimpLayout {
//new HierarchyImpact(reasoner),
//new HierarchySizeImpact(reasoner),
//new GraphDistanceImpact(reasoner)
new SizeSubclassImpact(reasoner),
new ChangeImpact(reasoner),
new ChangeSubclassImpact(reasoner),
new ChangeNoiseImpact(reasoner)
//new SizeSubclassImpact(reasoner),
new ChangeImpact(reasoner)
//new ChangeSubclassImpact(reasoner)
//new ChangeNoiseImpact(reasoner)
//new ChangeImpact(reasoner,changes)
//new ChangeHierarchyImpact(reasoner,changes)
));
......
package view.lastchange;
import net.miginfocom.swing.MigLayout;
import org.knowm.xchart.XChartPanel;
import org.knowm.xchart.PieChart;
import org.knowm.xchart.PieChartBuilder;
import org.protege.editor.owl.model.OWLModelManager;
import org.semanticweb.owlapi.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import view.ChimpLayout;
import viewcomponents.ChimpIcons;
import viewcomponents.ChimpScrollPane;
import viewcomponents.TitleLabel;
import javax.annotation.Nonnull;
......@@ -17,12 +21,16 @@ import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class LastChangePanel extends JPanel implements ChimpLayout {
Logger log = LoggerFactory.getLogger(LastChangePanel.class);
// private PieChart changeGraph;
// private XChartPanel changeGraphPanel;
// private HashMap<String,Integer> changeMap;
private final OWLModelManager modelManager;
private final OWLOntologyChangeListener changeListener = changes -> {
boolean realChange = true;
......@@ -32,11 +40,15 @@ public class LastChangePanel extends JPanel implements ChimpLayout {
}
}
if (realChange) {
// constructTree(changes);
this.displayChanges(changes);
// changeGraph.updateChart(changes);
}
};
private static final String title = "Last Change";
// private JPanel changeListView;
private static final String title = "Changes";
private final JLabel noChangesLabel = new JLabel("No changes yet");
private JTree tree;
......@@ -52,18 +64,33 @@ public class LastChangePanel extends JPanel implements ChimpLayout {
setLayout(new MigLayout("wrap 1"));
setBackground(BACKGROUND_COLOR);
setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, PANEL_BORDER_COLOR));
add(new TitleLabel(title));
add(noChangesLabel, "center");
// add(new TitleLabel(title));
// add(noChangesLabel, "center");
log.debug("LastChangePanel initialized");
}
private void displayChanges(@Nonnull List<? extends OWLOntologyChange> changes) {
if (changes.size() > 0) {
DefaultMutableTreeNode root = constructTree(changes);
displayTree(root);
}
}
// private void addPanels(){
//// changeGraph = new PieChartBuilder().width(100).height(10).build();
//// changeGraph.setTitle("No changes yet.");
//
//// changeGraphPanel = new XChartPanel<>(changeGraph);
//
// changeListView = new JPanel(new MigLayout("wrap 1"));
// changeListView.setLayout(new MigLayout("wrap 1"));
// changeListView.setBackground(BACKGROUND_COLOR);
// changeListView.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, PANEL_BORDER_COLOR));
// changeListView.add(new TitleLabel(title));
// changeListView.add(noChangesLabel, "center");
//// listViewPanel.setBackground(Color.WHITE);
//// listViewPanel.add(this);
//
// add(new ChimpScrollPane(changeListView));
//// addTab("Listview", new ChimpScrollPane(changeListView));
//// addTab("Chartview",new ChimpScrollPane(changeGraphPanel));
// }
private DefaultMutableTreeNode constructTree(List<? extends OWLOntologyChange> changes) {
DefaultMutableTreeNode root = new DefaultMutableTreeNode("");
......@@ -89,6 +116,92 @@ public class LastChangePanel extends JPanel implements ChimpLayout {
return root;
}
private void displayChanges(@Nonnull List<? extends OWLOntologyChange> changes) {
if (changes.size() > 0) {
DefaultMutableTreeNode root = constructTree(changes);
// constructMap(changes);
displayTree(root);
// displayChart();
}
}
// private void constructMap(@Nonnull List<? extends OWLOntologyChange> changes) {
// if(changeMap==null){
// changeMap = new HashMap<>();
// }
// for (int i = 1; i < changes.size(); i++) {
// OWLOntologyChange change = changes.get(i);
// String key = "";
// if (change instanceof OWLAxiomChange) {
// key ="axiom";
// } else if (change instanceof AnnotationChange) {
// key ="annotation";
// } else {
// key = "other";
// }
//
// if(changeMap.containsKey(key)){
// int count = changeMap.get(key);
// count++;
// changeMap.put(key,count);
// }
// else {
// changeMap.put(key,1);
// }
// }
// }
// private void displayChart(){
// if(changeGraph==null){
// changeGraph = new PieChartBuilder().width(100).height(10).build();
// Color[] sliceColors = new Color[] { new Color(224, 68, 14), new Color(230, 105, 62), new Color(236, 143, 110), new Color(243, 180, 159), new Color(246, 199, 182) };
// changeGraph.getStyler().setSeriesColors(sliceColors);
// }
//
//
// changeGraph.updatePieSeries(changeMap.);
//
// chart.addSeries("Gold",24);
// chart.addSeries("Silver",47);
// chart.addSeries("Platinum",50);
// chartPanel = new XChartPanel<>(chart);
//
// }
private String getRootChangeString(OWLOntologyChange change) {
final String returnString;
if (change instanceof AddAxiom) {
returnString = "Added axiom: ";
} else if (change instanceof RemoveAxiom) {
returnString = "Removed axiom: ";
} else if (change instanceof AddImport) {
returnString = "Added import: ";
} else if (change instanceof RemoveImport) {
returnString = "Removed import: ";
} else if (change instanceof AddOntologyAnnotation) {
returnString = "Added annotation: ";
} else if (change instanceof RemoveOntologyAnnotation) {
returnString = "Removed annotation: ";
} else {
return "Unidentified change: " + change.getClass().getName();
}
return returnString + getChangeString(change);
}
private String getChangeString(OWLOntologyChange change) {
if (change instanceof OWLAxiomChange) {
return "&lt;" + change.getAxiom().toString() + "&gt;";
} else if (change instanceof AnnotationChange) {
return ((AnnotationChange) change).getAnnotation().toString();
} else {
return change.getClass().getName();
}
}
private void displayTree(DefaultMutableTreeNode root) {
if (tree == null) {
defaultTreeModel = new DefaultTreeModel(root);
......@@ -115,8 +228,8 @@ public class LastChangePanel extends JPanel implements ChimpLayout {
});
// the following line is needed to ensure that the multiline html has variable height
tree.setRowHeight(0);
remove(noChangesLabel);
add(tree, BorderLayout.CENTER);
this.remove(noChangesLabel);
this.add(tree, BorderLayout.CENTER);
} else {
defaultTreeModel.setRoot(root);
defaultTreeModel.reload();
......@@ -126,35 +239,8 @@ public class LastChangePanel extends JPanel implements ChimpLayout {
}
}
private String getRootChangeString(OWLOntologyChange change) {
final String returnString;
if (change instanceof AddAxiom) {
returnString = "Added axiom: ";
} else if (change instanceof RemoveAxiom) {
returnString = "Removed axiom: ";
} else if (change instanceof AddImport) {
returnString = "Added import: ";
} else if (change instanceof RemoveImport) {
returnString = "Removed import: ";
} else if (change instanceof AddOntologyAnnotation) {
returnString = "Added annotation: ";
} else if (change instanceof RemoveOntologyAnnotation) {
returnString = "Removed annotation: ";
} else {
return "Unidentified change: " + change.getClass().getName();
}
return returnString + getChangeString(change);
}
private String getChangeString(OWLOntologyChange change) {
if (change instanceof OWLAxiomChange) {
return "&lt;" + change.getAxiom().toString() + "&gt;";
} else if (change instanceof AnnotationChange) {
return ((AnnotationChange) change).getAnnotation().toString();
} else {
return change.getClass().getName();
}
}
public void dispose() {
this.modelManager.removeOntologyChangeListener(this.changeListener);
......
......@@ -81,6 +81,7 @@ public class StandardMetricsPanel extends JTabbedPane implements ChimpLayout {
//TODO: add difference between import closure and only ontology in file here (and in the graph panel)
standardMetrics = Arrays.asList(
new NumberOfAxioms(modelManager.getActiveOntologies()),
new NumberOfClasses(modelManager.getActiveOntologies()),
new NumberOfIndividuals(modelManager.getActiveOntologies()),
new NumberOfProperties(modelManager.getActiveOntologies()),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment