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