package info.ipaw.pc3.PSLoadWorkflow; import java.util.Collection; import java.util.Set; import org.tupeloproject.provenance.ProvenanceAccount; import org.tupeloproject.provenance.ProvenanceArc; import org.tupeloproject.provenance.ProvenanceNode; import org.tupeloproject.provenance.ProvenanceRoleArc; import org.tupeloproject.provenance.ReadableProvenanceGraph; import org.tupeloproject.rdf.Resource; public final class PC3Utilities { public static final String PC3_HOME = "C:\\dev\\workspace\\PC3\\Java"; public static final String TEST_HOME = "C:\\dev\\workspace\\PC3\\Java\\etc"; public static final String RDF_FILE_NAME = "output.rdf"; public static Resource ns(String s) { return Resource.uriRef("http://pc3#"+s); } public static boolean compareAccounts(ReadableProvenanceGraph graph1, ProvenanceNode node1, ProvenanceAccount account1, ReadableProvenanceGraph graph2, ProvenanceNode node2, ProvenanceAccount account2, Set beenThere) { if(beenThere.contains(node1)){ return compareNodes(graph1, node1, account1, graph2, node2, account2); } beenThere.add(node1); for(ProvenanceArc arc1 : graph1.getAccountSpecificArcs(node1, account1)) { for(ProvenanceArc arc2 : graph2.getAccountSpecificArcs(node2, account2)) { if(sameArc(arc1,arc2)) { if((shouldVisitSource(arc1, node1, beenThere) && !compareAccounts(graph1, arc1.getSource(), account1, graph2, arc2.getSource(), account2, beenThere)) || (shouldVisitSink(arc1, node1, beenThere) && !compareAccounts(graph1, arc1.getSink(), account1, graph2, arc2.getSink(), account2, beenThere))) { return false; } } } } return compareAccounts(graph1, node1, account1, graph2, node2, account2, beenThere); } private static boolean shouldVisitSink(ProvenanceArc arc1, ProvenanceNode node1, Set beenThere) { if(arc1.getSource().equals(node1) && !beenThere.contains(arc1.getSink())) return true; return false; } private static boolean shouldVisitSource(ProvenanceArc arc1, ProvenanceNode node1, Set beenThere) { if(arc1.getSink().equals(node1) && !beenThere.contains(arc1.getSource())) return true; return false; } private static boolean compareNodes(ReadableProvenanceGraph graph1, ProvenanceNode node1, ProvenanceAccount account1, ReadableProvenanceGraph graph2, ProvenanceNode node2, ProvenanceAccount account2) { Collection arcs = graph1.getAccountSpecificArcs(node1, account1); Collection otherArcs = graph2.getAccountSpecificArcs(node2, account2); if(arcs.size() > otherArcs.size()) { return false; } if(!node1.getName().equals(node2.getName())) { return false; } boolean matchedEdge = false; for(ProvenanceArc arc : arcs) { for(ProvenanceArc otherArc : otherArcs) { if(sameArc(arc, otherArc)) { matchedEdge = true; } } if(!matchedEdge) { return false; } matchedEdge = false; } return true; } private static boolean sameArc(ProvenanceArc arc1, ProvenanceArc arc2) { if(shouldHaveRole(arc1) && shouldHaveRole(arc2) && !((ProvenanceRoleArc)arc1).getRole().getName().equals(((ProvenanceRoleArc) arc2).getRole().getName())) { return false; } // if one are should have a role and the other should not then, there is no way the two could be equal because the // a role arc has (source, sink) of the form (art, pro), (pro, art) or (pro, ag) whereas non-role arcs // are of the form (pro, pro) or (art, art). thus, the next conditional will allways be false. if(arc1.getSink().equals(arc2.getSink()) && arc1.getSource().equals(arc2.getSource())) { return true; } return false; } private static boolean shouldHaveRole(ProvenanceArc arc) { return arc instanceof ProvenanceRoleArc; } }