Skip to content

Commit

Permalink
update the metadata extractor to extract agents
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Aug 9, 2024
1 parent b99d26f commit 2602532
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
22 changes: 11 additions & 11 deletions config/schemes/ontology_submission.yml
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,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: false
extractedMetadata: true

### Description

Expand Down Expand Up @@ -503,7 +503,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: false
extractedMetadata: true
metadataMappings: [ "omv:hasCreator", "dc:creator", "dcterms:creator", "foaf:maker", "prov:wasAttributedTo", "doap:maintainer", "pav:authoredBy", "pav:createdBy", "schema:author", "schema:creator" ]

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

#Curator
Expand All @@ -528,7 +528,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: false
extractedMetadata: true
metadataMappings: [ "mod:evaluatedBy", "pav:curatedBy" ]

#Translator
Expand All @@ -538,7 +538,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: false
extractedMetadata: true
metadataMappings: [ "schema:translator" ]

#Publisher
Expand All @@ -550,7 +550,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: false
extractedMetadata: true
metadataMappings: [ "dc:publisher", "dcterms:publisher", "schema:publisher", "adms:schemaAgency" ]

#Funded or sponsored by
Expand All @@ -562,7 +562,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: false
extractedMetadata: true
metadataMappings: [ "foaf:fundedBy", "mod:sponsoredBy", "schema:sourceOrganization" ]

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

### Community
Expand Down Expand Up @@ -1429,7 +1429,7 @@ exampleIdentifier:
description: [
"VOID: Example resource of dataset.",
"IDOT: An example identifier used by one item (or record) from a dataset." ]
extractedMetadata: false
extractedMetadata: true
metadataMappings: [ "void:exampleResource", "idot:exampleIdentifier" ]

#Key classes
Expand All @@ -1441,7 +1441,7 @@ keyClasses:
"OMV: Representative classes in the ontology.",
"FOAF: The primary topic of some page or document.",
"SCHEMA: Indicates the primary entity described in some page or other CreativeWork." ]
extractedMetadata: false
extractedMetadata: true
metadataMappings: [ "foaf:primaryTopic", "schema:mainEntity", "omv:keyClasses"]

#Metadata vocabulary used
Expand All @@ -1454,7 +1454,7 @@ metadataVoc:
"SCHEMA: Indicates (by URL or string) a particular version of a schema used in some CreativeWork.",
"ADMS: A schema according to which the Asset Repository can provide data about its content, e.g. ADMS.",
"MOD: A vocabulary(ies) that is used and/or referred to create the current ontology." ]
extractedMetadata: false
extractedMetadata: true
enforcedValues: {
"http://w3id.org/nkos/nkostype#classification_schema": "Classification scheme",
"http://www.w3.org/2000/01/rdf-schema#": "RDF Schema (RDFS)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ def extract_ontology_metadata(logger, user_params)
end
end

# Set some metadata to default values if nothing extracted
def set_default_metadata

end

def empty_value?(value)
value.nil? || (value.is_a?(Array) && value.empty?) || value.to_s.strip.empty?
end
Expand All @@ -117,13 +112,17 @@ def send_value(attr, new_value, logger)
old_val = nil
single_extracted = false


if enforce?(attr, :list)
old_val = value(attr, :list)
new_values = old_val.dup
old_values = old_val.dup
new_values = new_value.values
new_values = new_values.map{ |v| find_or_create_agent(attr, v, logger) }.compact if enforce?(attr, :Agent)


new_values.push(*new_value.values)
old_values.push(*new_values)

@submission.send("#{attr}=", new_values.uniq)
@submission.send("#{attr}=", old_values.uniq)
elsif enforce?(attr, :concatenate)
# if multiple value for this attribute, then we concatenate it
# Add the concat at the very end, to easily join the content of the array
Expand All @@ -133,12 +132,17 @@ def send_value(attr, new_value, logger)

@submission.send("#{attr}=", (metadata_values + new_values).uniq.join(', '))
else
@submission.send("#{attr}=", new_value.values.first)
new_value = new_value.values.first

new_value = find_or_create_agent(attr, nil, logger) if enforce?(attr, :Agent)

@submission.send("#{attr}=", new_value)
single_extracted = true
end

unless @submission.valid?
logger.error("Error while extracting metadata for the attribute #{attr}: #{@submission.errors[attr] || @submission.errors}")
new_value&.delete if enforce?(attr, :Agent) && new_value.respond_to?(:delete)
@submission.send("#{attr}=", old_val)
end

Expand Down Expand Up @@ -269,6 +273,16 @@ def enforce?(attr, type)
LinkedData::Models::OntologySubmission.attribute_settings(attr)[:enforce].include?(type)
end

def find_or_create_agent(attr, old_val, logger)
agent = LinkedData::Models::Agent.where(agentType: 'person', name: old_val).first
begin
agent ||= LinkedData::Models::Agent.new(name: old_val, agentType: 'person', creator: @submission.ontology.administeredBy.first).save
rescue
logger.error("Error while extracting metadata for the attribute #{attr}: Can't create Agent #{agent.errors} ")
agent = nil
end
agent
end
end
end
end
Expand Down

0 comments on commit 2602532

Please sign in to comment.