public class ReasonerUtils extends Object
Utiliy class providing useful functionalities.
| Constructor and Description |
|---|
ReasonerUtils() |
| Modifier and Type | Method and Description |
|---|---|
static Var |
capture(Var var)
Capture a variable name, by prepending a constant to the name
|
static boolean |
checkTypesCompatible(Type parent,
Type child) |
static boolean |
checkTypesDisjoint(Type parent,
Type child) |
static void |
computeRoleCombinations(Set<Var> vars,
Set<RoleType> roles,
Map<Var,VarPattern> roleMap,
Set<Map<Var,VarPattern>> roleMaps)
compute all rolePlayer-roleType combinations complementing provided roleMap
|
static Rule |
createPropertyChainRule(RelationType relation,
TypeLabel fromRoleLabel,
TypeLabel toRoleLabel,
LinkedHashMap<RelationType,javafx.util.Pair<TypeLabel,TypeLabel>> chain,
GraknGraph graph)
creates rule R(fromRole: x, toRole: xm) :- R1(fromRole: x, ...), , R2, ...
|
static Rule |
createReflexiveRule(RelationType relType,
TypeLabel fromRoleLabel,
TypeLabel toRoleLabel,
GraknGraph graph)
create reflexive rule R(from: X, to: X) :- R(from: X,to: Y)
|
static Rule |
createSubPropertyRule(RelationType parent,
RelationType child,
Map<TypeLabel,TypeLabel> roleMappings,
GraknGraph graph)
creates rule parent :- child
|
static Rule |
createTransitiveRule(RelationType relType,
TypeLabel fromRoleLabel,
TypeLabel toRoleLabel,
GraknGraph graph)
create transitive rule R(from: X, to: Y) :- R(from: X,to: Z), R(from: Z, to: Y)
|
static <T extends Type> |
getCompatibleRelationTypesWithRoles(Set<T> types,
TypeConverter<T> typeConverter)
compute the map of compatible relation types for given types (intersection of allowed sets of relation types for each entry type)
and compatible role types
|
static Set<RoleType> |
getCompatibleRoleTypes(Type type,
Set<RoleType> relRoles)
Gets roletypes a given type can play in the provided relType relation type by performing
type intersection between type's playedRoles and relation's relates.
|
static IdPredicate |
getIdPredicate(Var typeVariable,
VarPatternAdmin typeVar,
Set<VarPatternAdmin> vars,
ReasonerQuery parent)
looks for an appropriate var property with a specified name among the vars and maps it to an IdPredicate,
covers both the cases when variable is and isn't user defined
|
static <T> List<List<T>> |
getListPermutations(List<T> entryList)
get all permutations of an entry list
|
static Set<Rule> |
getRules(GraknGraph graph) |
static Set<Type> |
getSuperTypes(Type type) |
static Type |
getTopType(Type type) |
static <T extends Type> |
getTopTypes(Set<T> types) |
static Set<Unifier> |
getUnifiersFromPermutations(List<Var> originalVars,
List<List<Var>> permutations)
get unifiers by comparing permutations with original variables
|
static IdPredicate |
getUserDefinedIdPredicate(Var typeVariable,
Set<VarPatternAdmin> vars,
ReasonerQuery parent)
looks for an appropriate var property with a specified name among the vars and maps it to an IdPredicate,
covers the case when specified variable name is user defined
|
static Set<ValuePredicate> |
getValuePredicates(Var valueVariable,
VarPatternAdmin valueVar,
Set<VarPatternAdmin> vars,
ReasonerQuery parent)
looks for appropriate var properties with a specified name among the vars and maps them to ValuePredicates,
covers both the case when variable is and isn't user defined
|
static boolean |
hasRules(GraknGraph graph) |
static boolean |
isCaptured(Var var)
Check if a variable has been captured
|
static <K,V> com.google.common.collect.Multimap<K,V> |
multimapIntersection(com.google.common.collect.Multimap<K,V> m1,
com.google.common.collect.Multimap<K,V> m2)
calculates map intersection by doing an intersection on key sets and accumulating the keys
|
static Var |
uncapture(Var var)
Uncapture a variable name, by removing a prepended constant
|
public static Set<Rule> getRules(GraknGraph graph)
graph - to be checked againstpublic static boolean hasRules(GraknGraph graph)
graph - to be checked againstpublic static Var capture(Var var)
var - the variable name to capturepublic static Var uncapture(Var var)
var - the variable name to uncapturepublic static boolean isCaptured(Var var)
var - the variable to checkpublic static IdPredicate getUserDefinedIdPredicate(Var typeVariable, Set<VarPatternAdmin> vars, ReasonerQuery parent)
typeVariable - variable name of interestvars - VarAdmins to look for propertiesparent - reasoner query the mapped predicate should belong topublic static IdPredicate getIdPredicate(Var typeVariable, VarPatternAdmin typeVar, Set<VarPatternAdmin> vars, ReasonerQuery parent)
typeVariable - variable name of interesttypeVar - VarPatternAdmin to look for in case the variable name is not user definedvars - VarAdmins to look for propertiesparent - reasoner query the mapped predicate should belong topublic static Set<ValuePredicate> getValuePredicates(Var valueVariable, VarPatternAdmin valueVar, Set<VarPatternAdmin> vars, ReasonerQuery parent)
valueVariable - variable name of interestvalueVar - VarPatternAdmin to look for in case the variable name is not user definedvars - VarAdmins to look for propertiesparent - reasoner query the mapped predicate should belong topublic static Set<Unifier> getUnifiersFromPermutations(List<Var> originalVars, List<List<Var>> permutations)
originalVars - original ordered variablespermutations - different permutations on the variablespublic static <T> List<List<T>> getListPermutations(List<T> entryList)
T - element typeentryList - entry list to generate permutations ofpublic static Set<Type> getSuperTypes(Type type)
type - input typepublic static Type getTopType(Type type)
type - for which top type is to be foundpublic static <T extends Type> Set<T> getTopTypes(Set<T> types)
types - entry type setpublic static Set<RoleType> getCompatibleRoleTypes(Type type, Set<RoleType> relRoles)
type - for which we want to obtain compatible roles it playsrelRoles - relation type of interestpublic static <K,V> com.google.common.collect.Multimap<K,V> multimapIntersection(com.google.common.collect.Multimap<K,V> m1,
com.google.common.collect.Multimap<K,V> m2)
K - map key typeV - map value typem1 - first operandm2 - second operandpublic static <T extends Type> com.google.common.collect.Multimap<RelationType,RoleType> getCompatibleRelationTypesWithRoles(Set<T> types, TypeConverter<T> typeConverter)
T - type generictypes - for which the set of compatible relation types is to be computed
//* @param typeMapper function mapping a type to the set of compatible relation typespublic static void computeRoleCombinations(Set<Var> vars, Set<RoleType> roles, Map<Var,VarPattern> roleMap, Set<Map<Var,VarPattern>> roleMaps)
vars - set of rolePlayersroles - set of roleTypesroleMap - initial rolePlayer-roleType roleMap to be complementedroleMaps - output set containing possible role mappings complementing the roleMap configurationpublic static Rule createTransitiveRule(RelationType relType, TypeLabel fromRoleLabel, TypeLabel toRoleLabel, GraknGraph graph)
relType - transitive relation typefromRoleLabel - from directional role type type labeltoRoleLabel - to directional role type type labelgraph - graph for the rule to be insertedpublic static Rule createReflexiveRule(RelationType relType, TypeLabel fromRoleLabel, TypeLabel toRoleLabel, GraknGraph graph)
relType - reflexive relation typefromRoleLabel - from directional role type type labeltoRoleLabel - to directional role type type labelgraph - graph for the rule to be insertedpublic static Rule createSubPropertyRule(RelationType parent, RelationType child, Map<TypeLabel,TypeLabel> roleMappings, GraknGraph graph)
parent - relation type of parentchild - relation type of childroleMappings - map of corresponding role type type namesgraph - graph for the rule to be insertedpublic static Rule createPropertyChainRule(RelationType relation, TypeLabel fromRoleLabel, TypeLabel toRoleLabel, LinkedHashMap<RelationType,javafx.util.Pair<TypeLabel,TypeLabel>> chain, GraknGraph graph)
relation - head relationfromRoleLabel - specifies the role directionality of the head relationtoRoleLabel - specifies the role directionality of the head relationchain - map containing ordered relation with their corresponding role mappingsgraph - graph for the rule to be insertedpublic static boolean checkTypesCompatible(Type parent, Type child)
parent - typechild - typeCopyright © 2017 Grakn Labs Ltd. All rights reserved.