### Displaying File Structure After Backend Flag Creation (Shell) Source: https://github.com/georgetown-ir-lab/quickumls/wiki/Migration-QuickUMLS-1.3-to-1.4 Illustrates the file structure of a QuickUMLS installation directory after creating the 'database_backend.flag' file to explicitly set the backend to LevelDB. This helps in verifying the correct setup to suppress warnings. ```shell ls -l total 88K drwxrwxr-x 4 ubuntu ubuntu 4.0K May 10 00:50 cui-semtypes.db -rw-rw-r-- 1 ubuntu ubuntu 7 May 10 00:50 database_backend.flag -rw-rw-r-- 1 ubuntu ubuntu 3 May 10 00:50 language.flag drwxrwxr-x 2 ubuntu ubuntu 76K May 10 01:03 umls-simstring.db ``` -------------------------------- ### POST /install Source: https://context7.com/georgetown-ir-lab/quickumls/llms.txt Initializes the QuickUMLS database from raw UMLS installation files (MRCONSO.RRF and MRSTY.RRF). ```APIDOC ## POST /install ### Description Processes raw UMLS files into an optimized database format for fast concept matching. ### Method CLI Command (python -m quickumls.install) ### Parameters #### Path Parameters - **source_path** (string) - Required - Path to UMLS installation files - **destination_path** (string) - Required - Path for optimized database #### Options - **-L** (flag) - Optional - Enable lowercase normalization - **-U** (flag) - Optional - Enable Unicode normalization - **-E** (string) - Optional - Language code (e.g., GER, SPA) - **-d** (string) - Optional - Backend type (leveldb or unqlite) ### Request Example python -m quickumls.install -L -U /path/to/umls /path/to/destination ``` -------------------------------- ### Install QuickUMLS Database from UMLS Files Source: https://context7.com/georgetown-ir-lab/quickumls/llms.txt Initializes the QuickUMLS database by processing raw UMLS installation files (MRCONSO.RRF and MRSTY.RRF). This command-line process supports various configurations including language selection, normalization, and backend storage engines. ```bash # Basic installation with default settings (English, UnQLite backend) python -m quickumls.install /path/to/umls/files /path/to/quickumls/destination # Installation with lowercase normalization for increased recall python -m quickumls.install -L /path/to/umls/files /path/to/quickumls/destination # Installation with Unicode normalization for non-ASCII text python -m quickumls.install -U /path/to/umls/files /path/to/quickumls/destination # Installation for a specific language (German) python -m quickumls.install -E GER /path/to/umls/files /path/to/quickumls/destination # Installation with LevelDB backend (more space efficient but no concurrent access) python -m quickumls.install -d leveldb /path/to/umls/files /path/to/quickumls/destination # Combined options: lowercase, unicode normalization, Spanish language python -m quickumls.install -L -U -E SPA /path/to/umls/files /path/to/quickumls/destination ``` -------------------------------- ### Deploy and Connect to QuickUMLS Server Source: https://github.com/georgetown-ir-lab/quickumls/blob/master/README.md Explains how to start the QuickUMLS server via command line and connect to it using the client API in Python. ```bash python -m quickumls.server /path/to/quickumls/files -P 4645 -H localhost ``` ```python from quickumls import get_quickumls_client matcher = get_quickumls_client() text = "The ulna has dislocated posteriorly from the trochlea of the humerus." matcher.match(text, best_match=True, ignore_syntax=False) ``` -------------------------------- ### Initialize QuickUMLS with Older Version Warning (Python) Source: https://github.com/georgetown-ir-lab/quickumls/wiki/Migration-QuickUMLS-1.3-to-1.4 Demonstrates initializing QuickUMLS with an older installation, triggering a warning about the deprecated LevelDB backend. This code snippet shows the expected output when an older QuickUMLS installation is detected. ```python import quickumls matcher = quickumls.QuickUMLS('path/to/1.3/install') ``` -------------------------------- ### Start QuickUMLS Server Source: https://context7.com/georgetown-ir-lab/quickumls/llms.txt Run QuickUMLS as a server for high-performance, multi-client deployments. The server loads the matcher once and handles concurrent requests. ```APIDOC ## Start QuickUMLS Server ### Description Run QuickUMLS as a server for high-performance, multi-client deployments. The server loads the matcher once and handles concurrent requests. ### Method ```bash python -m quickumls.server /path/to/quickumls/installation [OPTIONS] ``` ### Parameters - **/path/to/quickumls/installation** (string) - Required - Path to the QuickUMLS installation directory. - **-H, --host** (string) - Optional - Host address to bind the server to. Defaults to 'localhost'. - **-P, --port** (integer) - Optional - Port number to bind the server to. Defaults to 4645. - **-t, --threshold** (float) - Optional - Minimum similarity threshold for matching. - **-s, --similarity** (string) - Optional - Similarity measure to use (e.g., 'dice', 'jaccard'). - **-o, --overlap** (string) - Optional - Overlapping criteria ('none' or 'length'). - **-w, --window** (integer) - Optional - Window size for matching. - **-l, --min_match_length** (integer) - Optional - Minimum match length. - **-v, --verbose** (boolean) - Optional - Enable verbose output. ### Request Example ```bash # Start server with default settings python -m quickumls.server /path/to/quickumls/installation # Specify host and port python -m quickumls.server /path/to/quickumls/installation -H 0.0.0.0 -P 8080 # With custom matching parameters python -m quickumls.server /path/to/quickumls/installation \ -t 0.8 \ -s dice \ -o none \ -w 7 \ -l 4 # Run server in background nohup python -m quickumls.server /path/to/quickumls/installation \ -H 0.0.0.0 -P 4645 > quickumls.log 2>&1 & echo $! > quickumls.pid # Stop background server kill -9 $(cat quickumls.pid) && rm quickumls.pid ``` ``` -------------------------------- ### Get Matcher Information Source: https://context7.com/georgetown-ir-lab/quickumls/llms.txt Retrieve configuration details about the QuickUMLS instance for logging, debugging, or caching purposes. ```APIDOC ## Get Matcher Information ### Description Retrieve configuration details about the QuickUMLS instance for logging, debugging, or caching purposes. ### Method ```python matcher.get_info() matcher.get_accepted_semtypes() ``` ### Request Example ```python from quickumls import QuickUMLS matcher = QuickUMLS( '/path/to/quickumls/installation', threshold=0.8, similarity_name='dice', window=7 ) # Get matcher configuration info = matcher.get_info() print(info) # Get accepted semantic types semtypes = matcher.get_accepted_semtypes() print(f"Filtering by {len(semtypes)} semantic types") ``` ### Response Example ```json { "threshold": 0.8, "similarity_name": "dice", "window": 7, "ngram_length": 3, "min_match_length": 3, "accepted_semtypes": ["T023", "T029", "T031", ...], "negations": ["neither", "no", "non", "none", "nor", "not"], "valid_punct": ["\u002d", "\u007e", ...] } ``` ``` -------------------------------- ### Filtering QuickUMLS Concepts by Semantic Types Source: https://context7.com/georgetown-ir-lab/quickumls/llms.txt Demonstrates how to filter QuickUMLS results by specifying accepted UMLS semantic types. It shows examples for clinical, medication, anatomical, and procedural concepts, and how to disable filtering to accept all types. ```python from quickumls import QuickUMLS # Common clinical semantic types CLINICAL_SEMTYPES = { 'T047', # Disease or Syndrome 'T184', # Sign or Symptom 'T033', # Finding 'T037', # Injury or Poisoning 'T191', # Neoplastic Process 'T046', # Pathologic Function 'T048', # Mental or Behavioral Dysfunction } # Medication-related semantic types MEDICATION_SEMTYPES = { 'T121', # Pharmacologic Substance 'T200', # Clinical Drug 'T195', # Antibiotic 'T203', # Drug Delivery Device } # Anatomical semantic types ANATOMY_SEMTYPES = { 'T023', # Body Part, Organ, or Organ Component 'T029', # Body Location or Region 'T030', # Body Space or Junction 'T031', # Body Substance } # Procedure semantic types PROCEDURE_SEMTYPES = { 'T060', # Diagnostic Procedure 'T059', # Laboratory Procedure 'T061', # Therapeutic or Preventive Procedure 'T058', # Health Care Activity } # Create specialized matchers disease_matcher = QuickUMLS( '/path/to/quickumls/installation', accepted_semtypes=CLINICAL_SEMTYPES ) drug_matcher = QuickUMLS( '/path/to/quickumls/installation', accepted_semtypes=MEDICATION_SEMTYPES ) anatomy_matcher = QuickUMLS( '/path/to/quickumls/installation', accepted_semtypes=ANATOMY_SEMTYPES ) # Extract different concept types from same text clinical_note = """ Patient presents with pneumonia in the right lower lobe. Started on azithromycin 500mg daily. Chest X-ray ordered to monitor progression. """ diseases = disease_matcher.match(clinical_note) drugs = drug_matcher.match(clinical_note) anatomy = anatomy_matcher.match(clinical_note) print(f"Diseases: {[m[0]['ngram'] for m in diseases]}") print(f"Drugs: {[m[0]['ngram'] for m in drugs]}") print(f"Anatomy: {[m[0]['ngram'] for m in anatomy]}") # Accept all semantic types (no filtering) all_concepts_matcher = QuickUMLS( '/path/to/quickumls/installation', accepted_semtypes=None ) ``` -------------------------------- ### Initialize and Use QuickUMLS Matcher Source: https://github.com/georgetown-ir-lab/quickumls/blob/master/README.md Demonstrates how to instantiate the QuickUMLS object with configuration parameters and perform entity matching on a text string. ```python from quickumls import QuickUMLS matcher = QuickUMLS(quickumls_fp, overlapping_criteria="score", threshold=0.7, similarity_name="jaccard", window=5, accepted_semtypes=None) text = "The ulna has dislocated posteriorly from the trochlea of the humerus." matcher.match(text, best_match=True, ignore_syntax=False) ``` -------------------------------- ### Basic QuickUMLS Matching and Batch Processing Source: https://context7.com/georgetown-ir-lab/quickumls/llms.txt Demonstrates how to perform basic text matching with QuickUMLS, retrieve server information, and process a batch of documents. It shows how to iterate through matches and access details like ngram, cui, and similarity score. ```python from quickumls import QuickUMLS # Initialize QuickUMLS client (assuming default settings) # Replace '/path/to/quickumls/installation' with your actual installation path client = QuickUMLS('/path/to/quickumls/installation') # Use the same API as standalone QuickUMLS text = "Patient diagnosed with type 2 diabetes mellitus and hypertension." matches = client.match(text, best_match=True, ignore_syntax=False) for match_group in matches: for match in match_group: print(f"{match['ngram']}: {match['cui']} ({match['similarity']:.2f})") # Process batch of documents documents = [ "Acute myocardial infarction with ST elevation.", "Chronic obstructive pulmonary disease exacerbation.", "Urinary tract infection confirmed by culture." ] for doc in documents: results = client.match(doc) print(f"Document: {doc[:50]}...") print(f"Found {len(results)} concept groups") # Get server configuration info = client.get_info() print(f"Server threshold: {info['threshold']}") print(f"Server similarity: {info['similarity_name']}") ``` -------------------------------- ### Configuring QuickUMLS Similarity Measures Source: https://context7.com/georgetown-ir-lab/quickumls/llms.txt Illustrates how to initialize QuickUMLS with different similarity measures (Jaccard, Dice, Cosine, Overlap) and configure their respective thresholds. It compares the number of matches found across different measures for a given text. ```python from quickumls import QuickUMLS # Jaccard similarity (default) - balanced precision/recall # Formula: |A ∩ B| / |A ∪ B| jaccard_matcher = QuickUMLS( '/path/to/quickumls/installation', similarity_name='jaccard', threshold=0.7 ) # Dice coefficient - favors recall over precision # Formula: 2|A ∩ B| / (|A| + |B|) dice_matcher = QuickUMLS( '/path/to/quickumls/installation', similarity_name='dice', threshold=0.7 ) # Cosine similarity - normalized by vector lengths # Formula: |A ∩ B| / sqrt(|A| * |B|) cosine_matcher = QuickUMLS( '/path/to/quickumls/installation', similarity_name='cosine', threshold=0.7 ) # Overlap coefficient - good for substring matching # Formula: |A ∩ B| (raw intersection count) overlap_matcher = QuickUMLS( '/path/to/quickumls/installation', similarity_name='overlap', threshold=3 # Number of matching n-grams ) # Compare results across similarity measures text = "The patient has diabetis mellitus" # intentional misspelling for name, matcher in [ ('jaccard', jaccard_matcher), ('dice', dice_matcher), ('cosine', cosine_matcher) ]: matches = matcher.match(text) print(f"{name}: found {sum(len(m) for m in matches)} matches") ``` -------------------------------- ### Retrieve QuickUMLS Matcher Configuration Source: https://context7.com/georgetown-ir-lab/quickumls/llms.txt Shows how to inspect the current configuration of a QuickUMLS matcher instance, including thresholds, similarity measures, and semantic type filters. ```python from quickumls import QuickUMLS matcher = QuickUMLS('/path/to/quickumls/installation', threshold=0.8, similarity_name='dice', window=7) info = matcher.get_info() print(info) semtypes = matcher.get_accepted_semtypes() print(f"Filtering by {len(semtypes)} semantic types") ``` -------------------------------- ### Connect with QuickUMLS Client Source: https://context7.com/georgetown-ir-lab/quickumls/llms.txt Use the client to connect to a running QuickUMLS server. The client API mirrors the standalone QuickUMLS object. ```APIDOC ## Connect with QuickUMLS Client ### Description Use the client to connect to a running QuickUMLS server. The client API mirrors the standalone QuickUMLS object. ### Method ```python from quickumls import get_quickumls_client ``` ### Parameters - **host** (string) - Optional - The hostname or IP address of the QuickUMLS server. Defaults to 'localhost'. - **port** (integer) - Optional - The port number of the QuickUMLS server. Defaults to 4645. ### Request Example ```python from quickumls import get_quickumls_client # Connect to default server (localhost:4645) client = get_quickumls_client() # Connect to specific host/port client = get_quickumls_client(host='192.168.1.100', port=8080) # Use the client just like the standalone QuickUMLS object # For example: # results = client.match('Patient has chest pain') ``` ``` -------------------------------- ### Initialize QuickUMLS Matcher Source: https://context7.com/georgetown-ir-lab/quickumls/llms.txt Configures the QuickUMLS object to perform concept extraction. Users can define similarity metrics, thresholds, and semantic type filters to tune the precision and recall of the matching engine. ```python from quickumls import QuickUMLS # Basic initialization with default settings matcher = QuickUMLS('/path/to/quickumls/installation') # Customized initialization with all options matcher = QuickUMLS( quickumls_fp='/path/to/quickumls/installation', overlapping_criteria='score', # 'score' or 'length' - how to rank overlapping matches threshold=0.7, # Minimum similarity (0.0-1.0) similarity_name='jaccard', # 'jaccard', 'dice', 'cosine', or 'overlap' window=5, # Maximum tokens to consider for matching min_match_length=3, # Minimum character length for matches accepted_semtypes={ # Filter by UMLS semantic types 'T047', # Disease or Syndrome 'T184', # Sign or Symptom 'T121', # Pharmacologic Substance 'T200', # Clinical Drug }, verbose=False, # Enable debug output keep_uppercase=False # Preserve uppercase (for acronym detection) ) # High-recall configuration (lower threshold) high_recall_matcher = QuickUMLS( quickumls_fp='/path/to/quickumls/installation', threshold=0.5, similarity_name='dice' ) # High-precision configuration (higher threshold, longer matches) high_precision_matcher = QuickUMLS( quickumls_fp='/path/to/quickumls/installation', threshold=0.9, min_match_length=5 ) ``` -------------------------------- ### Manage Background QuickUMLS Server Process Source: https://github.com/georgetown-ir-lab/quickumls/blob/master/README.md Provides commands to run the QuickUMLS server in the background using nohup and terminate it using a PID file. ```bash nohup python -m quickumls.server /path/to/QuickUMLS > /dev/null 2>&1 & echo $! > nohup.pid # To stop the server: kill -9 `cat nohup.pid` rm nohup.pid ``` -------------------------------- ### Integrate QuickUMLS with spaCy Pipeline Source: https://github.com/georgetown-ir-lab/quickumls/blob/master/README.md Shows how to add QuickUMLS as a custom component to a spaCy pipeline to extract entities and access UMLS metadata via the underscore object. ```python import spacy from quickumls.spacy_component import SpacyQuickUMLS nlp = spacy.load('en_core_web_sm') quickumls_component = SpacyQuickUMLS(nlp, 'PATH_TO_QUICKUMLS_DATA') nlp.add_pipe(quickumls_component) doc = nlp('Pt c/o shortness of breath, chest pain, nausea, vomiting, diarrrhea') for ent in doc.ents: print('Entity text : {}'.format(ent.text)) print('Label (UMLS CUI) : {}'.format(ent.label_)) print('Similarity : {}'.format(ent._.similarity)) print('Semtypes : {}'.format(ent._.semtypes)) ``` -------------------------------- ### Process Clinical Notes with QuickUMLS Source: https://context7.com/georgetown-ir-lab/quickumls/llms.txt Demonstrates how to use QuickUMLS to extract medical concepts from clinical text and filter them by semantic type. ```APIDOC ## Process Clinical Notes ### Description This section shows how to process clinical notes using QuickUMLS to identify medical concepts and filter them based on semantic types. ### Method ```python matcher.match(text, best_match=True) ``` ### Parameters - **text** (string) - Required - The clinical note text to process. - **best_match** (boolean) - Optional - If True, returns only non-overlapping matches. ### Request Example ```python clinical_note = """ Patient presents with acute chest pain radiating to left arm. History of hypertension and type 2 diabetes mellitus. Prescribed metformin 500mg twice daily. """ results = matcher.match(clinical_note, best_match=True) ``` ### Response - **results** (list of dict) - A list of matched concepts, where each concept is a dictionary containing details like text, CUI, similarity, and semantic types. ### Filtering Example ```python diseases = [ match for match_group in results for match in match_group if 'T047' in match['semtypes'] # Disease or Syndrome ] print(f"Found {len(diseases)} disease mentions") ``` ``` -------------------------------- ### SpaCy Integration: SpacyQuickUMLS Pipeline Component Source: https://context7.com/georgetown-ir-lab/quickumls/llms.txt Integrate QuickUMLS as a spaCy pipeline component for seamless NLP workflows. Concepts are added as entity spans with CUI labels and custom attributes for similarity scores and semantic types. ```APIDOC ## SpaCy Integration: SpacyQuickUMLS Pipeline Component ### Description Integrate QuickUMLS as a spaCy pipeline component for seamless NLP workflows. Concepts are added as entity spans with CUI labels and custom attributes for similarity scores and semantic types. ### Method ```python from quickumls.spacy_component import SpacyQuickUMLS nlp.add_pipe(quickumls_component) ``` ### Parameters - **nlp** (spacy.lang.en.English) - The spaCy language model. - **quickumls_fp** (string) - Path to the QuickUMLS installation. - **best_match** (boolean) - Optional - If True, return only non-overlapping matches. - **ignore_syntax** (boolean) - Optional - Use syntax-based heuristics. - **threshold** (float) - Optional - Minimum similarity score. - **similarity_name** (string) - Optional - Similarity measure (e.g., 'jaccard'). ### Request Example ```python import spacy from quickumls.spacy_component import SpacyQuickUMLS # Load a spaCy model nlp = spacy.load('en_core_web_sm') # Create QuickUMLS component quickumls_component = SpacyQuickUMLS( nlp, quickumls_fp='/path/to/quickumls/installation', best_match=True, ignore_syntax=False, threshold=0.7, similarity_name='jaccard' ) # Add to pipeline nlp.add_pipe(quickumls_component) # Process text doc = nlp('Patient complains of shortness of breath, chest pain, nausea, and vomiting.') # Access extracted concepts as entities for ent in doc.ents: print(f"Entity: {ent.text}") print(f"UMLS CUI: {ent.label_}") print(f"Similarity: {ent._.similarity:.3f}") print(f"Semantic Types: {ent._.semtypes}") print(f"Character span: {ent.start_char}-{ent.end_char}") print("---") ``` ### Response Example ``` Entity: shortness of breath UMLS CUI: C0013404 Similarity: 1.000 Semantic Types: {'T184'} Character span: 22-41 --- Entity: chest pain UMLS CUI: C0008031 Similarity: 1.000 Semantic Types: {'T184'} Character span: 43-53 --- ``` ``` -------------------------------- ### Integrate QuickUMLS with spaCy Source: https://context7.com/georgetown-ir-lab/quickumls/llms.txt Configures QuickUMLS as a custom spaCy pipeline component to automatically extract UMLS entities and metadata during document processing. ```python import spacy from quickumls.spacy_component import SpacyQuickUMLS nlp = spacy.load('en_core_web_sm') quickumls_component = SpacyQuickUMLS(nlp, quickumls_fp='/path/to/quickumls/installation', best_match=True, threshold=0.7, similarity_name='jaccard') nlp.add_pipe(quickumls_component) doc = nlp('Patient complains of shortness of breath, chest pain, nausea, and vomiting.') for ent in doc.ents: print(f"Entity: {ent.text}, CUI: {ent.label_}, Similarity: {ent._.similarity}") ``` -------------------------------- ### POST /match Source: https://context7.com/georgetown-ir-lab/quickumls/llms.txt Extracts biomedical concepts from a provided text string using the initialized QuickUMLS matcher. ```APIDOC ## POST /match ### Description Performs concept extraction on input text and returns a list of matched UMLS concepts. ### Method Python Method (matcher.match) ### Parameters #### Request Body - **text** (string) - Required - The medical text to process - **best_match** (boolean) - Optional - If true, returns only non-overlapping matches - **ignore_syntax** (boolean) - Optional - If true, disables syntax-based heuristics ### Response #### Success Response (200) - **ngram** (string) - The matched text segment - **cui** (string) - The UMLS Concept Unique Identifier - **term** (string) - The preferred term - **similarity** (float) - The similarity score - **semtypes** (set) - UMLS semantic types - **start** (int) - Start position in text - **end** (int) - End position in text ### Response Example [ { "ngram": "ulna", "cui": "C0041600", "term": "Ulna", "similarity": 1.0, "semtypes": ["T023"], "start": 4, "end": 8 } ] ``` -------------------------------- ### Extract and Filter Clinical Concepts Source: https://context7.com/georgetown-ir-lab/quickumls/llms.txt Demonstrates how to match clinical text against the UMLS database and filter the resulting concepts based on specific semantic types. ```python clinical_note = """ Patient presents with acute chest pain radiating to left arm. History of hypertension and type 2 diabetes mellitus. Prescribed metformin 500mg twice daily. """ results = matcher.match(clinical_note, best_match=True) diseases = [ match for match_group in results for match in match_group if 'T047' in match['semtypes'] ] print(f"Found {len(diseases)} disease mentions") ``` -------------------------------- ### Extract UMLS Concepts from Text Source: https://context7.com/georgetown-ir-lab/quickumls/llms.txt Uses the match() method to identify UMLS concepts within a string. The method returns detailed match information including CUIs, semantic types, and similarity scores, with options to control overlap handling and syntax heuristics. ```python from quickumls import QuickUMLS matcher = QuickUMLS('/path/to/quickumls/installation') # Basic concept extraction text = "The ulna has dislocated posteriorly from the trochlea of the humerus." matches = matcher.match(text) # Process results for match_group in matches: for match in match_group: print(f"Text: {match['ngram']}") print(f"UMLS CUI: {match['cui']}") print(f"Preferred Term: {match['term']}") print(f"Similarity: {match['similarity']:.3f}") print(f"Semantic Types: {match['semtypes']}") print(f"Position: {match['start']}-{match['end']}") print(f"Is Preferred: {match['preferred']}") print("---") # Get only best (non-overlapping) matches (default behavior) best_matches = matcher.match(text, best_match=True) # Get all overlapping candidates for analysis all_matches = matcher.match(text, best_match=False) # Disable syntax-based heuristics (uses simple token sequences) raw_matches = matcher.match(text, ignore_syntax=True) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.