
org.coode.matrix.model.impl.RestrictionTreeMatrixModel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.coode.matrix Show documentation
Show all versions of org.coode.matrix Show documentation
A Swing Component that combines a JTree and a JTable.
The newest version!
package org.coode.matrix.model.impl;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.coode.matrix.model.api.AbstractColumnFilterPair;
import org.coode.matrix.model.api.AbstractMatrixModel;
import org.coode.matrix.model.helper.FillerHelper;
import org.coode.matrix.model.helper.PropertyHelper;
import org.protege.editor.owl.model.OWLModelManager;
import org.protege.editor.owl.model.hierarchy.OWLObjectHierarchyProvider;
import org.protege.editor.owl.ui.tree.OWLObjectTree;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLDataAllValuesFrom;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDataPropertyExpression;
import org.semanticweb.owlapi.model.OWLDataRange;
import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom;
import org.semanticweb.owlapi.model.OWLObject;
import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;
import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom;
import org.semanticweb.owlapi.model.OWLOntologyChange;
import org.semanticweb.owlapi.model.OWLPropertyExpression;
import org.semanticweb.owlapi.model.OWLPropertyRange;
import org.semanticweb.owlapi.model.OWLQuantifiedRestriction;
/**
* Author: Nick Drummond
* http://www.cs.man.ac.uk/~drummond/
*
* The University Of Manchester
* Bio Health Informatics Group
* Date: Jul 3, 2007
*/
public class RestrictionTreeMatrixModel extends AbstractMatrixModel {
public static final String NONE = "none";
private FillerHelper fillerHelper;
private PropertyHelper objHelper;
public RestrictionTreeMatrixModel(OWLObjectTree tree, OWLObjectHierarchyProvider hp, OWLModelManager mngr) {
super(tree, mngr);
fillerHelper = new FillerHelper(mngr, hp);
objHelper = new PropertyHelper(mngr);
}
public String getTreeColumnLabel() {
return "Class";
}
@Override
public Object getMatrixValue(OWLClass rowObject, Object columnObject) {
if (columnObject instanceof PropertyRestrictionPair){
return createFillerModel(rowObject, (PropertyRestrictionPair)columnObject, fillerHelper);
}
else {
return super.getMatrixValue(rowObject, columnObject);
}
}
private static FillerModel createFillerModel(OWLClass cls,
PropertyRestrictionPair pair,
FillerHelper helper){
return new FillerModel(cls, pair, helper);
}
@Override
public List setMatrixValue(OWLClass cls, Object col, Object value) {
List changes = new ArrayList ();
if (col instanceof PropertyRestrictionPair){
final PropertyRestrictionPair pair = (PropertyRestrictionPair)col;
OWLPropertyExpression prop = (OWLPropertyExpression) pair.getColumnObject();
Set fillers = getFillerSet(value);
if (fillers != null){
changes = fillerHelper.setFillers(cls,
prop,
fillers,
(Class) pair.getFilterObject(),
mngr.getActiveOntology());
}
}
else{
changes = super.setMatrixValue(cls, col, value);
}
return changes;
}
@Override
public List addMatrixValue(OWLClass cls, Object colObj, Object value) {
if (colObj instanceof PropertyRestrictionPair){
final PropertyRestrictionPair pair = (PropertyRestrictionPair) colObj;
OWLPropertyExpression objProp = (OWLPropertyExpression) pair.getColumnObject();
Set extends OWLPropertyRange> values = getFillerSet(value);
if (objHelper.isFunctional(objProp)){
if (fillerHelper.getAssertedFillers(cls, objProp, (Class) pair.getFilterObject()).isEmpty()){
return performAdd(cls, objProp, values, (Class) pair.getFilterObject());
}
}
else{
return performAdd(cls, objProp, values, (Class) pair.getFilterObject());
}
}
else{
return super.addMatrixValue(cls, colObj, value);
}
return Collections.emptyList();
}
private static Set getFillerSet(Object value) {
Set fillers = null;
if (value.equals(NONE)) {
fillers = Collections.EMPTY_SET;
}
else if (value instanceof Set) {
fillers = (Set)value;
}
else if (value instanceof OWLPropertyRange){
fillers = Collections.singleton((OWLPropertyRange)value);
}
return fillers;
}
@Override
protected String renderColumnTitle(Object columnObject) {
if (columnObject instanceof PropertyRestrictionPair){
PropertyRestrictionPair pair = (PropertyRestrictionPair)columnObject;
return mngr.getRendering((OWLObject) pair.getColumnObject()) + " (" + PropertyRestrictionPair.render((Class) pair.getFilterObject()) + ")";
}
return super.renderColumnTitle(columnObject);
}
private List performAdd(OWLClass cls,
P objProp,
Set values,
Class extends OWLQuantifiedRestriction> type) {
if (values != null && !values.isEmpty()){
return fillerHelper.addNamedFillers(cls, objProp, type, values, mngr.getActiveOntology());
}
return Collections.emptyList();
}
public boolean isSuitableCellValue(Object value, int row, int col) {
Object colObj = getColumnObjectAtModelIndex(col);
if (colObj instanceof PropertyRestrictionPair){
if (((PropertyRestrictionPair)colObj).getColumnObject() instanceof OWLObjectProperty){
return value instanceof OWLClass;
}
else{
return value instanceof OWLDataRange;
}
}
return false;
}
public Object getSuitableColumnObject(Object columnObject) {
if (columnObject instanceof OWLObjectProperty){
return new PropertyRestrictionPair((OWLObjectProperty)columnObject, OWLObjectSomeValuesFrom.class);
}
else if (columnObject instanceof OWLDataProperty){
return new PropertyRestrictionPair((OWLDataProperty)columnObject, OWLDataSomeValuesFrom.class);
}
else if (columnObject instanceof URI){
return columnObject;
}
return null;
}
public boolean isValueRestricted(OWLClass cls, Object p) {
return false;
}
public Set getSuggestedFillers(OWLClass cls, Object p, int threshold) {
return null;
}
public static class PropertyRestrictionPair extends AbstractColumnFilterPair>> {
private static Map renderMap = new HashMap();
static {
renderMap.put(OWLObjectSomeValuesFrom.class, "some");
renderMap.put(OWLObjectAllValuesFrom.class, "only");
renderMap.put(OWLDataSomeValuesFrom.class, "some");
renderMap.put(OWLDataAllValuesFrom.class, "only");
}
public PropertyRestrictionPair(P object, Class extends OWLQuantifiedRestriction> filter) {
super(object, filter);
}
public static String render(Class restrictionClass) {
return renderMap.get(restrictionClass);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy