TNO / knowledge-engine

Improves interoperability between systems (i.e. devices, platforms, apps, databases) by exchanging data based on their semantics
https://knowledge-engine.eu
Apache License 2.0
33 stars 4 forks source link

Error: "literal is not an unprefixed URI or literal." when sending literals as result bindingset in REACT interaction #428

Closed Sophietje closed 10 months ago

Sophietje commented 1 year ago

In GitLab by @jarne.kerkaert.inetum-realdolmen.world on May 11, 2023, 10:54

We are receiving an error when sending literals in a bindingset in REACT interactions. This is VERY blocking for us.

{
    "messageType": "error",
    "message": "'\"1.2\"^^http://www.w3.org/2001/XMLSchema#float' is not an unprefixed URI or literal."
}

Create sender kb

{
    "knowledgeBaseId": "http://ke.com/partner",
    "knowledgeBaseName": "ad ipsum amet aliquip",
    "knowledgeBaseDescription": "et nostrud in nisi"
}

Create partner kb

{
    "knowledgeBaseId": "http://ke.com/dr",
    "knowledgeBaseName": "ad ipsum amet aliquip",
    "knowledgeBaseDescription": "et nostrud in nisi"
}

Register post to sender kb

{
    "knowledgeInteractionType": "PostKnowledgeInteraction",
    "argumentGraphPattern": "?a a ?b",
    "resultGraphPattern": "?a a ?b"
}

Register react to partner kb

{
    "knowledgeInteractionType": "ReactKnowledgeInteraction",
    "argumentGraphPattern": "?a a ?b",
    "resultGraphPattern": "?a a ?b"
}

Start polling on parter kb

Send post with sender kb

[
    { 
        "a": "\"1.2\"^^http://www.w3.org/2001/XMLSchema#float",
        "b": "\"1.2\"^^http://www.w3.org/2001/XMLSchema#float"
    }
]

Receive post with partner kb

{
    "knowledgeInteractionId": "http://ke.com/partner/interaction/16514fd3-ecdb-485a-b7b3-cb53292b5ae3",
    "handleRequestId": 1,
    "bindingSet": [
        {
            "a": "\"1.2\"^^http://www.w3.org/2001/XMLSchema#float",
            "b": "\"1.2\"^^http://www.w3.org/2001/XMLSchema#float"
        }
    ],
    "requestingKnowledgeBaseId": "http://ke.com/dr"
}

React with partner kb

{
    "handleRequestId":  1,
    "bindingSet": [
        {
            "a": "\"1.2\"^^http://www.w3.org/2001/XMLSchema#float",
            "b": "\"1.2\"^^http://www.w3.org/2001/XMLSchema#float"
        }
    ]
}

Partner kb receives error from kb

{
    "messageType": "error",
    "message": "'\"1.2\"^^http://www.w3.org/2001/XMLSchema#float' is not an unprefixed URI or literal."
}

Notes

KE version 1.1.3

Sending POST interactions works

Same issue appears with different kinds of literals

"1.2^^http://www.w3.org/2001/XMLSchema#float"
"'1.2'^^http://www.w3.org/2001/XMLSchema#float"
"'\"1.2\"^^http://www.w3.org/2001/XMLSchema#float'"

We don't use generic adapter, we talk directly to KE

Sophietje commented 1 year ago

In GitLab by @han.kruiger.tno.nl on May 11, 2023, 11:00

Hi @jarne.kerkaert.inetum-realdolmen.world

This error occurs because the body contains this binding:

{
  "a": "\"1.2\"^^http://www.w3.org/2001/XMLSchema#float",
  "b": "\"1.2\"^^http://www.w3.org/2001/XMLSchema#float"
}

But it is missing the fish brackets:

{
  "a": "\"1.2\"^^<http://www.w3.org/2001/XMLSchema#float>",
  "b": "\"1.2\"^^<http://www.w3.org/2001/XMLSchema#float>"
}

That should fix it. Can you let me know if that works?

Sophietje commented 1 year ago

In GitLab by @jarne.kerkaert.inetum-realdolmen.world on May 11, 2023, 11:05

Hi Han,

Thank you very much! This does indeed work, but it doesn't explain why sending POST requests works without the brackets. It's quite difficult to change our code in this way.

It seems like react interactions are handled in a different way than post interactions

Sophietje commented 1 year ago

In GitLab by @han.kruiger.tno.nl on May 11, 2023, 12:22

Great!

Yes, the way that the Knowledge Engine REST server handles the proactive (ASK/POST) interactions differs from the way that it handles the reactive (ANSWER/REACT) interactions.

I can see that it would be pretty useful to have the binding validation working for the proactive interactions as well. (And honestly I thought that it already did that, but it appears not!)

Made an issue for it: #415

Sophietje commented 1 year ago

In GitLab by @barry.nouwt.tno.nl on May 11, 2023, 13:47

@jarne.kerkaert.inetum-realdolmen.world Good to hear it works now! Just wondering; why is it difficult to change your code in that way? Always using angle brackets (< and >) should always work if I am correct.

Sophietje commented 1 year ago

In GitLab by @jarne.kerkaert.inetum-realdolmen.world on May 12, 2023, 06:01

@barry.nouwt.tno.nl The reason I mentioned that is because we use a RDF library (Jena RDF API) internally, and the way we produce a literal to send to KE is like this:

ResourceFactory.createTypedLiteral(load).toString()

which returns "1.2"^^http://www.w3.org/2001/XMLSchema#float.

Up until now this has always worked as we haven't used the return function of REACT interactions anywhere. So updating this might take some searching. We can just hardcode the correct values though for now.

Seeing as using < > is actually supposed to be the correct way in all cases, I am fully in favour of updating our implementation :)

Sophietje commented 1 year ago

In GitLab by @barry.nouwt.tno.nl on May 12, 2023, 06:46

@jarne.kerkaert.inetum-realdolmen.world Try to use Apache Jena's FmtUtils (see code below) to generate correct nodes, since the Node#toString() method of Apache Jena is meant to be human-readable (see javadoc).

String s = "\"1.2\"^^<http://www.w3.org/2001/XMLSchema#float>";
Node n = SSE.parseNode(s);
String s2 = FmtUtils.stringForNode(n, new PrefixMappingMem());
System.out.println("String: " + s2);

The empty new PrefixMappingMem() is used to force it to not use prefixes. Hope this helps!

Sophietje commented 1 year ago

In GitLab by @barry.nouwt.tno.nl on Jun 9, 2023, 12:26

Closing this issue, because it seems solved. If it is not, please reopen it and provide further details.

Sophietje commented 1 year ago

In GitLab by @barry.nouwt.tno.nl on Jun 9, 2023, 12:26

changed the incident status to Resolved by closing the incident