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

Improve SKOS Concept parsing to allow use of intermediate SKOS Concept #10

Merged
merged 22 commits into from
Dec 11, 2023

Conversation

rioug
Copy link
Contributor

@rioug rioug commented Nov 29, 2023

This PR fixes the following issues :

Additional background : datafoodconsortium/connector-ruby#13 (comment)

It allows the ruby connector to use intermediate SKOS concept for Product Types and Facets ie:

  • connector.FACETS.TERRITORIALORIGIN.EUROPE.FRANCE
  • connector.PRODUCT_TYPES.DRINK.SOFT_DRINK

It didn't make sense to use intermediate for Measures so I kept the original behaviour (it can be easily fixed if needed)

I am not familiar with the design, but I don't think it makes sense for DataFoodConsortium::Connector::SKOSConcept to be a subclass of DataFoodConsortium::Connector::SKOSInstance, so I used a helper module to share method needed by both class.
This also populates narrowers and broaders for SKOSConcept so it's easier to navigate the tree. Ideally I would have like them to return a list of methods so could do something like below without additional steps :

types = connector.PRODUCT_TYPES.DRINK.SOFT_DRINK.narrowers 
# [:FRUIT_JUICE, :LEMONADE, :SMOOTHIE]

# Access connector.PRODUCT_TYPES.DRINK.SOFT_DRINK.FRUIT_JUICE
connector.PRODUCT_TYPES.DRINK.SOFT_DRINK.public_send(types.first)

I didn't want to alter the existing behaviour of DataFoodConsortium::Connector::SKOSConcept#narrowers, that said the original values would still be available via skos:narrower semantic property. Any thought ?

This also populates prefLabels for DataFoodConsortium::Connector::SKOSConcept, I used an hash with locale has keys for ease of use ie :

{
  en: "drink",
  fr: "boisson" 
}

rioug added 13 commits November 29, 2023 09:57
Add frozen_string_literal: true, it improves ruby performance by making
string immutable, thus reducing object allocation
It describe the expected API for product types and facets
It contains method needed by both SKOSInstance and SKOSConcept
This is used to by the ruby codegen to add specific code to the
SKOSConcept class
This so that SKOSParser can use  SKOSConcept instead of SKOSInstance
when needed
I don't think the first API make total sense, fix spec to match
current parsing implementation
It is easily extandable if we need more Concept Scheme to be parsed
using SkosConcept, you just need to add the name to CONCEPT_SCHEME
Copy link
Contributor

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! This solves so many scenario.

My suggestions below are just cosmetic, really.

Comment on lines 53 to 57
if element["http://www.w3.org/2004/02/skos/core#narrower"]
element["http://www.w3.org/2004/02/skos/core#narrower"].each do |narrower|
@narrower.push(narrower["@id"])
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work?

Suggested change
if element["http://www.w3.org/2004/02/skos/core#narrower"]
element["http://www.w3.org/2004/02/skos/core#narrower"].each do |narrower|
@narrower.push(narrower["@id"])
end
end
element["http://www.w3.org/2004/02/skos/core#narrower"]&.each do |narrower|
@narrower.push(narrower["@id"])
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, but I find it harder to read.

@rioug rioug changed the title Improve SKOS Concept parsing to allow use of intermetiate SKOS Concept Improve SKOS Concept parsing to allow use of intermediate SKOS Concept Dec 1, 2023
Copy link
Contributor

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! I'm looking forward to the merge.

Copy link
Member

@lecoqlibre lecoqlibre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @rioug.

I've made some recommendations, could you handle them?

Could you also update the general changelog (at the root of the project)?

I think one day the ruby connector should use a JSON-LD parser instead of our custom made one. The Ruby-RDF project seems to provide some great libs like json-ld. We should consider to use this some day. @mkllnk There is also a lib for LDP, it may be useful.

Like you said @rioug it would be nice to be able to navigate the tree like narrowers and broaders. It was the plan but I was not sure it would be used and at the beginning the connector was not supposed to provide a SKOS parser. But I think it is useful for everyone to have it.

@rioug I don't think narrowers was used in the existing behaviour of SKOSConcept. I think it is not populated by the parser.

@rioug rioug force-pushed the fix-product-types-parsing branch from 6baedc7 to 905c8b8 Compare December 8, 2023 00:44
@rioug rioug requested a review from lecoqlibre December 8, 2023 00:44
@rioug
Copy link
Contributor Author

rioug commented Dec 8, 2023

@lecoqlibre all done!

Like you said @rioug it would be nice to be able to navigate the tree like narrowers and broaders. It was the plan but I was not sure it would be used and at the beginning the connector was not supposed to provide a SKOS parser. But I think it is useful for everyone to have it.

I am curious of what you are doing in the other language, looks like you are just querying the parse JSON for php, is that right ?

Copy link
Member

@lecoqlibre lecoqlibre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rioug!

@lecoqlibre all done!

Like you said @rioug it would be nice to be able to navigate the tree like narrowers and broaders. It was the plan but I was not sure it would be used and at the beginning the connector was not supposed to provide a SKOS parser. But I think it is useful for everyone to have it.

I am curious of what you are doing in the other language, looks like you are just querying the parse JSON for php, is that right ?

The PHP version has an import method that save all the loaded RDF subjects (objects) into a store. We can then get them using a retrieve method (fetch). The intermediate SKOS concepts should be available in the store.

On the client side, in JavaScript/TypeScript we can use LDFlex which allows to access linked data using standard JavaScript dot property syntax. I use it in my different Solid projects, it's very nice and it's based on the incredible Comunica library (make SPARQL queries overs HTTP).

@lecoqlibre lecoqlibre merged commit 64e2089 into datafoodconsortium:main Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants