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

IllegalArgumentException #393

Closed Sophietje closed 10 months ago

Sophietje commented 2 years ago

In GitLab by @davide_micheletto_reply.whirlpool.com on Jul 25, 2022, 17:01

Hi all,

since you activated the binding validation on the KE, we encounter errors on all services. Here is an example:

GRAPHPATTERN

?appliances <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://saref.etsi.org/saref4ener/appliance> .
?appliances <https://saref.etsi.org/saref4ener/vendorCode> ?playerid .
?appliances <https://saref.etsi.org/saref4ener/deviceCode> ?deviceAddress .
?appliances <https://saref.etsi.org/saref4ener/manufacturerLabel> ?type .
?appliances <https://saref.etsi.org/saref4ener/deviceName> ?name .
?appliances <https://saref.etsi.org/saref4ener/brandName> ?brand .
?appliances <https://saref.etsi.org/saref4ener/manufacturerNodeIdentification> ?token .

ASK - REQUEST

[
    {
        "deviceAddress": "\"-\"^^<http://www.w3.org/2001/XMLSchema#string>",
        "appliances": "<https://www.example.org/appliances>",
        "name": "\"-\"^^<http://www.w3.org/2001/XMLSchema#string>",
        "type": "\"-\"^^<http://www.w3.org/2001/XMLSchema#string>",
        "brand": "\"-\"^^<http://www.w3.org/2001/XMLSchema#string>",
        "playerid": "\"xyz\"^^<http://www.w3.org/2001/XMLSchema#string>",
        "token": "\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjIzMTMxLCJSb2xlTmFtZSI6IlNUQU5EQVJEX1VTRVIiLCJjb21wYW55SWQiOjAsIlVzZXJOYW1lIjoiRmVkZXJpY2FJbmRlcnN0IiwidXNlcl9uYW1lIjoiRkVERVJJQ0EuSU5ERVJTVEBHTUFJTC5DT00iLCJzY29wZSI6WyJ0cnVzdCIsInJlYWQiLCJ3cml0ZSJdLCJleHAiOjE2NTcyMDQ2MTQsImF1dGhvcml0aWVzIjpbIlNUQU5EQVJEX1VTRVIiXSwianRpIjoiYjA4YTI5NGQtNmFhMi00NmRlLWJkMzMtNzg5MWZhMTQ2MzJkIiwiY2xpZW50X2lkIjoic3ludGVsIiwiU0FJRCI6WyJXUFI0TVY3OUJGOTQzIl19.8MVNARVYV7hpzmRGOOS-pbj_aCMyhCtaO4OzafY1kOM\"^^<http://www.w3.org/2001/XMLSchema#string>"
    }
]

ANSWER - SEND

{
  "handleRequestId": "1",
  "bindingSet": [
    {
      "deviceAddress": "\"WPR4KYJFNMBCC\"^^\u003chttp://www.w3.org/2001/XMLSchema#string\u003e",
      "appliances": "\u003chttps://www.example.org/appliances\u003e",
      "name": "\"natis\"^^\u003chttp://www.w3.org/2001/XMLSchema#string\u003e",
      "type": "\"FabricCare\"^^\u003chttp://www.w3.org/2001/XMLSchema#string\u003e",
      "brand": "\"Hotpoint\"^^\u003chttp://www.w3.org/2001/XMLSchema#string\u003e",
      "playerid": "\"null\"^^\u003chttp://www.w3.org/2001/XMLSchema#string\u003e",
      "token": "\"-\"^^\u003chttp://www.w3.org/2001/XMLSchema#string\u003e"
    },
    {
      "deviceAddress": "\"WPR4MV79BF943\"^^\u003chttp://www.w3.org/2001/XMLSchema#string\u003e",
      "appliances": "\u003chttps://www.example.org/appliances\u003e",
      "name": "\"Lavatrice\"^^\u003chttp://www.w3.org/2001/XMLSchema#string\u003e",
      "type": "\"FabricCare\"^^\u003chttp://www.w3.org/2001/XMLSchema#string\u003e",
      "brand": "\"Hotpoint\"^^\u003chttp://www.w3.org/2001/XMLSchema#string\u003e",
      "playerid": "\"xyz\"^^\u003chttp://www.w3.org/2001/XMLSchema#string\u003e",
      "token": "\"-\"^^\u003chttp://www.w3.org/2001/XMLSchema#string\u003e"
    }
  ]
}

ASK - RESPONSE

