Thanks to visit codestin.com
Credit goes to github.com

Skip to content
/ CASPER Public

A Clinical ASP-based Event Recognition System

License

yvoawk/CASPER

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

casper logo

CASPER (Clinical ASP-based Event Recognition)

CASPER badge ASP badge licence

CASPER leverages the expressive power of ASP to model medical knowledge and infer clinical events from sequences of raw observations. CASPER encodes rules that capture both expert knowledge and temporal patterns, enabling the identification of clinically meaningful eventsβ€”including their initiation and terminationβ€”even in the presence of imperfect data. An ASP solver (Clingo) is used to compute answer sets, which correspond to valid interpretations of events based on the encoded rules and the provided observations.

πŸ“‚ Repository Structure

CASPER/
β”œβ”€β”€ app/                              # Application directory
β”‚   └── lung_cancer/                  # Use case on lung cancer
β”‚       └── domain/                   # Folder for domain knowledge
β”‚       β”‚   └── atemporal_facts.lp    # Relevant atemporal domain knowledge file
β”‚       β”œβ”€β”€ facts/                    # Folder for facts
β”‚       β”‚   └── facts.lp              # Observation facts file
β”‚       └── user_parameters/          # Folder for event description
β”‚           β”œβ”€β”€ simple_event.lp       # Simple event definition file
β”‚           └── meta_event.lp         # Meta-event defintion file
β”œβ”€β”€ encoding/                         # CASPER system core
β”‚   β”œβ”€β”€ expansion.lp                  # Expansion technique encoding
β”‚   β”œβ”€β”€ linear.lp                     # Linear technique encoding
β”‚   β”œβ”€β”€ preference.lp                 # Preference encoding
β”‚   β”œβ”€β”€ repair.lp                     # Repair process encoding
β”‚   └── temporal_predicate.lp         # Temporal predicate encoding (Allen's interval algebra relations, Vilain's point interval algebra relations, etc.)
β”œβ”€β”€ execution/                        # Execution folder
β”‚   β”œβ”€β”€ parameters1.lp    
β”‚   β”œβ”€β”€ parameters2.lp            
β”‚   β”œβ”€β”€ parameters3.lp           
β”‚   └── run_casper.sh                 # CASPER execution script
β”œβ”€β”€ utils/                            # Utility folder
β”‚   β”œβ”€β”€ auxiliary.lp                  # Helper predicate
β”‚   β”œβ”€β”€ filter_fact.py                # Python function to filter observation facts  
β”‚   β”œβ”€β”€ process_answer.py             # Processeing meta-event script      
β”‚   └── python.lp                     # Embedded Python utility function
└── LICENSE                           # License file

πŸš€ Quick Start

CASPER has been tested using Clingo 5.8.0 and Python 3.12.9.

Prerequisites

An easy way to set up the required configuration is to use Conda to create an environment with the specified Python version and install Clingo.

πŸ”§ Recommended Setup (Using Conda)

You can easily configure the environment using Conda:

conda create -n casper-env python=3.12.9
conda activate casper-env
conda install -c conda-forge clingo=5.8.0

▢️ Basic Execution

An example application focused on lung cancer can be found in the ./app directory.

./execution/run_casper.sh --app=lung_cancer

The results will be output to a subfolder named after your application, located inside the results directory.

To view usage instructions or available options for CASPER, use the --help flag:

./execution/run_casper.sh --help

The output:

CASPER version 1.0.0
Usage: ./execution/run_casper.sh --app=APP_NAME [OPTIONS]

Required:
  --app=APP_NAME           Name of the app (must match a folder in ./app/ and not contain spaces)

Options:
  --repair=(yes|no)        Enable or disable repair mode (default: no)
  --timeline=MODE          Timeline mode (naive|preferred|cautious) (default: naive)
                           Note: 'preferred' & 'cautious' can only be used with --repair=yes
  --thread-N=N             Number of parallel threads (default: 1)
  --window=start-end       Time window for event recognition (format: start-end, both numeric)
                            Example: --window=1609459200-1609545600
                            Note: start must be less than end
  --unit=seconds           Units of the time used (default: seconds)
                           Other options: minutes, hours, days
  --verbose                Print configuration before execution
  --help                   Show helper message
  --version                Show CASPER version information

πŸ“¦ How to Add Your Application

To add a new application, create a folder named after your application (no spaces) in the ./app directory. This folder should follow the structure below:

