Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Coercion not working in a @container inside another @container #333

Closed
hyprdia opened this issue Apr 5, 2024 · 3 comments · Fixed by #342
Closed

Type Coercion not working in a @container inside another @container #333

hyprdia opened this issue Apr 5, 2024 · 3 comments · Fixed by #342
Labels
bug Something isn't working
Milestone

Comments

@hyprdia
Copy link

hyprdia commented Apr 5, 2024

Describe the bug
A clear and concise description of what the bug is.

Type coecion is not applied when a @container is defined inside another @container. In the example below I define friends as a container:

...
"friends": {
  "@id": "core:User@1/core:Friends",
  "@type": "@id",
  "@container": [
    "@id",
    "@set"
  ]
}
...

This container is present inside the top users container:

...
"users": {
  "@id": "core:Group@1/core:Users",
  "@container": "@set"
}
...

To Reproduce
Steps to reproduce the behavior:

Here is a test that will reproduce the bug:

    @Test
    void titaniumExpansionTest() throws JsonLdError {

        String jsonString = """
            {
              "@context": {
                "@base": "https://api.example.com/data/",
                "core": "https://api.example.com/classes/core:",
                "sh": "http://www.w3.org/ns/shacl#",
                "xsd": "http://www.w3.org/2001/XMLSchema#",
                "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
                "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
                "users": {
                  "@id": "core:Group@1/core:Users",
                  "@container": "@set"
                },
                "core:User@1": {
                  "@context": {
                    "type": {
                      "@id": "core:User@1/core:Type",
                      "@type": "@id"
                    },
                    "friends": {
                      "@id": "core:User@1/core:Friends",
                      "@type": "@id",
                      "@container": [
                        "@id",
                        "@set"
                      ]
                    },
                    "path": {
                      "@id": "core:User@1/core:Path",
                      "@type": "xsd:string",
                      "@container": "@list"
                    }
                  }
                }
              },
              "@id": "02wBzNotDceDYnLYE2ndhH",
              "@type": "core:Group@1/core:Users",
              "users": {
                "@set": [
                  {
                    "@id": "02wBzNotbWW1ROCZxlUjmw",
                    "@type": "core:User@1",
                    "type": "02w7bdDtd7owQzsKGCALDs",
                    "friends": {
                      "@set": [
                        "02w7bdDtj3RI0BJoMGltwK",
                        "02w7bdDtj3RI08x102ToY2"
                      ]
                    },
                    "path": {
                      "@list": [
                        "john"
                      ]
                    }
                  }
                ]
              }
            }
        """;

        ExpansionApi expanded = JsonLd.expand(
                        JsonDocument.of(
                                new ByteArrayInputStream(
                                        jsonString.getBytes(
                                                StandardCharsets.UTF_8
                                        )
                                )
                        )
                ).mode(JsonLdVersion.V1_1)
                .ordered(true)
                .base("https://api.example.com/");
        
        String expected = """
            [
              {
                "@id": "https://api.example.com/data/02wBzNotDceDYnLYE2ndhH",
                "@type": [
                  "https://api.example.com/classes/core:Group@1/core:Users"
                ],
                "https://api.example.com/classes/core:Group@1/core:Users": [
                  {
                    "@id": "https://api.example.com/data/02wBzNotbWW1ROCZxlUjmw",
                    "@type": [
                      "https://api.example.com/classes/core:User@1"
                    ],
                    "https://api.example.com/classes/core:User@1/core:Friends": [
                      {
                        "@id": "https://api.example.com/data/02w7bdDtj3RI0BJoMGltwK"
                      },
                      {
                        "@id": "https://api.example.com/data/02w7bdDtj3RI08x102ToY2"
                      }
                    ],
                    "https://api.example.com/classes/core:User@1/core:Path": [
                      {
                        "@list": [
                          {
                            "@value": "john"
                          }
                        ]
                      }
                    ],
                    "https://api.example.com/classes/core:User@1/core:Type": [
                      {
                        "@id": "https://api.example.com/data/02w7bdDtd7owQzsKGCALDs"
                      }
                    ]
                  }
                ]
              }
            ]
                """;

        assertEquals(StringUtils.deleteWhitespace(expected), expanded.get().toString());
    }

Expected behavior
A clear and concise description of what you expected to happen.

I would expect the values inside the friends list to be considered as ids and prepended the defined @base but it's not the case, although I take the same source Json and put it inside Json Playground and it works.

Here is a screenshot of the differences from Json Playground (on the left, Titanium on the right). Here we can clearly see that type coercion is applied in the Json Playground:

Screenshot 2024-04-05 at 9 12 20 AM

Additional context
Add any other context about the problem here.

I am using the latest distributed version (1.4.0), the same problem is present in Apache Jena 4.10.

@hyprdia hyprdia changed the title Type Coercion not working inside @container inside @container Type Coercion not working in a @container inside another @container Apr 5, 2024
@filip26
Copy link
Owner

filip26 commented Apr 5, 2024

@hyprdia thank you for reporting the bug, it will be fixed in the next release.

@filip26 filip26 added the bug Something isn't working label Apr 5, 2024
filip26 added a commit that referenced this issue Jun 8, 2024
@filip26
Copy link
Owner

filip26 commented Jun 8, 2024

It's a bug in @container: @id expansion. [@index, @set] container mapping works ok.

filip26 added a commit that referenced this issue Jun 8, 2024
@filip26 filip26 added this to the 1.4.1 milestone Jun 8, 2024
@filip26 filip26 linked a pull request Jun 8, 2024 that will close this issue
@hyprdia
Copy link
Author

hyprdia commented Jun 16, 2024

@filip26 Thank you!! I will put this to work pretty soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants