Code Monkey home page Code Monkey logo

Comments (9)

joachimvh avatar joachimvh commented on June 4, 2024 1

The thing you see in the Components.js config is actually not a list semantically speaking. In JSON-LD the brackets are used to create multiple triples with the same predicate. To have a list you need the @list keyword. Components.js is just nice enough to interpret all those triples as a list of values instead of separate values (I'm guessing because the @list syntax would make it a lot uglier), even though semantically that's not really a list. The disadvantage of that technique though is indeed that if there are no values (which is identical to writing [] in JSON-LD), it has no idea if this is an empty list or a value that is missing.

from components.js.

github-actions avatar github-actions commented on June 4, 2024

Thanks for the suggestion!

from components.js.

rubensworks avatar rubensworks commented on June 4, 2024

Marking a parameter as required actually means that there should be at least one value.

Due to the semantics of JSON-LD and RDF, "ClassName:_listParam": [] will produce no triples, which makes validation of the parameter requirement fail.

I presume that in this case, you probably want to make the parameter optional.

from components.js.

woutermont avatar woutermont commented on June 4, 2024

That would mean there is no semantic difference between an empty list and no list at all ...

from components.js.

rubensworks avatar rubensworks commented on June 4, 2024

One solution would be to introduce the following behaviour:
If Components.js sees a field that is non-unique+required (what the generator outputs for array params), and has no passed values, it will consider it an empty array.

Concretely, this would mean that passing "ClassName:_listParam": [] is equivalent to not defining a value for that field at all. In both cases, Components.js would pass an empty array to the constructor.

This is a minor change in semantics for Components.js (that would call for a major update), as non-unique+required fields would require at least one value before. Since this check could be considered a bit arbitrary for arrays, it makes sense to apply this change in semantics.

If the "if the array contains at least one value" check would be necessary, then we could add this via a new minimumElements property or something like that. But AFAIK, no one really makes use of this functionality, so it probably doesn't hurt if it is removed/modified.

@woutermont @joachimvh Would such a change make sense to you?

from components.js.

joachimvh avatar joachimvh commented on June 4, 2024

The only time unique is false is when the input parameter is an array right? In that case this sounds like a reasonable solution. Only disadvantage is that you lose the error message in case you forget to define the parameter.

I've never had a need yet for empty arrays but since it's currently impossible to define them I think this solution is better than the current situation.

from components.js.

woutermont avatar woutermont commented on June 4, 2024

While I think it's semantically a bit strange, it would definitely be more workable than the current situation.

from components.js.

rubensworks avatar rubensworks commented on June 4, 2024

Actually, after thinking about it a bit more, I think the following solution might be cleaner:

For a given config:

{
  "@type": "MyClass",
  "param1": []
}

The generator would set the JSON-LD container type to @list inside the type-scoped context entry of param1.
This would make the values a proper RDF list, which allows us to keep the "empty list" semantics.
(This generator change should be quite trivial)

Next, Components.js would require a small change, as it would now also need to support such RDF lists as input to parameters. I don't foresee major difficulties for this.

The advantage of this approach would be that Components.js will still throw an error if you don't define param1 in your config if it's required. This is because this approach doesn't consider a missing param1 and "param1": [] as the same thing.

@joachimvh @woutermont Any thoughts?

from components.js.

joachimvh avatar joachimvh commented on June 4, 2024

Ah yea, that's definitely better. I just assumed that one wasn't an option :D

from components.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.