public static final class HGQuery.hg extends Object
This class serves as a namespace to a set of syntactically concise functions for constructing HyperGraph query conditions and performing HyperGraph queries. With a Java 5+ compiler, you can import the class into your file's namespace and build HG condition with a much simpler syntax than constructing the expression tree explicitly. For example:
...other imports ...
import org.hypergraphdb.HGQuery.hg;
public void f(HyperGraph graph)
{
// find all link with weight > 1.5
HGSearchResult rs = graph.find(hg.and(hg.type(MyLink.class), hg.gt("weight", 1.5)));
}
or, even more concisely, if there is no naming conflict, import all the function names directly:
...other imports ...
import org.hypergraphdb.HGQuery.hg.*;
public void f(HyperGraph graph)
{
// find all link with weight > 1.5
HGSearchResult rs = graph.find(and(type(MyLink.class), gt("weight", 1.5)));
}
In addition, several methods names get*
and find*
will
execute queries and return their results in the form of individual objects or Java
collections, thus saving you from the burden of paying attention to always properly
close result sets.
Constructor and Description |
---|
HGQuery.hg() |
Modifier and Type | Method and Description |
---|---|
static HGHandle |
addUnique(HyperGraph graph,
Object instance,
Class<?> javaClass,
HGQueryCondition condition)
Add a new atom of a given type only if there's no atom matching the passed in
HGQueryCondition . |
static HGHandle |
addUnique(HyperGraph graph,
Object instance,
HGHandle typeHandle,
HGQueryCondition condition)
Add a new atom of a given type only if there's no atom matching the passed in
HGQueryCondition . |
static HGHandle |
addUnique(HyperGraph graph,
Object instance,
HGQueryCondition condition)
Add the given instance as an atom in the graph if and only if no atoms
match the passed in
HGQueryCondition |
static HGQueryCondition |
all()
Return a condition that will yield all atoms in the graph.
|
static And |
and(HGQueryCondition... clauses)
Return a conjunction (logical
and ) of conditions - atoms in the result set will have
to match all condition in the parameter list. |
static HGHandle |
anyHandle()
Return a special handle indicating a "don't care" in a condition expression (e.g.
|
static HGQueryCondition |
apply(Mapping<?,?> m,
HGQueryCondition c)
Return a "condition" that transforms the result set by applying an arbitrary
Mapping to each
element. |
static ArityCondition |
arity(int i)
Return a condition constraining the query result set to being links with the specified arity (number
of targets).
|
static ArityCondition |
arity(Ref<Integer> i)
Return a condition constraining the query result set to being links with the specified arity (number
of targets).
|
static HGHandle |
assertAtom(HyperGraph graph,
Object instance)
Return
assertAtom(graph, instance, false) . |
static HGHandle |
assertAtom(HyperGraph graph,
Object instance,
boolean ignoreValue)
Return the atom handle if
instance is already a loaded atom in the cache. |
static HGHandle |
assertAtom(HyperGraph graph,
Object instance,
HGHandle type)
Return
assertAtom(graph, instance, type, false) . |
static HGHandle |
assertAtom(HyperGraph graph,
Object instance,
HGHandle type,
boolean ignoreValue)
Add a new atom to the specified graph only if it is not already there.
|
static BFSCondition |
bfs(HGHandle start)
Return a condition whose result set is the breadth first traversal of the graph
starting a given atom.
|
static BFSCondition |
bfs(HGHandle start,
HGAtomPredicate lp,
HGAtomPredicate sp)
Return a condition whose result set is the breadth first traversal of the graph
starting a given atom.
|
static BFSCondition |
bfs(HGHandle start,
HGAtomPredicate lp,
HGAtomPredicate sp,
boolean returnPreceding,
boolean returnSucceeding)
Return a condition whose result set is the breadth first traversal of the graph
starting a given atom.
|
static BFSCondition |
bfs(Ref<HGHandle> start)
Return a condition whose result set is the breadth first traversal of the graph
starting a given atom.
|
static BFSCondition |
bfs(Ref<HGHandle> start,
HGAtomPredicate lp,
HGAtomPredicate sp)
Return a condition whose result set is the breadth first traversal of the graph
starting a given atom.
|
static BFSCondition |
bfs(Ref<HGHandle> start,
HGAtomPredicate lp,
HGAtomPredicate sp,
boolean returnPreceding,
boolean returnSucceeding)
Return a condition whose result set is the breadth first traversal of the graph
starting a given atom.
|
static <T> Ref<T> |
constant(T value)
Create a new constant reference.
|
static SubgraphContainsCondition |
contains(HGHandle atom)
Return a condition constraining the result set to atoms that are instances of
HGSubgraph and containing the specified atom. |
static long |
count(HGQuery<?> query)
Count the result set from executing the given query.
|
static long |
count(HyperGraph graph,
HGQueryCondition cond)
Count the number of atoms that match the query condition parameter.
|
static <T> Mapping<HGHandle,T> |
deref(HyperGraph graph)
|
static HGQueryCondition |
deref(HyperGraph graph,
HGQueryCondition condition)
Short for
hg.apply(hg.deref(graph), condition) - assuming the condition
parameter yields a result set of HGHandle s, the returned condition will yield a result set
of atoms loaded from the graph parameter. |
static DFSCondition |
dfs(HGHandle start)
Return a condition whose result set is the depth first traversal of the graph
starting with a given atom.
|
static DFSCondition |
dfs(HGHandle start,
HGAtomPredicate linkPredicate,
HGAtomPredicate siblingPredicate)
Return a condition whose result set is the depth first traversal of the graph
starting with a given atom.
|
static DFSCondition |
dfs(HGHandle start,
HGAtomPredicate linkPredicate,
HGAtomPredicate siblingPredicate,
boolean returnPreceeding,
boolean returnSucceeding)
Return a condition whose result set is the depth first traversal of the graph
starting a given atom.
|
static DFSCondition |
dfs(Ref<HGHandle> start)
Return a condition whose result set is the depth first traversal of the graph
starting with a given atom.
|
static DFSCondition |
dfs(Ref<HGHandle> start,
HGAtomPredicate linkPredicate,
HGAtomPredicate siblingPredicate)
Return a condition whose result set is the depth first traversal of the graph
starting with a given atom.
|
static DFSCondition |
dfs(Ref<HGHandle> start,
HGAtomPredicate linkPredicate,
HGAtomPredicate siblingPredicate,
boolean returnPreceeding,
boolean returnSucceeding)
Return a condition whose result set is the depth first traversal of the graph
starting a given atom.
|
static DisconnectedPredicate |
disconnected()
Return an atom predicate constraining the result set to atoms that are not connected
to other atoms, i.e.
|
static AtomValueCondition |
eq(Object x)
Return a condition constraining resulting atoms to atoms whose value is equal to
the passed in
x parameter. |
static AtomValueCondition |
eq(Ref<Object> x)
Return a condition constraining resulting atoms to atoms whose value is equal to
the passed in
x Ref parameter. |
static AtomPartCondition |
eq(String path,
Object x)
Return a condition constraining the result to atoms of some
HGCompositeType and having
a part (e.g. |
static AtomPartCondition |
eq(String path,
Ref<Object> x)
See
eq(String, Object) . |
static <T> List<T> |
findAll(HGQuery<T> query)
Execute the given query, put all the elements from the result set in a
List
and return that List |
static <T> List<T> |
findAll(HyperGraph graph,
HGQueryCondition condition)
Run a query based on the specified condition and put all
HGHandle s
from the result set into a java.util.List . |
static <T> T |
findOne(HyperGraph graph,
HGQueryCondition condition)
Run a query based on the passed in condition.
|
static <T> List<T> |
getAll(HGQuery<HGHandle> query)
Execute the given query, put all atom instances
from the result set into a
java.util.List . |
static <T> List<T> |
getAll(HyperGraph graph,
HGQueryCondition condition)
Run a query based on the specified condition and put all atom instances
from the result set into a
java.util.List . |
static <T> T |
getOne(HyperGraph graph,
HGQueryCondition condition)
Run a query based on the passed in condition.
|
static AtomValueCondition |
gt(Object x)
Return a condition constraining resulting atoms to atoms whose value is greater than
the passed in
x parameter. |
static AtomValueCondition |
gt(Ref<Object> x)
Return a condition constraining resulting atoms to atoms whose value is greater than
the passed in
x Ref parameter. |
static AtomPartCondition |
gt(String path,
Object x)
Return a condition constraining the result to atoms of some
HGCompositeType and having
a part (e.g. |
static AtomPartCondition |
gt(String path,
Ref<Object> x)
See
gt(String, Object) . |
static AtomValueCondition |
gte(Object x)
Return a condition constraining resulting atoms to atoms whose value is greater than equal to
the passed in
x parameter. |
static AtomValueCondition |
gte(Ref<Object> x)
Return a condition constraining resulting atoms to atoms whose value is greater than equal to
the passed in
x Ref parameter. |
static AtomPartCondition |
gte(String path,
Object x)
Return a condition constraining the result to atoms of some
HGCompositeType and having
a part (e.g. |
static AtomPartCondition |
gte(String path,
Ref<Object> x)
See
gte(String, Object) . |
static HGQueryCondition |
guessUniquenessCondition(HyperGraph graph,
Object instance)
Construct a
HGQueryCondition that uniquely identifies an atom based on
the passed in Object instance. |
static IncidentCondition |
incident(HGHandle atomHandle)
Return a condition constraining the result to links to a specific atom.
|
static IncidentCondition |
incident(Ref<?> atomHandle) |
static PositionedIncidentCondition |
incidentAt(HGHandle target,
int position) |
static PositionedIncidentCondition |
incidentAt(HGHandle target,
int lowerBound,
int upperBound) |
static PositionedIncidentCondition |
incidentAt(Ref<HGHandle> target,
int position) |
static PositionedIncidentCondition |
incidentAt(Ref<HGHandle> target,
Ref<Integer> lowerBound,
Ref<Integer> upperBound)
Return a condition constraining the query result set to links pointing to a target atom
positioned within a predetermined range in the link tuple.
|
static PositionedIncidentCondition |
incidentNotAt(HGHandle target,
int position) |
static PositionedIncidentCondition |
incidentNotAt(HGHandle target,
int lowerBound,
int upperBound) |
static PositionedIncidentCondition |
incidentNotAt(Ref<HGHandle> target,
int position) |
static PositionedIncidentCondition |
incidentNotAt(Ref<HGHandle> target,
Ref<Integer> lowerBound,
Ref<Integer> upperBound)
Same as {@link hg#incidentAt(Ref, Ref, Ref) except uses the complement of the specified range.
|
static IsCondition |
is(HGHandle atomHandle)
Return the "identity" condition that evaluates to true for a specific handle.
|
static <T> boolean |
isVar(Ref<T> ref)
|
static LinkCondition |
link(Collection<HGHandle> C)
Return a condition constraining the query result set to links pointing to a target set
of atoms.
|
static LinkCondition |
link(HGHandle... h)
Return a condition constraining the query result set to links pointing to a target set
of atoms.
|
static LinkCondition |
link(HGLink link)
Return a condition constraining the query result set to links pointing to a target set
of atoms.
|
static LinkCondition |
link(Ref<HGHandle>... h)
|
static Mapping<HGLink,HGHandle> |
linkProjection(int targetPosition)
Return a
Mapping that takes a link atom and returns a target at the given position. |
static Mapping<HGLink,HGHandle> |
linkProjection(Ref<Integer> targetPosition)
Return a
Mapping that takes a link atom and returns a target at the given position. |
static AtomValueCondition |
lt(Object x)
Return a condition constraining resulting atoms to atoms whose value is less than
the passed in
x parameter. |
static AtomValueCondition |
lt(Ref<Object> x)
Return a condition constraining resulting atoms to atoms whose value is less than
the passed in
x Ref parameter. |
static AtomPartCondition |
lt(String path,
Object x)
Return a condition constraining the result to atoms of some
HGCompositeType and having
a part (e.g. |
static AtomPartCondition |
lt(String path,
Ref<Object> x)
See
lt(String, Object) . |
static AtomValueCondition |
lte(Object x)
Return a condition constraining resulting atoms to atoms whose value is less than or equal to
the passed in
x parameter. |
static AtomValueCondition |
lte(Ref<Object> x)
Return a condition constraining resulting atoms to atoms whose value is less than or equal to
the passed in
x Ref parameter. |
static AtomPartCondition |
lte(String path,
Object x)
Return a condition constraining the result to atoms of some
HGCompositeType and having
a part (e.g. |
static AtomPartCondition |
lte(String path,
Ref<Object> x)
See
lte(String, Object) . |
static <T> HGQuery<T> |
make(Class<T> type,
HyperGraph graph) |
static AtomValueRegExPredicate |
matches(Pattern pattern)
Return a condition that matches a regular expression pattern against the string value of an atom.
|
static AtomValueRegExPredicate |
matches(String pattern)
Return a condition that matches a regular expression pattern against the string value of an atom.
|
static AtomPartRegExPredicate |
matches(String path,
Pattern pattern)
Return a condition that matches a regular expression pattern against the string value of
an atom's projection (property) along the given path.
|
static AtomPartRegExPredicate |
matches(String path,
String pattern)
Return a condition that matches a regular expression pattern against the string value of
an atom's projection (property) along the given path.
|
static SubgraphMemberCondition |
memberOf(HGHandle subgraphHandle)
Return a condition constraining the result set to atoms that are members of the
specified subgraph.
|
static Not |
not(HGAtomPredicate predicate)
Return the negation of an
HGAtomPredicate . |
static Or |
or(HGQueryCondition... clauses)
Return a disjunction (logical
or ) of conditions - atoms in the result set will have
to match at least one of the conditions in the parameter list. |
static OrderedLinkCondition |
orderedLink(HGHandle... h)
Return a condition constraining the query result set to being ordered links of a certain
form.
|
static OrderedLinkCondition |
orderedLink(List<HGHandle> L)
Return a condition constraining the query result set to being ordered links of a certain
form.
|
static OrderedLinkCondition |
orderedLink(Ref<HGHandle>... h)
Return a condition constraining the query result set to being ordered links of a certain
form.
|
static AtomPartCondition |
part(String path,
Object value,
ComparisonOperator op)
Return a condition constraining the result to atoms of some
HGCompositeType and having
a certain part (e.g. |
static AtomPartCondition |
part(String path,
Ref<Object> value,
ComparisonOperator op)
|
static SubsumedCondition |
subsumed(HGHandle general)
Return a condition constraining the result set to atoms more specific than the passed in
general parameter. |
static SubsumedCondition |
subsumed(Ref<HGHandle> general)
Return a condition constraining the result set to atoms more specific than the passed in
general reference parameter. |
static SubsumesCondition |
subsumes(HGHandle specific)
Return a condition constraining the result set to atoms more general than the passed in
specific parameter. |
static TargetCondition |
target(HGHandle linkHandle)
Return a query condition that constraints the result set to atoms that are targets to a specific link.
|
static TargetCondition |
target(Ref<HGHandle> linkHandle)
|
static Mapping<HGHandle,HGHandle> |
targetAt(HyperGraph graph,
int targetPosition)
Return a
Mapping that given a handle to a link will return the target (handle) at the specified
target position. |
static AtomTypeCondition |
type(Class<?> clazz)
Return a
HGQueryCondition constraining the type of the result
to the type corresponding to the Java class clazz . |
static AtomTypeCondition |
type(HGHandle typeHandle)
Return a
HGQueryCondition constraining the type of the result
to the type identified by typeHandle . |
static AtomTypeCondition |
type(Ref<?> type)
|
static TypePlusCondition |
typePlus(Class<?> clazz)
Return a
HGQueryCondition constraining the type of the result
to the type corresponding to the Java class clazz and all its sub-types. |
static TypePlusCondition |
typePlus(HGHandle h)
Return a
HGQueryCondition constraining the type of the result
to the type identified by typeHandle and all its sub-types. |
static AtomValueCondition |
value(Object value,
ComparisonOperator op)
Return a condition that constraints resulting atoms by a specific value and
ComparisonOperator . |
static AtomValueCondition |
value(Ref<Object> value,
ComparisonOperator op)
Return a condition that constraints resulting atoms by a specific value
Ref and ComparisonOperator . |
static <T> Var<T> |
var(String name)
Create a new variable and attach it to the current variable context.
|
static <T> Var<T> |
var(String name,
Class<T> t)
Create a new variable and attach it to the current variable context.
|
static <T> Var<T> |
var(String name,
T initialValue)
Create a new variable with an initial value and attach it to the current variable context.
|
public static <T> HGQuery<T> make(Class<T> type, HyperGraph graph)
public static HGHandle assertAtom(HyperGraph graph, Object instance)
Return assertAtom(graph, instance, false)
.
public static HGHandle assertAtom(HyperGraph graph, Object instance, boolean ignoreValue)
Return the atom handle if instance
is already a loaded atom in the cache.
Otherwise, get the default type corresponding to instance.getClass
and
return assertAtom(graph, instance, type, ignoreValue)
.
public static HGHandle assertAtom(HyperGraph graph, Object instance, HGHandle type)
Return assertAtom(graph, instance, type, false)
.
public static HGHandle assertAtom(HyperGraph graph, Object instance, HGHandle type, boolean ignoreValue)
Add a new atom to the specified graph only if it is not already there. An object is considered in the graph if:
HGHandle
in the graph's cache; orgraph
- The HyperGraph
database instance.instance
- The object to be asserted as an atom.type
- The type of the atom.ignoreValue
- Whether to ignore the atom value while performing the lookup. The value
of the atom is compared with Object.equals
so it is important that that method be implemented properly for your Java object. The default
implementation in the standard Object
class won't work. If the object class
doesn't implement this method and there are no other way to uniquely identify the atom's
value known to HyperGraph, then please use the addUnique
method to specify a condition
for lookup. If the value is not important, which is frequently the case with Java-type links,
then set this parameter to true
.HGHandle
of the asserted atom (either existing or newly added).public static HGQueryCondition guessUniquenessCondition(HyperGraph graph, Object instance)
Construct a HGQueryCondition
that uniquely identifies an atom based on
the passed in Object
instance.
graph
- The HyperGraph
database instance.instance
- The object for which an unique atom condition must be constructed.null
if instance == null
, otherwise a query condition
identifying instance
in the database.public static HGHandle addUnique(HyperGraph graph, Object instance, HGQueryCondition condition)
Add the given instance as an atom in the graph if and only if no atoms
match the passed in HGQueryCondition
public static HGHandle addUnique(HyperGraph graph, Object instance, HGHandle typeHandle, HGQueryCondition condition)
Add a new atom of a given type only if there's no atom matching the passed in
HGQueryCondition
. Note that an AtomTypeCondition
based on the typeHandle
parameter is "and-ed" with the condition
parameter.
public static HGHandle addUnique(HyperGraph graph, Object instance, Class<?> javaClass, HGQueryCondition condition)
Add a new atom of a given type only if there's no atom matching the passed in
HGQueryCondition
. Note that an AtomTypeCondition
based on the javaClass
parameter is "and-ed" with the condition
parameter.
public static AtomValueRegExPredicate matches(String pattern)
Return a condition that matches a regular expression pattern against the string value of an atom.
pattern
- The pattern following the syntax of Pattern
.public static AtomValueRegExPredicate matches(Pattern pattern)
Return a condition that matches a regular expression pattern against the string value of an atom.
public static AtomPartRegExPredicate matches(String path, String pattern)
Return a condition that matches a regular expression pattern against the string value of an atom's projection (property) along the given path.
pattern
- The pattern following the syntax of Pattern
.public static AtomPartRegExPredicate matches(String path, Pattern pattern)
Return a condition that matches a regular expression pattern against the string value of an atom's projection (property) along the given path.
public static IsCondition is(HGHandle atomHandle)
Return the "identity" condition that evaluates to true for a specific handle. It translates to a result set containing the specified atom handle.
atomHandle
- public static AtomTypeCondition type(HGHandle typeHandle)
Return a HGQueryCondition
constraining the type of the result
to the type identified by typeHandle
.
AtomTypeCondition
public static AtomTypeCondition type(Ref<?> type)
Return a HGQueryCondition
constraining the type of the result
to the type identified by type
Ref
. The content of the reference
can be a Class
or a and you can use a variable reference in a
compiled query.
public static AtomTypeCondition type(Class<?> clazz)
Return a HGQueryCondition
constraining the type of the result
to the type corresponding to the Java class clazz
.
AtomTypeCondition
public static TypePlusCondition typePlus(HGHandle h)
Return a HGQueryCondition
constraining the type of the result
to the type identified by typeHandle
and all its sub-types. The set
of sub-types is obtained as the closure of the HGSubsumes
relation.
TypePlusCondition
public static TypePlusCondition typePlus(Class<?> clazz)
Return a HGQueryCondition
constraining the type of the result
to the type corresponding to the Java class clazz
and all its sub-types. The set
of sub-types is obtained as the closure of the HGSubsumes
relation.
TypePlusCondition
public static SubsumesCondition subsumes(HGHandle specific)
Return a condition constraining the result set to atoms more general than the passed in
specific
parameter. This condition is generally useful when searching for types,
but it is applicable to any set atoms interlinked with the HGSubsumes
relation.
SubsumesCondition
public static SubsumedCondition subsumed(HGHandle general)
Return a condition constraining the result set to atoms more specific than the passed in
general
parameter. This condition is generally useful when searching for types,
but it is applicable to any set atoms interlinked with the HGSubsumes
relation.
SubsumedCondition
public static SubsumedCondition subsumed(Ref<HGHandle> general)
Return a condition constraining the result set to atoms more specific than the passed in
general
reference parameter. This condition is generally useful when searching for types,
but it is applicable to any set atoms interlinked with the HGSubsumes
relation.
SubsumedCondition
public static And and(HGQueryCondition... clauses)
Return a conjunction (logical and
) of conditions - atoms in the result set will have
to match all condition in the parameter list.
And
public static Or or(HGQueryCondition... clauses)
Return a disjunction (logical or
) of conditions - atoms in the result set will have
to match at least one of the conditions in the parameter list.
Or
public static Not not(HGAtomPredicate predicate)
Return the negation of an HGAtomPredicate
.
Not
public static TargetCondition target(HGHandle linkHandle)
Return a query condition that constraints the result set to atoms that are targets to a specific link.
linkHandle
- The handle of the HGLink
whose target the resulting atom should be.TargetCondition
public static TargetCondition target(Ref<HGHandle> linkHandle)
Return a query condition that constraints the result set to atoms that are targets to a specific link as
specified by the HGHandle
Ref
parameter.
linkHandle
- A (possibly Var
) reference to the handle of the HGLink
whose target
the resulting atom should be.TargetCondition
public static IncidentCondition incident(HGHandle atomHandle)
Return a condition constraining the result to links to a specific atom.
atomHandle
- The atom to which resulting links should point to.IncidentCondition
public static IncidentCondition incident(Ref<?> atomHandle)
public static PositionedIncidentCondition incidentAt(Ref<HGHandle> target, Ref<Integer> lowerBound, Ref<Integer> upperBound)
Return a condition constraining the query result set to links pointing to a target atom positioned within a predetermined range in the link tuple.
target
- A Ref
to the target atom specified as a HGHandle
.lowerBound
- A Ref
to the lower bound of the desired range. If the number is negative, it is
counted from the last target in the tuple (e.g. -1 means the last target, -2 the penultimate
target etc.).upperBound
- A Ref
to the upper bound of the desired range. If the number is negative, it is
counted from the last target in the tuple (e.g. -1 means the last target, -2 the penultimate
target etc.).PositionedIncidentCondition
public static PositionedIncidentCondition incidentAt(HGHandle target, int lowerBound, int upperBound)
#incidentAt(Ref, Ref, Ref)}.
public static PositionedIncidentCondition incidentAt(Ref<HGHandle> target, int position)
#incidentAt(Ref, Ref, Ref)} - position
is used both as lower and upper bound.
public static PositionedIncidentCondition incidentAt(HGHandle target, int position)
#incidentAt(Ref, Ref, Ref)} - position
is used both as lower and upper bound.
public static PositionedIncidentCondition incidentNotAt(Ref<HGHandle> target, Ref<Integer> lowerBound, Ref<Integer> upperBound)
PositionedIncidentCondition}
public static PositionedIncidentCondition incidentNotAt(HGHandle target, int lowerBound, int upperBound)
#incidentNotAt(Ref, Ref, Ref)}.
public static PositionedIncidentCondition incidentNotAt(HGHandle target, int position)
#incidentNotAt(Ref, Ref, Ref)} - position
is used both as lower and upper bound.
public static PositionedIncidentCondition incidentNotAt(Ref<HGHandle> target, int position)
#incidentNotAt(Ref, Ref, Ref)} - position
is used both as lower and upper bound.
public static LinkCondition link(HGLink link)
Return a condition constraining the query result set to links pointing to a target set of atoms.
link
- The target set specified as a HGLink
instance. The order of targets in this
link is ignored - it is treated as a set.LinkCondition
public static LinkCondition link(HGHandle... h)
Return a condition constraining the query result set to links pointing to a target set of atoms.
link
- The target set specified as a HGHandle
array. The order of targets in this
array is ignored - it is treated as a set.LinkCondition
public static LinkCondition link(Ref<HGHandle>... h)
Return a condition constraining the query result set to links pointing to a target set
of atoms, as specified by the list of HGHandle
Ref
.
link
- The target set specified as an of references to HGHandle
. The order of targets in this
array is ignored - it is treated as a set.LinkCondition
public static LinkCondition link(Collection<HGHandle> C)
Return a condition constraining the query result set to links pointing to a target set of atoms.
C
- The target set specified as a Java collection.LinkCondition
public static OrderedLinkCondition orderedLink(HGHandle... h)
Return a condition constraining the query result set to being ordered links of a certain form.
h
- The target set specified as a HGHandle
array. The order of targets in this
array sets the order of targets in the resulting atoms.OrderedLinkCondition
public static OrderedLinkCondition orderedLink(Ref<HGHandle>... h)
Return a condition constraining the query result set to being ordered links of a certain form.
h
- The target set specified as an of Ref
HGHandle
s. The order of targets in this
array sets the order of targets in the resulting atoms.OrderedLinkCondition
public static OrderedLinkCondition orderedLink(List<HGHandle> L)
Return a condition constraining the query result set to being ordered links of a certain form.
L
- The target set specified as a Java list. The order of targets in this
list sets the order of targets in the resulting atoms.OrderedLinkCondition
public static ArityCondition arity(int i)
Return a condition constraining the query result set to being links with the specified arity (number of targets).
i
- The arity of the atoms in the result set.ArityCondition
public static ArityCondition arity(Ref<Integer> i)
Return a condition constraining the query result set to being links with the specified arity (number of targets).
i
- A Ref
to the arity of the atoms in the result set.ArityCondition
public static DisconnectedPredicate disconnected()
Return an atom predicate constraining the result set to atoms that are not connected to other atoms, i.e. whose incidence set is empty.
DisconnectedPredicate
public static SubgraphMemberCondition memberOf(HGHandle subgraphHandle)
Return a condition constraining the result set to atoms that are members of the specified subgraph.
subgraphHandle
- The atom handle of the HGSubgraph
atoms.public static SubgraphContainsCondition contains(HGHandle atom)
Return a condition constraining the result set to atoms that are instances of
HGSubgraph
and containing the specified atom.
The
- atom that return subgraphs should contain.public static AtomValueCondition value(Object value, ComparisonOperator op)
Return a condition that constraints resulting atoms by a specific value and ComparisonOperator
.
value
- The value to compare with.op
- The ComparisonOperator
to use in the comparison.AtomValueCondition
public static AtomValueCondition value(Ref<Object> value, ComparisonOperator op)
Return a condition that constraints resulting atoms by a specific value
Ref
and ComparisonOperator
.
value
- The value reference to compare with.op
- The ComparisonOperator
to use in the comparison.AtomValueCondition
public static AtomValueCondition eq(Object x)
Return a condition constraining resulting atoms to atoms whose value is equal to
the passed in x
parameter.
AtomValueCondition
public static AtomValueCondition eq(Ref<Object> x)
Return a condition constraining resulting atoms to atoms whose value is equal to
the passed in x
Ref
parameter.
AtomValueCondition
public static AtomValueCondition lt(Object x)
Return a condition constraining resulting atoms to atoms whose value is less than
the passed in x
parameter.
AtomValueCondition
public static AtomValueCondition lt(Ref<Object> x)
Return a condition constraining resulting atoms to atoms whose value is less than
the passed in x
Ref
parameter.
AtomValueCondition
public static AtomValueCondition gt(Object x)
Return a condition constraining resulting atoms to atoms whose value is greater than
the passed in x
parameter.
AtomValueCondition
public static AtomValueCondition gt(Ref<Object> x)
Return a condition constraining resulting atoms to atoms whose value is greater than
the passed in x
Ref
parameter.
AtomValueCondition
public static AtomValueCondition lte(Object x)
Return a condition constraining resulting atoms to atoms whose value is less than or equal to
the passed in x
parameter.
AtomValueCondition
public static AtomValueCondition lte(Ref<Object> x)
Return a condition constraining resulting atoms to atoms whose value is less than or equal to
the passed in x
Ref
parameter.
AtomValueCondition
public static AtomValueCondition gte(Object x)
Return a condition constraining resulting atoms to atoms whose value is greater than equal to
the passed in x
parameter.
AtomValueCondition
public static AtomValueCondition gte(Ref<Object> x)
Return a condition constraining resulting atoms to atoms whose value is greater than equal to
the passed in x
Ref
parameter.
AtomValueCondition
public static AtomPartCondition part(String path, Object value, ComparisonOperator op)
Return a condition constraining the result to atoms of some HGCompositeType
and having
a certain part (e.g. a Java property) as specified by the value
and op
ComparisonOperator
parameters.
path
- The path of the property with the nested value structure of the atom. This is specified with
"dotted" notation. For example: user.address.street
.value
- The value to compare the atom part against.op
- The ComparisonOperator
to use. Not that if op != ComparisonOperator.EQ
, the
atom part must be Comparable
.AtomPartCondition
public static AtomPartCondition part(String path, Ref<Object> value, ComparisonOperator op)
part(String, Object, ComparisonOperator)
. This method specifying the value as a
Ref
.public static AtomPartCondition eq(String path, Object x)
Return a condition constraining the result to atoms of some HGCompositeType
and having
a part (e.g. a Java property) equal to the specified value
.
path
- The path of the property with the nested value structure of the atom. This is specified with
"dotted" notation. For example: user.address.street
.value
- The value to compare the atom part against.AtomPartCondition
public static AtomPartCondition eq(String path, Ref<Object> x)
eq(String, Object)
. This method specifying the value as a
Ref
.public static AtomPartCondition lt(String path, Object x)
Return a condition constraining the result to atoms of some HGCompositeType
and having
a part (e.g. a Java property) less than the specified value
.
path
- The path of the property with the nested value structure of the atom. This is specified with
"dotted" notation. For example: user.address.street
.value
- The value to compare the atom part against.AtomPartCondition
public static AtomPartCondition lt(String path, Ref<Object> x)
lt(String, Object)
. This method specifying the value as a
Ref
.public static AtomPartCondition gt(String path, Object x)
Return a condition constraining the result to atoms of some HGCompositeType
and having
a part (e.g. a Java property) greater than the specified value
.
path
- The path of the property with the nested value structure of the atom. This is specified with
"dotted" notation. For example: user.address.street
.value
- The value to compare the atom part against.AtomPartCondition
public static AtomPartCondition gt(String path, Ref<Object> x)
gt(String, Object)
. This method specifying the value as a
Ref
.public static AtomPartCondition lte(String path, Object x)
Return a condition constraining the result to atoms of some HGCompositeType
and having
a part (e.g. a Java property) less than or equal to the specified value
.
path
- The path of the property with the nested value structure of the atom. This is specified with
"dotted" notation. For example: user.address.street
.value
- The value to compare the atom part against.AtomPartCondition
public static AtomPartCondition lte(String path, Ref<Object> x)
lte(String, Object)
. This method specifying the value as a
Ref
.public static AtomPartCondition gte(String path, Object x)
Return a condition constraining the result to atoms of some HGCompositeType
and having
a part (e.g. a Java property) greater than or equal to the specified value
.
path
- The path of the property with the nested value structure of the atom. This is specified with
"dotted" notation. For example: user.address.street
.value
- The value to compare the atom part against.AtomPartCondition
public static AtomPartCondition gte(String path, Ref<Object> x)
gte(String, Object)
. This method specifying the value as a
Ref
.public static HGQueryCondition apply(Mapping<?,?> m, HGQueryCondition c)
Return a "condition" that transforms the result set by applying an arbitrary Mapping
to each
element.
m
- The Mapping
to apply.c
- The underlying condition to evaluate before applying the mapping.MapCondition
public static Mapping<HGLink,HGHandle> linkProjection(int targetPosition)
Return a Mapping
that takes a link atom and returns a target at the given position.
targetPosition
- The position of the target to be returned.LinkProjectionMapping
public static Mapping<HGLink,HGHandle> linkProjection(Ref<Integer> targetPosition)
Return a Mapping
that takes a link atom and returns a target at the given position.
targetPosition
- A Ref
to the position of the target to be returned.LinkProjectionMapping
public static <T> Mapping<HGHandle,T> deref(HyperGraph graph)
Return a Mapping
that takes a HGHandle
of an atom and return its runtime against
through a call to HyperGraph.get
.
graph
- The HyperGraph
instance against which to dereference the atom.DerefMapping
public static HGQueryCondition deref(HyperGraph graph, HGQueryCondition condition)
Short for hg.apply(hg.deref(graph), condition)
- assuming the condition
parameter yields a result set of HGHandle
s, the returned condition will yield a result set
of atoms loaded from the graph
parameter.
graph
- condition
- public static Mapping<HGHandle,HGHandle> targetAt(HyperGraph graph, int targetPosition)
Return a Mapping
that given a handle to a link will return the target (handle) at the specified
target position. This is a CompositeMapping
of deref(graph)
and linkProjection(targetPosition)
.
graph
- The HyperGraph instance.targetPosition
- The target position.CompositeMapping
public static HGQueryCondition all()
Return a condition that will yield all atoms in the graph.
AnyAtomCondition
public static BFSCondition bfs(HGHandle start)
Return a condition whose result set is the breadth first traversal of the graph starting a given atom.
start
- The starting atom.BFSCondition
public static BFSCondition bfs(Ref<HGHandle> start)
Return a condition whose result set is the breadth first traversal of the graph starting a given atom.
start
- A Ref
to the starting atom.BFSCondition
public static BFSCondition bfs(HGHandle start, HGAtomPredicate lp, HGAtomPredicate sp)
Return a condition whose result set is the breadth first traversal of the graph starting a given atom.
start
- The starting atom.lp
- A filtering HGAtomPredicate
constraining what links to follow - only
links satisfying this predicate will be followed.sp
- A filtering HGAtomPredicate
- only atoms satisfying this predicate
will be *traversed*. If you want all atoms to be traversed, but examine only a subset
of them, use a conjunction of this condition and an HGAtomPredicate
, e.g.
hg.and(hg.type(someType), hg.bfs(startingAtom))
.BFSCondition
public static BFSCondition bfs(Ref<HGHandle> start, HGAtomPredicate lp, HGAtomPredicate sp)
Return a condition whose result set is the breadth first traversal of the graph starting a given atom.
start
- A Ref
to the starting atom.lp
- A filtering HGAtomPredicate
constraining what links to follow - only
links satisfying this predicate will be followed.sp
- A filtering HGAtomPredicate
- only atoms satisfying this predicate
will be *traversed*. If you want all atoms to be traversed, but examine only a subset
of them, use a conjunction of this condition and an HGAtomPredicate
, e.g.
hg.and(hg.type(someType), hg.bfs(startingAtom))
.BFSCondition
public static BFSCondition bfs(HGHandle start, HGAtomPredicate lp, HGAtomPredicate sp, boolean returnPreceding, boolean returnSucceeding)
Return a condition whose result set is the breadth first traversal of the graph starting a given atom.
start
- The starting atom.lp
- A filtering HGAtomPredicate
constraining what links to follow - only
links satisfying this predicate will be followed.sp
- A filtering HGAtomPredicate
- only atoms satisfying this predicate
will be *traversed*. If you want all atoms to be traversed, but examine only a subset
of them, use a conjunction of this condition and an HGAtomPredicate
, e.g.
hg.and(hg.type(someType), hg.bfs(startingAtom))
.returnPreceding
- Whether to return siblings preceding the current atom in an ordered link.returnSucceeding
- Whether to return siblings following the current atom in an ordered link.BFSCondition
public static BFSCondition bfs(Ref<HGHandle> start, HGAtomPredicate lp, HGAtomPredicate sp, boolean returnPreceding, boolean returnSucceeding)
Return a condition whose result set is the breadth first traversal of the graph starting a given atom.
start
- A Ref
to the starting atom.lp
- A filtering HGAtomPredicate
constraining what links to follow - only
links satisfying this predicate will be followed.sp
- A filtering HGAtomPredicate
- only atoms satisfying this predicate
will be *traversed*. If you want all atoms to be traversed, but examine only a subset
of them, use a conjunction of this condition and an HGAtomPredicate
, e.g.
hg.and(hg.type(someType), hg.bfs(startingAtom))
.returnPreceding
- Whether to return siblings preceding the current atom in an ordered link.returnSucceeding
- Whether to return siblings following the current atom in an ordered link.BFSCondition
public static DFSCondition dfs(HGHandle start)
Return a condition whose result set is the depth first traversal of the graph starting with a given atom.
start
- The starting atom.DFSCondition
public static DFSCondition dfs(Ref<HGHandle> start)
Return a condition whose result set is the depth first traversal of the graph starting with a given atom.
start
- A Ref
to the starting atom.DFSCondition
public static DFSCondition dfs(HGHandle start, HGAtomPredicate linkPredicate, HGAtomPredicate siblingPredicate)
Return a condition whose result set is the depth first traversal of the graph starting with a given atom.
start
- The starting atom.linkPredicate
- A filtering HGAtomPredicate
constraining what links to follow - only
links satisfying this predicate will be followed.siblingPredicate
- A filtering HGAtomPredicate
- only atoms satisfying this predicate
will be *traversed*. If you want all atoms to be traversed, but examine only a subset
of them, use a conjunction of this condition and an HGAtomPredicate
, e.g.
hg.and(hg.type(someType), hg.bfs(startingAtom))
.DFSCondition
public static DFSCondition dfs(Ref<HGHandle> start, HGAtomPredicate linkPredicate, HGAtomPredicate siblingPredicate)
Return a condition whose result set is the depth first traversal of the graph starting with a given atom.
start
- A Ref
to the starting atom.linkPredicate
- A filtering HGAtomPredicate
constraining what links to follow - only
links satisfying this predicate will be followed.siblingPredicate
- A filtering HGAtomPredicate
- only atoms satisfying this predicate
will be *traversed*. If you want all atoms to be traversed, but examine only a subset
of them, use a conjunction of this condition and an HGAtomPredicate
, e.g.
hg.and(hg.type(someType), hg.bfs(startingAtom))
.DFSCondition
public static DFSCondition dfs(HGHandle start, HGAtomPredicate linkPredicate, HGAtomPredicate siblingPredicate, boolean returnPreceeding, boolean returnSucceeding)
Return a condition whose result set is the depth first traversal of the graph starting a given atom.
start
- The starting atom.linkPredicate
- A filtering HGAtomPredicate
constraining what links to follow - only
links satisfying this predicate will be followed.siblingPredicate
- A filtering HGAtomPredicate
- only atoms satisfying this predicate
will be *traversed*. If you want all atoms to be traversed, but examine only a subset
of them, use a conjunction of this condition and an HGAtomPredicate
, e.g.
hg.and(hg.type(someType), hg.bfs(startingAtom))
.returnPreceding
- Whether to return siblings preceding the current atom in an ordered link.returnSucceeding
- Whether to return siblings following the current atom in an ordered link.DFSCondition
public static DFSCondition dfs(Ref<HGHandle> start, HGAtomPredicate linkPredicate, HGAtomPredicate siblingPredicate, boolean returnPreceeding, boolean returnSucceeding)
Return a condition whose result set is the depth first traversal of the graph starting a given atom.
start
- A Ref
to the starting atom.linkPredicate
- A filtering HGAtomPredicate
constraining what links to follow - only
links satisfying this predicate will be followed.siblingPredicate
- A filtering HGAtomPredicate
- only atoms satisfying this predicate
will be *traversed*. If you want all atoms to be traversed, but examine only a subset
of them, use a conjunction of this condition and an HGAtomPredicate
, e.g.
hg.and(hg.type(someType), hg.bfs(startingAtom))
.returnPreceding
- Whether to return siblings preceding the current atom in an ordered link.returnSucceeding
- Whether to return siblings following the current atom in an ordered link.DFSCondition
public static HGHandle anyHandle()
Return a special handle indicating a "don't care" in a condition expression (e.g.
when specifying the form of a link in a hg.orderedLink(hg.anyHandle(), x, y)
condition.
Node: This is not a HGPersistentHandle
. To get a persistent "don't care" handle,
please use org.hypergraphdb.HGHandleFactory.anyHandle()
.
public static <T> Var<T> var(String name, T initialValue)
Create a new variable with an initial value and attach it to the current variable context.
name
- The name of the variable. Any previous variable with that name in the current context will
be overridden.initialValue
- The initial value of the variable.Var
instance.public static <T> Var<T> var(String name)
Create a new variable and attach it to the current variable context.
name
- The name of the variable. Any previous variable with that name in the current context will
be overriden.Var
instance.public static <T> Var<T> var(String name, Class<T> t)
Create a new variable and attach it to the current variable context.
name
- The name of the variable. Any previous variable with that name in the current context will
be overridden.t
- A class parameter allowing to specify the type of the variable without providing an initial
value. Use this to avoid ugly type casts.Var
instance.public static <T> Ref<T> constant(T value)
Create a new constant reference. The value of this reference cannot be changed.
value
- The value of the constant.Constant
whose Constant.get()
method will return
the passed in value.public static <T> boolean isVar(Ref<T> ref)
public static long count(HyperGraph graph, HGQueryCondition cond)
Count the number of atoms that match the query condition parameter. Retrieving
the count might require performing the actual query traversing the result set.
In cases where the condition is simple and the count is available directly from
an index, it is returned right away. Otherwise, the operation may be expensive
when the result set matching cond
is large or it takes time
to obtain it.
graph
- The HyperGraph against which the counting is performed.cond
- The condition specifying the result set.public static long count(HGQuery<?> query)
Count the result set from executing the given query. The query is executed and the result set scanned completely.
public static <T> T getOne(HyperGraph graph, HGQueryCondition condition)
Run a query based on the passed in condition. If the result set is not
empty, get and return the atom instance of the first element. Otherwise,
return null
.
graph
- The HyperGraph database to query.condition
- The query condition.public static <T> T findOne(HyperGraph graph, HGQueryCondition condition)
Run a query based on the passed in condition. If the result set is not
empty, return the first HGHandle
element. Otherwise,
return null
.
graph
- The HyperGraph
instance to run the query against.condition
- The query condition constraining the resulting atom.null
if
the result set is empty.public static <T> List<T> findAll(HyperGraph graph, HGQueryCondition condition)
Run a query based on the specified condition and put all HGHandle
s
from the result set into a java.util.List
.
graph
- The HyperGraph
to run the query against.condition
- The query condition constraining the result set.public static <T> List<T> getAll(HyperGraph graph, HGQueryCondition condition)
Run a query based on the specified condition and put all atom instances
from the result set into a java.util.List
.
graph
- The HyperGraph
to run the query against.condition
- The query condition constraining the result set.HGHandle
s
against the graph.public static <T> List<T> findAll(HGQuery<T> query)
Execute the given query, put all the elements from the result set in a List
and return that List
Copyright © 2015. All rights reserved.