Example #1
0
def init_kb(root, exist_ok=False, config=None) -> bool:
    success = False

    try:
        root = Config.get_root(root)

        os.makedirs(str(root), exist_ok=exist_ok)
        Config.create(root=root, config=config)

        KB(root=root)
        success = True

    except FileExistsError as e:
        logger.error(e)

    return success
Example #2
0
    def __init__(self, root=None):
        self.config = Config.create(root=root)

        self.user_store = self.config.create_user_store()

        self.normalizer = self.config.create_normalizer()

        self.tokenizer = self.config.create_tokenizer()

        self.graph = self.config.create_graph(normalizer=self.normalizer)

        self.pipelines = {}
        for name, pipeline_config in self.config.pipelines.items():
            pipeline = pipeline_config.create_pipeline(self)
            self.pipelines[name] = pipeline
Example #3
0
def sync_config(root: Optional[Path] = typer.Option(None)):
    """ Update configuration while keeping the current Secret Key. """

    root = Config.get_root(root)
    config = Config.create(root=root)
    old_json = config.json(indent=4)
    typer.echo(f"Getting current config: {config.file_path}")

    # retain the secret key
    default_config.secret_key = config.secret_key

    # write the new config
    with config.file_path.open(mode="w") as fp:
        new_json = default_config.json(indent=4)
        fp.write(new_json)
        fp.write("\n")

    typer.echo(f"Config updated: {config.file_path}")
    diff_gen = Differ().compare(old_json.splitlines(), new_json.splitlines())
    typer.echo("\n".join(diff_gen))
Example #4
0
from urllib.parse import unquote

from fastapi import APIRouter, Body, security, Depends

from entitykb import (
    ProxyKB,
    models,
    Config,
    Direction,
    exceptions,
    User,
    UserToken,
)

router = APIRouter()
config = Config.create()
kb = ProxyKB()

# nodes


@router.get("/nodes/{key}", tags=["nodes"])
def get_node(key: str) -> dict:
    """ Parse text and return document object. """
    key = unquote(key)
    return kb.get_node(key)


@router.post("/nodes", tags=["nodes"])
async def save_node(node: dict = Body(...)) -> dict:
    """ Saves nodes to graph and terms to index. """