0

I am fairly new to this whole topic and i hope somebody may help me.

I currently have a problem while comparing data of an ontology, when using SQWRL. The built-in swrlb:stringEqualIgnoreCase - Function in SQWRL won't let me compare rdf:PlainLiteral with common strings. Following error message is thrown:

org.swrlapi.exceptions.SWRLBuiltInException: exception thrown by built-in swrlb:stringEqualIgnoreCase in rule q2: cannot convert value of type rdf:PlainLiteral to xsd:string

The SQWRL query:

ctest:Operation(?o) ^ ctest:name(?o, ?n) ^ swrlb:stringEqualIgnoreCase(?n, \"testop\") -> sqwrl:select(?o, ?n)

The data itself is marked as ^^http://www.w3.org/2001/XMLSchema#string in GraphDB, but i just receive it as plain literal.

Is there any easy way to convert the rdf:PlainLiteral to xsd:string using owl-api or any other tool?

edit: stack trace

[Error: invoker.invoke("q2", "swrlb:stringEqualIgnoreCase", 0, false, new VPATH($o), new BAVNs("n", ""), $n, new L("testop", "xsd:string")): built-in exception thrown by built-in swrlb:stringEqualIgnoreCase in rule q2: exception thrown by built-in swrlb:stringEqualIgnoreCase in rule q2: cannot convert value of type rdf:PlainLiteral to xsd:string]
[Near : {... invoker.invoke("q2", "swrlb:st ....}]
             ^
[Line: 1, Column: 1]: built-in exception thrown by built-in swrlb:stringEqualIgnoreCase in rule q2: exception thrown by built-in swrlb:stringEqualIgnoreCase in rule q2: cannot convert value of type rdf:PlainLiteral to xsd:string
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngine.runSQWRLQuery(DefaultSWRLRuleAndQueryEngine.java:121)
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngine.runSQWRLQuery(DefaultSWRLRuleAndQueryEngine.java:156)
    at at.fhv.cidop.manager.bidding.SQWRL.SqwrlExperimenter.main(SqwrlExperimenter.java:101)
Caused by: org.swrlapi.exceptions.TargetSWRLRuleEngineException: error running Drools rule engine:
[Error: invoker.invoke("q2", "swrlb:stringEqualIgnoreCase", 0, false, new VPATH($o), new BAVNs("n", ""), $n, new L("testop", "xsd:string")): built-in exception thrown by built-in swrlb:stringEqualIgnoreCase in rule q2: exception thrown by built-in swrlb:stringEqualIgnoreCase in rule q2: cannot convert value of type rdf:PlainLiteral to xsd:string]
[Near : {... invoker.invoke("q2", "swrlb:st ....}]
             ^
[Line: 1, Column: 1]: built-in exception thrown by built-in swrlb:stringEqualIgnoreCase in rule q2: exception thrown by built-in swrlb:stringEqualIgnoreCase in rule q2: cannot convert value of type rdf:PlainLiteral to xsd:string
    at org.swrlapi.drools.core.DroolsSWRLRuleEngine.runRuleEngine(DroolsSWRLRuleEngine.java:219)
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngine.run(DefaultSWRLRuleAndQueryEngine.java:90)
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngine.runSQWRLQuery(DefaultSWRLRuleAndQueryEngine.java:118)
    ... 2 more
Caused by: [Error: invoker.invoke("q2", "swrlb:stringEqualIgnoreCase", 0, false, new VPATH($o), new BAVNs("n", ""), $n, new L("testop", "xsd:string")): built-in exception thrown by built-in swrlb:stringEqualIgnoreCase in rule q2: exception thrown by built-in swrlb:stringEqualIgnoreCase in rule q2: cannot convert value of type rdf:PlainLiteral to xsd:string]
[Near : {... invoker.invoke("q2", "swrlb:st ....}]
             ^
[Line: 1, Column: 1]
    at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:435)
    at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:163)
    at org.mvel2.ast.ASTNode.optimize(ASTNode.java:159)
    at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115)
    at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
    at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
    at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
    at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:113)
    at org.mvel2.MVEL.executeExpression(MVEL.java:941)
    at org.drools.core.util.MVELSafeHelper$RawMVELEvaluator.executeExpression(MVELSafeHelper.java:501)
    at org.drools.core.base.dataproviders.MVELDataProvider.evaluate(MVELDataProvider.java:138)
    at org.drools.core.base.dataproviders.MVELDataProvider.getResults(MVELDataProvider.java:133)
    at org.drools.core.phreak.PhreakFromNode.doLeftInserts(PhreakFromNode.java:106)
    at org.drools.core.phreak.PhreakFromNode.doNode(PhreakFromNode.java:68)
    at org.drools.core.phreak.RuleNetworkEvaluator.evalNode(RuleNetworkEvaluator.java:387)
    at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:333)
    at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:169)
    at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:127)
    at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:212)
    at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:87)
    at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:34)
    at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
    at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1072)
    at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1019)
    at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1011)
    at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1321)
    at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1312)
    at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1304)
    at org.swrlapi.drools.core.DroolsSWRLRuleEngine.runRuleEngine(DroolsSWRLRuleEngine.java:211)
    ... 4 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1120)
    at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1003)
    at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:396)
    ... 32 more
