FAIRLinked.InterfaceMDS package
Submodules
FAIRLinked.InterfaceMDS.add_ontology_term module
Script to interactively add a new term to an existing ontology in Turtle (TTL) format.
Prompts the user for term metadata (label, parent class, value type, unit) and appends RDF triples to a new file (original name suffixed with _rxl895) to preserve the original.
- FAIRLinked.InterfaceMDS.add_ontology_term.add_term_to_ontology(ontology_path)[source]
Add a new term to a TTL ontology file and write to a new versioned file.
- Parameters:
ontology_path (str) – Path to the TTL ontology file.
- Returns:
True if added successfully, else False.
- Return type:
bool
FAIRLinked.InterfaceMDS.convert_ttl_to_drawio module
- FAIRLinked.InterfaceMDS.convert_ttl_to_drawio.convert_ttl_to_cemento(ttl_input_path, drawio_output_path)[source]
This function uses the CEMENTO package to generate a draw.io diagram from a turtle file, allowing for better visualization of ontologies.
- Parameters:
ttl_input_path – Path to turtle file
drawio_output_path – Path to store draw.io diagram
- Returns:
None
FAIRLinked.InterfaceMDS.domain_subdomain_viewer module
- FAIRLinked.InterfaceMDS.domain_subdomain_viewer.domain_subdomain_viewer()[source]
Display all unique domain and subdomain values from an RDF ontology file.
This function parses the RDF graph from the given file path and prints the unique values of the predicates mds:hasDomain and mds:hasSubDomain. Uniqueness is determined in a case-insensitive manner.
- Prints:
A list of unique domain values.
A list of unique subdomain values.
FAIRLinked.InterfaceMDS.load_mds_ontology module
- FAIRLinked.InterfaceMDS.load_mds_ontology.load_mds_ontology_graph()[source]
Attempts to load the MDS ontology RDF graph by following redirects and using content negotiation to request different RDF serialization formats.
- Tries to fetch the ontology in the following formats (in order of preference):
Turtle (“text/turtle”)
JSON-LD (“application/ld+json”)
RDF/XML (“application/rdf+xml”)
If a request is successful, the RDF data is parsed into an rdflib Graph. It also prints the owl:versionInfo if available, to indicate the version of the ontology that was loaded.
- Returns:
The parsed RDF graph of the MDS ontology, or None if all attempts fail.
- Return type:
rdflib.Graph
- Raises:
None explicitly. All exceptions are caught and printed. –
FAIRLinked.InterfaceMDS.rdf_subject_extractor module
- FAIRLinked.InterfaceMDS.rdf_subject_extractor.extract_subject_details(graph)[source]
Extract all subjects from an RDF graph, including preferred labels and predicate-object details.
- Parameters:
graph (rdflib.Graph) – The parsed RDF graph.
- Returns:
DataFrame with ‘subject_id’, ‘label’, and ‘info’.
- Return type:
pd.DataFrame
- FAIRLinked.InterfaceMDS.rdf_subject_extractor.fuzzy_filter_subjects_strict(df, keywords, column='label', max_l_dist=1)[source]
Perform strict fuzzy word-level matching using Levenshtein distance.
- Parameters:
df (pd.DataFrame) – DataFrame to filter.
keywords (list of str) – Keywords to search for.
column (str) – Column to search.
max_l_dist (int) – Max Levenshtein distance.
- Returns:
Filtered DataFrame of matches.
- Return type:
pd.DataFrame
FAIRLinked.InterfaceMDS.term_search_general module
- FAIRLinked.InterfaceMDS.term_search_general.term_search_general(mds_ontology_graph=None, query_term=None, search_types=None, ttl_extr=0, ttl_path=None)[source]
Search an RDF ontology for subjects with a specified predicate and optional query term.
- Parameters:
mds_ontology_graph (rdflib.Graph, optional) – An existing RDF graph. If None, one will be loaded.
query_term (str, optional) – Term to match against the object of the predicate. If None, all values will be returned for the given search types.
search_types (list[str]) – List of search types: “Domain”, “SubDomain”, or “Study Stage”.
ttl_extr (int, optional) – If not 0, extract the search results into a new graph. Defaults to 0.
ttl_path (str, optional) – The file path to save the extracted turtle (.ttl) file. Required if ttl_extr is not 0.
- Prints:
A list of labels for matching subjects, grouped by search type.
Module contents
- FAIRLinked.InterfaceMDS.domain_subdomain_viewer()[source]
Display all unique domain and subdomain values from an RDF ontology file.
This function parses the RDF graph from the given file path and prints the unique values of the predicates mds:hasDomain and mds:hasSubDomain. Uniqueness is determined in a case-insensitive manner.
- Prints:
A list of unique domain values.
A list of unique subdomain values.
- FAIRLinked.InterfaceMDS.term_search_general(mds_ontology_graph=None, query_term=None, search_types=None, ttl_extr=0, ttl_path=None)[source]
Search an RDF ontology for subjects with a specified predicate and optional query term.
- Parameters:
mds_ontology_graph (rdflib.Graph, optional) – An existing RDF graph. If None, one will be loaded.
query_term (str, optional) – Term to match against the object of the predicate. If None, all values will be returned for the given search types.
search_types (list[str]) – List of search types: “Domain”, “SubDomain”, or “Study Stage”.
ttl_extr (int, optional) – If not 0, extract the search results into a new graph. Defaults to 0.
ttl_path (str, optional) – The file path to save the extracted turtle (.ttl) file. Required if ttl_extr is not 0.
- Prints:
A list of labels for matching subjects, grouped by search type.