### Start Webserver Source: https://github.com/ijmarshall/robotreviewer/blob/master/README.md Launch the webserver for standard use or for the Swagger API. ```bash python -m robotreviewer ``` ```bash REST_API=true python -m robotreviewer --rest ``` -------------------------------- ### Local Configuration Example Source: https://github.com/ijmarshall/robotreviewer/blob/master/README.md Example configuration for running RobotReviewer locally via Docker. ```json { "robotreviewer": { "use_grobid": true, "grobid_threads": 4, "spacy_threads": 4, "dont_delete": 0, "log": "log.txt", "api_keys": { "a_secret_key": { "uid": 1 } } } } ``` -------------------------------- ### Install TensorFlow Source: https://github.com/ijmarshall/robotreviewer/blob/master/README.md Install either the CPU or GPU version of TensorFlow 1.12.0. ```bash conda activate robotreviewer pip install tensorflow==1.12.0 # OR pip install tensorflow-gpu==1.12.0 ``` -------------------------------- ### Clone and Setup Repository Source: https://github.com/ijmarshall/robotreviewer/blob/master/README.md Commands to clone the repository and prepare the SciBERT model directory. ```bash git clone https://github.com/ijmarshall/robotreviewer.git wget https://s3-us-west-2.amazonaws.com/ai2-s2-research/scibert/tensorflow_models/scibert_scivocab_uncased.tar.gz tar -zxf scibert_scivocab_uncased.tar.gz --directory robotreviewer/robotreviewer/data ``` -------------------------------- ### Start RabbitMQ Server Source: https://github.com/ijmarshall/robotreviewer/blob/master/README.md Manually invoke the RabbitMQ server if it is not configured to start automatically. ```bash rabbitmq-server ``` -------------------------------- ### Setup Conda Environment Source: https://github.com/ijmarshall/robotreviewer/blob/master/README.md Create the environment and download required NLP data packages. ```bash conda env create -f robotreviewer_env.yml conda activate robotreviewer python -m spacy download en python -m nltk.downloader punkt stopwords ``` -------------------------------- ### Start BERT Service Source: https://github.com/ijmarshall/robotreviewer/blob/master/README.md Initialize the BERT service with the required SciBERT weights. ```bash bert-serving-start -model_dir=/Path/to/SciBERT-weights/ ``` -------------------------------- ### Docker Build and Execution Commands Source: https://github.com/ijmarshall/robotreviewer/blob/master/README.md Commands to build, start, and stop the RobotReviewer Docker services. ```bash docker-compose build ``` ```bash docker-compose up -d ``` ```bash docker-compose down --remove-orphans ``` -------------------------------- ### Start Machine Learning Worker Source: https://github.com/ijmarshall/robotreviewer/blob/master/README.md Launch the ML worker using either GPU or CPU configurations. ```bash celery -A robotreviewer.ml_worker worker --loglevel=info --concurrency=1 --pool=solo ``` ```bash env CUDA_VISIBLE_DEVICES=-1 celery -A robotreviewer.ml_worker worker --loglevel=info --concurrency=1 --pool=solo ``` -------------------------------- ### Manage Docker Services Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Common commands for building, starting, monitoring, and stopping the Docker Compose stack. ```bash # Build and start services docker-compose build docker-compose up -d # Check logs docker-compose logs -f worker # Stop services docker-compose down --remove-orphans ``` -------------------------------- ### Manage GPU Docker Services Source: https://github.com/ijmarshall/robotreviewer/blob/master/README.md Commands to build, start, and stop RobotReviewer services with GPU support. ```bash docker-compose -f docker-compose.gpu.yml build docker-compose -f docker-compose.gpu.yml up -d ``` ```bash docker-compose -f docker-compose.gpu.yml down --remove-orphans ``` -------------------------------- ### Manage Development Docker Services Source: https://github.com/ijmarshall/robotreviewer/blob/master/README.md Commands to build, start, and stop services using the Flask development server. ```bash docker compose -f docker-compose.dev.yml build docker compose -f docker-compose.dev.yml up ``` ```bash docker compose -f docker-compose.dev.yml down --remove-orphans ``` -------------------------------- ### Annotate Examples with RCTRobot Source: https://github.com/ijmarshall/robotreviewer/blob/master/robotreviewer/testing out human tagger code.ipynb Calls the api_annotate method on an RCTRobot instance, likely to process a list of examples and return annotated results. Note the potential UserWarning regarding scikit-learn estimator version mismatches. ```python b.api_annotate(examples) ``` -------------------------------- ### Get Report in Various Formats Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Retrieve annotation reports in HTML, DOC, or JSON format for viewing or download. ```APIDOC ## Get Report in Various Formats ### Description Retrieve annotation reports in HTML, DOC, or JSON format for viewing or download. ### Method GET ### Endpoint - `/report_view/{report_uuid}/{format}` (for viewing) - `/download_report/{report_uuid}/{format}` (for downloading) ### Parameters #### Path Parameters - **report_uuid** (string) - Required - The unique identifier for the annotation report. - **format** (string) - Required - The desired format for the report (e.g., "html", "doc", "json"). ### Response Example (JSON) ```json { "article_ids": ["pdf_uuid_1", "pdf_uuid_2"], "article_data": [ { "title": "Trial Title", "abstract": "Trial abstract...", "authors": [{"lastname": "Smith", "forename": "John", "initials": "J"}], "rct": {"is_rct": true, "decision_score": 0.95}, "bias": [ {"domain": "Random sequence generation", "judgement": "low", "annotations": [...]}, {"domain": "Allocation concealment", "judgement": "high/unclear", "annotations": [...]} ], "pico_text": [ {"domain": "Population", "text": ["patients with hypertension"], "annotations": [...]}, {"domain": "Intervention", "text": ["Drug X 10mg daily"], "annotations": [...]}, {"domain": "Outcomes", "text": ["blood pressure reduction"], "annotations": [...]} ], "sample_size": "500" } ], "report_id": "Tvg0-pHV2QBsYpJxE2KW-" } ``` ``` -------------------------------- ### Iterate Over DataFrame Rows Source: https://github.com/ijmarshall/robotreviewer/blob/master/vocabs/vocab generation.ipynb Demonstrates iterating over the rows of a pandas DataFrame using the iterrows() method. This specific example appears to be incomplete or illustrative. ```python (graph_data.iterrows()) ``` -------------------------------- ### GET /report-status/{report_id} Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Check the processing status of a queued annotation report. Returns progress information including current processing step. ```APIDOC ## GET /report-status/{report_id} ### Description Check the processing status of a queued annotation report. Returns progress information including current processing step. ### Method GET ### Endpoint https://api.robotreviewer.net/report-status/{report_id} ### Parameters #### Path Parameters - **report_id** (string) - Required - The unique identifier of the report. #### Query Parameters - **api-key** (string) - Required - Your API key for authentication. ### Response #### Success Response (200) - **state** (string) - The current state of the report (e.g., "PROGRESS", "SUCCESS", "FAILED"). - **meta** (object) - Additional metadata about the report's status. - **status** (string or integer) - Processing status details. - **position** (string) - Current processing step (if in progress). #### Response Example (While Processing) ```json { "state": "PROGRESS", "meta": { "status": "in process", "position": "bias_bot classification" } } ``` #### Response Example (Completed) ```json { "state": "SUCCESS", "meta": { "status": 100, "task": "completed" } } ``` ``` -------------------------------- ### Initialize Database and NLP Source: https://github.com/ijmarshall/robotreviewer/blob/master/vocabs/vocab generation.ipynb Establishes a connection to the UMLS database and loads the spaCy English model. ```python cnx = mysql.connector.connect(user='root', database='umls') ``` ```python nlp = spacy.load("en_core_web_sm") ``` -------------------------------- ### Clone Repository Source: https://github.com/ijmarshall/robotreviewer/blob/master/README.md Download the source code and navigate to the project directory. ```bash git clone https://github.com/ijmarshall/robotreviewer.git cd robotreviewer ``` -------------------------------- ### Run Test Suite Source: https://github.com/ijmarshall/robotreviewer/blob/master/README.md Execute the unit tests to verify the integrity of the core code. ```bash python -m unittest ``` -------------------------------- ### GET /report/{report_id} Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Retrieve the completed annotation results for all processed articles. Returns structured data with predictions from all requested robots. ```APIDOC ## GET /report/{report_id} ### Description Retrieve the completed annotation results for all processed articles. Returns structured data with predictions from all requested robots. ### Method GET ### Endpoint https://api.robotreviewer.net/report/{report_id} ### Parameters #### Path Parameters - **report_id** (string) - Required - The unique identifier of the report. #### Query Parameters - **api-key** (string) - Required - Your API key for authentication. ### Response #### Success Response (200) - Returns an array of objects, where each object represents an annotated article with predictions from various robots. - **ti** (string) - The title of the article. - **ab** (string) - The abstract of the article. - **rct_bot** (object) - Results from the RCT detection robot. - **is_rct** (boolean) - Whether the article is an RCT. - **is_rct_precise** (boolean) - Precision of RCT detection. - **is_rct_balanced** (boolean) - Whether the RCT is balanced. - **is_rct_sensitive** (boolean) - Sensitivity of RCT detection. - **model** (string) - The model used for detection. - **score** (number) - The confidence score. - **pico_bot** (object) - Results from the PICO extraction robot. - **participants** (object) - Extracted participant information. - **annotations** (array) - List of participant annotations. - **text** (string) - The annotated text. - **start_index** (integer) - The starting index of the annotation. - **interventions** (object) - Extracted intervention information. - **outcomes** (object) - Extracted outcome information. - **bias_bot** (object) - Results from the Risk of Bias assessment robot. - **random_sequence_generation** (object) - Judgement and rationales for random sequence generation. - **allocation_concealment** (object) - Judgement and rationales for allocation concealment. - **blinding_participants_personnel** (object) - Judgement and rationales for blinding of participants and personnel. - **blinding_outcome_assessment** (object) - Judgement and rationales for blinding of outcome assessment. - **sample_size_bot** (object) - Results from the sample size extraction robot. - **num_randomized** (integer) - The number of randomized participants. - **punchline_bot** (object) - Results from the key conclusions extraction robot. - **punchline_text** (string) - The extracted key conclusion. - **effect** (string) - The described effect size or direction. #### Response Example ```json [ { "ti": "Efficacy of Drug X for Treating Hypertension...", "ab": "BACKGROUND: Hypertension affects millions...", "rct_bot": { "is_rct": true, "is_rct_precise": true, "is_rct_balanced": true, "is_rct_sensitive": true, "model": "svm_cnn_ptyp", "score": 2.45 }, "pico_bot": { "participants": {"annotations": [{"text": "500 patients with mild to moderate hypertension", "start_index": 156}]}, "interventions": {"annotations": [{"text": "Drug X", "start_index": 89}]}, "outcomes": {"annotations": [{"text": "systolic blood pressure", "start_index": 312}]} }, "bias_bot": { "random_sequence_generation": {"judgement": "low", "rationales": ["randomly assigned"]}, "allocation_concealment": {"judgement": "low", "rationales": ["double-blind"]}, "blinding_participants_personnel": {"judgement": "low", "rationales": ["placebo-controlled"]}, "blinding_outcome_assessment": {"judgement": "high/unclear", "rationales": []} }, "sample_size_bot": {"num_randomized": 500}, "punchline_bot": {"punchline_text": "Drug X significantly reduced systolic blood pressure by 15 mmHg compared to placebo", "effect": "↑ sig increase"} } ] ``` ``` -------------------------------- ### Import necessary libraries for RobotReviewer Source: https://github.com/ijmarshall/robotreviewer/blob/master/robotreviewer/testing out human tagger code.ipynb Import the required libraries at the beginning of your script. This includes the main robotreviewer library, os for path manipulation, pickle for object serialization, tqdm for progress bars, and numpy for numerical operations. ```python import robotreviewer import os import pickle import tqdm import numpy as np ``` -------------------------------- ### Initialize PICORobot Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Initialize the PICORobot for extracting PICO spans from clinical trial reports. ```python from robotreviewer.robots.pico_robot import PICORobot from robotreviewer.textprocessing.tokenizer import nlp pico_robot = PICORobot(top_k=3, min_k=1) ``` -------------------------------- ### Configure RobotReviewer Settings Source: https://context7.com/ijmarshall/robotreviewer/llms.txt JSON configuration file for setting thread counts, logging, and API key authentication. ```json { "robotreviewer": { "use_grobid": true, "grobid_threads": 4, "spacy_threads": 4, "dont_delete": 0, "log": "log.txt", "api_keys": { "your-api-key-here": { "uid": 1 }, "another-api-key": { "uid": 2 } } } } ``` -------------------------------- ### Predict Human Classifications Source: https://github.com/ijmarshall/robotreviewer/blob/master/robotreviewer/testing out human tagger code.ipynb Transforms text examples using pre-trained vectorizers and predicts classifications using trained classifiers for each specified field. It then ensembels these predictions to determine if the input is human-generated. ```python examples = [ {"ti":"Comparison of the effectiveness and outcome of microendoscopic and open discectomy in patients suffering from lumbar disc herniation. ", "ab": "\n BACKGROUND:\nThe purpose of our study is to compare the outcomes and effectiveness of MED vs OLD for lumbar disc herniation. OBJECTIVES:\nTo identify the functional outcomes in terms of ODI score, VAS score complications in terms of intraoperative blood loss, use of general anesthesia, and morbidity in terms of total hospital stay between MED and OLD. METHODS:\nIn our randomized prospective study we analyzed 60 patients with clinical signs and symptoms with 2 weeks of failed conservative treatment plus MRI or CT scan findings of lumbar disc herniation who underwent MED and OLD. The study was undertaken from November 2017 to January 2019 at Guangzhou Medical University of Second Affiliated Hospital, department of orthopedic surgery in spinal Unit, Guangzhou, China. Patients were divided into 2 groups i.e. who underwent MED group and the OLD group then we compared the preoperative and postoperative ODI and VAS score, duration of total hospital stay, intraoperative blood loss, and operation time. RESULTS:\nWe evaluated 60 patients. Among them, 30 underwent MED (15 female and 15 male) and 30 underwent OLD 14 male 16 female. Surgical and anesthesia time was significantly shorter, blood loss and hospital stay were significantly reduced in patients having MED than OLD (<0.005). The improvement in the ODI in both groups was clinically significant and statistically (P\u2039.005) at postoperative 1st day (with greater improvement in the MED group), at 6 weeks (P\u2039.005), month 6 (>0.005) statistically no significant. The clinical improvement was similar in both groups. VAS and ODI scores improved significantly postoperatively in both groups. However, the MED group was superior to the OLD group with less time in bed, shorter operation time, less blood loss which is clinically and statistically significant (P\u2039.05). CONCLUSIONS:\nThe standard surgical treatment of lumbar disc herniation has been open discectomy but there has been a trend towards minimally invasive procedures. MED for lumbar spine disc herniation is a well-known but developing field, which is increasingly spreading in the last few years. The success rate of MED is about approximately 90%. Both methods are equally effective in relieving radicular pain. MED was superior in terms of total hospital stay, morbidity, and earlier return to work and anesthetic exposure, blood loss, intra-op time comparing to OLD. MED is a safe and effective alternative to conventional OLD for patients with lumbar disc herniation." }, {"ti": "Increased Cadmium Excretion Due to Oral Administration of Lactobacillus plantarum Strains by Regulating Enterohepatic Circulation in Mice.", "ab": "The heavy metal cadmium (Cd) is a contaminant widely distributed in the food chain. In the present study, 8-week oral administration of a probiotic strain, Lactobacillus plantarum CCFM8610, markedly decreased blood Cd levels in volunteers. Further animal study showed that three L. plantarum strains administered orally exhibited significantly different effects on the regulation of bile acid (BA) metabolism and Cd excretion in mice. Among the strains, L. plantarum CCFM8610 showed the most significant effects on enhancing hepatic BA synthesis, biliary glutathione output, and fecal BA excretion. Biliary Cd output and fecal Cd excretion were markedly increased after L. plantarum CCFM8610 administration, resulting in a marked reduction in tissue Cd levels. The regulation of BA homeostasis and Cd excretion was due to the suppression of the enterohepatic farnesoid X receptor-fibroblast growth factor 15 (FXR-FGF15) axis by L. plantarum CCFM8610 and could be abolished by treatment with the FXR agonist GW4064. The regulatory effects were also related to the gut microbiota, as antibiotic pretreatment reversed L. plantarum CCFM8610-induced effects in BA and Cd metabolism." } ] fields = ["ti", "ab"] human_preds = [] for field in tqdm.tqdm(fields): X = human_models["vecs"][field].transform((r[field] for r in examples)) human_preds.append(human_models["clfs"][field].predict(X)) human_preds = np.array(human_preds).T human_ens_preds = list(map(lambda x: {"is_human": x}, human_models["ensembler"].predict(human_preds))) ``` -------------------------------- ### Load human models from a pickle file Source: https://github.com/ijmarshall/robotreviewer/blob/master/robotreviewer/testing out human tagger code.ipynb This snippet shows how to open and load human models from a specified pickle file. Ensure the file path is correctly constructed using os.path.join and robotreviewer.DATA_ROOT. ```python # with open(os.path.join(robotreviewer.DATA_ROOT, "human/human_models.pck"), "rb") as f: ``` -------------------------------- ### Queue Documents for Annotation (REST API) Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Submit multiple articles for asynchronous machine learning annotation via the REST API. Requires a JSON payload with article details and a list of desired robots. An API key is necessary for authentication. ```bash curl -X POST "https://api.robotreviewer.net/queue-documents" \ -H "Content-Type: application/json" \ -H "api-key: YOUR_API_KEY" \ -d '{ "articles": [ { "ti": "Efficacy of Drug X for Treating Hypertension: A Randomized Controlled Trial", "ab": "BACKGROUND: Hypertension affects millions worldwide. We conducted a randomized, double-blind, placebo-controlled trial to evaluate Drug X. METHODS: We enrolled 500 patients with mild to moderate hypertension and randomly assigned them to receive Drug X (n=250) or placebo (n=250) for 12 weeks. RESULTS: Drug X significantly reduced systolic blood pressure by 15 mmHg compared to placebo (p<0.001). CONCLUSIONS: Drug X is effective for treating hypertension.", "ptyp": ["Randomized Controlled Trial", "Journal Article"], "fullText": "Full manuscript text extracted from PDF..." }, { "ti": "Meta-analysis of Statin Therapy", "ab": "We conducted a systematic review of statin therapy...", "ptyp": ["Meta-Analysis", "Review"] } ], "robots": ["rct_bot", "pico_bot", "bias_bot", "sample_size_bot", "punchline_bot"], "filter_rcts": "is_rct_balanced" }' ``` -------------------------------- ### Import Dependencies Source: https://github.com/ijmarshall/robotreviewer/blob/master/vocabs/vocab generation.ipynb Required libraries for database connectivity, NLP processing, and data manipulation. ```python import pandas.io.sql as sqlio import mysql.connector import tqdm import csv import spacy from spacy.attrs import LOWER, POS, ENT_TYPE, IS_ALPHA from spacy.tokens import Doc import pandas as pd import tqdm from collections import defaultdict import pickle ``` -------------------------------- ### Verify GPU in Docker Source: https://github.com/ijmarshall/robotreviewer/blob/master/README.md Test if the GPU is correctly exposed to the container. ```bash docker run -it --rm --gpus all ubuntu nvidia-smi ``` -------------------------------- ### Create CUI to Preferred String Map Source: https://github.com/ijmarshall/robotreviewer/blob/master/vocabs/vocab generation.ipynb Builds a dictionary mapping CUIs to their preferred string representations, sourced from different vocabularies. Requires pandas and tqdm. ```python cui_to_pstr = defaultdict(dict) for i, r in tqdm.tqdm(df.iterrows()): cui_to_pstr[r['cui']][r['sab']] = r['str'] order = ["RXNORM", "MSH", "SNOMEDCT_US", "ICD10", "MDR", "ATC"] ``` -------------------------------- ### Download and Decompress SciBERT Model Source: https://github.com/ijmarshall/robotreviewer/blob/master/README.md Retrieve the SciBERT model and extract it into the data directory. ```bash wget https://s3-us-west-2.amazonaws.com/ai2-s2-research/scibert/tensorflow_models/scibert_scivocab_uncased.tar.gz ``` ```bash tar -zxf scibert_scivocab_uncased.tar.gz --directory robotreviewer/data ``` -------------------------------- ### Upload and Annotate PDFs (Web Application) Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Upload multiple PDF files for automatic annotation through the web interface. This endpoint returns a report UUID for tracking and retrieval of the annotation results. ```bash curl -X POST "http://localhost:5050/upload_and_annotate_pdfs" \ -F "file=@trial1.pdf" \ -F "file=@trial2.pdf" \ -F "file=@trial3.pdf" ``` -------------------------------- ### Deploy RobotReviewer with Docker Compose Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Defines the multi-service architecture including web, API, worker, RabbitMQ, Grobid, and BERT components. ```yaml # docker-compose.yml version: "3.9" services: web: build: . ports: - "5050:5000" depends_on: - rabbitmq - grobid - bert environment: - ROBOTREVIEWER_GROBID_HOST=http://grobid:8070 - SECRET=your-secret-key volumes: - ./robotreviewer/data:/var/lib/deploy/robotreviewer/data command: web api: build: . ports: - "5051:5000" depends_on: - rabbitmq - grobid - bert environment: - ROBOTREVIEWER_GROBID_HOST=http://grobid:8070 - ROBOTREVIEWER_REST_API=true command: api worker: build: . depends_on: - rabbitmq - grobid - bert environment: - ROBOTREVIEWER_GROBID_HOST=http://grobid:8070 command: worker rabbitmq: image: rabbitmq:3-management ports: - "5672:5672" - "15672:15672" grobid: image: lfoppiano/grobid:0.7.0 ports: - "8070:8070" bert: build: ./bert ports: - "5555:5555" - "5556:5556" ``` -------------------------------- ### Import NetworkX Library Source: https://github.com/ijmarshall/robotreviewer/blob/master/vocabs/vocab generation.ipynb Imports the NetworkX library, commonly used for graph creation and manipulation in Python. ```python import networkx as nx ``` -------------------------------- ### Create CUI to String Mapping Source: https://github.com/ijmarshall/robotreviewer/blob/master/vocabs/vocab generation.ipynb Iterates through CUI-to-PSTR items and orders them based on a predefined list 'order'. Stores the first matching PSTR for each CUI in cui_to_str. ```python cui_to_str = {} for k, v in cui_to_pstr.items(): for p in order: if p in v: cui_to_str[k] = v[p] break ``` -------------------------------- ### Instantiate HumanRobot Source: https://github.com/ijmarshall/robotreviewer/blob/master/robotreviewer/testing out human tagger code.ipynb Creates an instance of the HumanRobot class, initializing the robot for use in classification tasks. ```python b = human_robot.HumanRobot() ``` -------------------------------- ### Retrieve Annotation Reports Source: https://context7.com/ijmarshall/robotreviewer/llms.txt View or download annotation reports in different formats. ```bash # View report as HTML curl "http://localhost:5050/report_view/Tvg0-pHV2QBsYpJxE2KW-/html" # Download report as JSON curl "http://localhost:5050/download_report/Tvg0-pHV2QBsYpJxE2KW-/json" -o report.json ``` -------------------------------- ### Serialize String to CUI Map Source: https://github.com/ijmarshall/robotreviewer/blob/master/vocabs/vocab generation.ipynb Saves the generated string-to-CUI mapping to a pickle file for later use. Requires the pickle library. ```python import pickle with open('str_to_cui.pck', 'wb') as f: pickle.dump(str_to_cui_full, f) ``` -------------------------------- ### Load CSV and Build Directed Graph Source: https://github.com/ijmarshall/robotreviewer/blob/master/vocabs/vocab generation.ipynb Reads a tab-separated CSV file into a pandas DataFrame and constructs a NetworkX directed graph. Edges are added from 'cui2' to 'cui1' for each row, with a progress bar indicating the iteration status. ```python graph_data = pd.read_csv('cui_graph.csv', sep='\t') G = nx.DiGraph() G.add_edges_from(((r['cui2'], r['cui1']) for i, r in tqdm.tqdm(graph_data.iterrows()))) ``` -------------------------------- ### Save CUI to String Mapping to Pickle Source: https://github.com/ijmarshall/robotreviewer/blob/master/vocabs/vocab generation.ipynb Saves the generated 'cui_to_str' dictionary to a file named 'cui_to_str.pck' in binary write mode using the pickle module. ```python with open('cui_to_str.pck', 'wb') as f: pickle.dump(cui_to_str, f) ``` -------------------------------- ### Import HumanRobot Class Source: https://github.com/ijmarshall/robotreviewer/blob/master/robotreviewer/testing out human tagger code.ipynb Imports the HumanRobot class from the robotreviewer.robots module, making it available for instantiation and use. ```python from robotreviewer.robots import human_robot ``` -------------------------------- ### Instantiate RCTRobot Source: https://github.com/ijmarshall/robotreviewer/blob/master/robotreviewer/testing out human tagger code.ipynb Initializes an instance of the RCTRobot class. This object is used for tasks related to RCT (Randomized Controlled Trial) analysis. ```python b = rct_robot.RCTRobot() ``` -------------------------------- ### Process PDFs in Batch with Python Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Uses PdfReader to process multiple PDF binaries in parallel using a thread pool. Requires an active connection to the reader service. ```python from robotreviewer.textprocessing.pdfreader import PdfReader pdf_reader = PdfReader() pdf_reader.connect() # Load multiple PDFs pdf_binaries = [] for filename in ["trial1.pdf", "trial2.pdf", "trial3.pdf"]: with open(filename, "rb") as f: pdf_binaries.append(f.read()) # Process in parallel with 4 threads results = pdf_reader.convert_batch(pdf_binaries, num_threads=4) for i, data in enumerate(results): if data.grobid.get('_parse_error'): print(f"PDF {i}: Parse error") else: print(f"PDF {i}: {data.grobid['title']}") ``` -------------------------------- ### PICORobot.annotate Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Extract Population, Intervention, and Outcome text spans from full-text clinical trial reports using supervised distant supervision models. ```APIDOC ## PICORobot.annotate ### Description Extract Population, Intervention, and Outcome text spans from full-text clinical trial reports using supervised distant supervision models. ### Method `annotate` ### Parameters #### Request Body - **doc** (object) - Required - The document object to annotate. This object is typically a spaCy `Doc` object. #### Query Parameters - **top_k** (integer) - Optional - The maximum number of PICO spans to extract for each category (Population, Intervention, Outcome). Defaults to 3. - **min_k** (integer) - Optional - The minimum number of PICO spans to extract for each category. Defaults to 1. ### Response #### Success Response (200) - **annotated_doc** (object) - The input document object with PICO annotations added. - **ents** (list of objects) - A list of named entities identified in the document, including PICO spans. - **start** (integer) - The starting character index of the entity. - **end** (integer) - The ending character index of the entity. - **label** (string) - The label of the entity (e.g., "POPULATION", "INTERVENTION", "OUTCOME"). ### Request Example ```python from robotreviewer.robots.pico_robot import PICORobot from robotreviewer.textprocessing.tokenizer import nlp pico_robot = PICORobot(top_k=3, min_k=1) # Assuming 'text' is a string containing the full text of a clinical trial report doc = nlp(text) annotated_doc = pico_robot.annotate(doc) # You can then access the annotations like this: # for ent in annotated_doc.ents: # if ent.label_ in ["POPULATION", "INTERVENTION", "OUTCOME"]: # print(f"Label: {ent.label_}, Text: {ent.text}") ``` ``` -------------------------------- ### SampleSizeBot.api_annotate Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Extracts the number of randomized participants from clinical trial abstracts. ```APIDOC ## SampleSizeBot.api_annotate ### Description Extracts the number of randomized participants from clinical trial abstracts using neural network models. ### Request Body - **articles** (list) - Required - A list of dictionaries, each containing 'ab' (abstract). ### Response #### Success Response (200) - **num_randomized** (int) - The total number of randomized participants extracted. ``` -------------------------------- ### POST /queue-documents Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Submit articles for asynchronous machine learning annotation. The API accepts JSON-formatted clinical trial data with title, abstract, optional publication types, and full text. ```APIDOC ## POST /queue-documents ### Description Submit articles for asynchronous machine learning annotation. The API accepts JSON-formatted clinical trial data with title, abstract, optional publication types, and full text. ### Method POST ### Endpoint https://api.robotreviewer.net/queue-documents ### Parameters #### Query Parameters - **api-key** (string) - Required - Your API key for authentication. #### Request Body - **articles** (array) - Required - A list of articles to be annotated. - **ti** (string) - Required - The title of the article. - **ab** (string) - Required - The abstract of the article. - **ptyp** (array of strings) - Optional - Publication types of the article. - **fullText** (string) - Optional - The full text of the article. - **robots** (array of strings) - Required - A list of robots to use for annotation. - **filter_rcts** (string) - Optional - A filter for RCTs (e.g., "is_rct_balanced"). ### Request Example ```json { "articles": [ { "ti": "Efficacy of Drug X for Treating Hypertension: A Randomized Controlled Trial", "ab": "BACKGROUND: Hypertension affects millions worldwide. We conducted a randomized, double-blind, placebo-controlled trial to evaluate Drug X. METHODS: We enrolled 500 patients with mild to moderate hypertension and randomly assigned them to receive Drug X (n=250) or placebo (n=250) for 12 weeks. RESULTS: Drug X significantly reduced systolic blood pressure by 15 mmHg compared to placebo (p<0.001). CONCLUSIONS: Drug X is effective for treating hypertension.", "ptyp": ["Randomized Controlled Trial", "Journal Article"], "fullText": "Full manuscript text extracted from PDF..." }, { "ti": "Meta-analysis of Statin Therapy", "ab": "We conducted a systematic review of statin therapy...", "ptyp": ["Meta-Analysis", "Review"] } ], "robots": ["rct_bot", "pico_bot", "bias_bot", "sample_size_bot", "punchline_bot"], "filter_rcts": "is_rct_balanced" } ``` ### Response #### Success Response (200) - **report_id** (string) - The unique identifier for the annotation report. #### Response Example ```json { "report_id": "d9181607-8a44-7601-322c-d2aa84b5f0c2" } ``` ``` -------------------------------- ### Load Human Models Source: https://github.com/ijmarshall/robotreviewer/blob/master/robotreviewer/testing out human tagger code.ipynb Loads pre-trained human models, likely for text classification tasks. Assumes 'human_models' is a dictionary containing vectorizers and classifiers. ```python human_models = pickle.load(f) ``` -------------------------------- ### Save Graph to Pickle File Source: https://github.com/ijmarshall/robotreviewer/blob/master/vocabs/vocab generation.ipynb Saves a graph object to a pickle file for later use. Ensure the 'pickle' library is imported. ```python with open('cui_subtrees.pck', 'wb') as f: pickle.dump(G, f) ``` -------------------------------- ### BibTeX Citation Source: https://github.com/ijmarshall/robotreviewer/blob/master/README.md BibTeX entry for citing the RobotReviewer publication. ```bibtex @article{RobotReviewer2017, title = "Automating Biomedical Evidence Synthesis: {RobotReviewer}", author = "Marshall, Iain J and Kuiper, Jo{"e}l and Banner, Edward and Wallace, Byron C", journal = "Proceedings of the Conference of the Association for Computational Linguistics (ACL)", volume = 2017, pages = "7--12", month = jul, year = 2017, } ``` -------------------------------- ### Query UMLS Database Source: https://github.com/ijmarshall/robotreviewer/blob/master/vocabs/vocab generation.ipynb Retrieves preferred terms and CUIs from the MRCONSO table. ```python df = sqlio.read_sql_query("SELECT str, cui, sab from MRCONSO where sab in ('MSH', 'RXNORM', 'SNOMEDCT_US', 'MDR', 'ICD10', 'ATC') and LAT='ENG';", cnx) ``` -------------------------------- ### POST /upload_and_annotate_pdfs Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Upload PDF files for automatic annotation through the web interface. Returns a report UUID for tracking and retrieval. ```APIDOC ## POST /upload_and_annotate_pdfs ### Description Upload PDF files for automatic annotation through the web interface. Returns a report UUID for tracking and retrieval. ### Method POST ### Endpoint http://localhost:5050/upload_and_annotate_pdfs ### Parameters #### Request Body - **file** (file) - Required - One or more PDF files to upload. ### Request Example ```bash curl -X POST "http://localhost:5050/upload_and_annotate_pdfs" \ -F "file=@trial1.pdf" \ -F "file=@trial2.pdf" \ -F "file=@trial3.pdf" ``` ### Response #### Success Response (200) - **report_id** (string) - The unique identifier for the annotation report. #### Response Example ```json { "report_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef" } ``` ``` -------------------------------- ### Generate String to CUI Map Source: https://github.com/ijmarshall/robotreviewer/blob/master/vocabs/vocab generation.ipynb Processes a CSV file to create a mapping from string representations to Concept Unique Identifiers (CUIs). Requires pandas, nlp, and tqdm. ```python interesting_cuis = set(df.cui.values) str_to_cui_full = defaultdict(list) with open('umls_full_index.csv') as csvfile: reader = csv.DictReader(csvfile, delimiter='\t') for row in tqdm.tqdm(reader): if row['cui'] in interesting_cuis: # just keep those which are in the Cochrane vocabs doc = nlp(pipeline(row['str'], umls_mode=True).lower()) str_to_cui_full[' '.join(t.lemma_ for t in doc)].append(row['cui']) ``` -------------------------------- ### Extract PICO elements with PICOSpanRobot Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Use the PICOSpanRobot to extract PICO elements from titles and abstracts, optionally including BERT embeddings and MeSH term mappings. ```python from robotreviewer.robots.pico_span_robot import PICOSpanRobot from robotreviewer.textprocessing.tokenizer import nlp pico_span_robot = PICOSpanRobot() # Parse title and abstract title = nlp("Metformin versus Sitagliptin for Type 2 Diabetes: A Randomized Trial") abstract = nlp(""" OBJECTIVE: To compare the efficacy of metformin and sitagliptin in patients with newly diagnosed type 2 diabetes. METHODS: Adults aged 40-70 with HbA1c 7-9% were randomized to metformin or sitagliptin for 24 weeks. RESULTS: HbA1c reduction was greater with metformin (-1.2%) than sitagliptin (-0.9%). """) result = pico_span_robot.annotate( {"title": title, "abstract": abstract}, get_berts=True, # Include BERT embeddings get_meshes=True # Include MeSH term mappings ) ``` -------------------------------- ### Call RCTRobot Summary Method Source: https://github.com/ijmarshall/robotreviewer/blob/master/robotreviewer/testing out human tagger code.ipynb Attempts to call the summary method on an RCTRobot object. This snippet is associated with an AttributeError, indicating that the 'summary' attribute is not available on RCTRobot instances. ```python b.summary() ``` -------------------------------- ### Parse document text with PICO Robot Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Extract PICO elements from raw text using the annotate method. ```python doc_text = nlp(""" METHODS: We enrolled adults aged 40-75 years with type 2 diabetes mellitus and HbA1c levels between 7.0% and 10.0%. Patients with severe renal impairment were excluded. Participants were randomized to receive metformin 1000mg twice daily or sitagliptin 100mg once daily for 24 weeks. RESULTS: The primary outcome was change in HbA1c from baseline. Secondary outcomes included fasting plasma glucose, body weight, and adverse events. Metformin reduced HbA1c by 1.2% compared to 0.9% with sitagliptin (p=0.03). """) annotations = pico_robot.annotate(doc_text, top_k=3, min_k=1, alpha=0.7) ``` -------------------------------- ### Parse PDF Files with Grobid - PdfReader Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Parses PDF files using Grobid to extract structured text, metadata, and bibliographic information. Ensure the Grobid service is running and accessible. ```python from robotreviewer.textprocessing.pdfreader import PdfReader pdf_reader = PdfReader() pdf_reader.connect() # Wait for Grobid service with open("clinical_trial.pdf", "rb") as f: pdf_binary = f.read() data = pdf_reader.convert(pdf_binary) # Access extracted data print(data.grobid['title']) # "Efficacy of Drug X: A Randomized Trial" print(data.grobid['abstract']) # "BACKGROUND: We conducted a trial..." print(data.grobid['text']) # Full text of the document print(data.grobid['authors']) # [{'lastname': 'Smith', 'forename': 'John', 'initials': 'J'}, ...] print(data.grobid['journal']) # "New England Journal of Medicine" print(data.grobid['year']) # 2023 print(data.grobid['volume']) # "388" print(data.grobid['pages']) # "123-135" print(data.gold['filehash']) # SHA1 hash of PDF ``` -------------------------------- ### Retrieve Annotation Report (REST API) Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Fetch the completed annotation results for a specific report ID. The response is a JSON array containing structured data and predictions from all requested robots for each processed article. Requires an API key. ```bash curl -X GET "https://api.robotreviewer.net/report/d9181607-8a44-7601-322c-d2aa84b5f0c2" \ -H "api-key: YOUR_API_KEY" ``` -------------------------------- ### Text Normalization Pipeline Source: https://github.com/ijmarshall/robotreviewer/blob/master/vocabs/vocab generation.ipynb Orchestrates the cleaning process for input strings, including syntactic uninversion and whitespace removal. ```python def minimap(text_str, chunks=False): return matcher(pipeline(text_str, umls_mode=False), chunks=chunks) def pipeline(text_str, umls_mode=True): # 1. removal of parentheticals if umls_mode: text_str = ne_parentheticals(text_str) # hyphens to spaces text_str = text_str.replace('-', ' ') # 3. conversion to lowercase # text_str = text_str.lower() # 2. syntactic uninverstion if umls_mode: text_str = syn_uninv(text_str) # 4. stripping of possessives text_str = remove_pos(text_str) # strip NOS's if umls_mode: text_str = remove_nos(text_str) # last... remove any multiple spaces, or starting/ending with space text_str = strip_space.sub(' ', text_str) text_str = text_str.strip() return text_str ``` -------------------------------- ### Filter RIS References with RCTRobot.filter_articles Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Filter RIS-formatted reference lists to identify RCTs for systematic review screening. ```python from robotreviewer.robots.rct_robot import RCTRobot rct_robot = RCTRobot() # RIS format string from reference manager export ris_string = """ TY - JOUR TI - Randomized trial of aspirin for cardiovascular prevention AB - We randomly assigned 10000 participants to aspirin or placebo... AU - Smith, J PY - 2023 ER - TY - JOUR TI - Review of aspirin mechanisms AB - This narrative review discusses the pharmacology of aspirin... AU - Jones, M PY - 2023 ER - """ # Filter to keep only RCTs filtered_ris = rct_robot.filter_articles( ris_string, ensemble_type="svm_cnn", threshold_type="sensitive", # Use high-sensitivity threshold for screening auto_use_ptyp=True, remove_non_rcts=True ) # Returns RIS string with only RCT articles, plus prediction metadata print(filtered_ris) ``` -------------------------------- ### PdfReader.convert Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Parses PDF files to extract structured text and metadata. ```APIDOC ## PdfReader.convert ### Description Parse PDF files using Grobid to extract structured text, metadata, and bibliographic information. ### Request Body - **pdf_binary** (bytes) - Required - The binary content of the PDF file. ### Response #### Success Response (200) - **grobid** (object) - Extracted metadata including title, abstract, text, authors, journal, year, volume, and pages. - **gold** (object) - Additional metadata including filehash. ``` -------------------------------- ### Check PDF Annotation Status Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Monitor the progress of PDF annotation tasks using the task UUID. ```bash # Check annotation status curl "http://localhost:5050/annotate_status/Tvg0-pHV2QBsYpJxE2KW-" ``` -------------------------------- ### RCTRobot.filter_articles Source: https://context7.com/ijmarshall/robotreviewer/llms.txt Filter RIS-formatted reference lists to identify RCTs, useful for systematic review screening. ```APIDOC ## RCTRobot.filter_articles ### Description Filter RIS-formatted reference lists to identify RCTs, useful for systematic review screening. ### Method `filter_articles` ### Parameters #### Request Body - **ris_string** (string) - Required - A string containing articles in RIS format. #### Query Parameters - **ensemble_type** (string) - Optional - The type of ensemble model to use (e.g., "svm_cnn"). Defaults to "svm_cnn". - **threshold_type** (string) - Optional - The type of threshold to apply for classification (e.g., "balanced", "sensitive", "precise"). Defaults to "balanced". - **auto_use_ptyp** (boolean) - Optional - Whether to automatically use publication types if available. Defaults to True. - **remove_non_rcts** (boolean) - Required - If True, only RCT articles are returned. If False, all articles are returned with RCT prediction metadata. ### Response #### Success Response (200) - **filtered_ris** (string) - A RIS-formatted string containing only the articles identified as RCTs (if `remove_non_rcts` is True), or the original RIS string with added prediction metadata for each article. ### Request Example ```python from robotreviewer.robots.rct_robot import RCTRobot rct_robot = RCTRobot() ris_string = """ TY - JOUR TI - Randomized trial of aspirin for cardiovascular prevention AB - We randomly assigned 10000 participants to aspirin or placebo... AU - Smith, J PY - 2023 ER - TY - JOUR TI - Review of aspirin mechanisms AB - This narrative review discusses the pharmacology of aspirin... AU - Jones, M PY - 2023 ER - """ filtered_ris = rct_robot.filter_articles( ris_string, ensemble_type="svm_cnn", threshold_type="sensitive", auto_use_ptyp=True, remove_non_rcts=True ) print(filtered_ris) ``` ```