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.add_ontology_term.format_term(term_details)[source]

Format term details into RDF/Turtle syntax.

Parameters:

term_details (dict) – Metadata for the new term.

Returns:

RDF Turtle triples to be appended.

Return type:

str

FAIRLinked.InterfaceMDS.add_ontology_term.get_term_details()[source]

Prompt the user to input details for a new ontology term.

Returns:

A dictionary with term_name, label, parent_class, definition, value_type, and unit.

Return type:

dict

FAIRLinked.InterfaceMDS.convert_ttl_to_drawio module

FAIRLinked.InterfaceMDS.domain_subdomain_viewer module

FAIRLinked.InterfaceMDS.domain_subdomain_viewer.build_dynamic_dsm(onto_graph)[source]

Dynamically builds a domain-subdomain mapping from the ontology graph.

Returns:

{ domain_URIRef: [subdomain_URIRef, …], … }

Return type:

dict

FAIRLinked.InterfaceMDS.domain_subdomain_viewer.domain_subdomain_dir_interface()[source]

Interactive CLI for creating a directory of ontology Turtle files.

FAIRLinked.InterfaceMDS.domain_subdomain_viewer.domain_subdomain_directory(onto_graph: Graph | None = None, output_dir: str | None = None)[source]

Dynamically parses the domain-subdomain tree from the ontology. Prints an ASCII tree and splits triples into matching directory structures.

FAIRLinked.InterfaceMDS.domain_subdomain_viewer.domain_subdomain_viewer()[source]

Display unique domain and subdomain values from an RDF ontology file.

  • Domains: Absolute top-level classes (no rdfs:subClassOf).

  • Subdomains: Any class in the hierarchy that IS a subclass of something else.

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):
  1. Turtle (“text/turtle”)

  2. JSON-LD (“application/ld+json”)

  3. 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.rdf_subject_extractor.fuzzy_search_interface()[source]

CLI interface compatible with extract_subject_details and fuzzy_filter_subjects_strict.

FAIRLinked.InterfaceMDS.rdf_subject_extractor.get_adaptive_distance(keyword)[source]

Determines allowed typos based on keyword length.

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 (bool, optional) – If True, extract the search results into a new graph. Defaults to False.

  • ttl_path (str, optional) – The file path to save the extracted turtle (.ttl) file. Required if ttl_extr is True.

Prints:
  • A list of labels for matching subjects.

Module contents

FAIRLinked.InterfaceMDS.domain_subdomain_viewer()[source]

Display unique domain and subdomain values from an RDF ontology file.

  • Domains: Absolute top-level classes (no rdfs:subClassOf).

  • Subdomains: Any class in the hierarchy that IS a subclass of something else.

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 (bool, optional) – If True, extract the search results into a new graph. Defaults to False.

  • ttl_path (str, optional) – The file path to save the extracted turtle (.ttl) file. Required if ttl_extr is True.

Prints:
  • A list of labels for matching subjects.