mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Fix DFC context in spec to resolve product types
The `dfc-b:hasType` value can only be parsed as object id if the context
contains:
```
"dfc-b:hasType":{
"@type":"@id"
},
```
The standard context includes this and it's easier to use. Now that the
URIs of product types are correctly resolved, we don't need to
substitute the URI manually.
Also dropped an old unneeded spec for backwards compatibility.
This commit is contained in:
committed by
Gaetan Craig-Riou
parent
35da321e15
commit
28e17aff68
@@ -120,18 +120,13 @@ module DataFoodConsortium
|
||||
end
|
||||
|
||||
def skos_concept(object)
|
||||
# Sometimes we get given a literal object with a value referring to skos concept
|
||||
# ie "dfc-pt:drink"
|
||||
return unless object.value.match(":") || object.uri?
|
||||
return unless object.uri?
|
||||
|
||||
id = object.value.sub(
|
||||
"http://static.datafoodconsortium.org/data/measures.rdf#", "dfc-m:"
|
||||
).sub(
|
||||
"https://github.com/datafoodconsortium/taxonomies/releases/latest/download/measures.rdf#",
|
||||
"dfc-m:"
|
||||
).sub(
|
||||
"dfc-pt:",
|
||||
"https://github.com/datafoodconsortium/taxonomies/releases/latest/download/productTypes.rdf#"
|
||||
)
|
||||
|
||||
SKOSParser.concepts[id]
|
||||
|
||||
@@ -42,33 +42,14 @@ describe DataFoodConsortium::Connector::Importer do
|
||||
}
|
||||
JSON
|
||||
end
|
||||
let(:product_data_with_context) do
|
||||
<<~JSON
|
||||
{
|
||||
"@context": {
|
||||
"dfc-b": "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#",
|
||||
"dfc-m": "http://static.datafoodconsortium.org/data/measures.rdf#",
|
||||
"dfc-pt": "http://static.datafoodconsortium.org/data/productTypes.rdf#"
|
||||
},
|
||||
"@id":"https://example.net/tomato",
|
||||
"@type":"dfc-b:SuppliedProduct",
|
||||
"dfc-b:name":"Tomato",
|
||||
"dfc-b:description":"Awesome tomato",
|
||||
"dfc-b:alcoholPercentage":0.0,
|
||||
"dfc-b:lifetime":"",
|
||||
"dfc-b:usageOrStorageCondition":"",
|
||||
"dfc-b:totalTheoreticalStock":3,
|
||||
"dfc-b:hasType": "dfc-pt:non-local-vegetable"
|
||||
}
|
||||
JSON
|
||||
end
|
||||
let(:product_data_with_context_v1_8) do
|
||||
<<~JSON
|
||||
{
|
||||
"@context": {
|
||||
"dfc-b": "https://github.com/datafoodconsortium/ontology/releases/latest/download/DFC_BusinessOntology.owl#",
|
||||
"dfc-m": "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/measures.rdf#",
|
||||
"dfc-pt": "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/productTypes.rdf#"
|
||||
"dfc-pt": "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/productTypes.rdf#",
|
||||
"dfc-b:hasType":{"@type":"@id"}
|
||||
},
|
||||
"@id":"https://example.net/tomato",
|
||||
"@type":"dfc-b:SuppliedProduct",
|
||||
@@ -130,18 +111,6 @@ describe DataFoodConsortium::Connector::Importer do
|
||||
expect(result.totalTheoreticalStock).to eq 3
|
||||
end
|
||||
|
||||
it "imports an object with included context" do
|
||||
result = connector.import(product_data_with_context)
|
||||
|
||||
expect(result).to be_a DataFoodConsortium::Connector::SuppliedProduct
|
||||
expect(result.semanticType).to eq "dfc-b:SuppliedProduct"
|
||||
expect(result.semanticId).to eq "https://example.net/tomato"
|
||||
expect(result.name).to eq "Tomato"
|
||||
expect(result.description).to eq "Awesome tomato"
|
||||
expect(result.productType).to eq non_local_vegetable
|
||||
expect(result.totalTheoreticalStock).to eq 3
|
||||
end
|
||||
|
||||
it "imports an object with DFC v1.8 context" do
|
||||
result = connector.import(product_data_with_context_v1_8)
|
||||
|
||||
|
||||
@@ -44,14 +44,7 @@ describe "SuppliedProducts", type: :request, swagger_doc: "dfc.yaml", rswag_auto
|
||||
|
||||
parameter name: :supplied_product, in: :body, schema: {
|
||||
example: {
|
||||
'@context': {
|
||||
'dfc-b': "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#",
|
||||
'dfc-m': "http://static.datafoodconsortium.org/data/measures.rdf#",
|
||||
'dfc-pt': "http://static.datafoodconsortium.org/data/productTypes.rdf#",
|
||||
'dfc-b:hasUnit': {
|
||||
'@type': "@id"
|
||||
},
|
||||
},
|
||||
'@context': "https://www.datafoodconsortium.org",
|
||||
'@id': "http://test.host/api/dfc/enterprises/6201/supplied_products/0",
|
||||
'@type': "dfc-b:SuppliedProduct",
|
||||
'dfc-b:name': "Apple",
|
||||
|
||||
@@ -553,12 +553,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
example:
|
||||
"@context":
|
||||
dfc-b: http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#
|
||||
dfc-m: http://static.datafoodconsortium.org/data/measures.rdf#
|
||||
dfc-pt: http://static.datafoodconsortium.org/data/productTypes.rdf#
|
||||
dfc-b:hasUnit:
|
||||
"@type": "@id"
|
||||
"@context": https://www.datafoodconsortium.org
|
||||
"@id": http://test.host/api/dfc/enterprises/6201/supplied_products/0
|
||||
"@type": dfc-b:SuppliedProduct
|
||||
dfc-b:name: Apple
|
||||
|
||||
Reference in New Issue
Block a user