Package com.articulate.sigma
Class KBcache
java.lang.Object
com.articulate.sigma.KBcache
- All Implemented Interfaces:
Serializable
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringAll the cached "child" relations of all transitive relations meaning the relations between all first arguments and the transitive closure of second arguments.static booleanErrors found during processing formulasDisjoint relationships which were explicitly defined in "partition", "disjoint", and "disjointDecomposition" expressionsbooleanParent relations from instances, including those that are transitive through (instance,instance) relations, such as subAttribute and subrelation.A temporary list of instances built during creation of the children map, in order to efficiently create the instances mapAll the cached "parent" relations of all transitive relations meaning the relations between all first arguments and the transitive closure of second arguments.Relation name keys and argument types with 0th arg always "" except in the case of Functions where the 0th arg will be the function range. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInstance(String child, String parent) voidAdd transitive relationships to instances in the "instances" mapvoidMain entry point for the class.voidFor each transitive relation, find its transitive closure.voidRecord instances and their explicitly defined parent classesvoidcache the transitive closure of disjoint relationsvoidvoidbuild a disjoint-relations-map which were explicitly defined in "partition", "exhaustiveDecomposition", "disjointDecomposition" and "disjoint" expressions;voidvoidFind all instancesvoidCompile the set of transitive relations that are between instancesvoidFor each transitive relation, find its transitive closure.voidDo a proper search for relations (including Functions), utilizing the formal definitions, rather than the convention of initial lower case letter.voidCache whether a given instance has a given parent class.voidDo a proper search for relations (including Functions), utilizing the formal definitions, rather than the convention of initial lower case letter.booleancheckDisjoint(KB kb, String c1, String c2) Check if given classes are disjointbooleancheckDisjoint(KB kb, Set<String> typeSet) check if there are any two types in typeSet are disjoint or not;booleanFind whether the given child has the given parent for the given transitive relation.voidExperimental: Utility method to clear the KBcachecollectArgFromFormulas(int arg, List<Formula> forms) Get the HashSet of the given arguments from an ArrayList of Formulas.voidBuild the argument type list for every relation.voidcopyNewPredFromVariableArity(String pred, String oldPred, int arity) Copy all relevant information from a VariableArityRelation to a new predicate that is a particular fixed arity.voidsince domains are collected before we know the instances of VariableArityRelation we need to go back and correct valencesvoidextendInstance(String term, String suffix) Add a new instance from an existing one plus a suffix, updating the cachesintAn ArrayList utility methodreturn child classes for the given cl from subclass expressions.return child classes for the given cl from subclass expressions.getChildRelations(String rel) return child relations for the given rel from subrelation expressions.getChildTerms(String cl, String rel) return child term for the given cl from rel expressions.getCommonChild(Set<String> t2) getCommonParent(String t1, String t2) Get all instances for the given input class For example, given the class "Nation", getInstancesForType(Nation) returns all instances, like "America", "Austria", "Albania", etc.return parent classes for the given cl from subclass expressions.return classes for the given instance cl.Get the range (return type) of a Function.getSignature(String rel) voidFind domain and domainSubclass definitions that impact a child relation.booleanreturn true if rel1 and rel2 are explicitly defined as disjoint relations; otherwise return false.booleanisInstanceOf(String i, String c) Returns true if i is an instance of c, else returns false.booleanisTransitivePredicate(String pred) static voidCommand line entry point for the classvoidmergeCaches(KBcache kbCacheIn) Experimental: Utility method to perform a merge with the KBcache inputmostSpecificParent(Set<String> p1) static voidstatic voidstatic voidshowChildren(KBcache nkbc) static voidshowChildrenOf(KBcache nkbc, String term) static voidInformational routine to show the sizes of the caches as a way to determine what might be the best sizes to pre-allocate, relative to the number of statements in a knowledge basestatic voidvoidAdd the cached formulas as though they were from a file.booleansubAttributeOf(String child, String parent) Find whether the given class is the subAttribute of the given parent class.booleansubclassOf(String child, String parent) Find whether the given class has the given parent class.booleantransInstOf(String child, String parent) Find whether the given instance has the given parent class.voidDeprecated.This is not needed since we have storeCacheAsFormulas()
-
Field Details
-
_cacheFileSuffix
- See Also:
-
intendedTransRels
-
debug
public static boolean debug -
errors
Errors found during processing formulas -
kb
-
relations
-
functions
-
predicates
-
transRels
-
instRels
-
instTransRels
-
parents
All the cached "parent" relations of all transitive relations meaning the relations between all first arguments and the transitive closure of second arguments. The external HashMap pairs relation name String keys to values that are the parent relationships. The interior HashMap is the set of terms and their transitive closure of parents. -
instanceOf
Parent relations from instances, including those that are transitive through (instance,instance) relations, such as subAttribute and subrelation. May not do what you think since the key is the child (instance) -
instances
-
insts
A temporary list of instances built during creation of the children map, in order to efficiently create the instances map -
children
All the cached "child" relations of all transitive relations meaning the relations between all first arguments and the transitive closure of second arguments. The external HashMap pairs relation name String keys to values that are the child relationships. The interior HashMap is the set of terms and their transitive closure of children. -
signatures
Relation name keys and argument types with 0th arg always "" except in the case of Functions where the 0th arg will be the function range. Variable arity relations may have a type for the last argument, which will be the type repeated for all extended arguments. Note that types can be functions, rather than just terms. Note that types (when there's a domainSubclass etc) are designated by a '+' appended to the class name. -
valences
-
explicitDisjoint
Disjoint relationships which were explicitly defined in "partition", "disjoint", and "disjointDecomposition" expressions -
disjoint
-
disjointRelations
-
initialized
public boolean initialized -
logOpValences
-
-
Constructor Details
-
KBcache
public KBcache()empty constructor for testing only -
KBcache
-
KBcache
-
-
Method Details
-
mergeCaches
Experimental: Utility method to perform a merge with the KBcache input- Parameters:
kbCacheIn- the incoming cache to merge
-
clearCaches
public void clearCaches()Experimental: Utility method to clear the KBcache -
getArity
An ArrayList utility method -
childOfP
Find whether the given child has the given parent for the given transitive relation.- Returns:
- false if they are equal
-
isInstanceOf
Returns true if i is an instance of c, else returns false.- Parameters:
i- A String denoting an instance.c- A String denoting a Class.- Returns:
- true or false.
-
transInstOf
Find whether the given instance has the given parent class. Include paths the have transitive relations between instances such as an Attribute that is a subAttribute of another instance, which in turn then is an instance of the given class. Return false if they are equal. -
subclassOf
Find whether the given class has the given parent class. -
subAttributeOf
Find whether the given class is the subAttribute of the given parent class. -
addInstance
-
extendInstance
Add a new instance from an existing one plus a suffix, updating the caches -
buildDirectInstances
public void buildDirectInstances()Record instances and their explicitly defined parent classes -
addTransitiveInstances
public void addTransitiveInstances()Add transitive relationships to instances in the "instances" map -
buildDisjointRelationsMap
public void buildDisjointRelationsMap() -
buildExplicitDisjointMap
public void buildExplicitDisjointMap()build a disjoint-relations-map which were explicitly defined in "partition", "exhaustiveDecomposition", "disjointDecomposition" and "disjoint" expressions; -
buildDisjointMap
public void buildDisjointMap()cache the transitive closure of disjoint relations -
checkDisjoint
check if there are any two types in typeSet are disjoint or not; -
checkDisjoint
Check if given classes are disjoint- Parameters:
kb- the current knowledge basec1- class #1c2- class #2- Returns:
- true if c1 and c2 are disjoint; otherwise return false. TODO: can find spurious type conflict when in scope of disjunctions
-
isExplicitDisjoint
public boolean isExplicitDisjoint(Map<String, Set<String>> explicitDisjointRelations, String c1, String c2) return true if rel1 and rel2 are explicitly defined as disjoint relations; otherwise return false. -
buildTransInstOf
public void buildTransInstOf()Cache whether a given instance has a given parent class. Include paths the have transitive relations between instances such as an Attribute that is a subAttribute of another instance, which in turn then is an instance of the given class. TODO: make sure that direct instances are recorded too -
correctValences
public void correctValences()since domains are collected before we know the instances of VariableArityRelation we need to go back and correct valences -
mostSpecificParent
- Returns:
- the most specific parent of a set of classes
-
getCommonParent
- Returns:
- the most specific parent of the two parameters or null if there is no common parent. TODO: Take into account that there are instances, classes, relations, and attributes,
-
getCommonChild
-
getParentClasses
return parent classes for the given cl from subclass expressions. -
getChildRelations
return child relations for the given rel from subrelation expressions. -
getChildClasses
return child classes for the given cl from subclass expressions. -
getChildTerms
return child term for the given cl from rel expressions. -
getChildInstances
return child classes for the given cl from subclass expressions. -
getParentClassesOfInstance
return classes for the given instance cl. For example, if we know (instance UnitedStates Nation), then getParentClassesOfInstances(UnitedStates) returns Nation and its super classes from subclass expressions. -
getInstancesForType
Get all instances for the given input class For example, given the class "Nation", getInstancesForType(Nation) returns all instances, like "America", "Austria", "Albania", etc. Follow instances through transitive relations if applicable from the set of [subAttribute, subrelation]. TODO: do we need a DownwardHeritableRelation so that this list doesn't need to be hardcoded? -
getSignature
-
getRange
Get the range (return type) of a Function.- Returns:
- null if argument is not a function
-
collectArgFromFormulas
Get the HashSet of the given arguments from an ArrayList of Formulas. -
buildTransitiveRelationsSet
public void buildTransitiveRelationsSet()Do a proper search for relations (including Functions), utilizing the formal definitions, rather than the convention of initial lower case letter. This means getting any instance of Relation tracing back through subclasses as well. -
isTransitivePredicate
-
buildRelationsSet
public void buildRelationsSet()Do a proper search for relations (including Functions), utilizing the formal definitions, rather than the convention of initial lower case letter. This means getting any instance of Relation tracing back through subclasses as well. -
buildFunctionsSet
public void buildFunctionsSet() -
buildInsts
public void buildInsts()Find all instances -
buildParents
public void buildParents()For each transitive relation, find its transitive closure. If rel is transitive, and (rel A B) and (rel B C) then the entry for rel is a HashMap where the key A has value ArrayList of {B,C}. -
buildChildren
public void buildChildren()For each transitive relation, find its transitive closure. If rel is transitive, and (rel A B) and (rel B C) then the entry for rel is a HashMap where the key A has value ArrayList of {B,C}. Note that this routine builds "up" from the leaves -
collectDomains
public void collectDomains()Build the argument type list for every relation. If the argument is a domain subclass, append a "+" to the argument type. If no domain is defined for the given relation and argument position, inherit it from the parent. If there is no argument type, send an error to the Sigma error list. Relation name keys and argument types with 0th arg always "" except for functions which will have the range type as their 0th argument public Map<String,List<String>> signatures = new HashMap<>(); -
writeCacheFile
Deprecated.This is not needed since we have storeCacheAsFormulas()Delete and writes the cache .kif file then call addConstituent() so that the file can be processed and loaded by the inference engine. -
storeCacheAsFormulas
public void storeCacheAsFormulas()Add the cached formulas as though they were from a file. There's no need to write the file since if it hasn't been created, it must be created new. If it has been created already, then it will be written out as part of the serialized info. -
inheritDomains
public void inheritDomains()Find domain and domainSubclass definitions that impact a child relation. If the type of an argument is less specific than the same type of a parent's argument, use that of the parent. -
buildInstTransRels
public void buildInstTransRels()Compile the set of transitive relations that are between instances -
buildCaches
public void buildCaches()Main entry point for the class. -
copyNewPredFromVariableArity
Copy all relevant information from a VariableArityRelation to a new predicate that is a particular fixed arity. Fill the signature from final argument type in the predicate -
variableArityType
- Returns:
- the type of the last argument to the given relation, which will be the type of all the expanded row variables
-
showState
-
showAll
-
showChildrenOf
-
showChildren
-
showSizes
Informational routine to show the sizes of the caches as a way to determine what might be the best sizes to pre-allocate, relative to the number of statements in a knowledge base -
printHelp
public static void printHelp() -
main
Command line entry point for the class- Parameters:
args- command line arguments
-