datafoodconsortium / connector-codegen

An Acceleo project to generate the source code of the DFC connector into all the supported programming languages.
MIT License
3 stars 3 forks source link

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

Closed rioug closed 9 months ago

rioug commented 9 months ago

This PR fixes the following issues :

Additional background : https://github.com/datafoodconsortium/connector-ruby/issues/13#issuecomment-1786333685

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

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 commented 9 months ago

@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 ?