Cross Reference: AtomListImpl.java
xref
: /
owl-s
/
src
/
impl
/
swrl
/
AtomListImpl.java
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
2
ronwalf
/*
2
ronwalf
* Created on Dec 28, 2004
2
ronwalf
*/
2
ronwalf
package
impl
.
swrl
;
2
ronwalf
2
ronwalf
2
ronwalf
import
impl
.
owl
.
list
.
RDFListImpl
;
2
ronwalf
2
ronwalf
import
java
.
util
.
ArrayList
;
2
ronwalf
import
java
.
util
.
List
;
2
ronwalf
2
ronwalf
import
org
.
mindswap
.
exceptions
.
NotImplementedException
;
2
ronwalf
import
org
.
mindswap
.
owl
.
OWLDataValue
;
2
ronwalf
import
org
.
mindswap
.
owl
.
OWLIndividual
;
2
ronwalf
import
org
.
mindswap
.
owl
.
OWLOntology
;
2
ronwalf
import
org
.
mindswap
.
owl
.
OWLValue
;
2
ronwalf
import
org
.
mindswap
.
owl
.
list
.
RDFList
;
2
ronwalf
import
org
.
mindswap
.
owl
.
vocabulary
.
SWRL
;
2
ronwalf
import
org
.
mindswap
.
owl
.
vocabulary
.
SWRLB
;
2
ronwalf
import
org
.
mindswap
.
query
.
ABoxQuery
;
2
ronwalf
import
org
.
mindswap
.
query
.
ValueMap
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
Atom
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
AtomList
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
BuiltinAtom
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
ClassAtom
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
DataPropertyAtom
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
DifferentIndividualsAtom
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
IndividualPropertyAtom
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
SWRLDataObject
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
SWRLDataValue
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
SWRLFactory
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
SWRLFactoryCreator
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
SWRLIndividual
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
SWRLIndividualObject
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
SWRLObject
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
SameIndividualAtom
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
Variable
;
2
ronwalf
2
ronwalf
/**
2
ronwalf
*
@author
Evren Sirin
2
ronwalf
*
2
ronwalf
*/
2
ronwalf
public
class
AtomListImpl
extends
RDFListImpl
implements
AtomList
{
2
ronwalf
public
AtomListImpl
(
OWLIndividual
ind
) {
2
ronwalf
super
(
ind
);
2
ronwalf
2
ronwalf
setVocabulary
(
SWRL
.
AtomListVocabulary
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
AtomList
add
(
Atom
item
) {
2
ronwalf
if
(
isEmpty
() )
2
ronwalf
return
insert
(
item
);
2
ronwalf
2
ronwalf
RDFList
rest
=
getRest
();
2
ronwalf
2
ronwalf
if
(
rest
.
isEmpty
())
2
ronwalf
setRest
(
rest
.
insert
(
item
) );
2
ronwalf
else
2
ronwalf
rest
.
add
(
item
);
2
ronwalf
2
ronwalf
return
this
;
2
ronwalf
}
2
ronwalf
2
ronwalf
public
AtomList
insert
(
Atom
first
) {
2
ronwalf
OWLOntology
ont
=
getOntology
();
38
daenzerorama
AtomListImpl
list
=
new
AtomListImpl
(
ont
.
createInstance
(
vocabulary
.
List
() ) );
38
daenzerorama
2
ronwalf
list
.
setFirst
(
first
);
2
ronwalf
list
.
setRest
(
this
);
2
ronwalf
2
ronwalf
return
list
;
2
ronwalf
}
2
ronwalf
2
ronwalf
public
AtomList
insertAt
(
int
index
,
Atom
item
) {
2
ronwalf
return
(
AtomList
)
super
.
insertAt
(
index
,
item
).
castTo
(
AtomList
.
class
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
RDFList
insert
(
OWLValue
item
) {
2
ronwalf
Atom
atom
= (
Atom
)
item
.
castTo
(
Atom
.
class
);
2
ronwalf
2
ronwalf
return
add
(
atom
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
OWLValue
getFirstValue
() {
2
ronwalf
return
(
Atom
)
getProperty
(
vocabulary
.
first
()).
castTo
(
Atom
.
class
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
RDFList
getRest
() {
2
ronwalf
return
(
RDFList
)
getProperty
(
vocabulary
.
rest
()).
castTo
(
AtomList
.
class
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
Atom
atomAt
(
int
index
) {
2
ronwalf
return
(
Atom
)
get
(
index
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
ABoxQuery
toQuery
() {
2
ronwalf
return
new
ABoxQuery
(
this
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
ABoxQuery
toQuery
(
List
resultVars
) {
2
ronwalf
return
new
ABoxQuery
(
this
,
resultVars
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
SWRLIndividualObject
getIndidividualObject
(
SWRLIndividualObject
arg
,
ValueMap
binding
) {
2
ronwalf
if
(
arg
.
isVariable
() &&
binding
.
hasValue
( (
Variable
)
arg
) ) {
2
ronwalf
OWLIndividual
ind
= (
OWLIndividual
)
binding
.
getValue
( (
Variable
)
arg
);
2
ronwalf
arg
= (
SWRLIndividual
)
ind
.
castTo
(
SWRLIndividual
.
class
);
2
ronwalf
}
2
ronwalf
2
ronwalf
return
arg
;
2
ronwalf
}
2
ronwalf
2
ronwalf
public
SWRLDataObject
getDataObject
(
SWRLDataObject
arg
,
ValueMap
binding
) {
2
ronwalf
if
(
arg
.
isVariable
() &&
binding
.
hasValue
( (
Variable
)
arg
) ) {
2
ronwalf
OWLDataValue
dv
= (
OWLDataValue
)
binding
.
getValue
( (
Variable
)
arg
);
2
ronwalf
arg
= (
SWRLDataValue
)
dv
.
castTo
(
SWRLDataValue
.
class
);
2
ronwalf
}
2
ronwalf
2
ronwalf
return
arg
;
2
ronwalf
}
2
ronwalf
38
daenzerorama
public
void
evaluate
(
ValueMap
values
) {
38
daenzerorama
for
(
int
i =
0
; i <
size
(); i++)
38
daenzerorama
atomAt
(i).
evaluate
(
values
);
38
daenzerorama
}
38
daenzerorama
2
ronwalf
public
AtomList
apply
(
ValueMap
binding
) {
2
ronwalf
OWLOntology
ont
=
getOntology
();
2
ronwalf
SWRLFactory
swrl
=
SWRLFactoryCreator
.
createFactory
(
ont
);
2
ronwalf
2
ronwalf
AtomList
newList
=
swrl
.
createList
();
2
ronwalf
for
(
AtomList
list
=
this
; !
list
.
isEmpty
();
list
= (
AtomList
)
list
.
getRest
() ) {
2
ronwalf
Atom
atom
= (
Atom
)
list
.
getFirst
();
2
ronwalf
2
ronwalf
Atom
newAtom
=
null
;
2
ronwalf
if
(
atom
instanceof
ClassAtom
) {
2
ronwalf
ClassAtom
classAtom
= (
ClassAtom
)
atom
;
2
ronwalf
newAtom
=
swrl
.
createClassAtom
(
2
ronwalf
classAtom
.
getClassPredicate
(),
2
ronwalf
getIndidividualObject
(
classAtom
.
getArgument1
(),
binding
) );
2
ronwalf
}
2
ronwalf
else
if
(
atom
instanceof
IndividualPropertyAtom
) {
2
ronwalf
IndividualPropertyAtom
indPropAtom
= (
IndividualPropertyAtom
)
atom
;
2
ronwalf
newAtom
=
swrl
.
createIndividualPropertyAtom
(
2
ronwalf
indPropAtom
.
getPropertyPredicate
(),
2
ronwalf
getIndidividualObject
(
indPropAtom
.
getArgument1
(),
binding
),
2
ronwalf
getIndidividualObject
(
indPropAtom
.
getArgument2
(),
binding
));
2
ronwalf
}
2
ronwalf
else
if
(
atom
instanceof
DataPropertyAtom
) {
2
ronwalf
DataPropertyAtom
dataPropAtom
= (
DataPropertyAtom
)
atom
;
2
ronwalf
newAtom
=
swrl
.
createDataPropertyAtom
(
2
ronwalf
dataPropAtom
.
getPropertyPredicate
(),
2
ronwalf
getIndidividualObject
(
dataPropAtom
.
getArgument1
(),
binding
),
2
ronwalf
getDataObject
(
dataPropAtom
.
getArgument2
(),
binding
));
2
ronwalf
}
2
ronwalf
else
if
(
atom
instanceof
SameIndividualAtom
) {
2
ronwalf
SameIndividualAtom
sameAtom
= (
SameIndividualAtom
)
atom
;
2
ronwalf
newAtom
=
swrl
.
createSameIndividualAtom
(
2
ronwalf
getIndidividualObject
(
sameAtom
.
getArgument1
(),
binding
),
2
ronwalf
getIndidividualObject
(
sameAtom
.
getArgument2
(),
binding
));
2
ronwalf
}
2
ronwalf
else
if
(
atom
instanceof
DifferentIndividualsAtom
) {
2
ronwalf
DifferentIndividualsAtom
diffAtom
= (
DifferentIndividualsAtom
)
atom
;
2
ronwalf
newAtom
=
swrl
.
createDifferentIndividualsAtom
(
2
ronwalf
getIndidividualObject
(
diffAtom
.
getArgument1
(),
binding
),
2
ronwalf
getIndidividualObject
(
diffAtom
.
getArgument2
(),
binding
));
2
ronwalf
}
2
ronwalf
else
if
(
atom
instanceof
BuiltinAtom
) {
2
ronwalf
BuiltinAtom
builtinAtom
= (
BuiltinAtom
)
atom
;
2
ronwalf
OWLIndividual
builtin
=
builtinAtom
.
getBuiltin
();
2
ronwalf
int
argCount
=
atom
.
getArgumentCount
();
2
ronwalf
SWRLDataObject
[]
args
=
new
SWRLDataObject
[
argCount
];
2
ronwalf
for
(
int
i =
0
; i <
argCount
; i++ ) {
2
ronwalf
SWRLDataObject
arg
= (
SWRLDataObject
)
atom
.
getArgument
( i );
2
ronwalf
args
[i] =
getDataObject
(
arg
,
binding
);
2
ronwalf
}
2
ronwalf
2
ronwalf
if
(
builtin
.
equals
(
SWRLB
.
equal
) )
2
ronwalf
newAtom
=
swrl
.
createEqual
(
args
[
0
],
args
[
1
] );
2
ronwalf
else
if
(
builtin
.
equals
(
SWRLB
.
notEqual
) )
2
ronwalf
newAtom
=
swrl
.
createNotEqual
(
args
[
0
],
args
[
1
] );
2
ronwalf
else
if
(
builtin
.
equals
(
SWRLB
.
greaterThan
) )
2
ronwalf
newAtom
=
swrl
.
createGreaterThan
(
args
[
0
],
args
[
1
] );
2
ronwalf
else
if
(
builtin
.
equals
(
SWRLB
.
greaterThanOrEqual
) )
2
ronwalf
newAtom
=
swrl
.
createGreaterThanOrEqual
(
args
[
0
],
args
[
1
] );
2
ronwalf
else
if
(
builtin
.
equals
(
SWRLB
.
lessThan
) )
2
ronwalf
newAtom
=
swrl
.
createLessThan
(
args
[
0
],
args
[
1
] );
2
ronwalf
else
if
(
builtin
.
equals
(
SWRLB
.
lessThanOrEqual
) )
2
ronwalf
newAtom
=
swrl
.
createLessThanOrEqual
(
args
[
0
],
args
[
1
] );
2
ronwalf
else
if
(
builtin
.
equals
(
SWRLB
.
add
) )
2
ronwalf
newAtom
=
swrl
.
createAdd
(
args
[
0
],
args
[
1
],
args
[
2
] );
2
ronwalf
else
if
(
builtin
.
equals
(
SWRLB
.
subtract
) )
2
ronwalf
newAtom
=
swrl
.
createSubtract
(
args
[
0
],
args
[
1
],
args
[
2
] );
2
ronwalf
else
2
ronwalf
throw
new
NotImplementedException
(
builtin
.
toPrettyString
() );
2
ronwalf
}
2
ronwalf
else
2
ronwalf
throw
new
RuntimeException
(
"Unknown atom type "
+
atom
);
2
ronwalf
2
ronwalf
if
(
newList
.
isEmpty
() )
2
ronwalf
newList
=
newList
.
insert
(
newAtom
);
2
ronwalf
else
2
ronwalf
newList
.
add
(
newAtom
);
2
ronwalf
2
ronwalf
// newList = newList.add( newAtom );
2
ronwalf
}
2
ronwalf
2
ronwalf
return
newList
;
2
ronwalf
}
2
ronwalf
2
ronwalf
2
ronwalf
public
List
getVars
() {
2
ronwalf
List
vars
=
new
ArrayList
();
2
ronwalf
2
ronwalf
for
(
AtomList
list
=
this
; !
list
.
isEmpty
();
list
= (
AtomList
)
list
.
getRest
() ) {
2
ronwalf
Atom
atom
= (
Atom
)
list
.
getFirst
();
2
ronwalf
for
(
int
j =
0
; j <
atom
.
getArgumentCount
(); j++ ) {
2
ronwalf
SWRLObject
term
=
atom
.
getArgument
( j );
2
ronwalf
if
(
term
instanceof
Variable
)
2
ronwalf
vars
.
add
(
term
);
2
ronwalf
}
2
ronwalf
}
2
ronwalf
return
vars
;
2
ronwalf
}
2
ronwalf
2
ronwalf
public
String
toString
() {
2
ronwalf
StringBuffer
str
=
new
StringBuffer
(
"["
);
2
ronwalf
for
(
RDFList
list
=
this
; !
list
.
isEmpty
();
list
=
list
.
getRest
()) {
2
ronwalf
if
(
list
!=
this
)
2
ronwalf
str
.
append
(
", "
);
2
ronwalf
str
.
append
(
list
.
getFirst
().
toString
());
2
ronwalf
}
2
ronwalf
str
.
append
(
"]"
);
2
ronwalf
return
str
.
toString
();
2
ronwalf
}
16
daenzerorama
16
daenzerorama
public
RDFList
remove
() {
18
daenzerorama
AtomList
list
= (
AtomList
)
getRest
();
18
daenzerorama
16
daenzerorama
if
(
size
() >
1
) {
16
daenzerorama
list
.
setFirst
(
getRest
().
getFirstValue
());
18
daenzerorama
list
.
setRest
((
AtomList
)
getRest
().
getRest
());
18
daenzerorama
}
else
{
18
daenzerorama
list
= (
AtomList
)
vocabulary
.
nil
().
castTo
(
RDFList
.
class
);
16
daenzerorama
}
18
daenzerorama
if
(
hasProperty
(
vocabulary
.
first
()))
18
daenzerorama
removeProperties
(
vocabulary
.
first
());
18
daenzerorama
if
(
hasProperty
(
vocabulary
.
rest
()))
18
daenzerorama
removeProperties
(
vocabulary
.
rest
());
18
daenzerorama
individual
.
delete
();
18
daenzerorama
16
daenzerorama
return
list
;
16
daenzerorama
}
18
daenzerorama
18
daenzerorama
public
RDFList
removeAll
() {
18
daenzerorama
AtomList
list
=
this
;
18
daenzerorama
while
(
list
.
size
() >
0
)
18
daenzerorama
list
= (
AtomList
)
list
.
remove
();
18
daenzerorama
return
list
;
18
daenzerorama
}
2
ronwalf
}