Search in sources :

Example 1 with EventGroup

use of org.iobserve.service.behavior.analysis.model.EventGroup in project iobserve-analysis by research-iobserve.

the class GraphEditDistance method edgeDistance.

/**
 * Calculates the distance between two edges. This includes the distance between the contained
 * eventgroups
 */
private double edgeDistance(final BehaviorModelEdge edge1, final BehaviorModelEdge edge2) {
    double distance = 0;
    for (final EventGroup eventGroup1 : edge1.getEventGroups()) {
        boolean success = false;
        for (final EventGroup eventGroup2 : edge2.getEventGroups()) {
            if (eventGroup1.hasSameParameters(eventGroup2)) {
                // matching eventGroup found => must be compared
                distance += this.eventGroupDistance(eventGroup1, eventGroup2);
                success = true;
                break;
            }
        }
        // no matching eventGroup found => must be inserted
        if (!success) {
            distance += this.eventGroupInsertionCost(eventGroup1);
        }
    }
    for (final EventGroup eventGroup2 : edge2.getEventGroups()) {
        boolean success = false;
        for (final EventGroup eventGroup1 : edge1.getEventGroups()) {
            if (eventGroup1.hasSameParameters(eventGroup2)) {
                success = true;
                break;
            }
        }
        // if not necessary, as success should always be false
        if (!success) {
            // no matching eventGroup found => must be inserted
            distance += this.eventGroupInsertionCost(eventGroup2);
        }
    }
    return distance;
}
Also used : EventGroup(org.iobserve.service.behavior.analysis.model.EventGroup)

Example 2 with EventGroup

use of org.iobserve.service.behavior.analysis.model.EventGroup 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;
}
Also used : BehaviorModelNode(org.iobserve.service.behavior.analysis.model.BehaviorModelNode) BehaviorModelEdge(org.iobserve.service.behavior.analysis.model.BehaviorModelEdge) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) EventGroup(org.iobserve.service.behavior.analysis.model.EventGroup) BehaviorModelGED(org.iobserve.service.behavior.analysis.model.BehaviorModelGED) PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

EventGroup (org.iobserve.service.behavior.analysis.model.EventGroup)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 BehaviorModelEdge (org.iobserve.service.behavior.analysis.model.BehaviorModelEdge)1 BehaviorModelGED (org.iobserve.service.behavior.analysis.model.BehaviorModelGED)1 BehaviorModelNode (org.iobserve.service.behavior.analysis.model.BehaviorModelNode)1 PayloadAwareEntryCallEvent (org.iobserve.stages.general.data.PayloadAwareEntryCallEvent)1