Commit be24c617 authored by Nicolas Seydoux's avatar Nicolas Seydoux
Browse files

Fixed reinference for cir and added properties for iiot usecase

- Reinference was broken, because the condition in the applicantRule
required the lower node not to be a total producer of the rule head,
which may be the case for cir. This condition was held regardless of the
"applicable" status of the rule, that was created for this purpose.
- Conveyor and machine states were added
- Fixed machine namespace in r1
- Enabled separated log of model at runtime (easier than postman in some
cases)
parent 852235bf
{
"name":"comfort-app",
"uri":"http://localhost/",
"port":8006,
"endpoint":"http://localhost:6001/rules/add",
"ruleset":["shapes/iiot/r1.ttl", "shapes/iiot/r2.ttl"]
}
......@@ -38,7 +38,7 @@ ex:IIoTR1TransferShape
WHERE {
FILTER NOT EXISTS {
$this a lmu:Node ;
edr:producesDataOn adr:Presence, adr:Luminosity, adr:State ;
edr:producesDataOn adr:Presence, adr:Luminosity, adr:MachineState ;
lmu:hasUpstreamNode [
a lmu:HostNode;
].
......@@ -77,44 +77,44 @@ ex:IIoTR1RuleTransfer
""";
].
ex:IIoTR1ApplicableShape
a sh:NodeShape ;
a edr:ApplicableShape ;
a edr:NodeSensitiveComponent;
sh:targetClass lmu:HostNode ;
sh:sparql [
sh:select """
PREFIX edr: <http://w3id.org/laas-iot/edr#>
PREFIX lmu: <http://w3id.org/laas-iot/lmu#>
PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#>
prefix adr: <https://w3id.org/laas-iot/adream#>
prefix ex: <http://example.com/ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT $this
WHERE {
ex:IIoTR1ApplicableShape
a sh:NodeShape ;
a edr:ApplicableShape ;
a edr:NodeSensitiveComponent;
sh:targetClass lmu:HostNode ;
sh:sparql [
sh:select """
PREFIX edr: <http://w3id.org/laas-iot/edr#>
PREFIX lmu: <http://w3id.org/laas-iot/lmu#>
PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#>
prefix adr: <https://w3id.org/laas-iot/adream#>
prefix ex: <http://example.com/ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT $this
WHERE {
FILTER NOT EXISTS {
ex:IIoTR1CoreRule edr:isRuleActivable "true"^^xsd:boolean.
}
FILTER NOT EXISTS {
$this a lmu:HostNode.
$this lmu:hasDownstreamNode ?presenceProvider, ?luminosityProvider, ?stateProvider.
?presenceProvider edr:producesDataOn adr:Presence.
?luminosityProvider edr:producesDataOn adr:Luminosity.
?stateProvider edr:producesDataOn adr:MachineState.
FILTER NOT EXISTS {
ex:IIoTR1CoreRule edr:isRuleActivable "true"^^xsd:boolean.
ex:IIoTR1CoreRule edr:isRuleActive "true"^^xsd:boolean.
}
FILTER NOT EXISTS {
$this a lmu:HostNode.
$this lmu:hasDownstreamNode ?presenceProvider, ?luminosityProvider, ?stateProvider.
?presenceProvider edr:producesDataOn adr:Presence.
?luminosityProvider edr:producesDataOn adr:Luminosity.
?stateProvider edr:producesDataOn adr:State.
FILTER EXISTS {
$this lmu:hasDownstreamNode ?lowerNode.
FILTER(?lowerNode = ?luminosityProvider || ?lowerNode = ?presenceProvider || ?lowerNode = ?stateProvider)
FILTER NOT EXISTS {
ex:IIoTR1CoreRule edr:isRuleActive "true"^^xsd:boolean.
}
FILTER EXISTS {
$this lmu:hasDownstreamNode ?lowerNode.
FILTER(?lowerNode = ?luminosityProvider || ?lowerNode = ?presenceProvider || ?lowerNode = ?stateProvider)
FILTER NOT EXISTS {
?lowerNode edr:producesDataOn adr:Presence, adr:Luminosity, adr:State.
}
?lowerNode edr:producesDataOn adr:Presence, adr:Luminosity, adr:MachineState.
}
}
}
""" ;
].
}
}
""" ;
].
ex:IIoTR1ApplicantRule
a sh:NodeShape ;
......@@ -129,17 +129,21 @@ ex:IIoTR1ApplicantRule
prefix ex: <http://example.com/ns#>
prefix lmu: <http://w3id.org/laas-iot/lmu#>
CONSTRUCT {
$this edr:isInterestedIn adr:Luminosity, adr:Presence, adr:State.
$this edr:isInterestedIn adr:Luminosity, adr:Presence, adr:MachineState.
$this edr:producesDataOn ex:LowMachineVisibility.
?partialDataProvider edr:partialDataProvider ?partialProduction.
ex:IIoTR1CoreRule edr:isRuleActive "true"^^xsd:boolean.
?originator edr:consumesResult ex:IIoTR1CoreRule.
} WHERE {
$this a lmu:HostNode.
$this lmu:hasDownstreamNode ?partialDataProvider.
?partialDataProvider edr:producesDataOn ?partialProduction.
FILTER NOT EXISTS {
?partialDataProvider edr:producesDataOn adr:Luminosity, adr:Presence, adr:State.
{
$this lmu:hasDownstreamNode ?partialDataProvider.
?partialDataProvider edr:producesDataOn ?partialProduction.
FILTER NOT EXISTS {
?partialDataProvider edr:producesDataOn adr:Luminosity, adr:Presence, adr:MachineState.
}
} UNION {
ex:IIoTR1CoreRule edr:isRuleActivable "true"^^xsd:boolean.
}
ex:IIoTR1CoreRule edr:ruleOriginatedFrom ?originator.
OPTIONAL{ex:IIoTR1CoreRule edr:isRuleActive "false"^^xsd:boolean.}
......@@ -254,7 +258,7 @@ ex:IIoTR1CoreRule
?presence_obs ssn:observationResult/ssn:hasValue/dul:hasDataValue ?presenceValue;
ssn:observedProperty ?presence;
ssn:observedBy ?presence_sensor.
FILTER(?presenceValue = 'true'^^xsd:boolean)
FILTER(?presenceValue = '1.0'^^xsd:float)
?luminosity rdf:type/rdfs:subClassOf* <https://w3id.org/laas-iot/adream#Luminosity>;
ssn:isPropertyOf ?feature.
......@@ -268,9 +272,9 @@ ex:IIoTR1CoreRule
?state_obs ssn:observationResult/ssn:hasValue/dul:hasDataValue ?stateValue;
ssn:observedProperty ?state;
ssn:observedBy ?state_sensor.
FILTER(?stateValue = 'true'^^xsd:boolean)
FILTER(?stateValue = '1.0'^^xsd:float)
?machine a ex:Machine;
?machine a iiot:Machine;
iiot:onConveyor/iiot:locatedIn? ?presenceFeature.
?presenceFeature iiot:locatedIn? ?feature.
......
......@@ -48,3 +48,9 @@ python3 simulator/generator.py -t simulator/ieee/minimal_local.json -o simulator
python3 simulator/generator.py -t simulator/ieee/minimal_local.json -o simulator/ieee/minimal_local_cdp -c cdp -r simulator/ieee/replay-minimal/
python3 simulator/generator.py -t simulator/ieee/minimal_local.json -o simulator/ieee/minimal_local_cip -c cip -r simulator/ieee/replay-minimal/
python3 simulator/generator.py -t simulator/ieee/minimal_local.json -o simulator/ieee/minimal_local_adp -c adp -r simulator/ieee/replay-minimal/
python3 simulator/generator.py -t simulator/coopis/mini_factory.json -o simulator/coopis/mini_factory_cdr -c cdr
python3 simulator/generator.py -t simulator/coopis/mini_factory.json -o simulator/coopis/mini_factory_cir -c cir
python3 simulator/generator.py -t simulator/coopis/mini_factory.json -o simulator/coopis/mini_factory_cdp -c cdp
python3 simulator/generator.py -t simulator/coopis/mini_factory.json -o simulator/coopis/mini_factory_cip -c cip
python3 simulator/generator.py -t simulator/coopis/mini_factory.json -o simulator/coopis/mini_factory_adp -c adp
......@@ -23,10 +23,13 @@
<Pattern>{"time":"%d{HH:mm:ss.SSS}{GMT+2}",%msg}%n</Pattern>
</Layout>
</Appender>
<Appender type="File" name="LogAppender" fileName="${sys:filename}">
<Appender type="File" name="LogAppender" fileName="execution_log.log">
<Layout type="PatternLayout">
<Pattern>%msg%n</Pattern>
</Layout>
<Filters>
<Filter type="MarkerFilter" marker="MODEL_MARKER" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
</Appender>
</Appenders>
......@@ -38,7 +41,7 @@
<Logger name="org.apache.commons" level="info" additivity="true">
<AppenderRef ref="STDOUT"/>
</Logger>
<Logger name="LogFile" level="info" additivity="false">
<Logger name="LogFile" level="debug" additivity="false">
<AppenderRef ref="LogAppender"/>
</Logger>
<Logger name="TraceFile" level="info" additivity="false">
......
prefix edr: <http://w3id.org/laas-iot/edr#>
prefix ssn: <http://purl.oclc.org/NET/ssnx/ssn#>
INSERT {
?obs edr:usedForDeductionBy <{{ rule }}>.
......
......@@ -3,9 +3,10 @@ PREFIX edr: <http://w3id.org/laas-iot/edr#>
DELETE {
<{{ rule }}> edr:transferableTo ?transferTarget.
} INSERT {
?transferTarget edr:producesDataOn ?interest.
?transferTarget edr:partialDataProvider ?interest.
?transferTarget edr:partialDataProvider ?production.
<{{ host }}> edr:isInterestedIn ?production.
} WHERE {
<{{ host }}> edr:isInterestedIn ?interest.
# <{{ host }}> edr:isInterestedIn ?interest.
<{{ rule }}> edr:transferableTo ?transferTarget.
?transferTarget edr:producesDataOn ?production.
}
......@@ -20,6 +20,8 @@ public enum E_Property {
PYRANOMETRY("https://w3id.org/laas-iot/adream#ADREAMPyranometry"),
HYGROMETRY("https://w3id.org/laas-iot/adream#ADREAMHygrometry"),
ATHMOSPHERIC_PRESSURE("https://w3id.org/laas-iot/adream#ADREAMAthmosphericPressure"),
MACHINE_STATE("https://w3id.org/laas-iot/adream#MachineState"),
CONVEYOR_STATE("https://w3id.org/laas-iot/adream#ConveyorState"),
POWER_REDISTRIBUTION("https://w3id.org/laas-iot/adream#PowerRedistribution");
private String uri;
private E_Property(String uri){
......@@ -71,6 +73,10 @@ public enum E_Property {
return E_Property.HYGROMETRY;
} else if(value.equals("athmospheric_pressure")){
return E_Property.ATHMOSPHERIC_PRESSURE;
} else if(value.equals("machineState")){
return E_Property.MACHINE_STATE;
} else if(value.equals("conveyorState")){
return E_Property.CONVEYOR_STATE;
} else {
return null;
}
......
......@@ -13,9 +13,11 @@ import java.util.Map.Entry;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ModelMaker;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.Marker;
import org.topbraid.shacl.util.ModelPrinter;
import fr.irit.melodi.edr.configuration.E_Centralization;
......@@ -29,6 +31,9 @@ import fr.irit.tools.queries.QueryEngine;
public class RuleManager {
private static final Logger LOGGER = LogManager.getLogger(RuleManager.class);
private static final Marker MODEL_MARKER = MarkerManager.getMarker("MODEL_MARKER");
private static final Logger LOGFILE = LogManager.getLogger("LogFile");
public static final String SHACL_URI = "http://www.w3.org/ns/shacl#";
private FolderManager queries;
public static Set<Entry<String, String>> prefixes;
......@@ -286,6 +291,7 @@ public class RuleManager {
LOGGER.debug("Shifting a transfer into an activation of "+ruleURI);
this.shiftTransferIntoInterest(ruleURI);
this.markRuleActivable(ruleURI);
LOGFILE.debug(MODEL_MARKER, Node.getInstance().getKBManager().serializeModel());
Model reinference = Node.getInstance().getKBManager().executeRules();
Node.getInstance().getKBManager().addToModel(reinference);
LOGGER.debug("Reinference : " + ModelPrinter.get().print(reinference));
......
{
"name": "simple-building",
"centralized": "adp",
"common_knowledge":[],
"common_knowledge":["https://w3id.org/laas-iot/edr/iiot/factory.ttl"],
"layers": {
"type": "building",
"count": 1,
......@@ -27,6 +27,16 @@
"feature": "https://w3id.org/laas-iot/edr/iiot/factory#Conveyor11",
"host": "http://localhost",
"concentrates": [{
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"conveyorState"
}, {
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"presence"
}, {
"type": "room",
"count": 1,
"feature": "https://w3id.org/laas-iot/edr/iiot/factory#Machine111",
......@@ -35,7 +45,7 @@
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"state"
"measures":"machineState"
}]
}, {
"type": "room",
......@@ -46,7 +56,7 @@
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"state"
"measures":"machineState"
}]
}, {
"type": "room",
......@@ -57,7 +67,7 @@
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"state"
"measures":"machineState"
}]
}]
}, {
......@@ -69,8 +79,8 @@
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"state"
},{
"measures":"conveyorState"
}, {
"type":"sensor",
"host": "http://localhost",
"count":1,
......@@ -84,7 +94,7 @@
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"state"
"measures":"machineState"
}]
}, {
"type": "room",
......@@ -95,7 +105,7 @@
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"state"
"measures":"machineState"
}]
}, {
"type": "room",
......@@ -106,7 +116,7 @@
"type":"sensor",
"host": "http://localhost",
"count":1,
"measures":"state"
"measures":"machineState"
}]
}]
}]
......
......@@ -71,7 +71,10 @@ def parametrize_sensor(node):
elif node["measures"] == "presence":
node["measureType"] = "boolean"
node["rate"] = 0.5
elif node["measures"] == "state":
elif node["measures"] == "machineState":
node["measureType"] = "boolean"
node["rate"] = 0.5
elif node["measures"] == "conveyroState":
node["measureType"] = "boolean"
node["rate"] = 0.5
elif node["measures"] == 'openness':
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment