Skip to content

Biotope Read

Draft stage

Biotope is in draft stage. Functionality may be missing or incomplete. The API is subject to change.

Read command implementation.

extract_knowledge(text)

Extract knowledge using NLP and other methods.

Parameters:

Name Type Description Default
text str

Input text to process

required

Returns:

Type Description
str

Extracted knowledge (currently just returns input)

Source code in biotope/biotope/commands/read.py
def extract_knowledge(text: str) -> str:
    """
    Extract knowledge using NLP and other methods.

    Args:
        text: Input text to process

    Returns:
        Extracted knowledge (currently just returns input)

    """
    return f"Extracted knowledge: {text}"

read(text, file)

Extract knowledge from input text or file using NLP.

Parameters:

Name Type Description Default
text str | None

Input text to process

required
file str | None

Input file to process

required

Raises:

Type Description
UsageError

If neither --text nor --file is provided.

Source code in biotope/biotope/commands/read.py
@click.command()
@click.option(
    "--text",
    "-t",
    type=str,
    help="Text to extract knowledge from",
    required=False,
)
@click.option(
    "--file",
    "-f",
    type=click.Path(exists=True, dir_okay=False, path_type=str),
    help="File to extract knowledge from",
    required=False,
)
def read(text: str | None, file: str | None) -> None:
    """
    Extract knowledge from input text or file using NLP.

    Args:
        text: Input text to process
        file: Input file to process

    Raises:
        click.UsageError: If neither --text nor --file is provided.

    """
    if text is None and file is None:
        msg = "Either --text or --file must be provided"
        raise click.UsageError(msg)

    if file is not None:
        with open(file) as f:
            text = f.read()

    if text is not None:  # This will now be true in both cases
        result = extract_knowledge(text)
        click.echo(result)