Skip to content

Multiple ontology support#1296

Open
cwant wants to merge 6 commits intoElixirTeSS:masterfrom
cwant:cwant/multi_ontology
Open

Multiple ontology support#1296
cwant wants to merge 6 commits intoElixirTeSS:masterfrom
cwant:cwant/multi_ontology

Conversation

@cwant
Copy link
Copy Markdown
Contributor

@cwant cwant commented Apr 29, 2026

Summary of changes

This is a scheme to specify multiple ontologies for a field that is completely backwards compatible with the current single ontology implementation.

As before, we can specify an ontology like we do in the models:

has_ontology_terms(:scientific_topics, branch: EDAM.topics)

(This takes the default of Edam::Ontology.instance for the ontology argument.)

Now you could allow terms from more than one ontology, like in the tests in test/unit/has_ontology_terms_test.rb:

 has_ontology_terms(:test_topics, ontology: DummyOntology.instance)
 has_ontology_terms(:multi_test_topics,
                     ontologies: [{ ontology: Edam::Ontology.instance,
                                    branch: EDAM.topics},
                                  { ontology: DummyOntology.instance}])

The ontologies argument takes an array of hashes, each hash having keys ontology and branch (and if either key is excluded, it takes similar defaults as before).
In the example above, terms come from Edam (topics branch) and from DummyOntology (no branch specified).

Motivation and context

Explora uses multiple ontologies for scientific topics, and this implementation is adapted from that work. In the Explora case, we use a preferred ontology (CRDC from Statistics Canada) that we expose in the user interface (auto-complete), but we also want to be able to ingest Bioschemas that uses Edam.

Out of scope: this work does not address auto-complete in any controllers. The person implementing the ontology has to figure that one out themselves (in the Explora case, we basically did a s/edam/crdc/ and renames EdamController to CRDCController.

Screenshots

Not much to screenshot, since this works at a very abstract level and in fact there are no concrete examples in the code base. The test to look at though is test/unit/has_ontology_terms_test.rb, which has examples of this working in a mocked sense.

Checklist

  • I have read and followed the CONTRIBUTING guide.
  • I confirm that I have the authority necessary to make this contribution on behalf of its copyright owner and agree to license it to the TeSS codebase under the BSD license.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR generalizes ontology-term handling so models can accept terms from multiple ontologies instead of only EDAM, while keeping existing single-ontology declarations working the same way in the core codebase.

Changes:

  • Extends has_ontology_terms to accept an ontologies: array and adds tests covering single- and multi-ontology assignment by names and URIs.
  • Adds ontology-level URI matching/lookup helpers so OntologyTermLink can resolve terms from different ontology implementations.
  • Renames the EDAM-specific synonym concern to a more generic name and updates Event, Material, and Workflow to use it.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/unit/has_ontology_terms_test.rb Adds new unit coverage for custom and multi-ontology term assignment.
lib/has_ontology_terms.rb Extends the macro to support multiple ontologies and changes field registration behavior.
app/ontologies/ontology.rb Adds abstract URI helpers to the base ontology class.
app/ontologies/edam/ontology.rb Adds combined label/synonym lookup for EDAM.
app/models/workflow.rb Switches workflow synonym helper concern to the renamed module.
app/models/ontology_term_link.rb Resolves linked terms by ontology URI prefix instead of assuming EDAM.
app/models/material.rb Switches material synonym helper concern to the renamed module.
app/models/event.rb Switches event synonym helper concern to the renamed module.
app/models/concerns/has_terms_and_synonyms.rb Renames and retains the term/synonym expansion helper used for indexing.
Comments suppressed due to low confidence (1)

app/models/concerns/has_terms_and_synonyms.rb:16

  • This concern is still EDAM-specific: OntologyTerm only provides label/uri, and has_exact_synonym / has_narrow_synonym are added only by Edam::Term. As soon as a resource contains terms from another ontology, calls like scientific_topics_and_synonyms will raise here during indexing/search.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/has_ontology_terms.rb Outdated
Comment thread lib/has_ontology_terms.rb
Comment thread app/models/ontology_term_link.rb
cwant added 3 commits May 5, 2026 07:52
…iable

work better with STI (have not really tested the STI part). Seems to work
(in the "test suite passes" sense), and does not suffer from the same
inheritance problems that the cattr_accessor code had (the specific
problem is that fields added to `ontology_term_fields` would infect the
superclass!).
@cwant
Copy link
Copy Markdown
Contributor Author

cwant commented May 5, 2026

All (current) Co-pilot suggestions resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants