Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 8 additions & 8 deletions config/schemes/ontology_submission.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ copyrightHolder:
description: [
"SCHEMA: The party holding the legal copyright to the CreativeWork.",
"DCTERMS: A person or organization owning or managing rights over the resource." ]
extractedMetadata: true
extractedMetadata: once

### Description

Expand Down Expand Up @@ -504,7 +504,7 @@ hasCreator:
"DOAP: Maintainer of a project, a project leader.",
"SCHEMA:author: The author of this content or rating.",
"SCHEMA:creator: The creator/author of this CreativeWork." ]
extractedMetadata: true
extractedMetadata: once
metadataMappings: [ "omv:hasCreator", "dc:creator", "dcterms:creator", "foaf:maker", "prov:wasAttributedTo", "doap:maintainer", "pav:authoredBy", "pav:createdBy", "schema:author", "schema:creator" ]

#Contributor
Expand All @@ -518,7 +518,7 @@ hasContributor:
"OMV: Contributors to the creation of the ontology.",
"PAV: The resource was contributed to by the given agent.",
"DOAP: Project contributor" ]
extractedMetadata: true
extractedMetadata: once
metadataMappings: [ "omv:hasContributor", "dc:contributor", "dcterms:contributor", "doap:helper", "schema:contributor", "pav:contributedBy" ]

#Curator
Expand All @@ -529,7 +529,7 @@ curatedBy:
description: [
"PAV: Specifies an agent specialist responsible for shaping the expression in an appropriate format. Often the primary agent responsible for ensuring the quality of the representation.",
"MOD: An ontology that is evaluated by an agent." ]
extractedMetadata: true
extractedMetadata: once
metadataMappings: [ "mod:evaluatedBy", "pav:curatedBy" ]

#Translator
Expand All @@ -539,7 +539,7 @@ translator:
helpText: "Organization or person who adapts a creative work to different languages."
description: [
"SCHEMA: Organization or person who adapts a creative work to different languages, regional differences and technical requirements of a target market, or that translates during some event." ]
extractedMetadata: true
extractedMetadata: once
metadataMappings: [ "schema:translator" ]

#Publisher
Expand All @@ -551,7 +551,7 @@ publisher:
"DCTERMS: An entity responsible for making the resource available.",
"SCHEMA: The publisher of creative work.",
"ADMS: The name of the agency that issued the identifier." ]
extractedMetadata: true
extractedMetadata: once
metadataMappings: [ "dc:publisher", "dcterms:publisher", "schema:publisher", "adms:schemaAgency" ]

#Funded or sponsored by
Expand All @@ -563,7 +563,7 @@ fundedBy:
"MOD: An ontology that is sponsored by and developed under a project.",
"FOAF: An organization funding a project or person.",
"SCHEMA: The organization on whose behalf the creator was working." ]
extractedMetadata: true
extractedMetadata: once
metadataMappings: [ "foaf:fundedBy", "mod:sponsoredBy", "schema:sourceOrganization" ]

#Endorsed by
Expand All @@ -574,7 +574,7 @@ endorsedBy:
description: [
"MOD: An ontology endorsed by an agent.",
"OMV: The parties that have expressed support or approval to this ontology." ]
extractedMetadata: true
extractedMetadata: once
metadataMappings: [ "omv:endorsedBy", "mod:endorsedBy" ]

### Community
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ def extract_ontology_metadata(logger, user_params)

next unless attr_settings[:extractedMetadata] && attr_not_excluded

extracted_once = attr_settings[:extractedMetadata] == "once"
if extracted_once
# if the attribute should be extracted only once, check if it has already been set in the before last submission
values_before = check_value_from_before_latest_submission(attr, logger)

if values_before.present?
@submission.send("#{attr}=", values_before)
next
end
end


# a boolean to check if a value that should be single have already been extracted
single_extracted = false
type = enforce?(attr, :list) ? :list : :string
Expand Down Expand Up @@ -283,6 +295,21 @@ def find_or_create_agent(attr, old_val, logger)
end
agent
end

def check_value_from_before_latest_submission(attr, logger)
@ontology ||= @submission.ontology
@ontology.bring(submissions: [:submissionId])