Caused by: org.swrlapi.exceptions.SWRLAPIException: built-in exception thrown by built-in swrlb:stringEqualIgnoreCase in rule q2: exception thrown by built-in swrlb:stringEqualIgnoreCase in rule q2: cannot convert value of type rdf:PlainLiteral to xsd:string
    at org.swrlapi.drools.core.DroolsSWRLBuiltInInvoker.invoke(DroolsSWRLBuiltInInvoker.java:417)
    at org.swrlapi.drools.core.DroolsSWRLBuiltInInvoker.invoke(DroolsSWRLBuiltInInvoker.java:90)
    ... 39 more
Caused by: org.swrlapi.exceptions.SWRLBuiltInException: exception thrown by built-in swrlb:stringEqualIgnoreCase in rule q2: cannot convert value of type rdf:PlainLiteral to xsd:string
    at org.swrlapi.builtins.AbstractSWRLBuiltInLibrary.invokeBuiltInMethod(AbstractSWRLBuiltInLibrary.java:226)
    at org.swrlapi.builtins.SWRLBuiltInLibraryManager.invokeSWRLBuiltIn(SWRLBuiltInLibraryManager.java:184)
    at org.swrlapi.factory.DefaultSWRLBridge.invokeSWRLBuiltIn(DefaultSWRLBridge.java:150)
    at org.swrlapi.drools.core.DroolsSWRLBuiltInInvoker.invoke(DroolsSWRLBuiltInInvoker.java:399)
    ... 40 more
Caused by: org.swrlapi.exceptions.LiteralException: cannot convert value of type rdf:PlainLiteral to xsd:string
    at org.swrlapi.factory.DefaultLiteral.getString(DefaultLiteral.java:186)
    at org.swrlapi.builtins.AbstractSWRLBuiltInLibrary.getArgumentAsAString(AbstractSWRLBuiltInLibrary.java:1232)
    at org.swrlapi.builtins.swrlb.SWRLBuiltInLibraryImpl.stringEqualIgnoreCase(SWRLBuiltInLibraryImpl.java:497)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.swrlapi.builtins.AbstractSWRLBuiltInLibrary.invokeBuiltInMethod(AbstractSWRLBuiltInLibrary.java:219)
    ... 43 more
Kelschi
  • 1
  • 2
  • Does the data have a language tag? Plain literals are strings with a language tag, this might be part of the issue. – Ignazio Dec 14 '20 at 12:03
  • The data does not have any language tag and looks like this in graphdb: `testOp ^^http://www.w3.org/2001/XMLSchema#string` – Kelschi Dec 14 '20 at 12:15
  • Can you post the stacktrace for the SWRLBuiltInException? – Ignazio Dec 20 '20 at 08:15
  • i have added the stacktrace for the exception – Kelschi Dec 21 '20 at 07:15
  • Hmmm, it's hard for me to believe that GraphDB converts xsd:string to rdf:PlainLiteral. Try a CONSTRUCT query in SPARQL and download it as Turtle to check. BTW, xsd:string is default so it can also be omitted: `"foo"` is the same as `"foo"^^xsd:string` – Vladimir Alexiev Feb 12 '21 at 12:02

0 Answers0