24 package org.lightjason.agentspeak.language.unify;
36 import javax.annotation.Nonnull;
37 import java.text.MessageFormat;
38 import java.util.Collections;
39 import java.util.HashSet;
40 import java.util.LinkedList;
41 import java.util.List;
43 import java.util.stream.Collectors;
44 import java.util.stream.Stream;
77 m_hashbased = p_hashbased;
78 m_recursive = p_recursive;
87 final Set<IVariable<?>> l_result =
new HashSet<>();
91 p_target.structurehash() == p_source.structurehash()
99 p_source.orderedvalues(),
100 p_target.orderedvalues()
102 return Collections.emptySet();
110 @Nonnull
final IExpression p_expression,
final boolean p_parallel )
113 final List<Set<IVariable<?>>> l_variables = this.
variables( p_context.agent(), p_literal, p_variables );
114 if ( l_variables.isEmpty() )
118 final Set<IVariable<?>> l_result =
parallelstream( l_variables.stream(), p_parallel )
121 .orElse( Collections.emptySet() );
124 if ( l_result.isEmpty() )
136 return m_hashbased.hashCode() ^ m_recursive.hashCode();
141 public final boolean equals(
final Object p_object )
143 return ( p_object instanceof
IUnifier ) && ( this.
hashCode() == p_object.hashCode() );
149 return MessageFormat.format(
"hash-based unification: {0} / recursive unification: {1}", m_hashbased, m_recursive );
160 private static <T> Stream<T>
parallelstream(
final Stream<T> p_stream,
final boolean p_parallel )
162 return p_parallel ? p_stream.parallel() : p_stream;
175 final List<ITerm> l_return =
new LinkedList<>();
178 Collections.emptyList(),
182 return ( l_return.size() == 1 ) && ( l_return.get( 0 ).<Boolean>raw() );
197 .filter( i -> i.emptyValues() == p_literal.
emptyValues() )
199 .filter( i -> p_variablenumber == i.size() )
200 .collect( Collectors.toList() );
List< Set< IVariable<?> > > variables(final IAgent<?> p_agent, final ILiteral p_literal, final long p_variablenumber)
search all relevant literals within the agent beliefbase and unifies the variables ...
< T extends ITerm > boolean unify(final Set< IVariable<?>> p_variables, final Stream< T > p_source, final Stream< T > p_target)
unify algorithm
final IAlgorithm m_recursive
recursive unify algorithm
IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
final IAlgorithm m_hashbased
hash-based unify algorithm
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
common structure for execution definition
interface of an unification algorithm
Stream< ILiteral > stream( @Nullable final IPath... p_path)
returns stream of literal
CUnifier( @Nonnull final IUnifier.IAlgorithm p_hashbased, @Nonnull final IUnifier.IAlgorithm p_recursive)
ctor
unify on at hash-based quality
static Stream< ITerm > flattenrecursive( @Nonnull final Stream< ITerm > p_input)
recursive stream of term values
IPath fqnfunctor()
returns the full-qualified functor with path and name
execution context with local data
final boolean equals(final Object p_object)
boolean emptyValues()
check for empty values
static IContext updatecontext( @Nonnull final IContext p_context, @Nonnull final Stream< IVariable<?>> p_unifiedvariables)
updates within an instance context all variables of the stream
static< T > Stream< T > parallelstream(final Stream< T > p_stream, final boolean p_parallel)
execute stream in parallel
result for an immutable fuzzy value
boolean negated()
getter of the literal for the negation
final Set< IVariable<?> > unify( @Nonnull final ILiteral p_source, @Nonnull final ILiteral p_target)
unifies a literal
T deepcopy( @Nullable final IPath... p_prefix)
clones the object (shallow-copy)
IFuzzyValue< Boolean > unify( @Nonnull final IContext p_context, @Nonnull final ILiteral p_literal, final long p_variables, @Nonnull final IExpression p_expression, final boolean p_parallel)
unifies the literal with the expression
IView beliefbase()
returns the beliefbase
IContext duplicate()
duplicates the context with a shallow-copy
static boolean evaluateexpression(final IContext p_context, final IExpression p_expression, final Set< IVariable<?>> p_variables)
evaluate expression