@submissions ||= @ontology.submissions.to_a.sort_by { |s| -s.submissionId }
return nil if @submissions.size < 2

before_last_sub = @submissions[1]
before_last_sub.bring(attr)

before_last_sub.public_send(attr.to_s)
end


end
end
end
Expand Down
4 changes: 2 additions & 2 deletions rakelib/docker_based_test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace :test do
ENV["COMPOSE_PROFILES"]="vo"
Rake::Task["test:docker:up"].invoke
#
unless system("curl -sf http://localhost:8890/sparql || exit 1")
unless system("curl -sf -o /dev/null http://localhost:8890/sparql || exit 1")
printf("waiting for Virtuoso container to initialize")
sec = 0
until system("curl -sf http://localhost:8890/sparql || exit 1") do
Expand Down Expand Up @@ -99,7 +99,7 @@ namespace :test do
#system("docker compose cp ./test/data/graphdb-repo-config.ttl graphdb:/opt/graphdb/dist/configs/templates/graphdb-repo-config.ttl")
#system("docker compose cp ./test/data/graphdb-test-load.nt graphdb:/opt/graphdb/dist/configs/templates/graphdb-test-load.nt")
#system('docker compose exec graphdb sh -c "importrdf load -f -c /opt/graphdb/dist/configs/templates/graphdb-repo-config.ttl -m parallel /opt/graphdb/dist/configs/templates/graphdb-test-load.nt ;"')
unless system("curl -sf http://localhost:7200/repositories || exit 1")
unless system("curl -o /dev/null -sf http://localhost:7200/repositories || exit 1")
printf("waiting for Graphdb container to initialize")
sec = 0
until system("curl -sf http://localhost:7200/repositories || exit 1") do
Expand Down
45 changes: 45 additions & 0 deletions test/models/test_ontology_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,51 @@ def test_submission_extract_metadata
end
end

def test_submission_extract_metadata_once
# This test is only testing one attributefields which is :hasCreator
# TO-DO: make generic to all the fields that has extracted once
submission_parse("AGROOE", "AGROOE Test extract metadata ontology",
"./test/data/ontology_files/agrooeMappings-05-05-2016.owl", 1,
process_rdf: true, extract_metadata: true, generate_missing_labels: false, delete: true)
ont = LinkedData::Models::Ontology.find("AGROOE").first
sub1 = ont.latest_submission
refute_nil sub1

sub1.bring_remaining
hasCreator_old_values = ["Alfred DC", "Clement Jonquet", "Gaston Dcterms", "Huguette Doap", "Mirabelle Prov", "Paul Foaf", "Vincent Emonet"]
assert_equal hasCreator_old_values.sort, sub1.hasCreator.map { |x| x.bring_remaining.name }.sort
sub1.save

agents_number = LinkedData::Models::Agent.where.count

# modifing the names of the agents (the curation phase)
hasCreator_old_values.each do |agent_name|
agent = LinkedData::Models::Agent.where(name: agent_name).first
refute_nil agent
agent.bring_remaining
agent.name = "#{agent_name}#{rand(1000..9999)}"
agent.save
end

assert agents_number, LinkedData::Models::Agent.where.count

# Create new submission
submission_parse("AGROOE", "AGROOE Test extract metadata ontology", "./test/data/ontology_files/agrooeMappings-05-05-2016.owl", 2,
process_rdf: true, extract_metadata: true, generate_missing_labels: false, delete: false)
ont = LinkedData::Models::Ontology.find("AGROOE").first
sub2 = ont.latest_submission
refute_nil sub2

sub2.bring_remaining
sub2.save

# Check if there is duplications
assert agents_number, LinkedData::Models::Agent.where.count
all_sub = LinkedData::Models::Ontology.find("AGROOE").first.bring(:submissions => [:hasCreator => [:name]]).submissions
sub0 = all_sub[0]
sub1 = all_sub[1]
sub0.hasCreator.map { |x| x.name }.sort == sub1.hasCreator.map { |x| x.name }.sort
end

def test_submission_delete_remove_files
#This one has resources wih accents.
Expand Down