Skip to content

Annotator split #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions generators/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

from fastapi import APIRouter

from .distance import (
Expand All @@ -11,6 +12,10 @@
spacy_lemmatizer,
)

from .numbers import (
annotator_split
)

from .paths import (
url_keyword_parser,
domain_parser,
Expand Down Expand Up @@ -96,6 +101,7 @@
bert_toxicity_detector,
gpt_grammar_correction,
gpt_tldr_summarization,
annotator_split,
]:
module_name = module.__name__.split(".")[-1]
model_name = (
Expand Down
1 change: 1 addition & 0 deletions generators/numbers/annotator_split/README.md
Original file line number Diff line number Diff line change
@@ -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.
18 changes: 18 additions & 0 deletions generators/numbers/annotator_split/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions generators/numbers/annotator_split/code_snippet_common.md
Original file line number Diff line number Diff line change
@@ -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()
```
14 changes: 14 additions & 0 deletions generators/numbers/annotator_split/code_snippet_refinery.md
Original file line number Diff line number Diff line change
@@ -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.")


```
36 changes: 36 additions & 0 deletions generators/numbers/annotator_split/config.py
Original file line number Diff line number Diff line change
@@ -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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This brick doesn't require input.

"addInfo": [
BricksVariableType.ATTRIBUTE.value,
BricksVariableType.GENERIC_STRING.value,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct?

],
},
},
},
)