You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Craig Trim <cr...@gmail.com> on 2012/04/11 02:56:07 UTC
List Statements by Subject
I'm trying to list statements in a model, searching by rdfs:label. The
first statement works, and the second one doesn't.
String qLabel = label.concat("@en");
StmtIterator iter2 = model.listStatements((Resource) null,
RDFS.label, (RDFNode) null);
while (iter2.hasNext()) {
Statement stmt = iter2.next();
if (stmt.getObject().toString().equalsIgnoreCase(qLabel)) {
// this works ...
}
}
StmtIterator iter = model.listStatements((Resource) null,
RDFS.label, qLabel);
while (iter.hasNext()) {
list.add(iter.next());
}
Any insight appreciated. Thanks!
lib:
arq-2.8.8.jar, icu4j-3.4.4.jar, iri-0.8.jar, jena-2.6.4-A.jar,
junit-4.5.jar, log4j-1.2.14.jar, lucene-core-2.3.1.jar,
slf4j-api-1.6.4.jar, slf4j-log4j12-1.6.4.jar, stax, api-1.0.1.jar,
tdb-0.8.10.jar, wstx-asl-3.2.9.jar, xercesImpl-2.7.1.jar
O/S:
Microsoft Windows [Version 6.1.7601] 64 bit
JDK:
java version "1.6.0"
Java(TM) SE Runtime Environment (build pwa6460sr9fp2-20110625_01(SR9 FP2))
IBM J9 VM (build 2.4, JRE 1.6.0 IBM J9 2.4 Windows 7 amd64-64
jvmwa6460sr9-20110624_85526 (JIT enabled, AOT enabled)
J9VM - 20110624_085526
JIT - r9_20101028_17488ifx17
GC - 20101027_AA)
JCL - 20110530_01
Re: Jena rule for SWRL's string literal comparison
Posted by Dave Reynolds <da...@gmail.com>.
On 11/04/12 15:31, Rodrigo Jardim wrote:
> and RIF Rules :) ?
A contribution of those builtins would be good too :)
Indeed a contribution of a RIF implementation would definitely be great :)
Though RIF is harder because RIF is a more powerful (and useful)
language. The way that the RIF/RDF mapping works means that you can use
RIF tuples to do lots of interesting computations and then express the
results back in RDF. At a stroke it removes the need for clunky things
like Jena's "hide" meta-predicates and gives you full power of recursion
for that intermediate working.
Dave
>
> --
> Rodrigo
>
> Em 11/04/2012 11:25, Dave Reynolds escreveu:
>> HI Taha,
>>
>> On 11/04/12 09:19, Osman, Taha wrote:
>>> Hello,
>>>
>>> We are trying to convert our system's SWRL rules into equivalent Jena
>>> rules, but are stuck at the point where we have to compare a variable
>>> to a
>>> string literal while ignoring the case. The corresponding functor in
>>> SWRL
>>> is stringEqualIgnoreCase (our SWRL rule is examplified below). Is
>>> there an
>>> equivalent functor in Jena rules? Can you provide an example?
>>
>> No sorry, the set of builtin functions is Jena rules is a bit
>> minimalist. If anyone was interested in contributing a fuller SWRL
>> compatible set that would be great :)
>>
>> It would be easy enough for you to create a custom builtin. Something
>> like:
>>
>> class StringEqualIgnoreCase extends BaseBuiltin implements Builtin {
>>
>> public String getName() {
>> return "stringEqualIgnoreCase";
>> }
>>
>> @Override
>> public int getArgLength() {
>> return 2;
>> }
>>
>> @Override
>> public boolean bodyCall(Node[] args, int length, RuleContext context) {
>> checkArgs(length, context);
>> Node n1 = getArg(0, args, context);
>> Node n2 = getArg(1, args, context);
>> if (n1.isLiteral() && n1.isLiteral()) {
>> return n1.getLiteralLexicalForm().equalsIgnoreCase(
>> n2.getLiteralLexicalForm() );
>> } else {
>> return false;
>> }
>> }
>>
>> }
>>
>> Which you need to install in the registry before use:
>>
>> BuiltinRegistry.theRegistry.register( new StringEqualIgnoreCase() );
>>
>> Dave
>
Re: Jena rule for SWRL's string literal comparison
Posted by Rodrigo Jardim <ro...@gmail.com>.
and RIF Rules :) ?
--
Rodrigo
Em 11/04/2012 11:25, Dave Reynolds escreveu:
> HI Taha,
>
> On 11/04/12 09:19, Osman, Taha wrote:
>> Hello,
>>
>> We are trying to convert our system's SWRL rules into equivalent Jena
>> rules, but are stuck at the point where we have to compare a variable
>> to a
>> string literal while ignoring the case. The corresponding functor in
>> SWRL
>> is stringEqualIgnoreCase (our SWRL rule is examplified below). Is
>> there an
>> equivalent functor in Jena rules? Can you provide an example?
>
> No sorry, the set of builtin functions is Jena rules is a bit
> minimalist. If anyone was interested in contributing a fuller SWRL
> compatible set that would be great :)
>
> It would be easy enough for you to create a custom builtin. Something
> like:
>
> class StringEqualIgnoreCase extends BaseBuiltin implements Builtin {
>
> public String getName() {
> return "stringEqualIgnoreCase";
> }
>
> @Override
> public int getArgLength() {
> return 2;
> }
>
> @Override
> public boolean bodyCall(Node[] args, int length, RuleContext
> context) {
> checkArgs(length, context);
> Node n1 = getArg(0, args, context);
> Node n2 = getArg(1, args, context);
> if (n1.isLiteral() && n1.isLiteral()) {
> return n1.getLiteralLexicalForm().equalsIgnoreCase(
> n2.getLiteralLexicalForm() );
> } else {
> return false;
> }
> }
>
> }
>
> Which you need to install in the registry before use:
>
> BuiltinRegistry.theRegistry.register( new StringEqualIgnoreCase() );
>
> Dave
Re: Jena rule for SWRL's string literal comparison
Posted by Dave Reynolds <da...@gmail.com>.
HI Taha,
On 11/04/12 09:19, Osman, Taha wrote:
> Hello,
>
> We are trying to convert our system's SWRL rules into equivalent Jena
> rules, but are stuck at the point where we have to compare a variable to a
> string literal while ignoring the case. The corresponding functor in SWRL
> is stringEqualIgnoreCase (our SWRL rule is examplified below). Is there an
> equivalent functor in Jena rules? Can you provide an example?
No sorry, the set of builtin functions is Jena rules is a bit
minimalist. If anyone was interested in contributing a fuller SWRL
compatible set that would be great :)
It would be easy enough for you to create a custom builtin. Something like:
class StringEqualIgnoreCase extends BaseBuiltin implements Builtin {
public String getName() {
return "stringEqualIgnoreCase";
}
@Override
public int getArgLength() {
return 2;
}
@Override
public boolean bodyCall(Node[] args, int length, RuleContext context) {
checkArgs(length, context);
Node n1 = getArg(0, args, context);
Node n2 = getArg(1, args, context);
if (n1.isLiteral() && n1.isLiteral()) {
return n1.getLiteralLexicalForm().equalsIgnoreCase(
n2.getLiteralLexicalForm() );
} else {
return false;
}
}
}
Which you need to install in the registry before use:
BuiltinRegistry.theRegistry.register( new StringEqualIgnoreCase() );
Dave
Jena rule for SWRL's string literal comparison
Posted by "Osman, Taha" <ta...@ntu.ac.uk>.
Hello,
We are trying to convert our system's SWRL rules into equivalent Jena
rules, but are stuck at the point where we have to compare a variable to a
string literal while ignoring the case. The corresponding functor in SWRL
is stringEqualIgnoreCase (our SWRL rule is examplified below). Is there an
equivalent functor in Jena rules? Can you provide an example?
AccidentalFall(?af), hasDP_Location(?re, ?l),
<swrlb#stringEqualIgnoreCase>(?l, "Bathroom"@)
-> AccidentalFallInsideBathroom(?af)
Thanks
Taha
--
Dr Taha Osman
Computing and Informatics Building
School of Science and Technology
Nottingham Trent University
Nottingham NG11 8NS
Tel: +44 (0)115 848 8370
Fax: +44(0)115 848 8429
DISCLAIMER:
This email is intended solely for the addressee. It may contain private
and confidential information. If you are not the intended addressee,
please take no action based on it nor show a copy to anyone. In this
case, please reply to this email to highlight the error. Opinions and
information in this email that do not relate to the official business of
Nottingham Trent University shall be understood as neither given nor
endorsed by the University. Nottingham Trent University has taken steps to
ensure that this email and any attachments are virus-free, but we do
advise that the recipient should check that the email and its attachments
are actually virus free. This is in keeping with good computing practice.
DISCLAIMER: This email is intended solely for the addressee. It may contain private and confidential information. If you are not the intended addressee, please take no action based on it nor show a copy to anyone. In this case, please reply to this email to highlight the error. Opinions and information in this email that do not relate to the official business of Nottingham Trent University shall be understood as neither given nor endorsed by the University. Nottingham Trent University has taken steps to ensure that this email and any attachments are virus-free, but we do advise that the recipient should check that the email and its attachments are actually virus free. This is in keeping with good computing practice.
Re: List Statements by Subject
Posted by Brian McBride <br...@epimorphics.com>.
Hi Trim,
You could try:
Literal qLabel = model.createLiteral(label, "en");
Iterator<Statement> iter =
model.listStatements(
null,
RDFS.label,
qLabel);
Brian
On 11/04/12 01:56, Craig Trim wrote:
> I'm trying to list statements in a model, searching by rdfs:label. The
> first statement works, and the second one doesn't.
>
>
> String qLabel = label.concat("@en");
>
> StmtIterator iter2 = model.listStatements((Resource) null,
> RDFS.label, (RDFNode) null);
> while (iter2.hasNext()) {
> Statement stmt = iter2.next();
> if (stmt.getObject().toString().equalsIgnoreCase(qLabel)) {
> // this works ...
> }
> }
>
> StmtIterator iter = model.listStatements((Resource) null,
> RDFS.label, qLabel);
> while (iter.hasNext()) {
> list.add(iter.next());
> }
>
> Any insight appreciated. Thanks!
>
>
> lib:
> arq-2.8.8.jar, icu4j-3.4.4.jar, iri-0.8.jar, jena-2.6.4-A.jar,
> junit-4.5.jar, log4j-1.2.14.jar, lucene-core-2.3.1.jar,
> slf4j-api-1.6.4.jar, slf4j-log4j12-1.6.4.jar, stax, api-1.0.1.jar,
> tdb-0.8.10.jar, wstx-asl-3.2.9.jar, xercesImpl-2.7.1.jar
>
>
> O/S:
> Microsoft Windows [Version 6.1.7601] 64 bit
>
> JDK:
> java version "1.6.0"
> Java(TM) SE Runtime Environment (build pwa6460sr9fp2-20110625_01(SR9 FP2))
> IBM J9 VM (build 2.4, JRE 1.6.0 IBM J9 2.4 Windows 7 amd64-64
> jvmwa6460sr9-20110624_85526 (JIT enabled, AOT enabled)
> J9VM - 20110624_085526
> JIT - r9_20101028_17488ifx17
> GC - 20101027_AA)
> JCL - 20110530_01
>
--
Epimorphics Ltd www.epimorphics.com
Tel: 01275 399069
Court Lodge, 105 High Street, Portishead, Bristol BS20 6PT
Epimorphics Ltd. is a limited company registered in England #7016688
Registered address: 105 High Street, Portishead, Bristol BS20 6PT, UK
Re: List Statements by Subject
Posted by Dave Reynolds <da...@gmail.com>.
On 11/04/12 01:56, Craig Trim wrote:
> I'm trying to list statements in a model, searching by rdfs:label. The
> first statement works, and the second one doesn't.
>
>
> String qLabel = label.concat("@en");
>
> StmtIterator iter2 = model.listStatements((Resource) null,
> RDFS.label, (RDFNode) null);
> while (iter2.hasNext()) {
> Statement stmt = iter2.next();
> if (stmt.getObject().toString().equalsIgnoreCase(qLabel)) {
> // this works ...
> }
> }
>
> StmtIterator iter = model.listStatements((Resource) null,
> RDFS.label, qLabel);
> while (iter.hasNext()) {
> list.add(iter.next());
> }
>
> Any insight appreciated. Thanks!
The syntax "foo@en" indicates a label "foo" with an "en" language tag
which is not the same thing as a plain label which happens to be spelt
"foo@en".
I assume you have language tags on your labels in which case in the
second version use:
model.listStatements(null, RDFS.label, model.createLiteral(label, "en"))
Dave
>
>
> lib:
> arq-2.8.8.jar, icu4j-3.4.4.jar, iri-0.8.jar, jena-2.6.4-A.jar,
> junit-4.5.jar, log4j-1.2.14.jar, lucene-core-2.3.1.jar,
> slf4j-api-1.6.4.jar, slf4j-log4j12-1.6.4.jar, stax, api-1.0.1.jar,
> tdb-0.8.10.jar, wstx-asl-3.2.9.jar, xercesImpl-2.7.1.jar
>
>
> O/S:
> Microsoft Windows [Version 6.1.7601] 64 bit
>
> JDK:
> java version "1.6.0"
> Java(TM) SE Runtime Environment (build pwa6460sr9fp2-20110625_01(SR9 FP2))
> IBM J9 VM (build 2.4, JRE 1.6.0 IBM J9 2.4 Windows 7 amd64-64
> jvmwa6460sr9-20110624_85526 (JIT enabled, AOT enabled)
> J9VM - 20110624_085526
> JIT - r9_20101028_17488ifx17
> GC - 20101027_AA)
> JCL - 20110530_01
>