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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# frozen_string_literal: true

describe "parse with skos concept" do
let(:connector) { DataFoodConsortium::Connector::Connector.instance }

describe "productTypes" do
before { connector.loadProductTypes(parse_json_file("productTypes.json")) }

describe "topConcepts" do
it "returns a list of available topConcepts" do
product_types = connector.PRODUCT_TYPES.topConcepts

expected = [
:BAKERY, :DAIRY_PRODUCT, :DRINK, :FROZEN, :FRUIT, :INEDIBLE, :LOCAL_GROCERY_STORE,
:MEAT_PRODUCT, :VEGETABLE
]
expect(product_types).to eq(expected)
end
end

it "parses the first level" do
drink_type = connector.PRODUCT_TYPES.DRINK

expect(drink_type.is_a?(DataFoodConsortium::Connector::SKOSConcept)).to be(true)
expect(drink_type.broaders).to eq([])
expect(drink_type.narrowers).to eq([:ALCOHOLIC_BEVERAGE, :SOFT_DRINK])
end

it "parses the second level" do
drink_type = connector.PRODUCT_TYPES.DRINK.SOFT_DRINK

expect(drink_type.is_a?(DataFoodConsortium::Connector::SKOSConcept)).to be(true)
expect(drink_type.broaders).to eq([:DRINK])
expect(drink_type.narrowers).to eq([:FRUIT_JUICE, :LEMONADE, :SMOOTHIE])
end


it "parses leaf level" do
drink_type = connector.PRODUCT_TYPES.DRINK.SOFT_DRINK.LEMONADE

expect(drink_type.is_a?(DataFoodConsortium::Connector::SKOSConcept)).to be(true)
expect(drink_type.broaders).to eq([:SOFT_DRINK])
expect(drink_type.narrowers).to eq([])
end
end


describe "facets" do
before { connector.loadFacets(parse_json_file("facets.json")) }

describe "topConcepts" do
it "returns a list of available topConcepts" do
facets = connector.FACETS.topConcepts

expected = [:CERTIFICATION, :CLAIM, :NATUREORIGIN, :PARTORIGIN, :TERRITORIALORIGIN]
expect(facets).to eq(expected)
end
end

# We tested with Product Types further levels up to a leaf. So it's fair to expect
# if the first level is good, the others are as well due to the recursive nature of the parser
it "parses the first level" do
facet = connector.FACETS.CERTIFICATION

expect(facet.is_a?(DataFoodConsortium::Connector::SKOSConcept)).to be(true)
expect(facet.broaders).to eq([])
expect(facet.narrowers).to eq(
[:ORGANICLABEL, :LOCALLABEL, :BIODYNAMICLABEL, :ETHICALLABEL, :MARKETINGLABEL]
)
end
end
end