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.domain_subdomain_viewer module
- FAIRLinked.InterfaceMDS.domain_subdomain_viewer.domain_subdomain_dir_interface()[source]
Interactive CLI for creating a directory of ontology Turtle files based on domains and subdomains.
- If the user chooses “yes”:
Ask for the output directory path.
Ask whether to provide a custom ontology file path or use the default loader.
Load the ontology graph accordingly.
Call domain_subdomain_directory(onto_graph=…, output_dir=…).
- If the user chooses “no”:
Just print the ASCII tree using domain_subdomain_directory() with default args.
- FAIRLinked.InterfaceMDS.domain_subdomain_viewer.domain_subdomain_directory(dsm={'BuiltEnv': ['PV-Cell', 'PV-Module', 'PV-Site', 'PV-CrgCont'], 'Charact': ['Opt-UvVis', 'Material-Profil', 'Material-LPBF', 'Material-AFM', 'Opt-FTIR', 'Material-Pyrom', 'Material-Fract', 'Material-XRD', 'Elec-SIR', 'Elec-Interdig'], 'Chem': ['Chem-Rxn'], 'Exposure': ['Accelerated']}, onto_graph: Graph | None = None, output_dir: str | None = None)[source]
Displays an ASCII tree of domain-subdomain structure and optionally splits an RDF ontology into separate Turtle files for each domain/subdomain combination.
- Parameters:
dsm (dict, optional) –
A dictionary mapping domain names (str) to lists of subdomain names (list of str). Default is DOMAIN_SUBDOMAIN_MAPPING. Example:
- {
“Chem”: [“Chem-Rxn”], “Charact”: [“Opt-UvVis”, “Material-Profil”, …], …
}
onto_graph (rdflib.Graph, optional) –
- An RDF graph containing ontology data. Classes in this graph must have the predicates:
mds:hasDomain → string indicating domain
mds:hasSubDomain → string indicating subdomain
If None, the function will only print the ASCII tree without creating Turtle files.
output_dir (str, optional) – Path to the folder where domain/subdomain Turtle files will be saved. Each domain gets a subfolder, and each subdomain gets a .ttl file. If None, no files are created.
BEHAVIOR
--------
dsm. (1. Prints an ASCII tree of all domains and subdomains in) –
- Example output:
├── Chem │ └── Chem-Rxn ├── Charact │ ├── Opt-UvVis │ ├── Material-Profil │ … └── Exposure
└── Accelerated
provided (2. If onto_graph and output_dir are) –
Creates a folder structure output_dir/domain/subdomain.ttl.
- For each owl:Class in onto_graph with mds:hasDomain and mds:hasSubDomain:
If its domain and subdomain match dsm, writes all triples about that class into the corresponding Turtle file.
Only writes files for classes that exist in the ontology.
- Prints a confirmation for each file written, e.g.:
✅ Wrote split_ttl/Charact/Elec-SIR.ttl
- Returns:
The function prints output to stdout and optionally writes Turtle files to disk.
- Return type:
None
- 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.filter_interface(args)[source]
Term search using Domain, SubDomain, or Study Stage. For complete list of Domains and SubDomains, run the following commands in bash:
FAIRLinked view-domains FAIRLinked dir-make.
The current list of Study Stages include: Synthesis, Formulation, Materials Processing, Sample, Tool, Recipe, Result, Analysis, Modeling.
For more details about Study Stages, please view go see https://cwrusdle.bitbucket.io/.
- FAIRLinked.InterfaceMDS.term_search_general.term_search_general(mds_ontology_graph=None, query_term=None, search_types=None, ttl_extr=False, 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=False, 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.