public class ReasonerUtils extends Object
Utiliy class providing useful functionalities.
| Constructor and Description |
|---|
ReasonerUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
checkCompatible(OntologyConcept parent,
OntologyConcept child) |
static boolean |
checkDisjoint(OntologyConcept parent,
OntologyConcept child) |
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(RelationType relation,
Label fromRoleLabel,
Label toRoleLabel,
LinkedHashMap<RelationType,javafx.util.Pair<Label,Label>> chain,
GraknGraph graph)
creates rule R(fromRole: x, toRole: xm) :- R1(fromRole: x, ...), , R2, ...
|
static Rule |
createReflexiveRule(RelationType relType,
Label fromRoleLabel,
Label toRoleLabel,
GraknGraph graph)
create reflexive rule R(from: X, to: X) :- R(from: X,to: Y)
|
static Rule |
createSubPropertyRule(RelationType parent,
RelationType child,
Map<Label,Label> roleMappings,
GraknGraph graph)
creates rule parent :- child
|
static Rule |
createTransitiveRule(RelationType relType,
Label fromRoleLabel,
Label toRoleLabel,
GraknGraph graph)
create transitive rule R(from: X, to: Y) :- R(from: X,to: Z), R(from: Z, to: Y)
|
static <T extends OntologyConcept> |
getCompatibleRelationTypesWithRoles(Set<T> types,
OntologyConceptConverter<T> ontologyConceptConverter)
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<Role> |
getCompatibleRoleTypes(Type type,
Set<Role> 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 <T extends OntologyConcept> |
getOntologyConcepts(Set<T> ontologyConcepts) |
static Set<Rule> |
getRules(GraknGraph graph) |
static Set<OntologyConcept> |
getSupers(OntologyConcept ontologyConcept) |
static Type |
getTopType(Type type) |
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 <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
|
public static Set<Rule> getRules(GraknGraph graph)
graph - to be checked againstpublic static boolean hasRules(GraknGraph graph)
graph - to be checked againstpublic 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<OntologyConcept> getSupers(OntologyConcept ontologyConcept)
ontologyConcept - input typepublic static Type getTopType(Type type)
type - for which top type is to be foundpublic static <T extends OntologyConcept> Set<T> getOntologyConcepts(Set<T> ontologyConcepts)
ontologyConcepts - entry setOntologyConcept from within the provided set of Rolepublic static Set<Role> getCompatibleRoleTypes(Type type, Set<Role> 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 OntologyConcept> com.google.common.collect.Multimap<RelationType,Role> getCompatibleRelationTypesWithRoles(Set<T> types, OntologyConceptConverter<T> ontologyConceptConverter)
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<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(RelationType relType, Label fromRoleLabel, Label 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, Label fromRoleLabel, Label 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<Label,Label> 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, Label fromRoleLabel, Label toRoleLabel, LinkedHashMap<RelationType,javafx.util.Pair<Label,Label>> 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 checkCompatible(OntologyConcept parent, OntologyConcept child)
parent - typechild - typepublic static boolean checkDisjoint(OntologyConcept parent, OntologyConcept child)
parent - typechild - typeCopyright © 2017 Grakn Labs Ltd. All rights reserved.