if (ship == null) {
System.err.println("populateRelevantKB called with ship == null");
return;
}
DataBase db = DataBase.getInstance();
ObjectEntity entity;
String shipName;
String ship2Name;
String personName;
String organizationName;
ResidentNode residentNode;
ObjectEntityInstance[] arguments;
Entity state;
CategoricalStateEntity categoricalState = null;
entity = mebn.getObjectEntityContainer().getObjectEntityByName("Ship");
// TODO - Make sure to use a unique id later on
shipName = "ship" + db.getShips().indexOf(ship);
// Add the entity instance for ship if it was not added before
if (mebn.getObjectEntityContainer().getEntityInstanceByName(shipName) == null) {
mebnUtil.createEntityIntance(entity, shipName);
}
// Ship characteristics
if (ship.getShipType() != null) {
residentNode = mebn.getDomainResidentNode("hasTypeOfShip");
arguments = new ObjectEntityInstance[1];
arguments[0] = mebn.getObjectEntityContainer()
.getEntityInstanceByName(shipName);
if (ship.getShipType() == ShipType.FISHING) {
categoricalState = mebn.getCategoricalStatesEntityContainer().getCategoricalState("Fishing");
} else {
categoricalState = mebn.getCategoricalStatesEntityContainer().getCategoricalState("Merchant");
}
mebnUtil.createRandomVariableFinding(residentNode, arguments, categoricalState);
}
// populate findings for the continuous variables (only consider leaf nodes)
// populate propellerTurnCount
if (isContinuousCase()) {
residentNode = mebn.getDomainResidentNode("propellerTurnCount");
if (residentNode != null && (residentNode instanceof ContinuousResidentNode)) {
arguments = new ObjectEntityInstance[1];
arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName(shipName);
mebnUtil.createRandomVariableFinding((ContinuousResidentNode)residentNode, arguments, ship.getPropellerTurnCount());
} else {
System.err.println(residentNode + ": propellerTurnCount is not a continuous resident node in " + mebn);
}
} else {
residentNode = mebn.getDomainResidentNode("propellerTurnCount");
if (residentNode != null && !(residentNode instanceof ContinuousResidentNode)) {
arguments = new ObjectEntityInstance[1];
arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName(shipName);
try {
categoricalState = mebn.getCategoricalStatesEntityContainer().getCategoricalState(ship.getPropellerTurnCountDiscretizedValue());
if (categoricalState != null) {
mebnUtil.createRandomVariableFinding(residentNode, arguments, categoricalState);
}
} catch (CategoricalStateDoesNotExistException e) {
System.err.println(residentNode + " does not have state " + ship.getPropellerTurnCountDiscretizedValue());
}
} else {
System.err.println(residentNode + ": propellerTurnCount is not a discrete resident node in " + mebn);
}
}
// populate cavitation
if (isContinuousCase()) {
residentNode = mebn.getDomainResidentNode("cavitation");
if (residentNode != null && (residentNode instanceof ContinuousResidentNode)) {
arguments = new ObjectEntityInstance[1];
arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName(shipName);
mebnUtil.createRandomVariableFinding((ContinuousResidentNode)residentNode, arguments, ship.getCavitation());
} else {
System.err.println(residentNode + ": cavitation is not a continuous resident node in " + mebn);
}
} else {
residentNode = mebn.getDomainResidentNode("cavitation");
if (residentNode != null && !(residentNode instanceof ContinuousResidentNode)) {
arguments = new ObjectEntityInstance[1];
arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName(shipName);
try {
categoricalState = mebn.getCategoricalStatesEntityContainer().getCategoricalState(ship.getCavitationDiscretizedValue());
if (categoricalState != null) {
mebnUtil.createRandomVariableFinding(residentNode, arguments, categoricalState);
}
} catch (CategoricalStateDoesNotExistException e) {
System.err.println(residentNode + " does not have state " + ship.getCavitationDiscretizedValue());
}
} else {
System.err.println(residentNode + ": cavitation is not a discrete resident node in " + mebn);
}
}
// populate shipRCSChange
if (isContinuousCase()) {
residentNode = mebn.getDomainResidentNode("shipRCSChange");
if (residentNode != null && (residentNode instanceof ContinuousResidentNode)) {
arguments = new ObjectEntityInstance[1];
arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName(shipName);
mebnUtil.createRandomVariableFinding((ContinuousResidentNode)residentNode, arguments, ship.getShipRCSChange());
} else {
System.err.println(residentNode + ": shipRCSChange is not a continuous resident node in " + mebn);
}
} else {
residentNode = mebn.getDomainResidentNode("shipRCSChange");
if (residentNode != null && !(residentNode instanceof ContinuousResidentNode)) {
arguments = new ObjectEntityInstance[1];
arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName(shipName);
try {
categoricalState = mebn.getCategoricalStatesEntityContainer().getCategoricalState(ship.getShipRCSChangeDiscretizedValue());
if (categoricalState != null) {
mebnUtil.createRandomVariableFinding(residentNode, arguments, categoricalState);
}
} catch (CategoricalStateDoesNotExistException e) {
System.err.println(residentNode + " does not have state " + ship.getShipRCSChangeDiscretizedValue());
}
} else {
System.err.println(residentNode + ": ShipRCSChange is not a discrete resident node in " + mebn);
}
}
// speed of ship (depending on the reasoning mode, this value is continuous or discrete values)
// TODO add findings to ship's speedChange, turnRate, propellerTurnCount,cavitation,shipRCSChange.
// if (isContinuousCase()) {
// residentNode = mebn.getDomainResidentNode("speed");
// if (residentNode != null && (residentNode instanceof ContinuousResidentNode)) {
// arguments = new ObjectEntityInstance[1];
// arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName(shipName);
// mebnUtil.createRandomVariableFinding((ContinuousResidentNode)residentNode, arguments, ship.getSpeed());
// } else {
// System.err.println(residentNode + " is not a continuous resident node.");
// }
// } else {
// residentNode = mebn.getDomainResidentNode("speed");
// if (residentNode != null && !(residentNode instanceof ContinuousResidentNode)) {
// arguments = new ObjectEntityInstance[1];
// arguments[0] = mebn.getObjectEntityContainer().getEntityInstanceByName(shipName);
// categoricalState = mebn.getCategoricalStatesEntityContainer().getCategoricalState(ship.getDiscretizedSpeed());
// if (categoricalState != null) {
// mebnUtil.createRandomVariableFinding(residentNode, arguments, categoricalState);
// }
// } else {
// System.err.println(residentNode + " is not a discrete resident node.");
// }
// }
// Evidence that support the hyposthesis hasEvasiveBehavior(ship)
if (!ship.hasResponsiveAIS()) {
residentNode = mebn.getDomainResidentNode("hasResponsiveAIS");
arguments = new ObjectEntityInstance[1];
arguments[0] = mebn.getObjectEntityContainer()
.getEntityInstanceByName(shipName);
state = mebn.getBooleanStatesEntityContainer()
.getFalseStateEntity();
mebnUtil
.createRandomVariableFinding(residentNode, arguments, state);
}
if (!ship.hasResponsiveRadio()) {
residentNode = mebn.getDomainResidentNode("hasResponsiveRadio");
arguments = new ObjectEntityInstance[1];
arguments[0] = mebn.getObjectEntityContainer()
.getEntityInstanceByName(shipName);
state = mebn.getBooleanStatesEntityContainer()
.getFalseStateEntity();
mebnUtil
.createRandomVariableFinding(residentNode, arguments, state);
}
// Evidence (report) that supports the hypothesis hasUnusualRoute(ship)
if (ship.isOnUnusualRoute()) {
residentNode = mebn.getDomainResidentNode("hasUnusualRouteReport");
arguments = new ObjectEntityInstance[1];
arguments[0] = mebn.getObjectEntityContainer()
.getEntityInstanceByName(shipName);
state = mebn.getBooleanStatesEntityContainer().getTrueStateEntity();
mebnUtil
.createRandomVariableFinding(residentNode, arguments, state);
}
// Load all ships that possibly met
// Also evidence (report) that supports the hypothesis hasUnusualRoute(ship)
if (ship.getPossibleMeeting().size() > 0) {
for (ShipEntity shipMeeting : ship.getPossibleMeeting()) {
ship2Name = "ship" + db.getShips().indexOf(shipMeeting);
// Add the entity instance for ship2 if it was not added
// before
if (mebn.getObjectEntityContainer().getEntityInstanceByName(
ship2Name) == null) {
mebnUtil.createEntityIntance(entity, ship2Name);
}
residentNode = mebn.getDomainResidentNode("areMeetingReport");
arguments = new ObjectEntityInstance[2];
arguments[0] = mebn.getObjectEntityContainer()
.getEntityInstanceByName(shipName);
arguments[1] = mebn.getObjectEntityContainer()
.getEntityInstanceByName(ship2Name);
state = mebn.getBooleanStatesEntityContainer()
.getTrueStateEntity();
mebnUtil.createRandomVariableFinding(residentNode, arguments,
state);
}
}
// Evidence that support the hyposthesis hasErraticBehavior(ship)
if (ship.isCrewVisible()) {
residentNode = mebn.getDomainResidentNode("isCrewVisible");
arguments = new ObjectEntityInstance[1];
arguments[0] = mebn.getObjectEntityContainer()
.getEntityInstanceByName(shipName);
state = mebn.getBooleanStatesEntityContainer()
.getTrueStateEntity();
mebnUtil
.createRandomVariableFinding(residentNode, arguments, state);
}
// Evidence that support the hyposthesis hasAggressiveBehavior(ship)
if (ship.hasWeaponVisible()) {
residentNode = mebn.getDomainResidentNode("hasWeaponVisible");
arguments = new ObjectEntityInstance[1];
arguments[0] = mebn.getObjectEntityContainer()
.getEntityInstanceByName(shipName);
state = mebn.getBooleanStatesEntityContainer()
.getTrueStateEntity();
mebnUtil
.createRandomVariableFinding(residentNode, arguments, state);
}
if (ship.isJettisoningCargo()) {
residentNode = mebn.getDomainResidentNode("isJettisoningCargo");
arguments = new ObjectEntityInstance[1];
arguments[0] = mebn.getObjectEntityContainer()
.getEntityInstanceByName(shipName);
state = mebn.getBooleanStatesEntityContainer()
.getTrueStateEntity();
mebnUtil
.createRandomVariableFinding(residentNode, arguments, state);
}
// Load all crew members
for (PersonEntity person : ship.getCrew()) {
entity = mebn.getObjectEntityContainer().getObjectEntityByName(
"Person");
// TODO - Make sure to use a unique id later on
personName = "person" + db.getPeople().indexOf(person);
mebnUtil.createEntityIntance(entity, personName);
// Adding finding stating that this person is a crew member of this ship
residentNode = mebn.getDomainResidentNode("hasCrewMember");
arguments = new ObjectEntityInstance[2];
arguments[0] = mebn.getObjectEntityContainer()
.getEntityInstanceByName(shipName);
arguments[1] = mebn.getObjectEntityContainer()
.getEntityInstanceByName(personName);
state = mebn.getBooleanStatesEntityContainer().getTrueStateEntity();
mebnUtil
.createRandomVariableFinding(residentNode, arguments, state);
// Add information about the terrorist organizations associated to this crew member
if (person.isPartOfTerroristOrganisation()) {
for (OrganizationEntity organization : person
.getRelatedOrganizations()) {
if (organization.isTerroristOrganisation()) {
entity = mebn.getObjectEntityContainer()
.getObjectEntityByName("Organization");
// TODO - Make sure to use a unique id later on
organizationName = "organization"
+ db.getOrganizations().indexOf(organization);
mebnUtil.createEntityIntance(entity, organizationName);
// Add this crew member as member of this organization
residentNode = mebn
.getDomainResidentNode("isMemberOfOrganization");