diff --git a/generators/__init__.py b/generators/__init__.py index d25aae0e..b890e750 100644 --- a/generators/__init__.py +++ b/generators/__init__.py @@ -1,3 +1,4 @@ + from fastapi import APIRouter from .distance import ( @@ -11,6 +12,10 @@ spacy_lemmatizer, ) +from .numbers import ( + annotator_split +) + from .paths import ( url_keyword_parser, domain_parser, @@ -96,6 +101,7 @@ bert_toxicity_detector, gpt_grammar_correction, gpt_tldr_summarization, + annotator_split, ]: module_name = module.__name__.split(".")[-1] model_name = ( diff --git a/generators/numbers/annotator_split/README.md b/generators/numbers/annotator_split/README.md new file mode 100644 index 00000000..d2945064 --- /dev/null +++ b/generators/numbers/annotator_split/README.md @@ -0,0 +1 @@ +The module gives out a random number within a given frame. With that, you can split annotations randomly. Every split between 0 and the maximal lenght of the frame is possible. \ No newline at end of file diff --git a/generators/numbers/annotator_split/__init__.py b/generators/numbers/annotator_split/__init__.py new file mode 100644 index 00000000..f8963c9f --- /dev/null +++ b/generators/numbers/annotator_split/__init__.py @@ -0,0 +1,18 @@ +from pydantic import BaseModel +import random + +INPUT_EXAMPLE = { + "number": 4 +} + + +class AnnotationSplitModel(BaseModel): + number: int + + class Config: + schema_example = {"example": INPUT_EXAMPLE} + +def annotator_split(request: AnnotationSplitModel): + """Generates a random number for split annotations""" + number = request.number + return random.randint(0, number-1) diff --git a/generators/numbers/annotator_split/code_snippet_common.md b/generators/numbers/annotator_split/code_snippet_common.md new file mode 100644 index 00000000..ddbeac42 --- /dev/null +++ b/generators/numbers/annotator_split/code_snippet_common.md @@ -0,0 +1,17 @@ +```python +import random + +def annotator_split(record) -> int: + return random.randint(0, record-1) + +# ↑ necessary bricks function +# ----------------------------------------------------------------------------------------- +# ↓ example implementation + +def example_integration(): + max_number = [2, 4, 6, 8, 10] + for number in max_number: + print(f"the random number in the maximal number-range of {number} is {annotator_split(number)}") + +example_integration() +``` \ No newline at end of file diff --git a/generators/numbers/annotator_split/code_snippet_refinery.md b/generators/numbers/annotator_split/code_snippet_refinery.md new file mode 100644 index 00000000..a6187dc3 --- /dev/null +++ b/generators/numbers/annotator_split/code_snippet_refinery.md @@ -0,0 +1,14 @@ + +```python +import random + +ATTRIBUTE: int + +def annotator_split(record): + try: + return random.randint(0, record[ATTRIBUTE]-1) + except: + print("Something went wrong. Please make sure, your desired maximal number is an Integer and bigger than 0.") + + +``` diff --git a/generators/numbers/annotator_split/config.py b/generators/numbers/annotator_split/config.py new file mode 100644 index 00000000..8e125fae --- /dev/null +++ b/generators/numbers/annotator_split/config.py @@ -0,0 +1,36 @@ +from util.configs import build_generator_function_config +from util.enums import State, RefineryDataType, BricksVariableType, SelectionType +from . import annotator_split, INPUT_EXAMPLE + + +def get_config(): + return build_generator_function_config( + function=annotator_split, + input_example=INPUT_EXAMPLE, + issue_id=240, + tabler_icon="Dice-3", + min_refinery_version="1.7.0", + state=State.PUBLIC.value, + type="python_function", + kern_token_proxy_usable="false", + docker_image="none", + available_for=["refinery", "common"], + part_of_group=[ + "numbers", + ], # first entry should be parent directory + # bricks integrator information + integrator_inputs={ + "name": "annotator_split", + "refineryDataType": RefineryDataType.INTEGER.value, + "variables": { + "N_SPLIT": { + "selectionType": SelectionType.CHOICE.value, + "description": "only text fields", + "addInfo": [ + BricksVariableType.ATTRIBUTE.value, + BricksVariableType.GENERIC_STRING.value, + ], + }, + }, + }, + )