CASPER is an Answer Set Programming (ASP)βbased framework for inferring high-level temporal events from raw, timestamped observations. It integrates domain knowledge, temporal reasoning, and confidence propagation to identify event initiation and termination intervals, while explicitly handling imperfect data through a dedicated temporal repair pipeline.
CASPER/
βββ app/ # Clinical use-case applications
β βββ lung_cancer/
β βββ domain/
β β βββ atemporal_facts.lp
β βββ facts/
β β βββ facts.lp
β βββ user_parameters/
β βββ simple_event.lp
β βββ meta_event.lp
βββ encoding/ # Core ASP encodings
β βββ np_simple_event.lp
β βββ p_simple_event.lp
β βββ repair.lp
β βββ greedy_preference.lp
β βββ temporal_predicate.lp
β βββ ...
βββ execution/
β βββ parameters1.lp
β βββ parameters2.lp
β βββ parameters3.lp
β βββ run_casper.sh # Main entrypoint
βββ utils/
β βββ auxiliary.lp
β βββ filter_fact.py
β βββ process_answers.py
β βββ python.lp
βββ results/ # Generated outputs
βββ LICENSE
CASPER has been tested using Clingo 5.8.0 and Python 3.12.9.
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.
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.0An example application focused on lung cancer can be found in the ./app directory.
./execution/run_casper.sh --app=lung_cancerThe 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 --helpThe output:
CASPER version 1.0.3
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 temporal repair mode (default: no).
--timeline=<MODE> Timeline mode (`naive|preferred|cautious`, default: naive).
--thread-N=<N> Number of parallel threads (integer >= 1, default: 1).
--window=<start-end> Numeric epoch window filter for observations. (format: start-end, both numeric)
Example: --window=1609459200-1609545600
Note: start must be less than end
--unit=<seconds|minutes|hours|days> Time unit constant used by encodings (default: `seconds`).
--verbose Print execution configuration before execution.
--help Print usage text.
--version Print version information.
β οΈ Note:
preferredandcautiousrequire--repair=yes.- When
--repair=yesis set withoutpreferredorcautious, the script internally switches to aconsistentoutput timeline.
Simple events + meta-events (no repair):
./execution/run_casper.sh --app=lung_cancerRepair mode with preferred timeline:
./execution/run_casper.sh --app=lung_cancer --repair=yes --timeline=preferredRepair mode with cautious reasoning:
./execution/run_casper.sh --app=lung_cancer --repair=yes --timeline=cautiousRun with a time window and alternate unit:
./execution/run_casper.sh \
--app=lung_cancer \
--window=447072-447934 \
--unit=hours \
--verboseResults are written to:
results/<app>/<timeline>/results_<YYYY-MM-DD_HH-MM-SS>.json
Timeline subfolders are created automatically (naive, preferred, cautious, or consistent).
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)
-
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.
CASPER uses a set of core predicates to represent observations, events, and temporal relationships. These predicates are used across the encodings and should be familiar to users defining their own applications.
-
obs([observation_name], [Patient], ..., [Time]):
Defines an observation fact at a given time.β οΈ Death Observation Format: Patient death must be recorded exactly asobs(death, Patient, Time)so the encodings can correctly detect and propagate the death information.
-
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
Timeargument must be a non-null integer.
terminates(...):
Indicates the termination condition for both persistent and non-persistent simple events.
Same format asexistsandexists_pers.
pt_window([event_name], [entity], [time_period]):
Specifies the time window for identifying non-persistent simple events.
-
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.
-
m_event([meta_event_name], [Patient], [Entity], ([Start], [End]), [Confidence])orm_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.
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.
-
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.
You can express temporal relations between intervals using Allenβs interval algebra. All 13 relations are supported (e.g., before, during, overlaps, etc.).
Support for key point-based relations: p_before/2, p_after/2, p_during/2, p_starts/2, p_finishes/2.
-
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.
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.
-
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 (Clingo cautious reasoning): retain only segments that appear in all repairs, yielding minimal but guaranteed-safe intervals
-
π License
MIT License - See LICENSE.
π¬ Contact
For questions or contributions, please open an issue or contact the maintainers.
