Cross Reference: PresentationSyntaxExpressionWriter.java
xref
: /
owl-s
/
src
/
org
/
mindswap
/
owls
/
io
/
PresentationSyntaxExpressionWriter.java
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
2
ronwalf
/*
2
ronwalf
* Created on May 7, 2005
2
ronwalf
*/
2
ronwalf
package
org
.
mindswap
.
owls
.
io
;
2
ronwalf
2
ronwalf
import
java
.
util
.
HashMap
;
2
ronwalf
import
java
.
util
.
Iterator
;
2
ronwalf
import
java
.
util
.
Map
;
2
ronwalf
2
ronwalf
import
org
.
mindswap
.
owl
.
OWLIndividual
;
2
ronwalf
import
org
.
mindswap
.
owl
.
vocabulary
.
SWRLB
;
2
ronwalf
import
org
.
mindswap
.
owls
.
io
.
BaseExpressionWriter
;
2
ronwalf
import
org
.
mindswap
.
owls
.
io
.
ExpressionWriter
;
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
.
SameIndividualAtom
;
2
ronwalf
2
ronwalf
2
ronwalf
/**
2
ronwalf
*
@author
Evren Sirin
2
ronwalf
*
2
ronwalf
*/
2
ronwalf
public
class
PresentationSyntaxExpressionWriter
extends
BaseExpressionWriter
implements
ExpressionWriter
{
2
ronwalf
static
final
Map
SYMBOLS
;
2
ronwalf
static
{
2
ronwalf
SYMBOLS
=
new
HashMap
();
2
ronwalf
SYMBOLS
.
put
(
SWRLB
.
add
,
new
String
[] {
"="
,
"+"
} );
2
ronwalf
SYMBOLS
.
put
(
SWRLB
.
subtract
,
new
String
[] {
"="
,
"-"
} );
2
ronwalf
SYMBOLS
.
put
(
SWRLB
.
divide
,
new
String
[] {
"="
,
"+"
} );
2
ronwalf
SYMBOLS
.
put
(
SWRLB
.
multiply
,
new
String
[] {
"="
,
"*"
} );
2
ronwalf
SYMBOLS
.
put
(
SWRLB
.
lessThan
,
new
String
[] {
"<"
} );
2
ronwalf
SYMBOLS
.
put
(
SWRLB
.
lessThanOrEqual
,
new
String
[] {
"<="
} );
2
ronwalf
SYMBOLS
.
put
(
SWRLB
.
greaterThan
,
new
String
[] {
">"
} );
2
ronwalf
SYMBOLS
.
put
(
SWRLB
.
greaterThanOrEqual
,
new
String
[] {
">="
} );
2
ronwalf
SYMBOLS
.
put
(
SWRLB
.
equal
,
new
String
[] {
"="
} );
2
ronwalf
SYMBOLS
.
put
(
SWRLB
.
notEqual
,
new
String
[] {
"~"
,
"="
} );
2
ronwalf
}
2
ronwalf
2
ronwalf
public
PresentationSyntaxExpressionWriter
() {
2
ronwalf
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
write
(
AtomList
atoms
) {
2
ronwalf
if
(
atoms
==
null
) {
2
ronwalf
out
.
print
(
"<No-Condition-Specified>"
);
2
ronwalf
return
;
2
ronwalf
}
2
ronwalf
boolean
first
=
true
;
2
ronwalf
for
(
Iterator
it
=
atoms
.
iterator
();
it
.
hasNext
(); ) {
2
ronwalf
if
( !
first
||
firstLineIndent
)
2
ronwalf
out
.
print
(
indent
);
2
ronwalf
else
2
ronwalf
first
=
false
;
2
ronwalf
2
ronwalf
write
( (
Atom
)
it
.
next
() );
2
ronwalf
2
ronwalf
if
(
it
.
hasNext
() )
2
ronwalf
out
.
println
(
" &"
);
2
ronwalf
}
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
write
(
ClassAtom
atom
) {
2
ronwalf
print
(
atom
.
getClassPredicate
() );
2
ronwalf
out
.
print
(
"("
);
2
ronwalf
print
(
atom
.
getArgument1
() );
2
ronwalf
out
.
print
(
")"
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
write
(
IndividualPropertyAtom
atom
) {
2
ronwalf
print
(
atom
.
getPropertyPredicate
() );
2
ronwalf
out
.
print
(
"("
);
2
ronwalf
print
(
atom
.
getArgument1
() );
2
ronwalf
out
.
print
(
", "
);
2
ronwalf
print
(
atom
.
getArgument2
() );
2
ronwalf
out
.
print
(
")"
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
write
(
DataPropertyAtom
atom
) {
2
ronwalf
print
(
atom
.
getPropertyPredicate
() );
2
ronwalf
out
.
print
(
"("
);
2
ronwalf
print
(
atom
.
getArgument1
() );
2
ronwalf
out
.
print
(
", "
);
2
ronwalf
print
(
atom
.
getArgument2
() );
2
ronwalf
out
.
print
(
")"
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
write
(
SameIndividualAtom
atom
) {
2
ronwalf
out
.
print
(
"("
);
2
ronwalf
print
(
atom
.
getArgument1
() );
2
ronwalf
out
.
print
(
" = "
);
2
ronwalf
print
(
atom
.
getArgument2
() );
2
ronwalf
out
.
print
(
")"
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
write
(
DifferentIndividualsAtom
atom
) {
2
ronwalf
out
.
print
(
"~("
);
2
ronwalf
print
(
atom
.
getArgument1
() );
2
ronwalf
out
.
print
(
" = "
);
2
ronwalf
print
(
atom
.
getArgument2
() );
2
ronwalf
out
.
print
(
")"
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
write
(
BuiltinAtom
atom
) {
2
ronwalf
OWLIndividual
builtin
=
atom
.
getBuiltin
();
2
ronwalf
int
count
=
atom
.
getArgumentCount
();
2
ronwalf
String
[]
symbols
= (
String
[])
SYMBOLS
.
get
(
builtin
);
2
ronwalf
if
(
symbols
!=
null
) {
2
ronwalf
int
extra
=
0
;
2
ronwalf
if
(
symbols
.
length
==
count
){
2
ronwalf
out
.
print
(
symbols
[
0
] );
2
ronwalf
extra
=
1
;
2
ronwalf
}
2
ronwalf
2
ronwalf
out
.
print
(
"("
);
2
ronwalf
for
(
int
i =
0
; i <
count
; i++ ) {
2
ronwalf
out
.
print
(
atom
.
getArgument
( i ) );
2
ronwalf
if
( i <
count
-
1
)
2
ronwalf
out
.
print
(
" "
+
symbols
[i +
extra
] +
" "
);
2
ronwalf
}
2
ronwalf
out
.
print
(
")"
);
2
ronwalf
}
2
ronwalf
else
{
2
ronwalf
print
(
builtin
);
2
ronwalf
out
.
print
(
"("
);
2
ronwalf
2
ronwalf
for
(
int
i =
0
; i <
atom
.
getArgumentCount
(); i++ ) {
2
ronwalf
if
( i >
0
)
out
.
print
(
", "
);
2
ronwalf
print
(
atom
.
getArgument
(
0
) );
2
ronwalf
}
2
ronwalf
out
.
print
(
")"
);
2
ronwalf
}
2
ronwalf
}
2
ronwalf
2
ronwalf
2
ronwalf
}