Commit f2fc4818 authored by Victor Marsault's avatar Victor Marsault

Fixed bug of uninstanciated variable appearing in expression map of patterns

parent 995fa0ec
......@@ -197,6 +197,14 @@ public class CompiledPattern {
{ return variables(x -> isNodeVariable(x)||isNodeVariable(x)); }
/** Return all the variables appearing in expressions of property maps. ***/
public Set<Name> expressionVariables() {
Set<Name> result = new HashSet<>();
for (Expression e : properties.values())
result.addAll(e.variables());
return result;
}
/** Map describing the properties appearing in node or relation patterns.
* Only relation or node variables may be key of this map.
* A relation/node variable is not a key of this map if no property map
......
......@@ -21,6 +21,7 @@ package uk.ac.ed.cyphsem.language.query;
import uk.ac.ed.cyphsem.Interruptor;
import uk.ac.ed.cyphsem.Utils.Policy;
import uk.ac.ed.cyphsem.exception.*;
import uk.ac.ed.cyphsem.language.expression.Expression;
import uk.ac.ed.cyphsem.datamodel.graph.Node;
......@@ -116,4 +117,20 @@ implements StandardReadingClause, PatternHolder
return result;
}
@Override
public void preassert(Set<Name> inputDomain)
throws UnspecifiedBehaviourException
{
Set<Name> free_variables =
compiledPattern.expressionVariables();
for (Name n : compiledPattern.genuineVariables())
free_variables.remove(n);
for (Name n : free_variables)
if (! inputDomain.contains(n))
throw new UnspecifiedBehaviourException(
"In " + this
+ ", Name " + n +" is not assigned by input table (domain is "
+ inputDomain + ") nor is a top-level variable of the pattern.");
}
}
......@@ -19,15 +19,17 @@
package uk.ac.ed.cyphsem.language.query;
import uk.ac.ed.cyphsem.Interruptor;
import uk.ac.ed.cyphsem.exception.UnreachableStatementError;
import uk.ac.ed.cyphsem.exception.*;
import uk.ac.ed.cyphsem.datamodel.graph.Graph;
import uk.ac.ed.cyphsem.table.Name;
import uk.ac.ed.cyphsem.table.Table;
import uk.ac.ed.cyphsem.table.Record;
import java.util.Collection;
import java.util.Set;
import java.util.Map;
/**
......@@ -55,6 +57,7 @@ public interface StandardReadingClause extends ReadingClause {
default public Table apply (Graph graph, Table table, Interruptor interruptor)
throws InterruptedException {
interruptor.check();
preassert(table.domain());
Table result = new Table();
for (Record record : table.recordSet())
result.addAll(apply(graph, record, interruptor), table.multiplicityOf(record));
......@@ -92,4 +95,12 @@ public interface StandardReadingClause extends ReadingClause {
// }
// }
/** Assertion to verify before computation.
* Allows implementing class to verify and possibly fail even if the input {@link Table} is empty.
* Implementation in {@link #} does nothing.
* @param inputDomain Immutable set representing the domain of the input Table
***/
public default void preassert (Set<Name> inputDomain)
throws UnspecifiedBehaviourException { }
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment