AtomListImpl.java revision 16
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/*
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen * Created on Dec 28, 2004
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen */
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenpackage impl.swrl;
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport impl.owl.list.RDFListImpl;
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport java.util.ArrayList;
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainenimport java.util.List;
436adac819e7cbeef04af08dcc6a4f3ecd4a1d9eMartti Rannanjärvi
905457e0982fc15930d90e174f271dc69f9afcf9Timo Sirainenimport org.mindswap.exceptions.NotImplementedException;
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainenimport org.mindswap.owl.OWLDataValue;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.owl.OWLIndividual;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.owl.OWLOntology;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.owl.OWLValue;
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainenimport org.mindswap.owl.list.RDFList;
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainenimport org.mindswap.owl.vocabulary.SWRL;
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainenimport org.mindswap.owl.vocabulary.SWRLB;
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainenimport org.mindswap.query.ABoxQuery;
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainenimport org.mindswap.query.ValueMap;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.swrl.Atom;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.swrl.AtomList;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.swrl.BuiltinAtom;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.swrl.ClassAtom;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.swrl.DataPropertyAtom;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.swrl.DifferentIndividualsAtom;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.swrl.IndividualPropertyAtom;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.swrl.SWRLDataObject;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.swrl.SWRLDataValue;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.swrl.SWRLFactory;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.swrl.SWRLFactoryCreator;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.swrl.SWRLIndividual;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenimport org.mindswap.swrl.SWRLIndividualObject;
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainenimport org.mindswap.swrl.SWRLObject;
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainenimport org.mindswap.swrl.SameIndividualAtom;
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainenimport org.mindswap.swrl.Variable;
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen
5948e3e120c5dcaf0aeb44405566381045fa82d6Timo Sirainen/**
7fc0ca6c1f664de6506afa816200d115f9f80391Timo Sirainen * @author Evren Sirin
7fc0ca6c1f664de6506afa816200d115f9f80391Timo Sirainen *
7fc0ca6c1f664de6506afa816200d115f9f80391Timo Sirainen */
5948e3e120c5dcaf0aeb44405566381045fa82d6Timo Sirainenpublic class AtomListImpl extends RDFListImpl implements AtomList {
5948e3e120c5dcaf0aeb44405566381045fa82d6Timo Sirainen public AtomListImpl(OWLIndividual ind) {
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen super(ind);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen setVocabulary( SWRL.AtomListVocabulary );
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen }
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen public AtomList add( Atom item ) {
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen if( isEmpty() )
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen return insert( item );
5b7ff90a6c078b07406bce434c719017a0f51825Timo Sirainen
5b7ff90a6c078b07406bce434c719017a0f51825Timo Sirainen RDFList rest = getRest();
5b7ff90a6c078b07406bce434c719017a0f51825Timo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen if(rest.isEmpty())
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen setRest( rest.insert( item ) );
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen else
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen rest.add(item);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen return this;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen }
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen public AtomList insert( Atom first ) {
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen OWLOntology ont = getOntology();
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen AtomList list = new AtomListImpl( ont.createInstance( vocabulary.List() ) );
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen list.setFirst( first );
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen list.setRest( this );
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen return list;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen }
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen public AtomList insertAt(int index, Atom item) {
3b49aee9ced3b0370a3be396aca53acd5f21418cTimo Sirainen return (AtomList) super.insertAt( index, item).castTo( AtomList.class );
212e9e43a7d49242446331fd43ba519eda936d60Timo Sirainen }
212e9e43a7d49242446331fd43ba519eda936d60Timo Sirainen
212e9e43a7d49242446331fd43ba519eda936d60Timo Sirainen public RDFList insert( OWLValue item ) {
3b49aee9ced3b0370a3be396aca53acd5f21418cTimo Sirainen Atom atom = (Atom) item.castTo( Atom.class );
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen return add( atom );
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen }
9badddc243d1a9925586c785a838b3bd81bacc7eAki Tuomi
9badddc243d1a9925586c785a838b3bd81bacc7eAki Tuomi public OWLValue getFirstValue() {
9badddc243d1a9925586c785a838b3bd81bacc7eAki Tuomi return (Atom) getProperty(vocabulary.first()).castTo(Atom.class);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen }
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen public RDFList getRest() {
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainen return (RDFList) getProperty(vocabulary.rest()).castTo(AtomList.class);
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainen }
84ed9f8f3d0e5ed47607ef417618e49e4f865557Timo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen public Atom atomAt(int index) {
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen return (Atom) get(index);
7fc0ca6c1f664de6506afa816200d115f9f80391Timo Sirainen }
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen public ABoxQuery toQuery() {
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen return new ABoxQuery(this);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen }
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen public ABoxQuery toQuery(List resultVars) {
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen return new ABoxQuery(this, resultVars);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen }
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
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 }
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen return arg;
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainen }
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainen
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);
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainen }
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen return arg;
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainen }
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
c9dea5c23355dea35c6fa423de69f6507852efe4Timo Sirainen public AtomList apply( ValueMap binding ) {
c9dea5c23355dea35c6fa423de69f6507852efe4Timo Sirainen OWLOntology ont = getOntology();
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen SWRLFactory swrl = SWRLFactoryCreator.createFactory( ont );
7a24bdc1a5e2d5368c2569b4852192f2bdb5a31fTimo Sirainen
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen AtomList newList = swrl.createList();
7a24bdc1a5e2d5368c2569b4852192f2bdb5a31fTimo Sirainen for( AtomList list = this; !list.isEmpty(); list = (AtomList) list.getRest() ) {
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen Atom atom = (Atom) list.getFirst();
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen Atom newAtom = null;
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen if(atom instanceof ClassAtom) {
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen ClassAtom classAtom = (ClassAtom) atom;
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen newAtom = swrl.createClassAtom(
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen classAtom.getClassPredicate(),
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen getIndidividualObject( classAtom.getArgument1(), binding ) );
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen }
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen else if(atom instanceof IndividualPropertyAtom) {
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen IndividualPropertyAtom indPropAtom = (IndividualPropertyAtom) atom;
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen newAtom = swrl.createIndividualPropertyAtom(
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen indPropAtom.getPropertyPredicate(),
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen getIndidividualObject( indPropAtom.getArgument1(), binding ),
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen getIndidividualObject( indPropAtom.getArgument2(), binding ));
8f90ef65db62946aabe1969755edcdefb4eb430aTimo Sirainen }
8f90ef65db62946aabe1969755edcdefb4eb430aTimo Sirainen else if(atom instanceof DataPropertyAtom) {
8f90ef65db62946aabe1969755edcdefb4eb430aTimo Sirainen DataPropertyAtom dataPropAtom = (DataPropertyAtom) atom;
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen newAtom = swrl.createDataPropertyAtom(
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen dataPropAtom.getPropertyPredicate(),
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen getIndidividualObject( dataPropAtom.getArgument1(), binding ),
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen getDataObject( dataPropAtom.getArgument2(), binding ));
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen }
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen else if(atom instanceof SameIndividualAtom) {
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen SameIndividualAtom sameAtom = (SameIndividualAtom) atom;
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen newAtom = swrl.createSameIndividualAtom(
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen getIndidividualObject( sameAtom.getArgument1(), binding ),
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen getIndidividualObject( sameAtom.getArgument2(), binding ));
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen }
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 ));
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen }
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen else if(atom instanceof BuiltinAtom) {
504337186520df7012315687fc0f88c945775471Timo Sirainen BuiltinAtom builtinAtom = (BuiltinAtom) atom;
504337186520df7012315687fc0f88c945775471Timo Sirainen OWLIndividual builtin = builtinAtom.getBuiltin();
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen int argCount = atom.getArgumentCount();
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen SWRLDataObject[] args = new SWRLDataObject[ argCount ];
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen for( int i = 0; i < argCount; i++ ) {
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen SWRLDataObject arg = (SWRLDataObject) atom.getArgument( i );
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen args[i] = getDataObject( arg, binding );
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen }
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen if ( builtin.equals( SWRLB.equal ) )
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen newAtom = swrl.createEqual( args[0], args[1] );
6d6c1517ef20e340a3aace406724fc8916f2d13fTimo Sirainen else if ( builtin.equals( SWRLB.notEqual ) )
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 else if ( builtin.equals( SWRLB.lessThan ) )
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] );
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen else if ( builtin.equals( SWRLB.add ) )
825b0e819a7c48a366ddca23ec78b87e8c30e9b4Aki Tuomi newAtom = swrl.createAdd( args[0], args[1], args[2] );
825b0e819a7c48a366ddca23ec78b87e8c30e9b4Aki Tuomi else if ( builtin.equals( SWRLB.subtract ) )
825b0e819a7c48a366ddca23ec78b87e8c30e9b4Aki Tuomi newAtom = swrl.createSubtract( args[0], args[1], args[2] );
825b0e819a7c48a366ddca23ec78b87e8c30e9b4Aki Tuomi else
825b0e819a7c48a366ddca23ec78b87e8c30e9b4Aki Tuomi throw new NotImplementedException( builtin.toPrettyString() );
825b0e819a7c48a366ddca23ec78b87e8c30e9b4Aki Tuomi }
825b0e819a7c48a366ddca23ec78b87e8c30e9b4Aki Tuomi else
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen throw new RuntimeException("Unknown atom type " + atom);
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen if( newList.isEmpty() )
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen newList = newList.insert( newAtom );
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen else
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen newList.add( newAtom );
939a0d82523538b2de38a02bc9f790a67b7ebf47Timo Sirainen
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen// newList = newList.add( newAtom );
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen }
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen return newList;
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen }
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen public List getVars() {
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen List vars = new ArrayList();
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen for( AtomList list = this; !list.isEmpty(); list = (AtomList) list.getRest() ) {
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen Atom atom = (Atom) list.getFirst();
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen for( int j = 0; j < atom.getArgumentCount(); j++ ) {
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen SWRLObject term = atom.getArgument( j );
939a0d82523538b2de38a02bc9f790a67b7ebf47Timo Sirainen if( term instanceof Variable )
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen vars.add( term );
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen }
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen }
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen return vars;
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen }
939a0d82523538b2de38a02bc9f790a67b7ebf47Timo Sirainen
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen public String toString() {
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen StringBuffer str = new StringBuffer("[");
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen for(RDFList list = this; !list.isEmpty(); list = list.getRest()) {
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen if(list != this)
939a0d82523538b2de38a02bc9f790a67b7ebf47Timo Sirainen str.append(", ");
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen str.append(list.getFirst().toString());
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen }
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen str.append("]");
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen return str.toString();
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen }
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen public RDFList remove() {
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen AtomListImpl list = new AtomListImpl(getOntology().createInstance(vocabulary.List()));
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen list.setVocabulary(vocabulary);
d85a1a9d9af4a36ded4d30cb277905c807de2ec5Timo Sirainen if (size() > 1) {
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen list.setFirst(getRest().getFirstValue());
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen list.setRest((AtomList) getRest().getRest());
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen } else {
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
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen list.setFirst(vocabulary.nil());
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen list.setRestToNil();
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen }
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainen
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen return list;
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen }
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen}
6d6c1517ef20e340a3aace406724fc8916f2d13fTimo Sirainen