Cross Reference: BuiltinAtomImpl.java
xref
: /
owl-s
/
src
/
impl
/
swrl
/
BuiltinAtomImpl.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
import
java
.
util
.
HashSet
;
2
ronwalf
import
java
.
util
.
Set
;
2
ronwalf
38
daenzerorama
import
org
.
mindswap
.
exceptions
.
NotImplementedException
;
2
ronwalf
import
org
.
mindswap
.
owl
.
OWLIndividual
;
2
ronwalf
import
org
.
mindswap
.
owl
.
OWLValue
;
2
ronwalf
import
org
.
mindswap
.
owl
.
list
.
RDFList
;
2
ronwalf
import
org
.
mindswap
.
owl
.
vocabulary
.
RDF
;
2
ronwalf
import
org
.
mindswap
.
owl
.
vocabulary
.
SWRL
;
2
ronwalf
import
org
.
mindswap
.
owl
.
vocabulary
.
SWRLB
;
38
daenzerorama
import
org
.
mindswap
.
query
.
ValueMap
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
BuiltinAtom
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
SWRLDataObject
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
SWRLObject
;
2
ronwalf
2
ronwalf
/**
2
ronwalf
*
@author
Evren Sirin
2
ronwalf
*
2
ronwalf
*/
2
ronwalf
public
class
BuiltinAtomImpl
extends
AtomImpl
implements
BuiltinAtom
{
2
ronwalf
private
final
static
Set
THREE_ARGS
=
new
HashSet
();
2
ronwalf
static
{
2
ronwalf
THREE_ARGS
.
add
(
SWRLB
.
add
);
2
ronwalf
THREE_ARGS
.
add
(
SWRLB
.
subtract
);
2
ronwalf
THREE_ARGS
.
add
(
SWRLB
.
multiply
);
2
ronwalf
THREE_ARGS
.
add
(
SWRLB
.
divide
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
BuiltinAtomImpl
(
OWLIndividual
ind
) {
2
ronwalf
super
(
ind
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
OWLIndividual
getBuiltin
() {
2
ronwalf
return
getProperty
(
SWRL
.
builtin
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
setBuiltin
(
OWLIndividual
builtin
) {
2
ronwalf
setProperty
(
SWRL
.
builtin
,
builtin
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
int
getArgumentCount
() {
2
ronwalf
if
(
THREE_ARGS
.
contains
(
getBuiltin
() ) )
2
ronwalf
return
3
;
2
ronwalf
2
ronwalf
return
2
;
2
ronwalf
}
2
ronwalf
2
ronwalf
private
RDFList
getArguments
() {
2
ronwalf
OWLIndividual
args
=
getProperty
(
SWRL
.
arguments
);
2
ronwalf
2
ronwalf
return
(
args
==
null
) ?
null
: (
RDFList
)
args
.
castTo
(
RDFList
.
class
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
SWRLObject
getArgument
(
int
index
) {
2
ronwalf
RDFList
args
=
getArguments
();
2
ronwalf
2
ronwalf
if
(
args
==
null
)
return
null
;
2
ronwalf
2
ronwalf
OWLValue
arg
=
args
.
getValue
(
index
);
2
ronwalf
2
ronwalf
if
(
arg
==
null
)
return
null
;
2
ronwalf
2
ronwalf
return
(
SWRLDataObject
)
arg
.
castTo
(
SWRLDataObject
.
class
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
addArgument
(
SWRLObject
arg
) {
2
ronwalf
if
(!(
arg
instanceof
SWRLDataObject
))
2
ronwalf
throw
new
IllegalArgumentException
(
"BuiltinAtom argument should be a SWRLDataObject"
);
2
ronwalf
2
ronwalf
RDFList
args
=
getArguments
();
2
ronwalf
2
ronwalf
if
(
args
==
null
) {
2
ronwalf
RDFList
nil
=
getOntology
().
createList
(
RDF
.
ListVocabulary
);
2
ronwalf
args
=
nil
.
insert
(
arg
);
2
ronwalf
setProperty
(
SWRL
.
arguments
,
args
);
2
ronwalf
}
2
ronwalf
else
2
ronwalf
args
.
add
(
arg
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
setArgument
(
int
index
,
SWRLObject
arg
) {
2
ronwalf
if
(!(
arg
instanceof
SWRLDataObject
))
2
ronwalf
throw
new
IllegalArgumentException
(
"BuiltinAtom argument should be a SWRLDataObject"
);
2
ronwalf
2
ronwalf
RDFList
args
=
getArguments
();
2
ronwalf
2
ronwalf
if
(
args
==
null
) {
2
ronwalf
if
(
index
==
0
) {
2
ronwalf
RDFList
nil
=
getOntology
().
createList
(
RDF
.
ListVocabulary
);
2
ronwalf
args
=
nil
.
insert
(
arg
);
2
ronwalf
setProperty
(
SWRL
.
arguments
,
args
);
2
ronwalf
}
2
ronwalf
else
2
ronwalf
throw
new
IndexOutOfBoundsException
();
2
ronwalf
}
2
ronwalf
else
{
2
ronwalf
args
.
set
(
index
,
arg
);
2
ronwalf
}
2
ronwalf
}
2
ronwalf
2
ronwalf
public
String
toString
() {
2
ronwalf
OWLIndividual
builtin
=
getBuiltin
();
2
ronwalf
if
(
builtin
==
null
)
2
ronwalf
return
"Missing_class_predicate"
;
2
ronwalf
2
ronwalf
StringBuffer
str
=
new
StringBuffer
();
2
ronwalf
if
(
builtin
.
equals
(
SWRLB
.
equal
) ) {
2
ronwalf
str
.
append
(
"("
);
2
ronwalf
str
.
append
(
getArgument
(
0
) );
2
ronwalf
str
.
append
(
" = "
);
2
ronwalf
str
.
append
(
getArgument
(
1
) );
2
ronwalf
str
.
append
(
")"
);
2
ronwalf
}
2
ronwalf
else
if
(
builtin
.
equals
(
SWRLB
.
lessThan
) ) {
2
ronwalf
str
.
append
(
"("
);
2
ronwalf
str
.
append
(
getArgument
(
0
) );
2
ronwalf
str
.
append
(
" < "
);
2
ronwalf
str
.
append
(
getArgument
(
1
) );
2
ronwalf
str
.
append
(
")"
);
2
ronwalf
}
2
ronwalf
else
if
(
builtin
.
equals
(
SWRLB
.
greaterThan
) ) {
2
ronwalf
str
.
append
(
"("
);
2
ronwalf
str
.
append
(
getArgument
(
0
) );
2
ronwalf
str
.
append
(
" > "
);
2
ronwalf
str
.
append
(
getArgument
(
1
) );
2
ronwalf
str
.
append
(
")"
);
2
ronwalf
}
2
ronwalf
else
if
(
builtin
.
equals
(
SWRLB
.
add
) ) {
2
ronwalf
str
.
append
(
"("
);
2
ronwalf
str
.
append
(
getArgument
(
0
) );
2
ronwalf
str
.
append
(
" = "
);
2
ronwalf
str
.
append
(
getArgument
(
1
) );
2
ronwalf
str
.
append
(
" + "
);
2
ronwalf
str
.
append
(
getArgument
(
2
) );
2
ronwalf
str
.
append
(
")"
);
2
ronwalf
}
2
ronwalf
else
if
(
builtin
.
equals
(
SWRLB
.
subtract
) ) {
2
ronwalf
str
.
append
(
"("
);
2
ronwalf
str
.
append
(
getArgument
(
0
) );
2
ronwalf
str
.
append
(
" = "
);
2
ronwalf
str
.
append
(
getArgument
(
1
) );
2
ronwalf
str
.
append
(
" - "
);
2
ronwalf
str
.
append
(
getArgument
(
2
) );
2
ronwalf
str
.
append
(
")"
);
2
ronwalf
}
2
ronwalf
else
{
2
ronwalf
str
.
append
(
builtin
.
getLocalName
() ).
append
(
"("
);
2
ronwalf
for
(
int
i =
0
; i <
getArgumentCount
(); i++) {
2
ronwalf
SWRLObject
arg
=
getArgument
( i );
2
ronwalf
if
( i >
0
)
2
ronwalf
str
.
append
(
", "
);
2
ronwalf
str
.
append
(
arg
);
2
ronwalf
}
2
ronwalf
str
.
append
(
")"
);
2
ronwalf
}
2
ronwalf
2
ronwalf
return
str
.
toString
();
2
ronwalf
}
38
daenzerorama
38
daenzerorama
public
void
evaluate
(
ValueMap
values
) {
38
daenzerorama
OWLIndividual
builtin
=
getBuiltin
();
38
daenzerorama
if
(! (
builtin
.
equals
(
SWRLB
.
add
) ||
builtin
.
equals
(
SWRLB
.
subtract
) ||
38
daenzerorama
builtin
.
equals
(
SWRLB
.
multiply
) ||
builtin
.
equals
(
SWRLB
.
divide
)))
38
daenzerorama
return
;
38
daenzerorama
38
daenzerorama
throw
new
NotImplementedException
(
"Builtin SWRL atoms cannot be evaluated"
);
38
daenzerorama
}
2
ronwalf
}