./app/your_application_name/
β”œβ”€β”€ domain/
β”‚   └── atemporal_facts.lp
β”œβ”€β”€ facts/
β”‚   └── facts.lp
β”œβ”€β”€ user_parameters/
β”‚   β”œβ”€β”€ simple_event.lp
β”‚   └── meta_event.lp  (optional)

Folder Descriptions

  • domain/atemporal_facts.lp:
    Contains atemporal domain knowledge relevant to your application.

  • facts/facts.lp:
    Contains observation facts for your application.

  • user_parameters/simple_event.lp:
    Defines simple events, both persistent and non-persistent.

  • user_parameters/meta_event.lp (optional):
    Defines meta-events, if your application includes any.

🧠 Predicates

Observation

  • obs([observation_name], [Patient], ..., [Time]):
    Defines an observation fact at a given time.

Event Existence

  • exists([event_name], [Patient], [entity], [Time], [confidence_level]):
    Specifies the existence of a non-persistent simple event.

  • exists_pers([event_name], [Patient], [entity], [Time], [confidence_level]):
    Specifies the existence of a persistent simple event.

⚠️ Note:

  • The Time argument must be a non-null integer.
  • CASPER currently supports three levels of confidence for initiation: 1 (highest), 2, and 3 (lowest), and one level for termination.

Termination

  • terminates(...):
    Indicates the termination condition for both persistent and non-persistent simple events.
    Same format as exists and exists_pers.

Time Window

  • pt_window([event_name], [entity], [time_period]):
    Specifies the time window for identifying non-persistent simple events.

Event

  • event([ID], [event_name], [Patient], [Entity], ([Start], [End]), [Confidence]):

    Events capture clinically meaningful patterns identified from observations.

    ⚠️ Note: For instance, the system does not yet support dynamic arguments during event definition, requiring events to be defined in this fixed format.

Meta-Event

  • m_event([meta_event_name], [Patient], [Entity], ([Start], [End]), [Confidence]) or m_event([meta_event_name], [Patient], ([Start], [End]), [Confidence]):

    Meta-events represent higher-level or composite clinical events derived from at least one event (simple or meta- event), based on temporal relationships or logical conjunctions.

⏱ Temporal Reasoning

The temporal_predicate.lp file defines the core predicates that enable CASPER to reason about the relative positions of timepoints and intervals. These predicates are essential for expressing and evaluating complex temporal relations between events, such as those required to construct meta-events.

Interval Operations

  • intersection_of((T1,T2), (T3,T4), (T, T')):
    Computes the intersection (T, T') of two intervals.

    Example: intersection_of((T1,T2), (T3,T4), (T,T')) computes the intersection (T, T') of intervals (T1, T2) and (T3, T4).

  • union_of(...):
    Computes the union of two time intervals.

Allen's Relations

You can express temporal relations between intervals using Allen’s interval algebra. All 13 relations are supported (e.g., before, during, overlaps, etc.).

Vilain’s Relations (Subset)

Support for key point-based relations: p_before/2, p_after/2, p_during/2, p_starts/2, p_finishes/2.

πŸ”§ Helper Predicates

  • start([event_name], [Patient], [Time], [confidence_level]):
    Returns the earliest time point of a given event.

  • end([event_name], [Patient], [Time], [confidence_level]):
    Returns the latest time point of a given event.

  • persist_end([Patient], [Time]):
    Indicates that the end time of an event is ongoing.

πŸ› οΈ Support Features

In addition to event inference, CASPER provides built-in support for:

  • Confidence Propagation

    Ensures that the confidence of inferred (simple or meta) events reflects the lowest confidence among their supporting observations and sub-events.

    ⚠️ CASPER supports up to 3 confidence levels for existence conditions (1 = high, 2, 3 = low), and a single level (1) for termination.

  • Repair Option (Temporal Repair Only)

    CASPER includes a repair mechanism to handle overlapping event intervals of the same type, selecting the most appropriate segment(s) based on temporal consistency and confidence preferences.

    πŸ› οΈ This allows correction of conflicting temporal segments.

    ❌ Domain repair (e.g., resolving logical inconsistencies in background knowledge) is currently not supported.

  • Windowing

    CASPER also supports temporal windowing, allowing the system to restrict reasoning to a specific time interval.

  • Two Modes

    • preferred: keep only the highest-confidence, longest-valid segments

    • cautious: prioritize minimal but safe segments


πŸ“œ License

MIT License - See LICENSE.

πŸ“¬ Contact

For questions or contributions, please open an issue or contact the maintainers.

About

A Clinical ASP-based Event Recognition System

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published