SameIndividualAtomImpl.java revision 38
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/*
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen * Created on Dec 28, 2004
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenpackage impl.swrl;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenimport org.mindswap.owl.EntityFactory;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenimport org.mindswap.owl.OWLIndividual;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenimport org.mindswap.owl.vocabulary.OWL;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenimport org.mindswap.owl.vocabulary.SWRL;
6d2b3ce2c6ef62334985ece4f0ab8b154e0e9560Timo Sirainenimport org.mindswap.owls.vocabulary.OWLS;
c6335901c67a4c9365319190a111a2168f3b06f5Timo Sirainenimport org.mindswap.query.ValueMap;
c6335901c67a4c9365319190a111a2168f3b06f5Timo Sirainenimport org.mindswap.swrl.SWRLIndividualObject;
c6335901c67a4c9365319190a111a2168f3b06f5Timo Sirainenimport org.mindswap.swrl.SWRLObject;
01230de017cd273de41143d88e9c18df1243ae8aTimo Sirainenimport org.mindswap.swrl.SameIndividualAtom;
01230de017cd273de41143d88e9c18df1243ae8aTimo Sirainenimport org.mindswap.swrl.Variable;
047c00cd3f7f403672f81569413669238df8c15aTimo Sirainen
047c00cd3f7f403672f81569413669238df8c15aTimo Sirainen/**
047c00cd3f7f403672f81569413669238df8c15aTimo Sirainen * @author Evren Sirin
047c00cd3f7f403672f81569413669238df8c15aTimo Sirainen *
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenpublic class SameIndividualAtomImpl extends AtomImpl implements SameIndividualAtom {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen public SameIndividualAtomImpl(OWLIndividual ind) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen super(ind);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen }
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen public SWRLIndividualObject getArgument1() {
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen return (SWRLIndividualObject) getPropertyAs(SWRL.argument1, SWRLIndividualObject.class);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen }
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen public SWRLIndividualObject getArgument2() {
7487ff578435377bbeefffdbfb78ca09ed1292dfTimo Sirainen return (SWRLIndividualObject) getPropertyAs(SWRL.argument2, SWRLIndividualObject.class);
89237470342ea6d4bbdf4cff9764037cfb3f6f45Timo Sirainen }
89237470342ea6d4bbdf4cff9764037cfb3f6f45Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen public int getArgumentCount() {
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen return 2;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen }
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen public SWRLObject getArgument(int index) {
4d4d6d4745682790c20d759ba93dbea46b812c5dTimo Sirainen if( index == 0 )
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen return getArgument1();
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen if( index == 1 )
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen return getArgument2();
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen throw new IndexOutOfBoundsException("Illegal argument index: "+index+" for a SameIndividualAtom");
a3fe8c0c54d87822f4b4f8f0d10caac611861b2bTimo Sirainen }
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen public void setArgument(int index, SWRLObject obj) {
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen if( index > 1 )
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen throw new IndexOutOfBoundsException("Illegal argument index: "+index+" for a SameIndividualAtom");
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen if(obj instanceof SWRLIndividualObject) {
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen if( index == 0 )
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen setArgument1((SWRLIndividualObject) obj);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen else
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen setArgument2((SWRLIndividualObject) obj);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen }
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen else
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen throw new IllegalArgumentException("SameIndividualAtom argument should be a SWRLIndivdiualObject");
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen }
e0740628f6ca05f4bc79a9d8a90b650f4d38d4d0Timo Sirainen
e0740628f6ca05f4bc79a9d8a90b650f4d38d4d0Timo Sirainen public void setArgument1(SWRLIndividualObject obj) {
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen setProperty(SWRL.argument1, obj);
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen }
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen public void setArgument2(SWRLIndividualObject obj) {
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen setProperty(SWRL.argument2, obj);
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen }
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen public String toString() {
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen return "sameAs(" + getArgument1().debugString() + ", " + getArgument2().debugString() + ")";
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen }
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainen
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainen public void evaluate(ValueMap values) {
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainen OWLIndividual ind1 = getArgument1();
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainen if (ind1.isType(OWLS.Process.Parameter))
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainen ind1 = values.getIndividualValue((Variable) ind1);
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen OWLIndividual ind2 = getArgument2();
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen if (ind2.isType(OWLS.Process.Parameter))
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen ind2 = values.getIndividualValue((Variable) ind2);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen ind1.setProperty(EntityFactory.createObjectProperty(OWL.sameAs), ind2);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen }
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen}
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen