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,VarAdmin> 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,
String fromRoleName,
String toRoleName,
LinkedHashMap<RelationType,javafx.util.Pair<String,String>> 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<String,String> roleMappings,
GraknGraph graph)
creates rule parent :- child
|
static Rule |
createTransitiveRule(RelationType relType,
String fromRoleName,
String 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 Set<RoleType> |
getNonMetaSuperRoleTypes(RoleType role)
For a given role returns all its non-meta super roles.
|
static RoleType |
getNonMetaTopRole(RoleType role) |
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 <T> Set<T> |
subtractSets(Set<T> A,
Set<T> B) |
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 void printAnswers(Set<Map<String,Concept>> answers)
answers - set of answers to be printedpublic 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,VarAdmin> 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, String fromRoleName, String 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<String,String> 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, String fromRoleName, String toRoleName, LinkedHashMap<RelationType,javafx.util.Pair<String,String>> 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 Set<RoleType> getNonMetaSuperRoleTypes(RoleType role)
role - in questionpublic static RoleType getNonMetaTopRole(RoleType role)
role - in questionpublic static boolean checkTypesCompatible(Type parent, Type child)
parent - typechild - typeCopyright © 2017 Grakn Labs Ltd. All rights reserved.