Resolve DFC Connector objects when importing graph

This commit is contained in:
Maikel Linke
2023-05-22 17:38:57 +10:00
parent 12d56d725b
commit f5f8c349e1
2 changed files with 14 additions and 8 deletions

View File

@@ -23,6 +23,7 @@ module DataFoodConsortium
@subjects = {}
graph = parse_rdf(json_string)
build_subjects(graph)
apply_statements(graph)
if @subjects.size > 1
@@ -39,6 +40,12 @@ module DataFoodConsortium
RDF::Graph.new << JSON::LD::API.toRdf(json_file)
end
def build_subjects(graph)
graph.query({ predicate: RDF.type }).each do |statement|
@subjects[statement.subject] = build_subject(statement)
end
end
def build_subject(type_statement)
id = type_statement.subject.value
type = type_statement.object.value
@@ -56,7 +63,7 @@ module DataFoodConsortium
def apply_statement(statement)
subject = subject_of(statement)
property_id = statement.predicate.value
value = statement.object.object
value = resolve_object(statement.object)
return unless subject.hasSemanticProperty?(property_id)
@@ -73,7 +80,11 @@ module DataFoodConsortium
end
def subject_of(statement)
@subjects[statement.subject] ||= build_subject(statement)
@subjects[statement.subject]
end
def resolve_object(object)
@subjects[object] || object.object
end
end
end

View File

@@ -66,12 +66,7 @@ describe DataFoodConsortium::Connector::Importer, vcr: true do
enterprise, tomato, ocra = result
# Work in progress, we get only the URLs as hashes:
expect(enterprise.suppliedProducts[0][:path]).to eq "/tomato"
expect(enterprise.suppliedProducts[1][:path]).to eq "/ocra"
# We would actually like to resolve the objects:
#expect(enterprise.suppliedProducts).to eq [tomato, ocra]
expect(enterprise.suppliedProducts).to eq [tomato, ocra]
end
def import(*args)