From 9dd512d92e050fe010e334a113019af100a32eeb Mon Sep 17 00:00:00 2001 From: rschoene <rene.schoene@tu-dresden.de> Date: Fri, 26 Apr 2019 15:48:33 +0200 Subject: [PATCH] Split grammar in logical pieces. - Possible with RelAST 0.2.1 --- eraser-base/build.gradle | 24 ++-- .../src/main/jastadd/MachineLearning.relast | 55 ++++++++ eraser-base/src/main/jastadd/Rules.relast | 25 ++++ eraser-base/src/main/jastadd/main.relast | 126 +----------------- eraser-base/src/main/jastadd/mqtt.relast | 4 + eraser-base/src/main/jastadd/openhab.relast | 57 ++++++++ 6 files changed, 155 insertions(+), 136 deletions(-) create mode 100644 eraser-base/src/main/jastadd/MachineLearning.relast create mode 100644 eraser-base/src/main/jastadd/Rules.relast create mode 100644 eraser-base/src/main/jastadd/mqtt.relast create mode 100644 eraser-base/src/main/jastadd/openhab.relast diff --git a/eraser-base/build.gradle b/eraser-base/build.gradle index d9e2b471..ec103c3c 100644 --- a/eraser-base/build.gradle +++ b/eraser-base/build.gradle @@ -50,20 +50,22 @@ jacocoTestReport { } } +def relastFiles = fileTree('src/main/jastadd/') { + include '**/*.relast' }.toList().toArray() +String[] relastArguments = [ + "libs/relast.jar", + "--grammarName=./src/main/jastadd/mainGen", + "--useJastAddNames", + "--listClass=RefList", + "--jastAddList=JastAddList", + "--file" +] task preprocess(type: JavaExec) { group = 'Build' main = "-jar" - args = [ - "libs/relast.jar", - "./src/main/jastadd/main.relast", - "--grammarName=./src/main/jastadd/mainGen", - "--useJastAddNames", - "--listClass=RefList", - "--jastAddList=JastAddList", - "--file" - ] - - inputs.files file("./src/main/jastadd/main.relast") + args relastArguments + relastFiles + + inputs.files relastFiles outputs.files file("./src/main/jastadd/mainGen.ast"), file("./src/main/jastadd/mainGen.jadd") } diff --git a/eraser-base/src/main/jastadd/MachineLearning.relast b/eraser-base/src/main/jastadd/MachineLearning.relast new file mode 100644 index 00000000..6ae08376 --- /dev/null +++ b/eraser-base/src/main/jastadd/MachineLearning.relast @@ -0,0 +1,55 @@ +// ---------------- Machine Learning Model ------------------------------ +MachineLearningRoot ::= [ActivityRecognition:MachineLearningModel] [PreferenceLearning:MachineLearningModel] Activity* ChangeEvent* ; + +Activity ::= <Identifier:int> <Label:String> ; + +abstract ChangeEvent ::= <Identifier:int> <Timestamp:long> ChangedItem* ; + +ChangedItem ::= <NewStateAsString:String> ; +rel ChangedItem.Item -> Item ; + +RecognitionEvent : ChangeEvent ; +rel RecognitionEvent.Activity -> Activity ; + +ManualChangeEvent : ChangeEvent ; + +abstract MachineLearningModel ::= <OutputApplication:DoubleDoubleFunction> ; + +abstract ItemPreference ::= ; +rel ItemPreference.Item -> Item ; + +ItemPreferenceColor : ItemPreference ::= <PreferredHSB:TupleHSB> ; +ItemPreferenceDouble : ItemPreference ::= <PreferredValue:double> ; + +// ---------------- Decision Tree ------------------------------ +DecisionTreeRoot : MachineLearningModel ::= RootRule:DecisionTreeRule ; +abstract DecisionTreeElement ::= Preference:ItemPreference*; +abstract DecisionTreeRule : DecisionTreeElement ::= Left:DecisionTreeElement Right:DecisionTreeElement <Label:String> ; +ItemStateCheckRule : DecisionTreeRule ::= ItemStateCheck ; + +abstract ItemStateCheck ::= <Comparator:ComparatorType> ; +rel ItemStateCheck.Item -> Item ; + +ItemStateNumberCheck : ItemStateCheck ::= <Value:double> ; +ItemStateStringCheck : ItemStateCheck ::= <Value:String> ; +DecisionTreeLeaf : DecisionTreeElement ::= <ActivityIdentifier:int> <Label:String> ; + +// ---------------- Neural Network ------------------------------ +NeuralNetworkRoot : MachineLearningModel ::= InputNeuron* HiddenNeuron* OutputLayer ; + +OutputLayer ::= OutputNeuron* <Combinator:DoubleArrayDoubleFunction> ; +rel OutputLayer.AffectedItem -> Item ; + +abstract Neuron ::= Output:NeuronConnection* ; + +NeuronConnection ::= <Weight:double> ; +rel NeuronConnection.Neuron <-> Neuron.Input* ; + +InputNeuron : Neuron ; +rel InputNeuron.Item -> Item ; + +HiddenNeuron : Neuron ::= <ActivationFormula:DoubleArrayDoubleFunction> ; +OutputNeuron : HiddenNeuron ::= <Label:String> ; + +DummyMachineLearningModel : MachineLearningModel ::= Current:DecisionTreeLeaf ; +rel DummyMachineLearningModel.Item* -> Item ; diff --git a/eraser-base/src/main/jastadd/Rules.relast b/eraser-base/src/main/jastadd/Rules.relast new file mode 100644 index 00000000..69854a70 --- /dev/null +++ b/eraser-base/src/main/jastadd/Rules.relast @@ -0,0 +1,25 @@ +// --- New ECA rules --- +Rule ::= Condition* Action* ; +abstract Condition ; +ItemStateCheckCondition : Condition ::= ItemStateCheck ; +abstract Action ; +LambdaAction : Action ::= <Lambda:Action2EditConsumer> ; + +TriggerRuleAction : Action ; +rel TriggerRuleAction.Rule -> Rule ; + +abstract SetStateAction : Action ; +rel SetStateAction.AffectedItem -> Item ; + +SetStateFromConstantStringAction : SetStateAction ::= <NewState:String> ; +SetStateFromLambdaAction : SetStateAction ::= <NewStateProvider:NewStateProvider> ; +SetStateFromTriggeringItemAction : SetStateAction ::= ; + +SetStateFromItemsAction : SetStateAction ::= <Combinator:ItemsToStringFunction> ; +rel SetStateFromItemsAction.SourceItem* -> Item ; + +AddDoubleToStateAction : SetStateAction ::= <Increment:double> ; +MultiplyDoubleToStateAction : SetStateAction ::= <Multiplier:double> ; + +ItemObserver ::= ; +rel ItemObserver.TriggeredRule* <-> Rule.Observer* ; diff --git a/eraser-base/src/main/jastadd/main.relast b/eraser-base/src/main/jastadd/main.relast index 9dc1b59b..f9601870 100644 --- a/eraser-base/src/main/jastadd/main.relast +++ b/eraser-base/src/main/jastadd/main.relast @@ -2,136 +2,12 @@ Root ::= Thing* Group* ThingType* ChannelType* ChannelCategory* ItemCategory* User* MqttRoot InfluxRoot MachineLearningRoot Rule* ; -// ---------------- openHAB ------------------------------ -abstract ModelElement ::= <ID:String> ; -abstract LabelledModelElement : ModelElement ::= <Label:String> ; -abstract DescribableModelElement : LabelledModelElement ::= <Description:String> ; - -ThingType : DescribableModelElement ::= Parameter* ; - -Thing : LabelledModelElement ::= Channel* ; - -ChannelType : DescribableModelElement ::= <ItemType:ItemType> <ReadOnly:boolean> ; - -abstract ChannelCategory ; -DefaultChannelCategory : ChannelCategory ::= <Value:DefaultChannelCategoryValue> ; -SimpleChannelCategory : ChannelCategory ::= <Value:String> ; - -Channel : ModelElement ::= Link* ; - -Link ::= <Item:Item> ; - -Parameter : DescribableModelElement ::= <Type:ParameterValueType> [DefaultValue:ParameterDefaultValue] <Context:String> <Required:boolean> ; -ParameterDefaultValue ::= <Value:String> ; - -abstract Item : LabelledModelElement ::= <_fetched_data:boolean> MetaData:ItemMetaData* [ItemObserver] ; -ItemMetaData ::= <Key:String> <Value:String> ; -abstract ItemWithBooleanState : Item ::= <_state:boolean> ; -abstract ItemWithStringState : Item ::= <_state:String> ; -abstract ItemWithDoubleState : Item ::= <_state:double> ; -ColorItem : Item ::= <_state:TupleHSB> ; -DateTimeItem : Item ::= <_state:Date> ; -ContactItem : ItemWithBooleanState ; -DimmerItem : ItemWithDoubleState ; -ImageItem : ItemWithStringState ; -LocationItem : ItemWithStringState ; -NumberItem : ItemWithDoubleState ; -PlayerItem : ItemWithStringState ; -RollerShutterItem : ItemWithBooleanState ; -StringItem : ItemWithStringState ; -SwitchItem : ItemWithBooleanState ; -DefaultItem : ItemWithStringState ; -ActivityItem : ItemWithDoubleState ; - -ItemCategory ::= <Name:String> ; - -Group : LabelledModelElement ::= Group* Item* [AggregationFunction:GroupAggregationFunction] ; -abstract GroupAggregationFunction ; -SimpleGroupAggregationFunction : GroupAggregationFunction ::= <FunctionName:SimpleGroupAggregationFunctionName> ; -ParameterizedGroupAggregationFunction : GroupAggregationFunction ::= <FunctionName:ParameterizedGroupAggregationFunctionName> - <Param1:String> <Param2:String> ; - // ---------------- Users ------------------------------ User : LabelledModelElement ; +rel Root.CurrentUser? -> User ; // ---------------- Util ------------------------------ ExternalHost ::= <HostName:String> <Port:int> ; -// ---------------- MQTT ------------------------------ -MqttRoot ::= Topic:MqttTopic* <IncomingPrefix:String> <OutgoingPrefix:String> [Host:ExternalHost] ; -MqttTopic ::= <Part:String> SubTopic:MqttTopic* ; - // ---------------- InfluxDB ------------------------------ InfluxRoot ::= <User:String> <Password:String> <DbName:String> [Host:ExternalHost] ; - -// ---------------- Machine Learning Model ------------------------------ -MachineLearningRoot ::= [ActivityRecognition:MachineLearningModel] [PreferenceLearning:MachineLearningModel] Activity* ChangeEvent* ; -Activity ::= <Identifier:int> <Label:String> ; -abstract ChangeEvent ::= <Identifier:int> <Timestamp:long> ChangedItem* ; -ChangedItem ::= <NewStateAsString:String> ; -RecognitionEvent : ChangeEvent ; -ManualChangeEvent : ChangeEvent ; -abstract MachineLearningModel ::= <OutputApplication:DoubleDoubleFunction> ; -abstract ItemPreference ::= ; -ItemPreferenceColor : ItemPreference ::= <PreferredHSB:TupleHSB> ; -ItemPreferenceDouble : ItemPreference ::= <PreferredValue:double> ; - -// ---------------- Decision Tree ------------------------------ -DecisionTreeRoot : MachineLearningModel ::= RootRule:DecisionTreeRule ; -abstract DecisionTreeElement ::= Preference:ItemPreference*; -abstract DecisionTreeRule : DecisionTreeElement ::= Left:DecisionTreeElement Right:DecisionTreeElement <Label:String> ; -ItemStateCheckRule : DecisionTreeRule ::= ItemStateCheck ; -abstract ItemStateCheck ::= <Comparator:ComparatorType> ; -ItemStateNumberCheck : ItemStateCheck ::= <Value:double> ; -ItemStateStringCheck : ItemStateCheck ::= <Value:String> ; -DecisionTreeLeaf : DecisionTreeElement ::= <ActivityIdentifier:int> <Label:String> ; - -// ---------------- Neural Network ------------------------------ -NeuralNetworkRoot : MachineLearningModel ::= InputNeuron* HiddenNeuron* OutputLayer ; -OutputLayer ::= OutputNeuron* <Combinator:DoubleArrayDoubleFunction> ; -abstract Neuron ::= Output:NeuronConnection* ; -NeuronConnection ::= <Weight:double> ; -InputNeuron : Neuron ; -HiddenNeuron : Neuron ::= <ActivationFormula:DoubleArrayDoubleFunction> ; -OutputNeuron : HiddenNeuron ::= <Label:String> ; - -DummyMachineLearningModel : MachineLearningModel ::= Current:DecisionTreeLeaf ; - -// --- New ECA rules --- -Rule ::= Condition* Action* ; -abstract Condition ; -ItemStateCheckCondition : Condition ::= ItemStateCheck ; -abstract Action ; -LambdaAction : Action ::= <Lambda:Action2EditConsumer> ; -TriggerRuleAction : Action ; -abstract SetStateAction : Action ; -SetStateFromConstantStringAction : SetStateAction ::= <NewState:String> ; -SetStateFromLambdaAction : SetStateAction ::= <NewStateProvider:NewStateProvider> ; -SetStateFromTriggeringItemAction : SetStateAction ::= ; -SetStateFromItemsAction : SetStateAction ::= <Combinator:ItemsToStringFunction> ; -AddDoubleToStateAction : SetStateAction ::= <Increment:double> ; -MultiplyDoubleToStateAction : SetStateAction ::= <Multiplier:double> ; -ItemObserver ::= ; - -// ---------------- Relations ------------------------------ -rel ThingType.ChannelType* -> ChannelType ; -rel Thing.Type -> ThingType ; -rel Channel.Type -> ChannelType ; -rel ChannelType.ChannelCategory -> ChannelCategory ; -rel Item.Topic <-> MqttTopic.Item ; -rel Item.Category? -> ItemCategory ; -rel ItemStateCheck.Item -> Item ; -rel NeuronConnection.Neuron <-> Neuron.Input* ; -rel InputNeuron.Item -> Item ; -rel OutputLayer.AffectedItem -> Item ; -rel ItemPreference.Item -> Item ; -rel Item.Controlling* <-> Item.ControlledBy* ; -rel Root.CurrentUser? -> User ; -rel ChangedItem.Item -> Item ; -rel RecognitionEvent.Activity -> Activity ; -rel DummyMachineLearningModel.Item* -> Item ; - -rel TriggerRuleAction.Rule -> Rule ; -rel SetStateAction.AffectedItem -> Item ; -rel SetStateFromItemsAction.SourceItem* -> Item ; -rel ItemObserver.TriggeredRule* <-> Rule.Observer* ; diff --git a/eraser-base/src/main/jastadd/mqtt.relast b/eraser-base/src/main/jastadd/mqtt.relast new file mode 100644 index 00000000..ca1a53b9 --- /dev/null +++ b/eraser-base/src/main/jastadd/mqtt.relast @@ -0,0 +1,4 @@ +// ---------------- MQTT ------------------------------ +MqttRoot ::= Topic:MqttTopic* <IncomingPrefix:String> <OutgoingPrefix:String> [Host:ExternalHost] ; +MqttTopic ::= <Part:String> SubTopic:MqttTopic* ; +rel Item.Topic <-> MqttTopic.Item ; diff --git a/eraser-base/src/main/jastadd/openhab.relast b/eraser-base/src/main/jastadd/openhab.relast new file mode 100644 index 00000000..e26d7b00 --- /dev/null +++ b/eraser-base/src/main/jastadd/openhab.relast @@ -0,0 +1,57 @@ +// ---------------- openHAB ------------------------------ +abstract ModelElement ::= <ID:String> ; +abstract LabelledModelElement : ModelElement ::= <Label:String> ; +abstract DescribableModelElement : LabelledModelElement ::= <Description:String> ; + +ThingType : DescribableModelElement ::= Parameter* ; +rel ThingType.ChannelType* -> ChannelType ; + +Thing : LabelledModelElement ::= Channel* ; +rel Thing.Type -> ThingType ; + +ChannelType : DescribableModelElement ::= <ItemType:ItemType> <ReadOnly:boolean> ; +rel ChannelType.ChannelCategory -> ChannelCategory ; + +abstract ChannelCategory ; +DefaultChannelCategory : ChannelCategory ::= <Value:DefaultChannelCategoryValue> ; +SimpleChannelCategory : ChannelCategory ::= <Value:String> ; + +Channel : ModelElement ::= Link* ; +rel Channel.Type -> ChannelType ; + +Link ::= <Item:Item> ; + +Parameter : DescribableModelElement ::= <Type:ParameterValueType> [DefaultValue:ParameterDefaultValue] <Context:String> <Required:boolean> ; +ParameterDefaultValue ::= <Value:String> ; + +abstract Item : LabelledModelElement ::= <_fetched_data:boolean> MetaData:ItemMetaData* [ItemObserver] ; +rel Item.Category? -> ItemCategory ; +rel Item.Controlling* <-> Item.ControlledBy* ; + +abstract ItemWithBooleanState : Item ::= <_state:boolean> ; +abstract ItemWithStringState : Item ::= <_state:String> ; +abstract ItemWithDoubleState : Item ::= <_state:double> ; +ColorItem : Item ::= <_state:TupleHSB> ; +DateTimeItem : Item ::= <_state:Date> ; +ContactItem : ItemWithBooleanState ; +DimmerItem : ItemWithDoubleState ; +ImageItem : ItemWithStringState ; +LocationItem : ItemWithStringState ; +NumberItem : ItemWithDoubleState ; +PlayerItem : ItemWithStringState ; +RollerShutterItem : ItemWithBooleanState ; +StringItem : ItemWithStringState ; +SwitchItem : ItemWithBooleanState ; +DefaultItem : ItemWithStringState ; +ActivityItem : ItemWithDoubleState ; + +ItemMetaData ::= <Key:String> <Value:String> ; + +ItemCategory ::= <Name:String> ; + +Group : LabelledModelElement ::= Group* Item* [AggregationFunction:GroupAggregationFunction] ; +abstract GroupAggregationFunction ; +SimpleGroupAggregationFunction : GroupAggregationFunction ::= <FunctionName:SimpleGroupAggregationFunctionName> ; +ParameterizedGroupAggregationFunction : GroupAggregationFunction ::= <FunctionName:ParameterizedGroupAggregationFunctionName> + <Param1:String> <Param2:String> ; + -- GitLab