bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/*
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen * Created on Dec 28, 2004
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen */
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainenpackage impl.swrl;
69b728ce94379c297dc0d9247db25648871e5a34Timo Sirainen
2aa48777a6a8e77758ae870ef9dfd3b092417893Timo Sirainenimport org.mindswap.owl.OWLClass;
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainenimport org.mindswap.owl.OWLIndividual;
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainenimport org.mindswap.owl.vocabulary.SWRL;
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainenimport org.mindswap.owls.vocabulary.OWLS;
4d909e4535f1f7b9fb08047ed1bde77975fdf450Timo Sirainenimport org.mindswap.query.ValueMap;
4d909e4535f1f7b9fb08047ed1bde77975fdf450Timo Sirainenimport org.mindswap.swrl.ClassAtom;
f7ecb87b93487f7d68d6dc5e76dc93af36eb6d89Timo Sirainenimport org.mindswap.swrl.SWRLIndividualObject;
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainenimport org.mindswap.swrl.SWRLObject;
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainenimport org.mindswap.swrl.Variable;
4d909e4535f1f7b9fb08047ed1bde77975fdf450Timo Sirainen
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen/**
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen * @author Evren Sirin
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen *
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen */
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainenpublic class ClassAtomImpl extends AtomImpl implements ClassAtom {
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen public ClassAtomImpl(OWLIndividual ind) {
2ac5f36aa7c2e7a07ba8815d43a6d7483f62e74cTimo Sirainen super(ind);
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen }
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen public OWLClass getClassPredicate() {
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen return (OWLClass) getPropertyAs(SWRL.classPredicate, OWLClass.class);
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen }
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen
69b728ce94379c297dc0d9247db25648871e5a34Timo Sirainen public void setClassPredicate(OWLClass c) {
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen setProperty(SWRL.classPredicate, (OWLIndividual) c.castTo(OWLIndividual.class));
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen }
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen public SWRLIndividualObject getArgument1() {
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen return (SWRLIndividualObject) getPropertyAs(SWRL.argument1, SWRLIndividualObject.class);
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen }
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen public int getArgumentCount() {
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen return 1;
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen }
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen public SWRLObject getArgument(int index) {
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen if( index > 0 )
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen throw new IndexOutOfBoundsException("Illegal argument index: "+index+" for a ClassAtom");
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen return getArgument1();
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen }
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen public void setArgument(int index, SWRLObject term) {
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen if( index > 0 )
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen throw new IndexOutOfBoundsException("Illegal argument index: "+index+" for a ClassAtom");
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen if(term instanceof SWRLIndividualObject)
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen setArgument1((SWRLIndividualObject) term);
2ac5f36aa7c2e7a07ba8815d43a6d7483f62e74cTimo Sirainen else
2ac5f36aa7c2e7a07ba8815d43a6d7483f62e74cTimo Sirainen throw new IllegalArgumentException("ClassAtom argument should be a SWRLIndividualObject");
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen }
09304bdc1e5e416aa343802732a15064f49495ccTimo Sirainen
09304bdc1e5e416aa343802732a15064f49495ccTimo Sirainen public void setArgument1(SWRLIndividualObject obj) {
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen setProperty(SWRL.argument1, obj);
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen }
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen public String toString() {
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen OWLClass classPredicate = getClassPredicate();
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen if(classPredicate == null)
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen return "Missing_class_predicate";
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen return "(" + getArgument1() + " rdf:type " + classPredicate.getQName() + ")";
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen }
2aa48777a6a8e77758ae870ef9dfd3b092417893Timo Sirainen
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen public void evaluate(ValueMap values) {
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen OWLIndividual subject = getArgument1();
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen if (subject.isType(OWLS.Process.Parameter))
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen subject = values.getIndividualValue((Variable) subject);
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen subject.addType(getClassPredicate());
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen }
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen}
7ed711d973b319320da100d3e905ef7b99ed69d6Timo Sirainen