public class ReasonerUtils extends Object
Utiliy class providing useful functionalities.
| Constructor and Description |
|---|
ReasonerUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
areDisjointTypes(SchemaConcept parent,
SchemaConcept child)
determines disjointness of parent-child types, parent defines the bound on the child
|
static <T extends SchemaConcept> |
compatibleRelationTypesWithRoles(Set<T> types,
SchemaConceptConverter<T> schemaConceptConverter)
NB: assumes MATCH semantics - all types and their subs are considered
compute the map of compatible
RelationshipTypes for a given set of Types
(intersection of allowed sets of relation types for each entry type) and compatible role types |
static Set<Role> |
compatibleRoles(Role parentRole,
Type parentType,
Set<Role> entryRoles)
NB: assumes MATCH semantics - all types and their subs are considered
|
static Set<Role> |
compatibleRoles(Type type,
Set<Role> relRoles) |
static void |
computeRoleCombinations(Set<Var> vars,
Set<Role> roles,
Map<Var,VarPattern> roleMap,
Set<Map<Var,VarPattern>> roleMaps)
compute all rolePlayer-roleType combinations complementing provided roleMap
|
static Rule |
createPropertyChainRule(String label,
RelationshipType relation,
Label fromRoleLabel,
Label toRoleLabel,
LinkedHashMap<RelationshipType,Pair<Label,Label>> chain,
GraknTx tx)
creates rule R(fromRole: x, toRole: xm) :- R1(fromRole: x, ...), , R2, ...
|
static Rule |
createReflexiveRule(String label,
RelationshipType relType,
Label fromRoleLabel,
Label toRoleLabel,
GraknTx tx)
create reflexive rule R(from: X, to: X) :- R(from: X,to: Y)
|
static Rule |
createSubPropertyRule(String label,
RelationshipType parent,
RelationshipType child,
Map<Label,Label> roleMappings,
GraknTx tx)
creates rule parent :- child
|
static Rule |
createTransitiveRule(String label,
RelationshipType relType,
Label fromRoleLabel,
Label toRoleLabel,
GraknTx tx)
create transitive
Rule R(from: X, to: Y) :- R(from: X,to: Z), R(from: Z, to: Y) |
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<Unifier> |
getUnifiersFromPermutations(List<Pair<Var,Var>> originalVars,
List<List<Pair<Var,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 <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 <T extends Predicate> |
predicatesCompatible(T parent,
T child,
boolean exact) |
static <T> Collection<T> |
subtract(Collection<T> a,
Collection<T> b) |
static Set<SchemaConcept> |
supers(SchemaConcept schemaConcept) |
static <T extends SchemaConcept> |
top(Set<T> schemaConcepts) |
static Type |
top(Type type) |
static boolean |
typesCompatible(SchemaConcept parent,
SchemaConcept child) |
static Unifier |
typeUnifier(Set<TypeAtom> childTypes,
Set<TypeAtom> parentTypes,
Unifier childParentUnifier) |
static Set<SchemaConcept> |
upstreamHierarchy(SchemaConcept concept) |
public 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 to@Nullable public 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<Pair<Var,Var>> originalVars, List<List<Pair<Var,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<SchemaConcept> supers(SchemaConcept schemaConcept)
schemaConcept - input typepublic static Set<SchemaConcept> upstreamHierarchy(SchemaConcept concept)
concept - which hierarchy should be consideredSchemaConcepts consisting of the provided SchemaConcept and all its supers including metapublic 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 SchemaConcept> com.google.common.collect.Multimap<RelationshipType,Role> compatibleRelationTypesWithRoles(Set<T> types, SchemaConceptConverter<T> schemaConceptConverter)
RelationshipTypes for a given set of Types
(intersection of allowed sets of relation types for each entry type) and compatible role typesT - type generictypes - for which the set of compatible RelationshipTypes is to be computedschemaConceptConverter - converter between SchemaConcept and relation type-role entriesRelationshipTypes and their corresponding Rolespublic static Set<Role> compatibleRoles(Role parentRole, Type parentType, Set<Role> entryRoles)
public static <T extends SchemaConcept> Set<T> top(Set<T> schemaConcepts)
schemaConcepts - entry setSchemaConcepts from within the provided set of Rolepublic static Type top(Type type)
type - for which top type is to be foundpublic static void computeRoleCombinations(Set<Var> vars, Set<Role> 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(String label, RelationshipType relType, Label fromRoleLabel, Label toRoleLabel, GraknTx tx)
Rule R(from: X, to: Y) :- R(from: X,to: Z), R(from: Z, to: Y)public static Rule createReflexiveRule(String label, RelationshipType relType, Label fromRoleLabel, Label toRoleLabel, GraknTx tx)
public static Rule createSubPropertyRule(String label, RelationshipType parent, RelationshipType child, Map<Label,Label> roleMappings, GraknTx tx)
label - the Label of the new Rule to createparent - RelationshipType of parentchild - RelationshipType of childroleMappings - map of corresponding Role namestx - for the Rule to be insertedRulepublic static Rule createPropertyChainRule(String label, RelationshipType relation, Label fromRoleLabel, Label toRoleLabel, LinkedHashMap<RelationshipType,Pair<Label,Label>> chain, GraknTx tx)
label - the Label of the new Rule to createrelation - head RelationshipTypefromRoleLabel - specifies the Role directionality of the head RelationshipTypetoRoleLabel - specifies the Role directionality of the head RelationshipTypechain - map containing ordered relation with their corresponding Role mappingstx - for the Rule to be insertedRulepublic static Unifier typeUnifier(Set<TypeAtom> childTypes, Set<TypeAtom> parentTypes, Unifier childParentUnifier)
childTypes - type atoms of child queryparentTypes - type atoms of parent querychildParentUnifier - unifier to unify child with parentpublic static boolean typesCompatible(SchemaConcept parent, SchemaConcept child)
parent - typechild - typepublic static <T extends Predicate> boolean predicatesCompatible(T parent, T child, boolean exact)
T - type genericparent - predicatechild - predicateexact - whether compatibility criterion should be exactpublic static boolean areDisjointTypes(SchemaConcept parent, SchemaConcept child)
parent - typechild - typepublic static <T> Collection<T> subtract(Collection<T> a, Collection<T> b)
T - collection typea - subtraction left operandb - subtraction right operandCopyright © 2017 Grakn Labs Ltd. All rights reserved.