use of org.iobserve.analysis.behavior.models.extended.BehaviorModel in project iobserve-analysis by research-iobserve.
the class BehaviorModelCreationStage method createBehaviorModel.
/**
* create a BehaviorModel from Instance.
*
* @param instances
* instances containing the attribute names
* @param instance
* instance containing the attributes
* @return behavior model if relevant
*/
private Optional<BehaviorModel> createBehaviorModel(final Instances instances, final Instance instance) {
final int size = instance.numAttributes();
final BehaviorModel behaviorModel = new BehaviorModel();
for (int i = 0; i < size; i++) {
final Attribute attribute = instances.attribute(i);
final String attributeName = attribute.name();
final Double attributeValue = instance.value(attribute);
if (this.matchEdge(attributeName)) {
final Optional<EntryCallEdge> edge = this.createEdge(attributeName, attributeValue);
if (edge.isPresent()) {
behaviorModel.addEdge(edge.get(), true);
}
} else if (this.matchNode(attributeName)) {
final Optional<EntryCallNode> node = this.createNode(attributeName, attributeValue);
if (node.isPresent()) {
behaviorModel.addNode(node.get(), true);
}
}
}
if (behaviorModel.getEdges().isEmpty() && behaviorModel.getNodes().isEmpty()) {
return Optional.empty();
}
return Optional.of(behaviorModel);
}
use of org.iobserve.analysis.behavior.models.extended.BehaviorModel in project iobserve-analysis by research-iobserve.
the class IntersectionModelGenerationStrategy method intersect.
private BehaviorModel intersect(final BehaviorModel a, final BehaviorModel b) {
final BehaviorModel result = new BehaviorModel();
Optional<EntryCallEdge> matchingEdge;
for (final EntryCallEdge edgeA : a.getEdges()) {
matchingEdge = b.findEdge(edgeA.getSource().getSignature(), edgeA.getTarget().getSignature());
if (matchingEdge.isPresent()) {
final EntryCallNode newSource = this.intersectNode(edgeA.getSource(), matchingEdge.get().getSource());
final EntryCallNode newTarget = this.intersectNode(edgeA.getTarget(), matchingEdge.get().getTarget());
final int edgeCount = (int) Math.min(edgeA.getCalls(), matchingEdge.get().getCalls());
final EntryCallEdge newEdge = new EntryCallEdge(newSource, newTarget, edgeCount);
result.addEdge(newEdge, false);
}
}
return result;
}
use of org.iobserve.analysis.behavior.models.extended.BehaviorModel in project iobserve-analysis by research-iobserve.
the class SessionToBehaviorModelTransformation method convert.
/**
* Convert a user session into a behavior model.
*
* @param session
* user session
* @return returns a behavior model
*/
public BehaviorModel convert(final UserSession session) {
final BehaviorModel model = new BehaviorModel();
model.setName(this.prefix);
final List<EntryCallEvent> entryCalls = session.getEvents();
final Iterator<EntryCallEvent> iterator = entryCalls.iterator();
// Assume list has at least one element
if (iterator.hasNext()) {
EntryCallNode lastNode = this.createNode((PayloadAwareEntryCallEvent) iterator.next());
EntryCallNode currentNode;
while (iterator.hasNext()) {
currentNode = this.createNode((PayloadAwareEntryCallEvent) iterator.next());
model.addNode(currentNode, true);
model.addEdge(new EntryCallEdge(lastNode, currentNode), false);
lastNode = currentNode;
}
return model;
} else {
SessionToBehaviorModelTransformation.LOGGER.error("Empty user session creates empty model");
return model;
}
}
use of org.iobserve.analysis.behavior.models.extended.BehaviorModel in project iobserve-analysis by research-iobserve.
the class ModelComparisonStageTest method createTestModel.
private BehaviorModel createTestModel() {
final BehaviorModel model = new BehaviorModel();
model.addNode(this.nodeAtest, false);
model.addNode(this.nodeBtest, false);
model.addNode(this.nodeDtest, false);
final EntryCallEdge edgeAB = new EntryCallEdge(this.nodeAtest, this.nodeBtest);
edgeAB.addCalls(4);
model.addEdge(edgeAB, false);
final EntryCallEdge edgeBA = new EntryCallEdge(this.nodeBtest, this.nodeAtest);
edgeBA.addCalls(3);
model.addEdge(edgeBA, false);
final EntryCallEdge edgeBD = new EntryCallEdge(this.nodeBtest, this.nodeDtest);
edgeBA.addCalls(1);
model.addEdge(edgeBD, false);
return model;
}
use of org.iobserve.analysis.behavior.models.extended.BehaviorModel in project iobserve-analysis by research-iobserve.
the class BehaviorModelJSONReader method execute.
@Override
protected void execute() throws Exception {
final ObjectMapper mapper = new ObjectMapper();
/**
* Have to read the model by hand
*/
final JsonNode tree = mapper.readTree(this.inputFile);
if (!(tree instanceof ObjectNode)) {
throw new IOException("Wrong format while reading model.");
}
final ObjectNode modelNode = (ObjectNode) tree;
final BehaviorModel model = new BehaviorModel();
/**
* Read name.
*/
final JsonNode name = modelNode.get("name");
if (name.isTextual()) {
model.setName(name.textValue());
}
// Read nodes
final JsonNode nodesNode = modelNode.get("nodes");
if (nodesNode.isArray()) {
final ArrayNode nodesArray = (ArrayNode) nodesNode;
final Iterator<JsonNode> nodesIter = nodesArray.elements();
while (nodesIter.hasNext()) {
final EntryCallNode newECNode = new EntryCallNode();
final ObjectNode node = (ObjectNode) nodesIter.next();
newECNode.setSignature(node.get("signature").textValue());
final ArrayNode callInfos = (ArrayNode) node.get("entryCallInformation");
final Iterator<JsonNode> callInfoIter = callInfos.elements();
while (callInfoIter.hasNext()) {
final ObjectNode ciNode = (ObjectNode) callInfoIter.next();
final CallInformation info = new CallInformation(ciNode.get("informationSignature").textValue(), ciNode.get("informationCode").textValue(), ciNode.get("count").asInt());
newECNode.mergeCallInformation(info);
}
model.addNode(newECNode, false);
}
}
final ArrayNode edgesNode = (ArrayNode) modelNode.findValue("edges");
final Iterator<JsonNode> edgesIter = edgesNode.elements();
while (edgesIter.hasNext()) {
final ObjectNode edge = (ObjectNode) edgesIter.next();
final ObjectNode source = (ObjectNode) edge.get("source");
final ObjectNode target = (ObjectNode) edge.get("target");
final EntryCallNode sourceECNode = model.findNode(source.get("signature").textValue()).get();
final EntryCallNode targetECNode = model.findNode(target.get("signature").textValue()).get();
final EntryCallEdge newECEdge = new EntryCallEdge(sourceECNode, targetECNode, edge.get("calls").asInt());
model.addEdge(newECEdge, false);
}
this.outputPort.send(model);
this.workCompleted();
}
Aggregations