use of org.iobserve.service.behavior.analysis.model.BehaviorModelNode in project iobserve-analysis by research-iobserve.
the class GraphEditDistance method calculate.
/**
* Calculates the Graph Edit Distance between two objects
*
* @param modelA
* The first model.
* @param modelB
* The second model.
*/
@Override
public double calculate(final BehaviorModelGED modelA, final BehaviorModelGED modelB) {
this.model1 = modelA;
this.model2 = modelB;
double distance = 0;
// check if nodes from model1 are in model2
for (final Map.Entry<String, BehaviorModelNode> pair : this.model1.getNodes().entrySet()) {
final String signature = pair.getKey();
final BehaviorModelNode node = pair.getValue();
final BehaviorModelNode match = this.model2.getNodes().get(signature);
if (match == null) {
// node only occurs in one objects => must be inserted
distance += this.nodeInsertionCost(node);
} else {
// node occurs in both objects => must be compared
distance += this.nodeDistance(node, match);
}
}
// check if nodes from model2 are in model1
for (final Map.Entry<String, BehaviorModelNode> pair : this.model2.getNodes().entrySet()) {
final String signature = pair.getKey();
final BehaviorModelNode node = pair.getValue();
final BehaviorModelNode match = this.model1.getNodes().get(signature);
// node only occurs in one objects => must be inserted
if (match == null) {
distance += this.nodeInsertionCost(node);
}
}
return distance;
}
use of org.iobserve.service.behavior.analysis.model.BehaviorModelNode in project iobserve-analysis by research-iobserve.
the class TestHelper method addEdge.
public static BehaviorModelEdge addEdge(final BehaviorModelGED model, final String sourceName, final String targetName) {
final BehaviorModelNode source = model.getNodes().get(sourceName);
final BehaviorModelNode target = model.getNodes().get(targetName);
final BehaviorModelEdge edge = new BehaviorModelEdge(source, target);
source.getOutgoingEdges().put(target, edge);
source.getIngoingEdges().put(source, edge);
model.getEdges().add(edge);
return edge;
}
use of org.iobserve.service.behavior.analysis.model.BehaviorModelNode in project iobserve-analysis by research-iobserve.
the class BehaviorModelDeserialization method deserialize.
public BehaviorModelGED deserialize() throws Exception {
final ObjectMapper mapper = new ObjectMapper();
final JsonNode tree = mapper.readTree(this.input);
if (!(tree instanceof ObjectNode)) {
throw new IOException("Wrong format");
}
final ObjectNode jsonModel = (ObjectNode) tree;
final BehaviorModelGED model = new BehaviorModelGED();
// Read nodes
final JsonNode jsonNode = jsonModel.get("nodes");
final Iterator<String> nodeIterator = jsonNode.fieldNames();
while (nodeIterator.hasNext()) {
final String operationSignature = nodeIterator.next();
model.getNodes().put(operationSignature, new BehaviorModelNode(operationSignature));
}
// Read edges
final JsonNode jsonEdges = jsonModel.get("edges");
final Iterator<JsonNode> edgeIterator = jsonEdges.elements();
while (edgeIterator.hasNext()) {
final JsonNode jsonEdge = edgeIterator.next();
final String source = jsonEdge.get("source").get("name").asText();
final String target = jsonEdge.get("target").get("name").asText();
final BehaviorModelNode sourceMatch = model.getNodes().get(source);
final BehaviorModelNode targetMatch = model.getNodes().get(target);
final BehaviorModelEdge newEdge = new BehaviorModelEdge(sourceMatch, targetMatch);
model.getEdges().add(newEdge);
sourceMatch.getOutgoingEdges().put(targetMatch, newEdge);
targetMatch.getIngoingEdges().put(sourceMatch, newEdge);
// Read event groups
final JsonNode jsonEventGroups = jsonEdge.get("eventGroups");
final Iterator<JsonNode> eventGroupIterator = jsonEventGroups.elements();
while (eventGroupIterator.hasNext()) {
final JsonNode jsonEventGroup = eventGroupIterator.next();
final Iterator<JsonNode> eventIterator = jsonEventGroup.get("events").elements();
final List<PayloadAwareEntryCallEvent> events = new ArrayList<>();
while (eventIterator.hasNext()) {
final JsonNode jsonEvent = eventIterator.next();
final String operationSignature = jsonEvent.get("operationSignature").asText();
final String[] parameters = mapper.treeToValue(jsonEvent.get("parameters"), String[].class);
final String[] values = mapper.treeToValue(jsonEvent.get("values"), String[].class);
final PayloadAwareEntryCallEvent event = new PayloadAwareEntryCallEvent(0, 0, operationSignature, operationSignature, "", "", parameters, values, 0);
events.add(event);
}
final EventGroup group = new EventGroup(events.get(0).getParameters());
group.getEvents().addAll(events);
newEdge.getEventGroups().add(group);
}
}
return model;
}
use of org.iobserve.service.behavior.analysis.model.BehaviorModelNode in project iobserve-analysis by research-iobserve.
the class ModelComparisonStage method findMatchingEdge.
/**
* searches an edge in the model, with the same source and target nodes as the edge parameter.
* The nodes are considered equal, if the names are equal
*
* @param edge
* @param model
* @return null, if no edge was found and the edge otherwise
*/
private BehaviorModelEdge findMatchingEdge(final BehaviorModelEdge edge, final BehaviorModelGED model) {
final String sourceName = edge.getSource().getName();
final String targetName = edge.getTarget().getName();
// finding corresponding nodes in other model
final BehaviorModelNode sourceNode = model.getNodes().get(sourceName);
final BehaviorModelNode targetNode = model.getNodes().get(targetName);
// if there are no corresponding nodes, there can't be the edge
if ((sourceNode == null) || (targetNode == null)) {
return null;
}
return sourceNode.getOutgoingEdges().get(targetNode);
}
use of org.iobserve.service.behavior.analysis.model.BehaviorModelNode in project iobserve-analysis by research-iobserve.
the class UserSessionToModelGeneratorTest method test.
@Test
public void test() {
final BehaviorModelGED model = this.startAndGetSolutions(this.session);
// 3 nodes: A, B, Init
MatcherAssert.assertThat(model.getNodes().size(), Matchers.is(3));
// 3 edges (Init -> A, A -> B, B -> B)
MatcherAssert.assertThat(model.getEdges().size(), Matchers.is(3));
final BehaviorModelNode nodeB = model.getNodes().get("B");
// only 1 edge: (B -> B)
MatcherAssert.assertThat(nodeB.getOutgoingEdges().size(), Matchers.is(1));
// get edge to itself
final BehaviorModelEdge edgeBtoB = nodeB.getOutgoingEdges().get(nodeB);
// two event groups
MatcherAssert.assertThat(edgeBtoB.getEventGroups().size(), Matchers.is(2));
}
Aggregations