FAIRLinked.RDFTableConversion package
Submodules
FAIRLinked.RDFTableConversion.csv_to_jsonld_mapper module
- FAIRLinked.RDFTableConversion.csv_to_jsonld_mapper.extract_terms_from_ontology(ontology_graph)[source]
Extract terms from an RDF graph representing an OWL ontology.
- Parameters:
ontology_graph (rdflib.Graph) – The ontology RDF graph.
- Returns:
A list of dictionaries containing term IRIs, original labels, and normalized labels.
- Return type:
list[dict]
- FAIRLinked.RDFTableConversion.csv_to_jsonld_mapper.find_best_match(column, ontology_terms)[source]
Find the best matching ontology term for a given column name.
- Parameters:
column (str) – The name of the column from the CSV file.
ontology_terms (list[dict]) – List of extracted ontology terms.
- Returns:
The best-matching ontology term, or None if no good match is found.
- Return type:
dict or None
- FAIRLinked.RDFTableConversion.csv_to_jsonld_mapper.json_ld_template_generator(csv_path, ontology_graph, output_path, matched_log_path, unmatched_log_path)[source]
Use a CSV file into a JSON-LD template that user can fill out column metadata.
- Parameters:
csv_path (str) – Path to the CSV file to generate JSON-LD template.
ontology_graph (rdflib.Graph) – The ontology RDF graph for matching terms.
output_path (str) – Path to write the resulting JSON-LD file.
matched_log_path (str) – Path to write the log of columns that matched the ontology.
unmatched_log_path (str) – Path to write the log of columns that can’t be found in the ontology.
FAIRLinked.RDFTableConversion.csv_to_jsonld_template_filler module
- FAIRLinked.RDFTableConversion.csv_to_jsonld_template_filler.extract_data_from_csv(metadata_template, csv_file, row_key_cols, orcid, output_folder, prop_column_pair_dict=None, ontology_graph=None, base_uri='https://cwrusdle.bitbucket.io/mds/')[source]
Converts CSV rows into RDF graphs using a JSON-LD template and optional property mapping, writing JSON-LD files.
- Parameters:
metadata_template (dict) – JSON-LD template with “@context” and “@graph”.
csv_file (str) – Path to the input CSV.
row_key_cols (list[str]) – Columns to uniquely identify each row.
orcid (str) – ORCID identifier (dashes removed automatically).
output_folder (str) – Directory to save JSON-LD files.
prop_column_pair_dict (dict or None, optional) – Maps property keys to (subject_column, object_column) column pairs. If None or empty, no properties are added.
ontology_graph (RDFLib Graph object or None, optional) – Ontology for property type/URI resolution. Required if prop_column_pair_dict is provided.
base_uri (str, optional) – Base URI used to construct subject and object URIs.
- Returns:
List of RDFLib Graphs, one per row.
- Return type:
List[rdflib.Graph]
- FAIRLinked.RDFTableConversion.csv_to_jsonld_template_filler.extract_from_folder(csv_folder, metadata_template, row_key_cols, orcid, output_base_folder, prop_column_pair_dict=None, ontology_graph=None, base_uri='https://cwrusdle.bitbucket.io/mds/')[source]
Processes all CSV files in a folder and converts each into RDF/JSON-LD files using a metadata template and optional object/datatype property mappings.
- Parameters:
csv_folder (str) – Path to the folder containing CSV files.
metadata_template (dict) – JSON-LD metadata template with “@context” and “@graph” describing the RDF structure.
row_key_cols (list[str]) – List of CSV column names used to construct a unique key for each row.
orcid (str) – ORCID iD of the user (dashes will be removed automatically).
output_base_folder (str) – Directory where output subfolders (one per CSV) will be created for JSON-LD files.
prop_column_pair_dict (dict or None, optional) – Mapping from property key (e.g., predicate label) to list of (subject_column, object_column) tuples. These define additional object or datatype properties to inject based on CSV columns. If None, no extra connections are added.
ontology_graph (str or None, optional) – RDFLib graph object of ontology from which property URIs and types are resolved. Required only if prop_column_pair_dict is given.
base_uri (str, optional) – Base URI used to construct RDF subject and object URIs. Defaults to the CWRU MDS base.
- Returns:
Writes JSON-LD files to disk. No return value.
- Return type:
None
- FAIRLinked.RDFTableConversion.csv_to_jsonld_template_filler.generate_prop_metadata_dict(ontology_graph)[source]
Generates a dictionary where the keys are human-readable labels of object/datatype properties, and the values are 2-tuples that contain the URI of that property in the first entry and the type (object/datatype) in second entry.
- Parameters:
ontology_graph (RDFLib graph object of the ontology) – Path to the RDF/OWL ontology file.
- Returns:
Dictionary of the form: {
”has material”: (”http://example.org/ontology#hasMaterial”, “Object Property”), “has value”: (”http://example.org/ontology#hasValue”, “Datatype Property”), …
}
- Return type:
dict
FAIRLinked.RDFTableConversion.jsonld_batch_converter module
- FAIRLinked.RDFTableConversion.jsonld_batch_converter.extract_row_from_jsonld(data: dict, filename: str)[source]
Extracts a single row of data from a JSON-LD object.
- Parameters:
data (dict) – JSON-LD data parsed as dictionary.
filename (str) – Name of the file the data came from.
- Returns:
(row_values, fair_types, units) as dictionaries.
- Return type:
tuple
- FAIRLinked.RDFTableConversion.jsonld_batch_converter.jsonld_directory_to_csv(input_dir: str, output_basename: str = 'merged_output', output_dir: str = 'outputs')[source]
Converts a directory of JSON-LD files into a tabular format (CSV, Parquet, Arrow). Each row represents a JSON-LD file with:
Column headers from skos:altLabel
Values from qudt:value
Extra header rows for FAIR type (@type) and units (qudt:hasUnit)
- Parameters:
input_dir (str) – Directory containing JSON-LD files.
output_basename (str) – Base name for output files.
output_dir (str) – Output directory to save CSV, Parquet, and Arrow files.