#!/usr/bin/env python3 # encoding: utf-8 # # This file is a part of the LinkAhead Project. # # Copyright (C) 2026 Indiscale GmbH # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . """ Setup for the 'Scripting with LinkAhead' tutorial. """ import linkahead as db from linkahead import Property, Record from caosadvancedtools.models.parser import Parser SCHEMA_YAML = """ Experiment: obligatory_properties: responsible_scientist: datatype: Person Person: obligatory_properties: first_name: datatype: TEXT last_name: datatype: TEXT recommended_properties: email: datatype: TEXT """ def main(): # Insert schema schema = Parser().parse_model_from_string(SCHEMA_YAML) schema.sync_data_model(noquestion=True) # Insert scientists scientists = [("Andreas", "Anders"), ("Berta", "Baker"), ("Charles", "Chaplin"), ("Doris", "Decker"), ("Erwin", "Ehrlich"), ("Frank", "Field")] new_records = db.Container() for first, last in scientists: person = Record(name=f"{first} {last}").add_parent(name="Person") person.add_property(property=Property(name="first_name"), value=first) person.add_property(property=Property(name="last_name"), value=last) email = f"{first}.{last}@science.tld".lower() person.add_property(property=Property(name="email"), value=email) new_records.append(person) new_records.insert() # Insert experiments new_records = db.Container() for i in range(10): experiment = Record(name=f"Experiment_{i+1}").add_parent(name="Experiment") scientist = Record(name=' '.join(scientists[i%len(scientists)])).add_parent(name="Person") experiment.add_property(property=Property(name="responsible_scientist"), value=scientist) new_records.append(experiment) # Update server new_records.insert() if __name__ == "__main__": main()