diff --git a/examples/spacy/instruction_spacy.md.jinja b/examples/spacy/instruction_spacy.md.jinja new file mode 100644 index 0000000..73dff60 --- /dev/null +++ b/examples/spacy/instruction_spacy.md.jinja @@ -0,0 +1,22 @@ +{# Kanushka's code #} +# Spacy Installation Instruction +{% if os == 'Windows' %} +{% if platform == 'x86' %} +{% if package_manager == 'pip' %} +{% if hardware == 'CPU' %} +{% if configuration == 'virtual env' %} +{% if pipeline == 'efficiency' %} +`pip install -U spacy` +{% else %} +> [!IMPORTANT] +> Error! +{% endif %} +{% endif %} +{% endif %} +{% endif %} +{% else %} +{% if package_manager == 'conda' %} +{% if hardware == 'CPU' %} +{% if configuration == 'virtual env' %} +{% if pipeline == 'efficiency' %} +`conda install -c conda-forge spacy` diff --git a/examples/spacy/instruction_spacy.schema.yml b/examples/spacy/instruction_spacy.schema.yml new file mode 100644 index 0000000..08d8919 --- /dev/null +++ b/examples/spacy/instruction_spacy.schema.yml @@ -0,0 +1,53 @@ +$schema: https://json-schema.org/draft/2020-12/schema +$id: https://github.com/instructions-d-installation/installation-instruction/examples/spacy/schema_spacy.yml +title: Spacy Install Schema +description: This is a schema which is used for constructing interactive installation instructions. +type: object +$comment: by Kanushka Gupta +properties: + os: + enum: + - macOs/OSX + - Windows + - Linux + platform: + enum: + - x86 + - ARM/M1 + package_manager: + enum: + - pip + - conda + - from source + hardware: + enum: + - CPU + - GPU + enum: + - CUDA 8.0 + - CUDA 9.0 + - CUDA 9.1 + - CUDA 9.2 + - CUDA 10.0 + - CUDA 10.1 + - CUDA 10.2 + - CUDA 11.0 + - CUDA 11.1 + - CUDA 11.2 - 11.x + - CUDA 12.x + configuration: + enum: + - virtual env + - train models + pipeline: + enum: + - efficiency + - accuracy + +required: + - os + - platform + - package_manager + - hardware + - configuration + - pipeline diff --git a/examples/spacy/user_input.yml b/examples/spacy/user_input.yml new file mode 100644 index 0000000..da2bcc0 --- /dev/null +++ b/examples/spacy/user_input.yml @@ -0,0 +1,6 @@ +os: Windows +platform: x86 +package_manager: pip +hardware: CPU +configuration: virtual env +pipeline: efficiency \ No newline at end of file diff --git a/examples/spacy/user_input_2.yml b/examples/spacy/user_input_2.yml new file mode 100644 index 0000000..1d5a359 --- /dev/null +++ b/examples/spacy/user_input_2.yml @@ -0,0 +1,6 @@ +os: Windows +platform: x86 +package_manager: conda +hardware: GPU +configuration: virtual env +pipeline: efficiency \ No newline at end of file diff --git a/examples/spacy/validate_user_schema.py b/examples/spacy/validate_user_schema.py new file mode 100644 index 0000000..fa91b53 --- /dev/null +++ b/examples/spacy/validate_user_schema.py @@ -0,0 +1,40 @@ +try: + from yaml import CLoader as Loader, CDumper as Dumper, load +except ImportError: + from yaml import Loader, Dumper + +from jsonschema import validate + +from jinja2 import Template + + + +def load_yml(path: str) -> dict: + with open(path, 'r') as file: + input_str = file.read() + + return load(input_str, Loader=Loader) + +def load_template(path: str) -> Template: + with open(path, 'r') as file: + template_str = file.read() + + return Template(template_str) + + + + +schema = load_yml('instruction_spacy.schema.yml') +input = load_yml('user_input_2.yml') + + +print("Test valid input.") +validate(input, schema) +print("It worked!") + + + +template = load_template("instruction_spacy.md.jinja") + +instructions = template.render(input) +print(instructions)