{
    "bindingSet": [],
    "exchangeInfo": [
        {
            "initiator": "knowledgeBase",
            "knowledgeBaseId": "https://ke.interconnectproject.eu/adapter/c5bd1620e15c0b9a62526f9e1b9722a5097d92f88e5b55bda331127c63921c2ad0c75d1e81889622486082151206d2f9e5ba81190f0d95cb43ec4bf1486134da",
            "knowledgeInteractionId": "https://ke.interconnectproject.eu/adapter/c5bd1620e15c0b9a62526f9e1b9722a5097d92f88e5b55bda331127c63921c2ad0c75d1e81889622486082151206d2f9e5ba81190f0d95cb43ec4bf1486134da/interaction/d4eccca6-334f-47fd-9bc2-466040bcf4ea",
            "exchangeStart": "2022-07-25T16:52:20.393+00:00",
            "exchangeEnd": "2022-07-25T16:52:29.250+00:00",
            "status": "FAILED",
            "failedMessage": "java.lang.IllegalArgumentException: KB gave outgoing binding Binding [map={deviceAddress=\"WPR4MV79BF943\"^^<http://www.w3.org/2001/XMLSchema#string>, appliances=<https://www.example.org/appliances>, name=\"Lavatrice\"^^<http://www.w3.org/2001/XMLSchema#string>, type=\"FabricCare\"^^<http://www.w3.org/2001/XMLSchema#string>, brand=\"Hotpoint\"^^<http://www.w3.org/2001/XMLSchema#string>, playerid=\"xyz\"^^<http://www.w3.org/2001/XMLSchema#string>, token=\"-\"^^<http://www.w3.org/2001/XMLSchema#string>}], but this doesn't have a matching incoming binding!",
            "bindingSet": []
        }
    ]
}

How can we understand the cause of the error? Can you give us some suggestions?

Sophietje commented 2 years ago

In GitLab by @han.kruiger.tno.nl on Jul 26, 2022, 08:02

Hi Davide,

Thanks for reaching out!

The reason that the validation is complaining here is because there are bindings in the ANSWER that do not 'fit' on the bindings that were sent in the ASK.

For example, the binding in the ASKing Knowledge Base sets (among other things) the "name" value to "\"-\"^^<http://www.w3.org/2001/XMLSchema#string>". This is like a query that SHOULD result only in an answer where the "name" values are also set to the same thing.

The error tells you that that specific binding (the 2nd one in the ANSWER, with "name" = "\"Lavatrice\"^^\u003chttp://www.w3.org/2001/XMLSchema#string\u003e") has no corresponding binding in the ASK bindings, as it conflicts with the singular binding that is in there (the one where "name" is set to "\"-\"^^<http://www.w3.org/2001/XMLSchema#string>").

There is also an example of how this validation works in this issue.

PS (but this is a separate issue, I think): It appears that sometimes, there is a formatting issue for the < and > in the JSON. I see that it's in there as \u003c and \u003e, which are their unicode codes.

I hope this helps. Let me know if it is still unclear.

Best, Han

Sophietje commented 2 years ago

In GitLab by @facoelho on Jul 26, 2022, 09:03

Dear @han.kruiger.tno.nl. I am collecting some other questions from partners that are falling into the same error.

So if I understood correctly, the problem in the case fo Davide is because 'name' in the ANSWER and 'name' in the ASK are not equal?

Can you provide an example, please?

Sophietje commented 2 years ago

In GitLab by @davide_micheletto_reply.whirlpool.com on Jul 26, 2022, 09:24

Yes, thank you, an example would be appreciated.

In our example, starting from two data (token and playerId) the other fields must be received in response. What would be a correct interaction?

Sophietje commented 2 years ago

In GitLab by @han.kruiger.tno.nl on Jul 26, 2022, 09:27

So if I understood correctly, the problem in the case fo Davide is because 'name' in the ANSWER and 'name' in the ASK are not equal?

@facoelho Correct, this is the reason. Or rather one of the reasons. The same holds for some of the other variables.

Can you provide an example, please?

Does the following example suffice?

