public class AtomCache extends Object
GroundAtoms
so that a Database
always returns the same object for a GroundAtom.
Also serves as the factory for GroundAtoms for a Database.
This class is not thread-safe, but does have some guarentees.
All write operations (remove and instantiation) are safe.
Read operations do not attempt any thread safety because of their heavy use.
However, any call to getCachedAtom() returning a null should be follwed up with an instantiation call.
These calls are thread-safe and will check the cache before creation.Modifier and Type | Field and Description |
---|---|
protected Map<QueryAtom,GroundAtom> |
cache |
protected Database |
db |
Constructor and Description |
---|
AtomCache(Database db)
Constructs a new AtomCache for a Database.
|
Modifier and Type | Method and Description |
---|---|
GroundAtom |
getCachedAtom(QueryAtom atom)
Checks whether a
GroundAtom matching a QueryAtom exists in the
cache and returns it if so. |
Iterable<GroundAtom> |
getCachedAtoms() |
Iterable<GroundAtom> |
getCachedAtoms(Predicate predicate)
Returns all GroundAtoms in this AtomCache with a given Predicate.
|
Iterable<ObservedAtom> |
getCachedObservedAtoms() |
Iterable<RandomVariableAtom> |
getCachedRandomVariableAtoms() |
ObservedAtom |
instantiateObservedAtom(Predicate predicate,
Constant[] args,
double value)
Instantiates an ObservedAtom and stores it in this AtomCache.
|
RandomVariableAtom |
instantiateRandomVariableAtom(StandardPredicate predicate,
Constant[] args,
double value)
Instantiates a RandomVariableAtom and stores it in this AtomCache.
|
boolean |
removeCachedAtom(QueryAtom qAtom)
Removes an atom from the AtomCache
|
protected final Database db
protected final Map<QueryAtom,GroundAtom> cache
public AtomCache(Database db)
db
- the Database for which GroundAtoms will be cachedpublic GroundAtom getCachedAtom(QueryAtom atom)
GroundAtom
matching a QueryAtom exists in the
cache and returns it if so.atom
- QueryAtom with all GroundTerms
public Iterable<GroundAtom> getCachedAtoms()
public Iterable<GroundAtom> getCachedAtoms(Predicate predicate)
predicate
- the Predicate of Atoms to returnpublic boolean removeCachedAtom(QueryAtom qAtom)
qAtom
- the Atom to removepublic Iterable<ObservedAtom> getCachedObservedAtoms()
public Iterable<RandomVariableAtom> getCachedRandomVariableAtoms()
public ObservedAtom instantiateObservedAtom(Predicate predicate, Constant[] args, double value)
Database
.
To retrieve a GroundAtom, all others should use Database.getAtom()
or AtomManager.getAtom().
Further, this method should only be called after ensuring that the Atom
is not already in this AtomCache using getCachedAtom(QueryAtom)
.predicate
- the Predicate of the Atomargs
- the arguments to this Atomvalue
- the Atom's truth valuepublic RandomVariableAtom instantiateRandomVariableAtom(StandardPredicate predicate, Constant[] args, double value)
Database
.
To retrieve a GroundAtom, all others should use Database.getAtom()
or AtomManager.getAtom().
Further, this method should only be called after ensuring that the Atom
is not already in this AtomCache using getCachedAtom(QueryAtom)
.predicate
- the Predicate of the Atomargs
- the arguments to this Atomvalue
- the Atom's truth valueCopyright © 2018 University of California, Santa Cruz. All rights reserved.