public class Utility extends Object
Utiliy class providing useful
| Modifier and Type | Field and Description |
|---|---|
static java.util.function.Function<RoleType,Set<RelationType>> |
roleToRelationTypes |
static java.util.function.Function<Type,Set<RelationType>> |
typeToRelationTypes |
| Constructor and Description |
|---|
Utility() |
| Modifier and Type | Method and Description |
|---|---|
static VarName |
capture(VarName var)
Capture a variable name, by prepending a constant to the name
|
static boolean |
checkTypesCompatible(Type parent,
Type child) |
static void |
computeRoleCombinations(Set<VarName> vars,
Set<RoleType> roles,
Map<VarName,Var> roleMap,
Set<Map<VarName,Var>> roleMaps)
compute all rolePlayer-roleType combinations complementing provided roleMap
|
static VarName |
createFreshVariable(Set<VarName> vars,
VarName var)
generate a fresh variable avoiding global variables and variables from the same query
|
static Rule |
createPropertyChainRule(RelationType relation,
TypeName fromRoleName,
TypeName toRoleName,
LinkedHashMap<RelationType,javafx.util.Pair<TypeName,TypeName>> chain,
GraknGraph graph)
creates rule R(fromRole: x, toRole: xm) :- R1(fromRole: x, ...), , R2, ...
|
static Rule |
createReflexiveRule(RelationType relType,
GraknGraph graph)
create reflexive rule R(from: X, to: X) :- R(from: X,to: Y)
|
static Rule |
createSubPropertyRule(RelationType parent,
RelationType child,
Map<TypeName,TypeName> roleMappings,
GraknGraph graph)
creates rule parent :- child
|
static Rule |
createTransitiveRule(RelationType relType,
TypeName fromRoleName,
TypeName toRoleName,
GraknGraph graph)
create transitive rule R(from: X, to: Y) :- R(from: X,to: Z), R(from: Z, to: Y)
|
static <T extends Type> |
getCompatibleRelationTypes(Set<T> types,
java.util.function.Function<T,Set<RelationType>> typeMapper) |
static Set<RoleType> |
getCompatibleRoleTypes(Type type,
Type relType)
Gets roletypes a given type can play in the provided relType relation type by performing
type intersection between type's playedRoles and relation's hasRoles.
|
static IdPredicate |
getIdPredicate(VarName typeVariable,
VarAdmin typeVar,
Set<VarAdmin> 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 RoleType |
getNonMetaTopRole(RoleType role) |
static Set<Map<VarName,VarName>> |
getUnifiersFromPermutations(List<VarName> originalVars,
List<List<VarName>> permutations)
get unifiers by comparing permutations with original variables
|
static IdPredicate |
getUserDefinedIdPredicate(VarName typeVariable,
Set<VarAdmin> 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<Predicate> |
getValuePredicates(VarName valueVariable,
VarAdmin valueVar,
Set<VarAdmin> 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 |
isCaptured(VarName var)
Check if a variable has been captured
|
static void |
printAnswers(Set<Map<String,Concept>> answers)
Provides more readable answer output.
|
static VarName |
uncapture(VarName var)
Uncapture a variable name, by removing a prepended constant
|
public static final java.util.function.Function<RoleType,Set<RelationType>> roleToRelationTypes
public static final java.util.function.Function<Type,Set<RelationType>> typeToRelationTypes
public static VarName capture(VarName var)
var - the variable name to capturepublic static VarName uncapture(VarName var)
var - the variable name to uncapturepublic static boolean isCaptured(VarName var)
var - the variable to checkpublic static IdPredicate getUserDefinedIdPredicate(VarName typeVariable, Set<VarAdmin> vars, ReasonerQuery parent)
typeVariable - variable name of interestvars - VarAdmins to look for propertiesparent - reasoner query the mapped predicate should belong topublic static IdPredicate getIdPredicate(VarName typeVariable, VarAdmin typeVar, Set<VarAdmin> vars, ReasonerQuery parent)
typeVariable - variable name of interesttypeVar - VarAdmin 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<Predicate> getValuePredicates(VarName valueVariable, VarAdmin valueVar, Set<VarAdmin> vars, ReasonerQuery parent)
valueVariable - variable name of interestvalueVar - VarAdmin 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 void printAnswers(Set<Map<String,Concept>> answers)
answers - set of answers to be printedpublic static Set<Map<VarName,VarName>> getUnifiersFromPermutations(List<VarName> originalVars, List<List<VarName>> 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<RoleType> getCompatibleRoleTypes(Type type, Type relType)
type - for which we want to obtain compatible roles it playsrelType - relation type of interestpublic static <T extends Type> Set<RelationType> getCompatibleRelationTypes(Set<T> types, java.util.function.Function<T,Set<RelationType>> typeMapper)
public static void computeRoleCombinations(Set<VarName> vars, Set<RoleType> roles, Map<VarName,Var> roleMap, Set<Map<VarName,Var>> 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 VarName createFreshVariable(Set<VarName> vars, VarName var)
vars - vars to be avoidedvar - variable to be generated a fresh replacementpublic static Rule createTransitiveRule(RelationType relType, TypeName fromRoleName, TypeName toRoleName, GraknGraph graph)
relType - transitive relation typefromRoleName - from directional role type type nametoRoleName - to directional role type type namegraph - graph for the rule to be insertedpublic static Rule createReflexiveRule(RelationType relType, GraknGraph graph)
relType - reflexive relation typegraph - graph for the rule to be insertedpublic static Rule createSubPropertyRule(RelationType parent, RelationType child, Map<TypeName,TypeName> 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, TypeName fromRoleName, TypeName toRoleName, LinkedHashMap<RelationType,javafx.util.Pair<TypeName,TypeName>> chain, GraknGraph graph)
relation - head relationfromRoleName - specifies the role directionality of the head relationtoRoleName - 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 RoleType getNonMetaTopRole(RoleType role)
role - in questionCopyright © 2017 Grakn Labs Ltd. All rights reserved.