Example (copied from #255)

Consider two KBs, KB1 and KB2.

KB1 has the following ASK KI:

?city :isCapitalOf ?country .

KB2 has the ANSWER KI with the same graph pattern.

Now, when KB1 triggers its ASK KI with the following binding set:

[{
  "country": "<https://example.org/Germany>"
}]

(effectively asking "What is the capital of Germany?")

and if KB1 then responds with this:

[{
  "city": "<https://example.org/Stockholm>",
  "country": "<https://example.org/Sweden>",
}]

(effectively answering with "The capital of Sweden is Stockholm!")

This new validation will not allow that anymore.

The answering KB MUST have country set to <https://example.org/Germany> in each of its bindings. (So, returning an empty binding set is still allowed!)

Similarly, if KB1 triggered its ASK with the following binding set:

[
  { "country": "<https://example.org/Germany>" },
  { "country": "<https://example.org/France>" }
]

(effectively asking for the capitals of Germany and France)

then the answering KB1 must have either Germany or France filled into the country variable in each of its bindings.

Sophietje commented 2 years ago

In GitLab by @han.kruiger.tno.nl on Jul 26, 2022, 09:33

In your scenario, an example of a valid interaction would be the following:

ASK sends:

[
  {
    "playerid": "\"xyz\"^^<http://www.w3.org/2001/XMLSchema#string>",
    "token": "\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjIzMTMxLCJSb2xlTmFtZSI6IlNUQU5EQVJEX1VTRVIiLCJjb21wYW55SWQiOjAsIlVzZXJOYW1lIjoiRmVkZXJpY2FJbmRlcnN0IiwidXNlcl9uYW1lIjoiRkVERVJJQ0EuSU5ERVJTVEBHTUFJTC5DT00iLCJzY29wZSI6WyJ0cnVzdCIsInJlYWQiLCJ3cml0ZSJdLCJleHAiOjE2NTcyMDQ2MTQsImF1dGhvcml0aWVzIjpbIlNUQU5EQVJEX1VTRVIiXSwianRpIjoiYjA4YTI5NGQtNmFhMi00NmRlLWJkMzMtNzg5MWZhMTQ2MzJkIiwiY2xpZW50X2lkIjoic3ludGVsIiwiU0FJRCI6WyJXUFI0TVY3OUJGOTQzIl19.8MVNARVYV7hpzmRGOOS-pbj_aCMyhCtaO4OzafY1kOM\"^^<http://www.w3.org/2001/XMLSchema#string>"
  }
]

(Notice how only the playerid and token variables are set. This makes it so that the ANSWER can fill in the other variables in its response bindings.)

ANSWER sends (I've omitted the handle request ID, and only pasted the bindingset here):

[
  {
    "deviceAddress": "\"WPR4KYJFNMBCC\"^^<http://www.w3.org/2001/XMLSchema#string>",
    "appliances": "<https://www.example.org/appliances>",
    "name": "\"natis\"^^<http://www.w3.org/2001/XMLSchema#string>",
    "type": "\"FabricCare\"^^<http://www.w3.org/2001/XMLSchema#string>",
    "brand": "\"Hotpoint\"^^<http://www.w3.org/2001/XMLSchema#string>",
    "playerid": "\"xyz\"^^<http://www.w3.org/2001/XMLSchema#string>",
    "token": "\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjIzMTMxLCJSb2xlTmFtZSI6IlNUQU5EQVJEX1VTRVIiLCJjb21wYW55SWQiOjAsIlVzZXJOYW1lIjoiRmVkZXJpY2FJbmRlcnN0IiwidXNlcl9uYW1lIjoiRkVERVJJQ0EuSU5ERVJTVEBHTUFJTC5DT00iLCJzY29wZSI6WyJ0cnVzdCIsInJlYWQiLCJ3cml0ZSJdLCJleHAiOjE2NTcyMDQ2MTQsImF1dGhvcml0aWVzIjpbIlNUQU5EQVJEX1VTRVIiXSwianRpIjoiYjA4YTI5NGQtNmFhMi00NmRlLWJkMzMtNzg5MWZhMTQ2MzJkIiwiY2xpZW50X2lkIjoic3ludGVsIiwiU0FJRCI6WyJXUFI0TVY3OUJGOTQzIl19.8MVNARVYV7hpzmRGOOS-pbj_aCMyhCtaO4OzafY1kOM\"^^<http://www.w3.org/2001/XMLSchema#string>"
  },
  {
    "deviceAddress": "\"WPR4MV79BF943\"^^<http://www.w3.org/2001/XMLSchema#string>",
    "appliances": "<https://www.example.org/appliances>",
    "name": "\"Lavatrice\"^^<http://www.w3.org/2001/XMLSchema#string>",
    "type": "\"FabricCare\"^^<http://www.w3.org/2001/XMLSchema#string>",
    "brand": "\"Hotpoint\"^^<http://www.w3.org/2001/XMLSchema#string>",
    "playerid": "\"xyz\"^^<http://www.w3.org/2001/XMLSchema#string>",
    "token": "\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50SWQiOjIzMTMxLCJSb2xlTmFtZSI6IlNUQU5EQVJEX1VTRVIiLCJjb21wYW55SWQiOjAsIlVzZXJOYW1lIjoiRmVkZXJpY2FJbmRlcnN0IiwidXNlcl9uYW1lIjoiRkVERVJJQ0EuSU5ERVJTVEBHTUFJTC5DT00iLCJzY29wZSI6WyJ0cnVzdCIsInJlYWQiLCJ3cml0ZSJdLCJleHAiOjE2NTcyMDQ2MTQsImF1dGhvcml0aWVzIjpbIlNUQU5EQVJEX1VTRVIiXSwianRpIjoiYjA4YTI5NGQtNmFhMi00NmRlLWJkMzMtNzg5MWZhMTQ2MzJkIiwiY2xpZW50X2lkIjoic3ludGVsIiwiU0FJRCI6WyJXUFI0TVY3OUJGOTQzIl19.8MVNARVYV7hpzmRGOOS-pbj_aCMyhCtaO4OzafY1kOM\"^^<http://www.w3.org/2001/XMLSchema#string>"
  }
]

Notice how all bindings in the ANSWER binding set 'match' with the ASK binding.

Sophietje commented 2 years ago

In GitLab by @han.kruiger.tno.nl on Jul 26, 2022, 09:49

@facoelho Note that we can easily disable this validation on ke.interconnectproject.eu with a system variable. That's something worth considering.

Sophietje commented 2 years ago

In GitLab by @facoelho on Jul 26, 2022, 10:02

@han.kruiger.tno.nl I am running some tests with my test graph patterns and from our own services. I will come back here to share my findings and validate with you if I am picturing this right.

In fact turn this off is an option. The problem is that the cloud instance can used by everybody, it is not a pilot specific install, so enabling or disabling features will have a wide impact.

After collecting your feedback from my assessment, we'll consider if disabling the feature is an option.

Sophietje commented 2 years ago

In GitLab by @facoelho on Jul 26, 2022, 12:49

@han.kruiger.tno.nl After my tests and fixes I was able to make things working. Please provide me just one more confirmation. For the case of the pairs POST/REACT, if the REACT has an argument and result GP, the result GP must be a sub-set of the argument GP and indeed have at least one Binding matching the incoming BS that arrives from the POST, correct?

If this is the case, this does not require us to change the flag in the cloud deployment of the KE. However, I would recommend that you guys could send a clarification forwarding the email you sent notifying the KE update. Partners have few experience with these technologies so they would be better served with a code example on what needs to be matched in order for it to work.

Sophietje commented 2 years ago

In GitLab by @han.kruiger.tno.nl on Jul 26, 2022, 13:12

Good to hear!

For the case of the pairs POST/REACT, if the REACT has an argument and result GP, the result GP must be a sub-set of the argument GP and indeed have at least one Binding matching the incoming BS that arrives from the POST, correct?

This is almost correct. If the argument and result graph patterns share variables, then only those shared variables are checked.

For example, if this is the argument graph pattern (variables ?a, ?b, ?c):

?a ex:example1 ?b .
?a ex:example2 ?c .

and this is the result graph pattern (variables ?a, ?b, ?d):

?a ex:example1 ?b .
?a ex:example3 ?d .

and if the POST part sends this binding:

[
  {
    "a": "<something-a>",
    "b": "<something-b>",
    "c": "<something-c>"
  }
]

then the REACT binding must be something like this:

[
  {
    "a": "<something-a>", // exactly this value MUST be here
    "b": "<something-b>", // exactly this value MUST be here
    "d": "<something-d>"  // can be whatever, but must be here
  }
]

So, the ?a and ?b variables must exactly match an incoming binding. The ?d variable must be present (because it must be a complete answer) but may be set to anything.

If there isn't any overlap in the variables of the argument and result graph patterns, then this validation should have no effect.

I would recommend that you guys could send a clarification forwarding the email you sent notifying the KE update.

Good point. It was mentioned in the original e-mail, and I linked to a page with an example. But seeing the impact of this change, I will send an e-mail with a clarification.

Sophietje commented 2 years ago

In GitLab by @davide_micheletto_reply.whirlpool.com on Jul 27, 2022, 10:53

Very kind, now I was able to understand the problem and fix it with some tricks. Thank you!