Beispiel #1
0
async def processing(
    _input: str,
    pipeline: str,
    _output: str = "terminal",
    _format: str = "json",
    use_db: str = None,
    tool_base: str = "stanza",
    boost: str = "ray",
    memory: int = None,
    cpus: int = None,
    gpus: int = None,
):
    try:
        nlp = Pipeline(
            _input=_input,
            pipeline=pipeline,
            _output=_output,
            _format=_format,
            use_db=use_db,
            tool_base=tool_base,
            boost=boost,
            memory=memory,
            cpus=cpus,
            gpus=gpus,
        )

        results = nlp.annotate()

        return results
    except Exception as err:
        return err
Beispiel #2
0
def annotation_processing():
    if request.method == 'POST':
        jsondata = request.get_json()
        custom_pipeline = json.loads(jsondata)
        annotation = Pipeline(custom_pipeline['id_corpus'], custom_pipeline,
                              True)
    else:
        id_corpus = request.args.get('id_corpus')
        tools = request.args.get('tools')
        custom_pipeline = json.loads(tools)
        annotation = Pipeline(id_corpus, custom_pipeline, True)

    response = annotation.annotate()

    return jsonify(response)
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from deepnlpf.pipeline import Pipeline

path_pipeline = '/home/fasr/Mestrado/Workspace/deepnlpf2/tests/unit/pipeline/custom_pipeline.json'
path_dataset = '/home/fasr/Mestrado/Workspace/deepnlpf2/tests/data/dataset_1doc_1sent'

nlp = Pipeline(_input=path_dataset, pipeline=path_pipeline, _format='xml')
annotation = nlp.annotate()
print(annotation)
Beispiel #4
0
Below are some usage examples for the stanza, spacy, scispacy and stanza-bio:
    echo 'Barack Obama was born in Hawaii.' | python3 pipeline.py pipeline-stanza.json
    echo 'Apple is looking at buying U.K. startup for $1 billion' | python3 pipeline.py pipeline-spacy.json
    echo 'Myeloid derived suppressor cells (MDSC) are immature myeloid cells with immunosuppressive activity.' | python3 pipeline.py pipeline-scispacy.json
    echo 'A single-cell transcriptomic atlas characterizes ageing tissues in the mouse.' | python3 pipeline.py pipeline-stanza-bio.json
"""
import argparse
import os
import sys

from deepnlpf.pipeline import Pipeline

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        prog='A generic testing pipeline using inputs from stdin')
    parser.add_argument('PIPELINE_PATH',
                        type=str,
                        help='The path to a pipeline')

    args = parser.parse_args()
    lines = [l.rstrip() for l in sys.stdin]
    rawtext = os.linesep.join(lines)

    if not os.path.exists(args.PIPELINE_PATH):
        print(f'ERROR: File {args.PIPELINE_PATH} not found!', file=sys.stderr)
        exit(1)

    nlp = Pipeline(_input=rawtext, pipeline=args.PIPELINE_PATH, _output='file')
    nlp.annotate()
def main():
  nlp = Pipeline(raw_text=sentence, json_string=custom_pipeline_string)
  annotation = nlp.annotate()
  print(json.dumps(annotation))
Beispiel #6
0
pipeline_json_string = """
{
    "lang": "en",
    "tools": {
        "stanza": {
            "processors": [
                "tokenize",
                "mwt",
                "pos",
                "lemma",
                "ner",
                "depparse"
            ]
        }
    }
}
"""

pipeline_json_url = "https://raw.githubusercontent.com/deepnlpf/deepnlpf/master/examples/pipelines/json/stanza.json"
pipeline_yaml_url = "https://raw.githubusercontent.com/deepnlpf/deepnlpf/master/examples/pipelines/yaml/stanza.yaml"


nlp = Pipeline(
    _input=sentence,
    pipeline=pipeline_json_url,
    _output="file"
)

results = nlp.annotate()
Beispiel #7
0
def processing():
    tools_name = set()
    tools = []
    id_dataset = ""
    raw_text = ""

    # get json-form.
    response = request.get_json()

    # get tools_name in json-form.
    for index, item in enumerate(response):
        if index == 0:
            if item["name"] == "id_dataset":
                id_dataset = item["value"]
            elif item["name"] == "raw_text":
                raw_text = item["value"]

        if index > 0:
            tool, analyze = item["name"].split("-")
            tools_name.add(tool)

    # get analyse in json-form.
    for tool in tools_name:
        analyze = {"pipeline": []}

        for index, item in enumerate(response):
            # remove corpus.
            if index > 0:
                t, a = item["name"].split("-")
                if tool == t:
                    analyze["pipeline"].append(a)

    # config properties.
    item = {tool: analyze}
    tools.append(item)

    if id_dataset != "":
        conv = {"id_dateset": id_dataset, "tools": tools}
    elif raw_text != "":
        conv = {"raw_text": raw_text, "tools": tools}

    jsondata = json.dumps(conv)
    print(jsondata)

    # split
    raw_text = conv["raw_text"]
    pipeline = conv["tools"]
    output_format = ""

    # raw_text = jsondata['raw_text']
    # pipeline = jsondata['pipeline']

    # if jsondata['output_format'] != None:
    #    output_format = jsondata['output_format']
    try:
        print(pipeline)
        nlp = Pipeline(raw_text=raw_text,
                       json_string=pipeline,
                       output_format=output_format)
        return jsonify(nlp.annotate())
    except Exception as err:
        return err