2ronwalf/*
2ronwalf * Created on Dec 28, 2004
2ronwalf */
2ronwalfpackage impl.swrl;
2ronwalf
2ronwalfimport org.mindswap.owl.OWLDataProperty;
2ronwalfimport org.mindswap.owl.OWLIndividual;
38daenzeroramaimport org.mindswap.owl.OWLValue;
2ronwalfimport org.mindswap.owl.vocabulary.SWRL;
38daenzeroramaimport org.mindswap.owls.vocabulary.OWLS;
38daenzeroramaimport org.mindswap.query.ValueMap;
2ronwalfimport org.mindswap.swrl.DataPropertyAtom;
2ronwalfimport org.mindswap.swrl.SWRLDataObject;
2ronwalfimport org.mindswap.swrl.SWRLDataValue;
2ronwalfimport org.mindswap.swrl.SWRLDataVariable;
2ronwalfimport org.mindswap.swrl.SWRLIndividualObject;
2ronwalfimport org.mindswap.swrl.SWRLObject;
38daenzeroramaimport org.mindswap.swrl.Variable;
2ronwalf
2ronwalf/**
2ronwalf * @author Evren Sirin
2ronwalf *
2ronwalf */
2ronwalfpublic class DataPropertyAtomImpl extends AtomImpl implements DataPropertyAtom {
2ronwalf public DataPropertyAtomImpl(OWLIndividual ind) {
22daenzerorama super(ind);
2ronwalf }
2ronwalf
2ronwalf public OWLDataProperty getPropertyPredicate() {
2ronwalf return (OWLDataProperty) getPropertyAs(SWRL.propertyPredicate, OWLDataProperty.class);
2ronwalf }
2ronwalf
2ronwalf public void setPropertyPredicate(OWLDataProperty p) {
2ronwalf setProperty(SWRL.propertyPredicate, (OWLIndividual) p.castTo(OWLIndividual.class));
2ronwalf }
2ronwalf
2ronwalf public SWRLIndividualObject getArgument1() {
2ronwalf return (SWRLIndividualObject) getPropertyAs(SWRL.argument1, SWRLIndividualObject.class);
2ronwalf }
2ronwalf
2ronwalf public SWRLDataObject getArgument2() {
2ronwalf SWRLDataObject arg = (SWRLDataVariable) getPropertyAs(SWRL.argument2, SWRLDataVariable.class);
2ronwalf if( arg == null )
2ronwalf arg = (SWRLDataValue) getPropertyAs(SWRL._argument2, SWRLDataValue.class);
2ronwalf
2ronwalf return arg;
2ronwalf }
2ronwalf
2ronwalf public int getArgumentCount() {
2ronwalf return 2;
2ronwalf }
2ronwalf
2ronwalf public SWRLObject getArgument(int index) {
2ronwalf if( index == 0 )
2ronwalf return getArgument1();
2ronwalf
2ronwalf if( index == 1 )
2ronwalf return getArgument2();
2ronwalf
2ronwalf throw new IndexOutOfBoundsException("Illegal argument index: "+index+" for a DataPropertyAtom");
2ronwalf }
2ronwalf
2ronwalf public void setArgument(int index, SWRLObject obj) {
2ronwalf if( index > 1 )
2ronwalf throw new IndexOutOfBoundsException("Illegal argument index: "+index+" for a DataPropertyAtom");
2ronwalf
2ronwalf
2ronwalf if( index == 0 ) {
2ronwalf if(obj instanceof SWRLIndividualObject)
2ronwalf setArgument1((SWRLIndividualObject) obj);
2ronwalf else
2ronwalf throw new IllegalArgumentException(
2ronwalf "First argument of a DataPropertyAtom should be an SWRLIndividiualObject");
2ronwalf }
2ronwalf else {
2ronwalf if(obj instanceof SWRLDataObject)
2ronwalf setArgument2((SWRLDataObject) obj);
2ronwalf else
2ronwalf throw new IllegalArgumentException(
2ronwalf "Second argument of a DataPropertyAtom should be an SWRLDataObject");
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf public void setArgument1(SWRLIndividualObject obj) {
2ronwalf setProperty(SWRL.argument1, obj);
2ronwalf }
2ronwalf
2ronwalf public void setArgument2(SWRLDataObject obj) {
2ronwalf if(obj.isDataValue())
2ronwalf setProperty(SWRL._argument2, obj);
2ronwalf else
2ronwalf setProperty(SWRL.argument2, (SWRLDataVariable) obj);
2ronwalf }
2ronwalf
2ronwalf public String toString() {
2ronwalf return
2ronwalf "(" + getArgument1() + " " +
2ronwalf getPropertyPredicate().getQName() +
2ronwalf " " + getArgument2() + ")";
2ronwalf }
38daenzerorama
38daenzerorama public void evaluate(ValueMap values) {
38daenzerorama OWLIndividual subject = getArgument1();
38daenzerorama OWLValue object = getArgument2();
38daenzerorama if (subject.isType(OWLS.Process.Parameter)) {
38daenzerorama OWLIndividual value = values.getIndividualValue((Variable) subject);
38daenzerorama value.setProperty(getPropertyPredicate(), object);
38daenzerorama }
38daenzerorama }
2ronwalf}