### Install LinkML-Store with all extras Source: https://linkml.io/linkml-store/_sources/about.rst.txt Use this command to install LinkML-Store with all optional dependencies included. ```bash pip install "linkml-store[all]" ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://linkml.io/linkml/_sources/maintainers/contributing.md.txt Clone the LinkML repository and install development dependencies using uv. Choose between a full installation or a lighter development setup. ```shell git clone https://github.com/linkml/linkml cd linkml # Full installation (all optional dependencies - same as CI) uv sync --all-groups # OR lighter development installation (recommended for most development) uv sync --group dev # OR if you need to run the full test suite locally uv sync --group dev --group tests-extra ``` -------------------------------- ### LinkML CLI Example: gen-project Source: https://linkml.io/linkml/intro/install.html Demonstrates the usage of the 'gen-project' command-line tool after starting the LinkML Docker image. This command generates a LinkML project. ```shell $ gen-project --help /home/runner/work/linkml/linkml/.venv/lib/python3.12/site-packages/requests/__init__.py:113: RequestsDependencyWarning: urllib3 (2.5.0) or chardet (7.4.3)/charset_normalizer (3.4.4) doesn't match a supported version! warnings.warn( Usage: gen-project [OPTIONS] YAMLFILE Generate an entire project LinkML schema ... ``` -------------------------------- ### Download Biolink Model and Setup Environment Source: https://linkml.io/linkml/_sources/generators/pydantic.rst.txt Commands to download the Biolink Model YAML, create a virtual environment, and install LinkML. ```bash curl -OJ https://raw.githubusercontent.com/biolink/biolink-model/master/biolink-model.yaml python3 -m venv venv source venv/bin/activate pip install linkml ``` -------------------------------- ### Setup for Array Generation and Comparison Source: https://linkml.io/linkml/_sources/schemas/arrays.md.txt Imports necessary libraries and defines helper functions for rendering and comparing LinkML schemas with their Pydantic and numpydantic representations. This setup is used throughout the examples. ```python from linkml.generators import PydanticGenerator from linkml_runtime.loaders.yaml_loader import YAMLLoader from linkml_runtime.dumpers.yaml_dumper import YAMLDumper from IPython.display import display, Markdown from pathlib import Path import numpy as np from rich.console import Console from rich.theme import Theme from rich.style import Style from rich.color import Color theme = Theme({ "repr.call": Style(color=Color.from_rgb(110,191,38), bold=True), "repr.attrib_name": Style(color="slate_blue1"), "repr.number": Style(color="deep_sky_blue1"), }) console = Console(theme=theme) schemas = Path('.').resolve().parent / '_includes' / 'arrays' COMPARISON = """ :::::{{tab-set}} ::::{{tab-item}} LinkML :::{{ code-block}} yaml {linkml} ::: :::: ::::{{tab-item}} pydantic - LoL :::{{ code-block}} python {pydantic_lol} ::: :::: ::::{{tab-item}} numpydantic :::{{ code-block}} python {pydantic_npd} ::: :::: ::::: """ def render_module(path, representation='list'): generator = PydanticGenerator(str(path), array_representations=[representation]) module = generator.render() return module def compile_module(path, representation='list'): generator = PydanticGenerator(str(path), array_representations=[representation]) module = generator.compile_module() return module def render_class(path, cls, representation='list') -> str: module = render_module(path, representation) cls = module.classes[cls] code = cls.render(black=True) return code def render_comparison(path, cls, string=False) -> str: if not isinstance(cls, list): cls = [cls] path = str(path) sch = YAMLLoader().load_as_dict(path) class_strs = [] pydantic_strs = [] npd_strs = [] for a_cls in cls: class_def = sch['classes'][a_cls] class_def = {a_cls: class_def} class_strs.append(YAMLDumper().dumps(class_def)) pydantic_strs.append(render_class(path, a_cls)) npd_strs.append(render_class(path, a_cls, representation='numpydantic')) class_str = "\n".join(class_strs) pydantic_str = "\n".join(pydantic_strs) npd_str = "\n".join(npd_strs) md = COMPARISON.format(linkml=class_str, pydantic_lol=pydantic_str, pydantic_npd=npd_str) if string: return md else: display(Markdown(md)) ``` -------------------------------- ### Install LinkML in a virtual environment Source: https://linkml.io/linkml/_sources/intro/tutorial01.md.txt Set up a virtual environment and install LinkML using pip. This is the recommended approach for development. ```bash mkdir linkml-tutorial cd linkml-tutorial python3 -m venv venv source venv/bin/activate pip install linkml ``` -------------------------------- ### Install LinkML-Store from source Source: https://linkml.io/linkml-store/_sources/about.rst.txt For developers working on the LinkML-Store codebase, clone the repository and use the make command to install all packages. ```bash git clone cd linkml-store make install ``` -------------------------------- ### Install linkml-store with all extras using Poetry Source: https://linkml.io/linkml-store/tutorials/Command-Line-Tutorial.html Installs all extras for the linkml-store package when using Poetry. ```bash poetry install --all-extras ``` -------------------------------- ### Install linkml-store with all dependencies Source: https://linkml.io/linkml-store/faq.html This command installs the linkml-store package along with all necessary and optional dependencies. It is recommended for most users. ```bash pip install "linkml-store[all]" ``` -------------------------------- ### Install minimal LinkML-Store Source: https://linkml.io/linkml-store/_sources/about.rst.txt Install the core LinkML-Store package without any optional dependencies. ```bash pip install "linkml-store" ``` -------------------------------- ### LinkML CLI Command Example Source: https://linkml.io/linkml/_sources/intro/install.md.txt Example of running a LinkML command within the Docker container to display help for the 'gen-project' command. ```bash gen-project --help ``` -------------------------------- ### Create Extraction Examples File Source: https://linkml.io/linkml-store/how-to/Perform-RAG-Inference.html Creates a YAML file containing a sample extraction example, defining text, subject, predicate, and object. ```bash echo '{text: I saw the cat sitting on the mat, subject: cat, predicate: sits-on, object: mat}' > tmp/extraction-examples.yaml ``` -------------------------------- ### Install linkml-store with MongoDB support Source: https://linkml.io/linkml-store/reference/linkml_store.api.stores.mongodb.html Install the linkml-store package with the 'mongodb' extra for MongoDB functionality, or 'all' for all available extras. ```bash pip install linkml-store[mongodb] ``` ```bash pip install linkml-store[all] ``` -------------------------------- ### Start linkml-store Web UI Source: https://linkml.io/linkml-store/faq.html To start the rudimentary web UI, create a configuration file (e.g., db/conf.yaml), set the LINKML_STORE_CONFIG environment variable, and then run the 'make app' command. ```bash export LINKML_STORE_CONFIG=./db/conf.yaml make app ``` -------------------------------- ### GitHub Actions CI/CD Validation Setup Source: https://linkml.io/linkml-term-validator/configuration Example GitHub Actions workflow to validate schemas, including setting up Python, installing dependencies, caching ontology databases, and running the validator in strict mode. ```yaml # .github/workflows/validate.yml name: Validate Schemas on: [push, pull_request] jobs: validate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.10' - name: Install dependencies run: | pip install linkml-term-validator - name: Cache ontology databases uses: actions/cache@v3 with: path: cache key: ontology-cache-${{ hashFiles('oak_config.yaml') }} - name: Validate schemas run: | linkml-term-validator validate-schema \ --strict \ --config oak_config.yaml \ --cache-dir cache \ src/schema/ ``` -------------------------------- ### Client Initialization with Configuration Source: https://linkml.io/linkml-store/_modules/linkml_store/api/client.html Shows how to create a client instance using a configuration object, file, or dictionary, with options for auto-attaching databases. ```APIDOC ## Client.from_config Method ### Description Creates a client instance from a provided configuration, which can be a `ClientConfig` object, a dictionary, a file path, or a `Path` object. Supports automatically attaching databases defined in the configuration. ### Usage with ClientConfig Object ```python from linkml_store.api.config import ClientConfig config = ClientConfig(databases={"test": {"handle": "duckdb:///:memory:"}}) client = Client().from_config(config) ``` ### Usage with Dictionary ```python config_dict = {"databases": {"test": {"handle": "duckdb:///:memory:"}}} client = Client().from_config(config_dict) ``` ### Usage with File Path ```python # Assuming a config.yaml file exists with database configurations client = Client().from_config("path/to/config.yaml") ``` ### Auto-attaching Databases ```python client = Client().from_config(config, auto_attach=True) ``` ### Parameters - `config` (Union[ClientConfig, dict, str, Path]): The configuration for the client. - `base_dir` (Optional[str]): The base directory for the client. - `auto_attach` (bool): If True, automatically attach databases defined in the config. - `**kwargs`: Additional keyword arguments. ``` -------------------------------- ### Neo4j Cypher RETURN DISTINCT Example Source: https://linkml.io/linkml-store/_sources/how-to/Use-Neo4j.ipynb.txt Example of using RETURN DISTINCT to get unique values from a query. Useful for avoiding duplicate results. ```cypher MATCH (p:Person) RETURN DISTINCT p.age ``` -------------------------------- ### Start linkml-store Web API Source: https://linkml.io/linkml-store/faq.html To start the web API, first create a configuration file (e.g., db/conf.yaml), then set the LINKML_STORE_CONFIG environment variable, and finally run the 'make api' command. ```bash export LINKML_STORE_CONFIG=./db/conf.yaml make api ``` -------------------------------- ### Set Up LinkML Project Source: https://linkml.io/linkml/howtos/linkml-project-copier.html Run this command after creating a new project to set up its environment and dependencies. ```bash just setup ``` -------------------------------- ### DocGen Post-Initialization Logic Source: https://linkml.io/linkml/_modules/linkml/generators/docgen.html This method handles the post-initialization setup for the DocGen generator, including dialect conversion, diagram type parsing, example runner initialization, and schema view setup. ```python def __post_init__(self): dialect = self.dialect if dialect is not None: # TODO: simplify this if isinstance(dialect, str): if dialect == MarkdownDialect.myst.value: dialect = MarkdownDialect.myst elif dialect == MarkdownDialect.python.value: dialect = MarkdownDialect.python else: raise NotImplementedError(f"{dialect} not supported") self.dialect = dialect if isinstance(self.diagram_type, str): self.diagram_type = DiagramType[self.diagram_type] if self.example_directory: self.example_runner = ExampleRunner(input_directory=Path(self.example_directory)) super().__post_init__() self.logger = logging.getLogger(__name__) self.schemaview = SchemaView(self.schema, merge_imports=self.mergeimports) # Override schemaview's get_mappings to use preserved URIs when needed if self.preserve_names: original_get_mappings = self.schemaview.get_mappings def get_mappings_with_preserved_uris(element_name, **kwargs): mappings = original_get_mappings(element_name, **kwargs) if mappings and element_name: try: element = self.schemaview.get_element(element_name) if element: preserved_uri = self.uri(element, expand=True) # Fix self and native mappings to use preserved URI for key in ("self", "native"): if key in mappings: mappings[key] = [preserved_uri] except Exception: pass return mappings self.schemaview.get_mappings = get_mappings_with_preserved_uris ``` -------------------------------- ### Initialize Client and Attach Database Source: https://linkml.io/linkml-store/reference/linkml_store.api.html Demonstrates initializing the LinkML Store client and attaching to a DuckDB database with an alias. Shows how to create a collection and verify its existence. ```python from linkml_store.api.client import Client client = Client() db = client.attach_database("duckdb", alias="test") collection = db.create_collection("Person") db.get_collection("Person") == collection ``` -------------------------------- ### SQLValidationGenerator Example Usage Source: https://linkml.io/linkml/_modules/linkml/generators/sqlvalidationgen.html Instantiate the generator and call generate_validation_queries to get SQL validation queries. The output can be printed directly. ```python gen = SQLValidationGenerator("schema.yaml", dialect="postgresql") queries = gen.generate_validation_queries() print(queries) ``` -------------------------------- ### Execute Tutorial Command Line Usage Source: https://linkml.io/linkml/_modules/linkml/utils/execute_tutorial.html Example of how to use the execute_tutorial module from the command line to process a tutorial markdown file. ```bash python -m linkml.utils.execute_tutorial -d /tmp/tutorial/ docs/intro/tutorial01.md ``` -------------------------------- ### Create Patient CSV File Source: https://linkml.io/linkml-store/_sources/how-to/Check-Referential-Integrity.ipynb.txt Write patient data to a CSV file named 'patients.csv'. This is a setup step for command-line examples. ```python PATIENTS = """id,name,age ``` ```python p1,John Doe,34 ``` ```python p2,Jane Doe,65 ``` ```python """ ``` ```python with open("output/patients.csv", "w") as stream: ``` ```python stream.write(PATIENTS) ``` -------------------------------- ### Set Up LinkML Project Environment Source: https://linkml.io/linkml/_sources/howtos/linkml-project-copier.md.txt Run this command after creating your project to install dependencies and configure the development environment. ```bash just setup ``` -------------------------------- ### Database Initialization and Usage Source: https://linkml.io/linkml-store/_modules/linkml_store/api/database.html Demonstrates how to attach a database, create collections, insert data, and query collections. ```APIDOC ## Database Initialization and Usage ### Description This section illustrates the basic usage of the Database class, including attaching to a database, creating collections, inserting data, and performing queries. ### Example Usage ```python from linkml_store.api.client import Client # Attach a database (using duckdb in-memory for example) client = Client() db = client.attach_database("duckdb:///:memory:", alias="test") # Check the handle and alias print(f"Database Handle: {db.handle}") assert db == client.get_database("test") # Create a collection collection = db.create_collection("Person") print(f"Number of collections: {len(db.list_collections())}") assert db.get_collection("Person") == collection # Insert data into the collection objs = [{"id": "P1", "name": "John", "age_in_years": 30}, {"id": "P2", "name": "Alice", "age_in_years": 25}] collection.insert(objs) # Find all objects in the collection qr_all = collection.find() print(f"Found {len(qr_all.rows)} objects.") print(f"First object ID: {qr_all.rows[0]['id']}") print(f"Second object name: {qr_all.rows[1]['name']}") # Find objects with a specific filter qr_filtered = collection.find({"name": "John"}) print(f"Found {len(qr_filtered.rows)} objects matching name 'John'.") print(f"Filtered object name: {qr_filtered.rows[0]['name']}") ``` ``` -------------------------------- ### Setup and Rendering Utilities for Array Examples Source: https://linkml.io/linkml/schemas/arrays.html This Python code provides utility functions for rendering LinkML schemas and comparing different array representations (LinkML, Pydantic LoL, numpydantic). It includes setup for Rich console theming and IPython display. ```python from linkml.generators import PydanticGenerator from linkml_runtime.loaders.yaml_loader import YAMLLoader from linkml_runtime.dumpers.yaml_dumper import YAMLDumper from IPython.display import display, Markdown from pathlib import Path import numpy as np from rich.console import Console from rich.theme import Theme from rich.style import Style from rich.color import Color theme = Theme({ "repr.call": Style(color=Color.from_rgb(110,191,38), bold=True), "repr.attrib_name": Style(color="slate_blue1"), "repr.number": Style(color="deep_sky_blue1"), }) console = Console(theme=theme) schemas = Path('.').resolve().parent / '_includes' / 'arrays' COMPARISON = """ :::::{{tab-set}} ::::{{tab-item}} LinkML :::{{ code-block}} yaml {linkml} ::: :::: ::::{{tab-item}} pydantic - LoL :::{{ code-block}} python {pydantic_lol} ::: :::: ::::{{tab-item}} numpydantic :::{{ code-block}} python {pydantic_npd} ::: :::: ::::: """ def render_module(path, representation='list'): generator = PydanticGenerator(str(path), array_representations=[representation]) module = generator.render() return module def compile_module(path, representation='list'): generator = PydanticGenerator(str(path), array_representations=[representation]) module = generator.compile_module() return module def render_class(path, cls, representation='list') -> str: module = render_module(path, representation) cls = module.classes[cls] code = cls.render(black=True) return code def render_comparison(path, cls, string=False) -> str: if not isinstance(cls, list): cls = [cls] path = str(path) sch = YAMLLoader().load_as_dict(path) class_strs = [] pydantic_strs = [] npd_strs = [] for a_cls in cls: class_def = sch['classes'][a_cls] class_def = {a_cls: class_def} class_strs.append(YAMLDumper().dumps(class_def)) pydantic_strs.append(render_class(path, a_cls)) npd_strs.append(render_class(path, a_cls, representation='numpydantic')) class_str = "\n".join(class_strs) pydantic_str = "\n".join(pydantic_strs) npd_str = "\n".join(npd_strs) md = COMPARISON.format(linkml=class_str, pydantic_lol=pydantic_str, pydantic_npd=npd_str) if string: return md else: display(Markdown(md)) ``` -------------------------------- ### LinkML Schema Definition Source: https://linkml.io/linkml-store/_sources/how-to/Perform-LLM-Inference.ipynb.txt Define a LinkML schema with enums, permissible values, descriptions, and examples. This schema can be used to guide LLM inference. ```yaml name: uniprot-comments id: http://example.org/uniprot-comments imports: - linkml: types prefixes: linkml: prefix_prefix: linkml prefix_reference: https://w3id.org/linkml/ up: prefix_prefix: up prefix_reference: http://example.org/tuniprot-comments default_prefix: up default_range: string enums: CommentCategory: name: CommentCategory permissible_values: FUNCTION_DISPUTED: text: FUNCTION_DISPUTED description: A caution indicating that a previously reported function has been challenged or disproven in subsequent studies; may warrant GO NOT annotation examples: - value: FUNCTION_DISPUTED description: Originally described for its in vitro hydrolytic activity towards dGMP, dAMP and dIMP. However, this was not confirmed in vivo FUNCTION_PREDICTION_ONLY: text: FUNCTION_PREDICTION_ONLY description: A caution indicating function is based only on computational prediction or sequence similarity examples: - value: FUNCTION_PREDICTION_ONLY description: Predicted to be involved in X based on sequence similarity FUNCTION_LACKS_EVIDENCE: text: FUNCTION_LACKS_EVIDENCE description: A caution indicating insufficient experimental evidence to support predicted function examples: - value: FUNCTION_LACKS_EVIDENCE description: In contrast to other Macro-domain containing proteins, lacks ``` -------------------------------- ### Run LinkML Docker Image Source: https://linkml.io/linkml/intro/install.html Start a shell session from the official LinkML Docker/OCI image. This allows using LinkML without local installation. ```shell docker run -v ./:/work -w /work/ --rm -ti docker.io/linkml/linkml ``` -------------------------------- ### Set configuration and start linkml-store web UI Source: https://linkml.io/linkml-store/_sources/faq.rst.txt To launch the linkml-store web UI, set the LINKML_STORE_CONFIG environment variable to your configuration file's location and then run 'make app'. ```bash export LINKML_STORE_CONFIG=./db/conf.yaml make app ``` -------------------------------- ### Induce Schema View Example Source: https://linkml.io/linkml-store/_modules/linkml_store/api/database.html Demonstrates how to get a schema view for a collection and inspect class attributes. If no explicit schema is provided, one will be generalized. ```python >>> from linkml_store.api.client import Client >>> client = Client() >>> db = client.attach_database("duckdb", alias="test", recreate_if_exists=True) >>> collection = db.create_collection("Person", alias="persons") >>> collection.insert([{"id": "P1", "name": "John", "age_in_years": 25}]) >>> schema_view = db.schema_view >>> cd = schema_view.get_class("Person") >>> cd.attributes["id"].range 'string' >>> cd.attributes["age_in_years"].range 'integer' We can reuse the same class: >>> collection2 = db.create_collection("Person", alias="other_persons") >>> collection2.class_definition().attributes["age_in_years"].range 'integer' ``` -------------------------------- ### Install linkml-store from source using Poetry Source: https://linkml.io/linkml-store/faq.html For developers, clone the repository, navigate to the directory, and use Poetry to install the project. This is the standard procedure for linkml projects. ```bash git clone cd linkml-store make install ``` -------------------------------- ### Run linkml-store CLI Help Source: https://linkml.io/linkml-store/faq.html Use this command to see all available options for the linkml-store command-line interface. Note that some options may change before version 1.0.0. ```bash linkml-store --help ``` -------------------------------- ### Python: Fetching Data with Monarch-API Source: https://linkml.io/linkml-store/_sources/how-to/Query-the-Monarch-KG.ipynb.txt Demonstrates how to use the Monarch-API Python client to fetch data. Requires installation of the `monarch-api` package. This example retrieves classes and their labels. ```python from monarch_api import MonarchService service = MonarchService() # Fetch classes and their labels response = service.get_classes(limit=10) for cls in response.classes: print(f"ID: {cls.id}, Label: {cls.label}") ``` -------------------------------- ### Create a LinkML-Store Client Source: https://linkml.io/linkml-store/how-to/Index-Phenopackets.html Initialize a LinkML-Store client. This is the entry point for interacting with the store. ```python from linkml_store import Client client = Client() ``` -------------------------------- ### Neo4j Cypher APOC Library Function Source: https://linkml.io/linkml-store/_sources/how-to/Use-Neo4j.ipynb.txt Example using a function from the APOC (Awesome Procedures On Cypher) library for text manipulation. Ensure APOC is installed and configured. ```cypher MATCH (n:Person) RETURN n.name, apoc.text.capitalize(n.title) AS capitalized_title ``` -------------------------------- ### Create Sample CSV File Source: https://linkml.io/linkml-store/_sources/how-to/Check-Referential-Integrity.ipynb.txt Write sample data to a CSV file named 'samples.csv', including a foreign key to the patient data. This is a setup step for command-line examples. ```python SAMPLES = """id,patient ``` ```python s1,p1 ``` ```python s2,p2 ``` ```python s3,p2 ``` ```python """ ``` ```python with open("output/samples.csv", "w") as stream: ``` ```python stream.write(SAMPLES) ``` -------------------------------- ### Create Collection and Inspect Schema Source: https://linkml.io/linkml-store/reference/linkml_store.api.html Shows how to create a client, attach a database, create a collection with specific data, and then inspect the induced schema view for class attributes. Useful for understanding data structure after insertion. ```python from linkml_store.api.client import Client client = Client() db = client.attach_database("duckdb", alias="test", recreate_if_exists=True) collection = db.create_collection("Person", alias="persons") collection.insert([{"id": "P1", "name": "John", "age_in_years": 25}]) schema_view = db.schema_view cd = schema_view.get_class("Person") cd.attributes["id"].range cd.attributes["age_in_years"].range ``` -------------------------------- ### Create Client from Configuration File Source: https://linkml.io/linkml-store/_modules/linkml_store/api/client.html Initialize a client by loading configuration from a YAML file. The `base_dir` can be specified to resolve relative paths within the configuration. `auto_attach` controls whether databases are automatically initialized. ```python client = Client().from_config("path/to/config.yaml", base_dir=Path("data/"), auto_attach=True) ``` -------------------------------- ### Get Local Imports Function Source: https://linkml.io/linkml/_modules/linkml/generators/projectgen.html Recursively retrieves all schema imports starting from a given schema path. It parses the schema to find import statements and resolves their paths relative to the schema's directory. ```python import logging from collections import defaultdict from dataclasses import dataclass, field from functools import lru_cache from pathlib import Path from typing import Any import click import yaml from linkml._version import __version__ from linkml.cli.logging import log_level_option from linkml.generators.excelgen import ExcelGenerator from linkml.generators.graphqlgen import GraphqlGenerator from linkml.generators.jsonldcontextgen import ContextGenerator from linkml.generators.jsonldgen import JSONLDGenerator from linkml.generators.jsonschemagen import JsonSchemaGenerator from linkml.generators.owlgen import OwlSchemaGenerator from linkml.generators.prefixmapgen import PrefixGenerator from linkml.generators.protogen import ProtoGenerator from linkml.generators.pythongen import PythonGenerator from linkml.generators.shaclgen import ShaclGenerator from linkml.generators.shexgen import ShExGenerator from linkml.generators.sqltablegen import SQLTableGenerator from linkml.utils.generator import Generator logger = logging.getLogger(__name__) PATH_FSTRING = str GENERATOR_NAME = str ARG_DICT = dict[str, Any] CONFIG_TUPLE = tuple[type[Generator], PATH_FSTRING, ARG_DICT] GEN_MAP: dict[GENERATOR_NAME, CONFIG_TUPLE] GEN_MAP = { "graphql": (GraphqlGenerator, "graphql/{name}.graphql", {}), "jsonldcontext": (ContextGenerator, "jsonld/{name}.context.jsonld", {}), "jsonld": ( JSONLDGenerator, "jsonld/{name}.jsonld", {"context": "{parent}/{name}.context.jsonld"}, ), "jsonschema": (JsonSchemaGenerator, "jsonschema/{name}.schema.json", {}), "owl": (OwlSchemaGenerator, "owl/{name}.owl.ttl", {}), "prefixmap": (PrefixGenerator, "prefixmap/{name}.yaml", {}), "proto": (ProtoGenerator, "protobuf/{name}.proto", {}), "python": (PythonGenerator, "{name}.py", {}), # 'rdf': (RDFGenerator, 'rdf/{name}.ttl', {}), # 'rdf': (RDFGenerator, 'rdf/{name}.ttl', {'context': '{parent}/../jsonld/{name}.context.jsonld'}), "shex": (ShExGenerator, "shex/{name}.shex", {}), "shacl": (ShaclGenerator, "shacl/{name}.shacl.ttl", {}), "sqltable": (SQLTableGenerator, "sqlschema/{name}.sql", {}), # # linkml/generators/javagen.py uses different architecture from most of the other generators # # also linkml/generators/excelgen.py, which has a different mechanism for determining the output path # 'java': (JavaGenerator, 'java/{name}.java', {'directory': '{parent}'}), "excel": (ExcelGenerator, "excel/{name}.xlsx", {"output": "{parent}/{name}.xlsx"}), } @lru_cache def get_local_imports(schema_path: Path, dir: Path): logger.info(f"GETTING IMPORTS = {schema_path}") all_imports = [schema_path] with open(schema_path, encoding="utf-8") as stream: schema = yaml.safe_load(stream) for imp in schema.get("imports", []): imp_path = dir / f"{imp}.yaml" logger.info(f" IMP={imp} // path={imp_path}") if imp_path.is_file(): all_imports += get_local_imports(imp_path, dir) return all_imports ``` -------------------------------- ### Install LLM Claude 3 Model Source: https://linkml.io/linkml-store/_sources/tutorials/Command-Line-Tutorial.ipynb.txt Installs the llm-claude-3 model using the 'llm install' command. Ensure you have the 'llm' tool installed. ```bash llm install llm-claude-3 ``` -------------------------------- ### Show linkml-store query help Source: https://linkml.io/linkml-store/_sources/tutorials/Command-Line-Tutorial.ipynb.txt Displays the available options and usage for the `linkml-store query` command. ```bash linkml-store query --help ``` -------------------------------- ### Initialize FileSystemCollection Source: https://linkml.io/linkml-store/_modules/linkml_store/api/stores/filesystem/filesystem_collection.html Initializes a FileSystemCollection, setting up the path and file format. If not provided, it defaults to 'json'. ```python def __init__(self, **kwargs): super().__init__(**kwargs) parent: DatabaseType = self.parent if not self.path: if self.parent: self.path = Path(parent.directory_path) self._objects_list = [] self._object_map = {} if not self.file_format: self.file_format = "json" ``` -------------------------------- ### Verify Python Installation Source: https://linkml.io/linkml/_sources/intro/install.md.txt Check if Python is installed and view its version information. This is a prerequisite for local LinkML installation. ```bash python ``` -------------------------------- ### LLM Installation Output Source: https://linkml.io/linkml-store/tutorials/Command-Line-Tutorial.html This output confirms the successful installation of the `llm-claude-3` package and its dependencies. It shows that the requirements are already satisfied, indicating the package is installed. ```text Requirement already satisfied: llm-claude-3 in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (0.4) Requirement already satisfied: llm in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from llm-claude-3) (0.15) Requirement already satisfied: anthropic>=0.17.0 in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from llm-claude-3) (0.32.0) Requirement already satisfied: anyio<5,>=3.5.0 in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from anthropic>=0.17.0->llm-claude-3) (4.4.0) Requirement already satisfied: distro<2,>=1.7.0 in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from anthropic>=0.17.0->llm-claude-3) (1.9.0) Requirement already satisfied: httpx<1,>=0.23.0 in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from anthropic>=0.17.0->llm-claude-3) (0.27.0) Requirement already satisfied: jiter<1,>=0.4.0 in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from anthropic>=0.17.0->llm-claude-3) (0.5.0) Requirement already satisfied: pydantic<3,>=1.9.0 in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from anthropic>=0.17.0->llm-claude-3) (2.8.2) Requirement already satisfied: sniffio in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from anthropic>=0.17.0->llm-claude-3) (1.3.1) Requirement already satisfied: tokenizers>=0.13.0 in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from anthropic>=0.17.0->llm-claude-3) (0.19.1) Requirement already satisfied: typing-extensions<5,>=4.7 in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from anthropic>=0.17.0->llm-claude-3) (4.12.2) Requirement already satisfied: click in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from llm->llm-claude-3) (8.1.7) Requirement already satisfied: openai>=1.0 in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from llm->llm-claude-3) (1.40.1) Requirement already satisfied: click-default-group>=1.2.3 in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from llm->llm-claude-3) (1.2.4) Requirement already satisfied: sqlite-utils>=3.37 in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from llm->llm-claude-3) (3.37) Requirement already satisfied: sqlite-migrate>=0.1a2 in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from llm->llm-claude-3) (0.1b0) Requirement already satisfied: PyYAML in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from llm->llm-claude-3) (6.0.2) Requirement already satisfied: pluggy in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from llm->llm-claude-3) (1.5.0) Requirement already satisfied: python-ulid in /Users/cjm/Library/Caches/pypoetry/virtualenvs/linkml-store-8ZYO4kTy-py3.10/lib/python3.10/site-packages (from llm->llm-claude-3) (2.7.0) ``` -------------------------------- ### Client Initialization and Usage Source: https://linkml.io/linkml-store/_modules/linkml_store/api/client.html Demonstrates how to initialize a LinkML Store Client, attach databases, create collections, and perform basic data operations. ```APIDOC ## Client Class ### Description A client is the top-level object for interacting with databases. It provides access to one or more `Database` objects, each of which consists of a number of `Collection` objects. ### Initialization ```python client = Client() ``` ### Attaching a Database ```python db = client.attach_database("duckdb", alias="test") ``` ### Creating a Collection and Inserting Data ```python collection = db.create_collection("Person") objs = [{"id": "P1", "name": "John", "age_in_years": 30}, {"id": "P2", "name": "Alice", "age_in_years": 25}] collection.insert(objs) ``` ### Querying Data ```python qr = collection.find() # qr.rows will contain the inserted objects qr = collection.find({"name": "John"}) # qr.rows will contain objects where name is 'John' ``` ### Client Handle ```python print(db.handle) # Example: 'duckdb:///:memory:' ``` ### Base Directory ```python print(client.base_dir) ``` ``` -------------------------------- ### Converting LinkML Examples to JSON Schema Format Source: https://linkml.io/linkml/_modules/linkml/generators/jsonschemagen.html Converts LinkML Example objects into a format suitable for the JSON Schema 'examples' keyword, handling type coercion and array-valued slots. ```python def _slot_examples_for_json_schema( examples: dict | Example | list[dict | Example] | None, *, json_schema_type: list[str] | str | None = None, is_array_valued: bool, ) -> list: """Convert a list of LinkML :class:`~linkml_runtime.linkml_model.meta.Example` objects into a list suitable for the JSON Schema ``examples`` keyword. In the LinkML metamodel ``Example.value`` is typed as ``str``, so any non-string value written in YAML (integer, boolean, list, …) is coerced to its Python ``str()`` representation on load. ``Example.object`` holds a single structured dict/object. Since ``Example.value`` is coerced to ``str`` in the LinkML metamodel, the values are coerced back to their original basic scalar type if json_schema_type is provided ("integer", "number", and "boolean" are supported). If ``is_array_valued`` is ``True``, values are coerced back to list (using ``ast.literal_eval()``). After coercion, the cardinality of the ``Example`` objects are mapped to the JSON Schema ``examples`` property according to the following rules: **Single-valued slots or class-level examples** (``is_array_valued=False``): each ``Example`` contributes one independent entry. **Array-valued slots** (``is_array_valued=True``): because the enclosing JSON Schema property is ``type: array``, every entry in ``examples`` must itself be an array so that it validates against the property schema. Two authoring styles are supported: 1. If ``Example.value`` is a basic scalar (either originally a str, or coerced to str) or if ``Example.object`` is defined, it is considered an example of an array item and not of the full array. Hence, all such scalar examples are merged into an array that together comprise a full entry in the JSON Schema ``examples`` array. 2. If ``Example.value`` is a list (coerced to str), it is considered a full entry in the JSON Schema ``examples`` array and returned as is (after coercion back to list). If examples of multiple types are present simultaneously, the merged entry is returned first, e.g.:: ``` -------------------------------- ### Show linkml-store describe help Source: https://linkml.io/linkml-store/_sources/tutorials/Command-Line-Tutorial.ipynb.txt Displays the available options and usage for the `linkml-store describe` command, which provides an overview of the data set schema. ```bash linkml-store describe --help ``` -------------------------------- ### Set configuration and start linkml-store API Source: https://linkml.io/linkml-store/_sources/faq.rst.txt To run the linkml-store web API, first set the LINKML_STORE_CONFIG environment variable to your configuration file path, then execute the 'make api' command. ```bash export LINKML_STORE_CONFIG=./db/conf.yaml make api ``` -------------------------------- ### Install linkml-term-validator Source: https://linkml.io/linkml-term-validator Install the package using pip. This is the first step to using the term validator. ```bash pip install linkml-term-validator ``` -------------------------------- ### Load and Query Data in SolrCollection Source: https://linkml.io/linkml-store/reference/linkml_store.api.stores.solr.solr_collection.html Shows the initial steps to set up a collection by creating a client, attaching a database, creating a collection, and inserting objects, before running a query. The actual query execution part is marked as TODO. ```python >>> from linkml_store import Client >>> from linkml_store.utils.format_utils import load_objects >>> client = Client() >>> db = client.attach_database("duckdb") >>> collection = db.create_collection("Country") >>> objs = load_objects("tests/input/countries/countries.jsonl") >>> collection.insert(objs) ``` -------------------------------- ### Install linkml-store with LLM extra Source: https://linkml.io/linkml-store/tutorials/Command-Line-Tutorial.html Installs the linkml-store package with the necessary extras for LLM functionality. ```bash pip install linkml-store[llm] ``` -------------------------------- ### Example Project Listing Output Source: https://linkml.io/linkml/_sources/intro/tutorial08.md.txt This is an example of the file listing you might see after generating a project. It shows the various artifacts created by the `gen-project` script in the specified output directory. ```text Makefile personinfo personinfo.json personinfo.py personinfo.shex setup.py ``` -------------------------------- ### Example Semi-structured Text Input Source: https://linkml.io/linkml/howtos/generate-ai-prompts.html This is an example of semi-structured text that can be processed to generate structured data. ```text PERSONRECORD: 1234 Izumi is a professor at the University of Tokyo, where she has been employed since 2017. She is 56 years old. She has a brother called Toshiro. ``` -------------------------------- ### Client Initialization and Database Attachment Source: https://linkml.io/linkml-store/reference/linkml_store.api.html Demonstrates how to initialize the LinkML Store client and attach to a database. ```APIDOC ## Client Initialization and Database Attachment ### Description Initialize the `Client` and attach to a database using a specified driver and alias. ### Method ```python client = Client() db = client.attach_database("duckdb", alias="test") ``` ### Parameters - **driver** (str) - The database driver to use (e.g., "duckdb"). - **alias** (str) - An alias for the attached database. ```