AtomListImpl.java revision 16
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen * Created on Dec 28, 2004
905457e0982fc15930d90e174f271dc69f9afcf9Timo Sirainenimport org.mindswap.exceptions.NotImplementedException;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.swrl.DifferentIndividualsAtom;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.swrl.IndividualPropertyAtom;
7fc0ca6c1f664de6506afa816200d115f9f80391Timo Sirainen * @author Evren Sirin
5948e3e120c5dcaf0aeb44405566381045fa82d6Timo Sirainenpublic class AtomListImpl extends RDFListImpl implements AtomList {
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen AtomList list = new AtomListImpl( ont.createInstance( vocabulary.List() ) );
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen public AtomList insertAt(int index, Atom item) {
3b49aee9ced3b0370a3be396aca53acd5f21418cTimo Sirainen return (AtomList) super.insertAt( index, item).castTo( AtomList.class );
9badddc243d1a9925586c785a838b3bd81bacc7eAki Tuomi return (Atom) getProperty(vocabulary.first()).castTo(Atom.class);
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainen return (RDFList) getProperty(vocabulary.rest()).castTo(AtomList.class);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen return new ABoxQuery(this);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen public SWRLIndividualObject getIndidividualObject(SWRLIndividualObject arg, ValueMap binding) {
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen if( arg.isVariable() && binding.hasValue( (Variable) arg ) ) {
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen OWLIndividual ind = (OWLIndividual) binding.getValue( (Variable) arg );
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen arg = (SWRLIndividual) ind.castTo(SWRLIndividual.class);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen public SWRLDataObject getDataObject(SWRLDataObject arg, ValueMap binding) {
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainen if( arg.isVariable() && binding.hasValue( (Variable) arg ) ) {
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen OWLDataValue dv = (OWLDataValue) binding.getValue( (Variable) arg );
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainen arg = (SWRLDataValue) dv.castTo(SWRLDataValue.class);
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen SWRLFactory swrl = SWRLFactoryCreator.createFactory( ont );
7a24bdc1a5e2d5368c2569b4852192f2bdb5a31fTimo Sirainen for( AtomList list = this; !list.isEmpty(); list = (AtomList) list.getRest() ) {
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen getIndidividualObject( classAtom.getArgument1(), binding ) );
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen else if(atom instanceof IndividualPropertyAtom) {
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen IndividualPropertyAtom indPropAtom = (IndividualPropertyAtom) atom;
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen getIndidividualObject( indPropAtom.getArgument1(), binding ),
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen getIndidividualObject( indPropAtom.getArgument2(), binding ));
8f90ef65db62946aabe1969755edcdefb4eb430aTimo Sirainen DataPropertyAtom dataPropAtom = (DataPropertyAtom) atom;
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen getIndidividualObject( dataPropAtom.getArgument1(), binding ),
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen getDataObject( dataPropAtom.getArgument2(), binding ));
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen SameIndividualAtom sameAtom = (SameIndividualAtom) atom;
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen getIndidividualObject( sameAtom.getArgument1(), binding ),
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen getIndidividualObject( sameAtom.getArgument2(), binding ));
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen else if(atom instanceof DifferentIndividualsAtom) {
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen DifferentIndividualsAtom diffAtom = (DifferentIndividualsAtom) atom;
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen newAtom = swrl.createDifferentIndividualsAtom(
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen getIndidividualObject( diffAtom.getArgument1(), binding ),
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen getIndidividualObject( diffAtom.getArgument2(), binding ));
504337186520df7012315687fc0f88c945775471Timo Sirainen OWLIndividual builtin = builtinAtom.getBuiltin();
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen SWRLDataObject[] args = new SWRLDataObject[ argCount ];
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen SWRLDataObject arg = (SWRLDataObject) atom.getArgument( i );
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen newAtom = swrl.createEqual( args[0], args[1] );
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen newAtom = swrl.createNotEqual( args[0], args[1] );
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen else if ( builtin.equals( SWRLB.greaterThan ) )
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen newAtom = swrl.createGreaterThan( args[0], args[1] );
7e209b78ca757294dbbc15604c88673b3a6b0c39Timo Sirainen else if ( builtin.equals( SWRLB.greaterThanOrEqual ) )
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen newAtom = swrl.createGreaterThanOrEqual( args[0], args[1] );
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen newAtom = swrl.createLessThan( args[0], args[1] );
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen else if ( builtin.equals( SWRLB.lessThanOrEqual ) )
7fa9d523d96b3002620cc1ff463f1d4ad2d90129Aki Tuomi newAtom = swrl.createLessThanOrEqual( args[0], args[1] );
825b0e819a7c48a366ddca23ec78b87e8c30e9b4Aki Tuomi newAtom = swrl.createAdd( args[0], args[1], args[2] );
825b0e819a7c48a366ddca23ec78b87e8c30e9b4Aki Tuomi newAtom = swrl.createSubtract( args[0], args[1], args[2] );
825b0e819a7c48a366ddca23ec78b87e8c30e9b4Aki Tuomi throw new NotImplementedException( builtin.toPrettyString() );
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen throw new RuntimeException("Unknown atom type " + atom);
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen// newList = newList.add( newAtom );
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen for( AtomList list = this; !list.isEmpty(); list = (AtomList) list.getRest() ) {
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen for( int j = 0; j < atom.getArgumentCount(); j++ ) {
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen for(RDFList list = this; !list.isEmpty(); list = list.getRest()) {
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen AtomListImpl list = new AtomListImpl(getOntology().createInstance(vocabulary.List()));
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen // TODO it is not possible to set nil to the full list because the list type of nil cannot be inferred (on whatever reason), so we set first and rest to null as well