Damian Steer wrote:
On 11 Mar 2011, at 12:30, Damian Steer wrote:
The only difference between Q3 and Q1|Q2 is that we have a different
variable name (i.e. ?y instead of ?v). The queries are different, but
they are "equivalent": they are structurally the same, only variable
names are different.
I don't think it handles this (but I may be wrong).

Ah, Op#equalTo(Op other, NodeIsomorphismMap labelMap) would do that, once you 
have the mapping.

Thank you Damian, I'll try this.

In the meantime, this is what I came up with (before reading your email):

Op op1 = Algebra.compile(q1);
Op op3 = Algebra.compile(q3);

Item it1 = SSE.parse(op1.toString());
it1 = ItemTransformer.transform(new RenameVariablesItemTransform(), it1);
Item it3 = SSE.parse(op3.toString());
it3 = ItemTransformer.transform(new RenameVariablesItemTransform(), it3);
                
op1 = Algebra.parse(it1);
op3 = Algebra.parse(it3);
                
assertEquals(op1, op3);



The RenameVariablesItemTransform is:

class RenameVariablesItemTransform extends ItemTransformBase {

    private HashMap<String, String> varNamesMapping = new HashMap<String, 
String>();
    private int count = 0;
        
    @Override
    public Item transform(Item item, Node node) {
        if ( node.isVariable() ) {
            if ( ! varNamesMapping.containsKey(node.toString()) ) {
                varNamesMapping.put(node.toString(), "v_" + count++);
            }
            Var var = Var.alloc(varNamesMapping.get(node.toString()));
            return Item.createNode(var, item.getLine(), item.getColumn()) ;
        } else {
            return Item.createNode(node, item.getLine(), item.getColumn()) ;    
                
        }
    }

}

Not an elegant solution, but it allows me to find (and count) "equivalent" 
queries
in my log files. :-)

Paolo



Damian

Reply via email to