diff options
Diffstat (limited to 'Application/hu.bme.mit.inf.dslreasoner.application/src')
9 files changed, 566 insertions, 31 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/GenerationTaskExecutor.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/GenerationTaskExecutor.xtend new file mode 100644 index 00000000..635d9dcc --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/GenerationTaskExecutor.xtend | |||
@@ -0,0 +1,156 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.execution | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.GenerationTask | ||
4 | import hu.bme.mit.inf.dslreasoner.application.validation.MetamodelValidator | ||
5 | import hu.bme.mit.inf.dslreasoner.application.validation.QueryAndMetamodelValidator | ||
6 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | ||
7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration | ||
8 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.SolutionScope | ||
9 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.InconsistencyResult | ||
10 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult | ||
11 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.UnknownResult | ||
12 | import hu.bme.mit.inf.dslreasoner.logic2ecore.Logic2Ecore | ||
13 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic | ||
14 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration | ||
15 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic | ||
16 | import hu.bme.mit.inf.dslreasoner.workspace.ProjectWorkspace | ||
17 | import org.eclipse.emf.common.util.URI | ||
18 | |||
19 | class GenerationTaskExecutor { | ||
20 | val metamodelLoader = new MetamodelLoader | ||
21 | val modelLoader = new ModelLoader | ||
22 | val queryLoader = new QueryLoader | ||
23 | val solverLoader = new SolverLoader | ||
24 | val scopeLoader = new ScopeLoader | ||
25 | |||
26 | val metamodelValidator = new MetamodelValidator | ||
27 | val queryAndMetamodelValidator = new QueryAndMetamodelValidator | ||
28 | |||
29 | def executeGenerationTask( | ||
30 | GenerationTask task, | ||
31 | ScriptExecutor scriptExecutor) | ||
32 | { | ||
33 | // 1. Load all resources | ||
34 | |||
35 | val metamodelSpecification = scriptExecutor.getMetamodelSpecification(task.metamodel) | ||
36 | val patternSpecification = scriptExecutor.getPatternSpecification(task.patterns) | ||
37 | val partialmodelSpecification = scriptExecutor.getPartialModelSpecification(task.partialModel) | ||
38 | val scopeSpecification = scriptExecutor.getScopeSpecification(task.scope) | ||
39 | val configurationMap = scriptExecutor.transformToMap( | ||
40 | scriptExecutor.getConfiguration(task.config)) | ||
41 | val messageFile = scriptExecutor.getFileSpecification(task.targetLogFile) | ||
42 | val debugFolder = scriptExecutor.getFileSpecification(task.debugFolder) | ||
43 | val outputFolder = scriptExecutor.getFileSpecification(task.getTagetFolder) | ||
44 | val statisticsFile = scriptExecutor.getFileSpecification(task.targetStatisticsFile) | ||
45 | |||
46 | // 2. create console | ||
47 | |||
48 | val console = new ScriptConsole(true,true, | ||
49 | if(messageFile!==null) URI.createURI(messageFile.path) else null, | ||
50 | if(debugFolder!==null) URI.createURI('''«debugFolder.path»/errors.txt''') else null, | ||
51 | if(statisticsFile!==null) URI.createURI(statisticsFile.path) else null | ||
52 | ) | ||
53 | |||
54 | // 3. interpret all specification to a description | ||
55 | val metamodelDescriptor = if(metamodelSpecification !== null) { | ||
56 | metamodelLoader.loadMetamodel(metamodelSpecification) | ||
57 | } else { | ||
58 | console.writeError('''Error during the loading of the metamodel: No metamodel specified!''') | ||
59 | throw new IllegalArgumentException('''No metamodel is specified!''') | ||
60 | } | ||
61 | val queryDescriptor = if(patternSpecification !== null) { | ||
62 | this.queryLoader.loadQueries(patternSpecification) | ||
63 | } else { | ||
64 | null | ||
65 | } | ||
66 | val partialModelDescriptor = if(partialmodelSpecification !== null) { | ||
67 | this.modelLoader.loadModel(partialmodelSpecification,scriptExecutor) | ||
68 | } else { | ||
69 | null | ||
70 | } | ||
71 | |||
72 | // 4. translate all description to a logic problem | ||
73 | val Ecore2Logic ecore2Logic = new Ecore2Logic | ||
74 | val Logic2Ecore logic2Ecore = new Logic2Ecore(ecore2Logic) | ||
75 | val Viatra2Logic viatra2Logic = new Viatra2Logic(ecore2Logic) | ||
76 | val InstanceModel2Logic instanceModel2Logic = new InstanceModel2Logic | ||
77 | |||
78 | var modelGeneration = ecore2Logic.transformMetamodel(metamodelDescriptor,new Ecore2LogicConfiguration()) | ||
79 | var problem = modelGeneration.output | ||
80 | if(partialModelDescriptor !== null) { | ||
81 | problem = instanceModel2Logic.transform( | ||
82 | modelGeneration, | ||
83 | partialModelDescriptor | ||
84 | ).output | ||
85 | } | ||
86 | if(queryDescriptor !== null){ | ||
87 | problem = viatra2Logic.transformQueries( | ||
88 | queryDescriptor.key, | ||
89 | modelGeneration, | ||
90 | new Viatra2LogicConfiguration | ||
91 | ).output | ||
92 | } | ||
93 | |||
94 | // 5. create a solver and a configuration | ||
95 | // 5.1 initialize | ||
96 | val solver = solverLoader.loadSolver(task.solver,configurationMap) | ||
97 | val solverConfig = solverLoader.loadSolverConfig(task.solver,configurationMap) | ||
98 | val reasonerWorkspace = if(debugFolder!== null) { | ||
99 | new ProjectWorkspace(debugFolder.path,"") | ||
100 | } else { | ||
101 | new NullWorkspace | ||
102 | } | ||
103 | |||
104 | // 5.2 set values that defined directly | ||
105 | solverConfig.solutionScope = new SolutionScope => [ | ||
106 | it.numberOfRequiredSolution = if(task.numberSpecified) { | ||
107 | 1 | ||
108 | } else { | ||
109 | task.number | ||
110 | } | ||
111 | ] | ||
112 | solverConfig.typeScopes = scopeLoader.loadScope( | ||
113 | scopeSpecification, | ||
114 | problem, | ||
115 | ecore2Logic, | ||
116 | modelGeneration.trace | ||
117 | ) | ||
118 | |||
119 | // 6. execute the solver on the problem with the configuration | ||
120 | val runs = if(task.runSpecified) { | ||
121 | task.runs | ||
122 | } else { | ||
123 | 1 | ||
124 | } | ||
125 | console.writeMessage("Start model generation") | ||
126 | |||
127 | for(run : 1..runs) { | ||
128 | val solution = solver.solve(problem,solverConfig,reasonerWorkspace) | ||
129 | console.writeMessage(solution.soutionDescription.toString) | ||
130 | } | ||
131 | } | ||
132 | |||
133 | private def dispatch soutionDescription(InconsistencyResult s) { | ||
134 | if(s.representation.size == 1) { | ||
135 | '''Problem is inconsistent!''' | ||
136 | } else { | ||
137 | '''Problem is inconsistent, only «s.representation.size» model can be created!''' | ||
138 | } | ||
139 | } | ||
140 | |||
141 | private def dispatch soutionDescription(ModelResult s) { | ||
142 | if(s.representation.size == 1) { | ||
143 | '''Problem is consistent!''' | ||
144 | } else { | ||
145 | '''Problem is consistent, «s.representation.size» model generated!''' | ||
146 | } | ||
147 | } | ||
148 | |||
149 | private def dispatch soutionDescription(UnknownResult s) { | ||
150 | if(s.representation.size == 1) { | ||
151 | '''Unable to solve problem!''' | ||
152 | } else { | ||
153 | '''Unable to solve problem, but «s.representation.size» model generated!''' | ||
154 | } | ||
155 | } | ||
156 | } \ No newline at end of file | ||
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/MetamodelLoader.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/MetamodelLoader.xtend index e554cc69..5e7f84f0 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/MetamodelLoader.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/MetamodelLoader.xtend | |||
@@ -1,29 +1,22 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.execution | 1 | package hu.bme.mit.inf.dslreasoner.application.execution |
2 | 2 | ||
3 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.AllPackageEntry | ||
4 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelElement | ||
5 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelEntry | ||
3 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelSpecification | 6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelSpecification |
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor | 7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor |
5 | import java.util.ArrayList | 8 | import java.util.LinkedHashSet |
6 | import java.util.LinkedList | ||
7 | import java.util.List | 9 | import java.util.List |
8 | import java.util.Set | 10 | import java.util.Set |
9 | import org.eclipse.emf.common.util.URI | ||
10 | import org.eclipse.emf.ecore.EAttribute | 11 | import org.eclipse.emf.ecore.EAttribute |
11 | import org.eclipse.emf.ecore.EClass | 12 | import org.eclipse.emf.ecore.EClass |
12 | import org.eclipse.emf.ecore.EDataType | ||
13 | import org.eclipse.emf.ecore.EEnum | 13 | import org.eclipse.emf.ecore.EEnum |
14 | import org.eclipse.emf.ecore.EEnumLiteral | 14 | import org.eclipse.emf.ecore.EEnumLiteral |
15 | import org.eclipse.emf.ecore.ENamedElement | ||
16 | import org.eclipse.emf.ecore.EPackage | ||
17 | import org.eclipse.emf.ecore.EReference | 15 | import org.eclipse.emf.ecore.EReference |
18 | import org.eclipse.emf.ecore.EcorePackage | 16 | import org.eclipse.emf.ecore.EcorePackage |
19 | import org.eclipse.emf.ecore.resource.Resource | 17 | import org.eclipse.emf.ecore.resource.Resource |
20 | import org.eclipse.emf.ecore.resource.ResourceSet | ||
21 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | 18 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl |
22 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.AllPackageEntry | ||
23 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelElement | ||
24 | import org.eclipse.xtext.xbase.lib.Functions.Function1 | 19 | import org.eclipse.xtext.xbase.lib.Functions.Function1 |
25 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelEntry | ||
26 | import java.util.LinkedHashSet | ||
27 | 20 | ||
28 | class MetamodelLoader { | 21 | class MetamodelLoader { |
29 | 22 | ||
@@ -34,7 +27,7 @@ class MetamodelLoader { | |||
34 | 27 | ||
35 | public new() { init } | 28 | public new() { init } |
36 | 29 | ||
37 | def loadMetamodel(MetamodelSpecification specification, ResourceSet rs) throws IllegalArgumentException { | 30 | def loadMetamodel(MetamodelSpecification specification) throws IllegalArgumentException { |
38 | 31 | ||
39 | val Set<EClass> classes = new LinkedHashSet | 32 | val Set<EClass> classes = new LinkedHashSet |
40 | val Set<EEnum> enums = new LinkedHashSet | 33 | val Set<EEnum> enums = new LinkedHashSet |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ModelLoader.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ModelLoader.xtend index 5fc2cdc5..95f14bc1 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ModelLoader.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ModelLoader.xtend | |||
@@ -2,23 +2,31 @@ package hu.bme.mit.inf.dslreasoner.application.execution | |||
2 | 2 | ||
3 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl | 3 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl |
4 | import org.eclipse.emf.common.util.URI | 4 | import org.eclipse.emf.common.util.URI |
5 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PartialModelSpecification | ||
5 | 6 | ||
6 | class ModelLoader { | 7 | class ModelLoader { |
7 | def loadModel(String path, Context context) { | 8 | |
8 | var URI uri | 9 | def loadModel(PartialModelSpecification specification, ScriptExecutor scriptExecutor) { |
9 | try { | 10 | val entries = specification.entry |
10 | uri = URI::createURI(path) | 11 | if (entries.size == 1) { |
11 | } catch(IllegalArgumentException e) { | 12 | var URI uri |
12 | context.writeError('''Malformed uri: "«uri»"!''') | 13 | try { |
13 | return null | 14 | uri = URI::createURI( |
14 | } | 15 | scriptExecutor.getFileSpecification(specification.entry.head.path).path |
15 | 16 | ) | |
16 | val resourceSet = new ResourceSetImpl | 17 | } catch (IllegalArgumentException e) { |
17 | val resource = resourceSet.getResource(uri,true) | 18 | return null |
18 | if(resource === null) { | 19 | } |
19 | 20 | ||
21 | val resourceSet = new ResourceSetImpl | ||
22 | val resource = resourceSet.getResource(uri, true) | ||
23 | if (resource === null) { | ||
24 | } else { | ||
25 | return resource.allContents.toList | ||
26 | } | ||
20 | } else { | 27 | } else { |
21 | return resource | 28 | throw new UnsupportedOperationException('''Currently single partial models are supported''') |
22 | } | 29 | } |
23 | } | 30 | |
24 | } \ No newline at end of file | 31 | } |
32 | } | ||
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/NullWorkspace.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/NullWorkspace.xtend new file mode 100644 index 00000000..4cc44df3 --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/NullWorkspace.xtend | |||
@@ -0,0 +1,52 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.execution | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace | ||
4 | import java.io.ByteArrayOutputStream | ||
5 | import java.io.FileNotFoundException | ||
6 | import java.util.Collections | ||
7 | import java.util.List | ||
8 | import org.eclipse.emf.common.util.URI | ||
9 | import org.eclipse.emf.ecore.EObject | ||
10 | import org.eclipse.emf.ecore.resource.Resource | ||
11 | |||
12 | class NullWorkspace extends ReasonerWorkspace{ | ||
13 | |||
14 | new() { | ||
15 | super(null, null) | ||
16 | } | ||
17 | |||
18 | static val message = "No workspace is specified!" | ||
19 | |||
20 | public override ReasonerWorkspace subWorkspace(String targetFolder, String prefix) { | ||
21 | return new NullWorkspace() | ||
22 | } | ||
23 | |||
24 | override URI getWorkspaceURI() { | ||
25 | throw new UnsupportedOperationException(message) | ||
26 | } | ||
27 | override public void initAndClear() {} | ||
28 | override protected URI getURI(String name) { | ||
29 | throw new UnsupportedOperationException(message) | ||
30 | } | ||
31 | protected override Resource getResource(String name) { | ||
32 | throw new UnsupportedOperationException(message) | ||
33 | } | ||
34 | override public URI writeModel(EObject modelRoot, String name) { } | ||
35 | override public <RootType extends EObject> RootType reloadModel(Class<RootType> type, String name) { | ||
36 | throw new UnsupportedOperationException(message) | ||
37 | } | ||
38 | override public <RootType extends EObject> RootType readModel(Class<RootType> type, String name) { | ||
39 | throw new UnsupportedOperationException(message) | ||
40 | } | ||
41 | override public deactivateModel(String name) { } | ||
42 | override protected void renameFile(String name) { } | ||
43 | |||
44 | override public List<String> allFiles() { | ||
45 | throw new UnsupportedOperationException(message) | ||
46 | } | ||
47 | override public URI writeText(String name, CharSequence content) { } | ||
48 | |||
49 | override public String readText(String name) { | ||
50 | throw new UnsupportedOperationException(message) | ||
51 | } | ||
52 | } \ No newline at end of file | ||
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScopeLoader.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScopeLoader.xtend new file mode 100644 index 00000000..ee1a92f0 --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScopeLoader.xtend | |||
@@ -0,0 +1,83 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.execution | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ClassTypeScope | ||
4 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ExactNumber | ||
5 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.IntEnumberation | ||
6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.IntegerTypeScope | ||
7 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.IntervallNumber | ||
8 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ObjectTypeScope | ||
9 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.RealEnumeration | ||
10 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.RealTypeScope | ||
11 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ScopeSpecification | ||
12 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.StringEnumeration | ||
13 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.StringTypeScope | ||
14 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | ||
15 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | ||
16 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes | ||
17 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | ||
18 | import org.eclipse.emf.ecore.EClass | ||
19 | |||
20 | class ScopeLoader { | ||
21 | def TypeScopes loadScope(ScopeSpecification specification, LogicProblem problem, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace) { | ||
22 | val res = new TypeScopes | ||
23 | for(scopeSpecification : specification.scopes) { | ||
24 | setSpecification(scopeSpecification,res,ecore2Logic,trace) | ||
25 | } | ||
26 | return res | ||
27 | } | ||
28 | |||
29 | def dispatch setSpecification(ObjectTypeScope scope, TypeScopes aggregated, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace) { | ||
30 | //val existingObjects = | ||
31 | aggregated.minNewElements = getLowerLimit(scope.number) | ||
32 | aggregated.maxNewElements = getUpperLimit(scope.number) | ||
33 | } | ||
34 | def dispatch setSpecification(ClassTypeScope scope, TypeScopes aggregated, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace) { | ||
35 | val target = scope.type.element | ||
36 | if(target.feature != null) { | ||
37 | throw new IllegalArgumentException('''Feature scopes are not supported: "«target.feature.name»"!''') | ||
38 | } else { | ||
39 | val targetClassifier = target.classifier | ||
40 | if(targetClassifier instanceof EClass) { | ||
41 | val type = ecore2Logic.TypeofEClass(trace,targetClassifier) | ||
42 | aggregated.minNewElementsByType.put(type,getLowerLimit(scope.number)) | ||
43 | aggregated.maxNewElementsByType.put(type,getUpperLimit(scope.number)) | ||
44 | } else { | ||
45 | throw new IllegalArgumentException('''Non-EClass scopes are not supported: "«targetClassifier.name»"!''') | ||
46 | } | ||
47 | } | ||
48 | } | ||
49 | def dispatch setSpecification(IntegerTypeScope scope, TypeScopes aggregated, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace) { | ||
50 | aggregated.minNewIntegers = scope.number.lowerLimit | ||
51 | aggregated.maxNewIntegers = scope.number.upperLimit | ||
52 | } | ||
53 | def dispatch setSpecification(RealTypeScope scope, TypeScopes aggregated, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace) { | ||
54 | aggregated.minNewReals = scope.number.lowerLimit | ||
55 | aggregated.maxNewReals = scope.number.upperLimit | ||
56 | } | ||
57 | def dispatch setSpecification(StringTypeScope scope, TypeScopes aggregated, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace) { | ||
58 | aggregated.minNewStrings = scope.number.lowerLimit | ||
59 | aggregated.maxNewStrings = scope.number.upperLimit | ||
60 | } | ||
61 | |||
62 | def dispatch getLowerLimit(IntervallNumber specification) { | ||
63 | return specification.min | ||
64 | } | ||
65 | def dispatch getLowerLimit(ExactNumber specification) { | ||
66 | if(specification.isExactUnlimited) return 0 | ||
67 | else return specification.exactNumber | ||
68 | } | ||
69 | def dispatch getLowerLimit(IntEnumberation specification) { 0 } | ||
70 | def dispatch getLowerLimit(RealEnumeration specification) { 0 } | ||
71 | def dispatch getLowerLimit(StringEnumeration specification) { 0 } | ||
72 | def dispatch getUpperLimit(IntervallNumber specification) { | ||
73 | if(specification.isMaxUnlimited) return -1 | ||
74 | else return specification.maxNumber | ||
75 | } | ||
76 | def dispatch getUpperLimit(ExactNumber specification) { | ||
77 | if(specification.isExactUnlimited) return -1 | ||
78 | else return specification.exactNumber | ||
79 | } | ||
80 | def dispatch getUpperLimit(IntEnumberation specification) { 0 } | ||
81 | def dispatch getUpperLimit(RealEnumeration specification) { 0 } | ||
82 | def dispatch getUpperLimit(StringEnumeration specification) { 0 } | ||
83 | } \ No newline at end of file | ||
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsole.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsole.xtend new file mode 100644 index 00000000..77c5252a --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsole.xtend | |||
@@ -0,0 +1,104 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.execution | ||
2 | |||
3 | import java.io.File | ||
4 | import java.io.PrintWriter | ||
5 | import java.util.LinkedHashSet | ||
6 | import java.util.LinkedList | ||
7 | import java.util.Map | ||
8 | import org.eclipse.emf.common.util.URI | ||
9 | import java.io.Closeable | ||
10 | import java.io.IOException | ||
11 | import java.util.LinkedHashMap | ||
12 | import java.util.HashMap | ||
13 | |||
14 | class ScriptConsole implements Closeable { | ||
15 | val boolean printToConsole | ||
16 | val boolean cleanFiles | ||
17 | |||
18 | val File messageConsoleFile | ||
19 | val File errorConsoleFile | ||
20 | val File statisticsConsoleFile | ||
21 | val Map<File,PrintWriter> file2Writer = new HashMap | ||
22 | |||
23 | val statisticsHeaderBuffer = new LinkedHashSet<String> | ||
24 | val statisticsDataBuffer = new LinkedList<Map<String,? extends Object>> | ||
25 | |||
26 | static val delimier = ';' | ||
27 | static val empty = "" | ||
28 | |||
29 | public new( | ||
30 | boolean printToConsole, | ||
31 | boolean cleanFiles, | ||
32 | URI messageConsoleURI, | ||
33 | URI errorConsoleURI, | ||
34 | URI statisticsConsoleURI) | ||
35 | { | ||
36 | this.printToConsole = printToConsole | ||
37 | this.cleanFiles = cleanFiles | ||
38 | this.messageConsoleFile = messageConsoleURI.prepareFile | ||
39 | this.errorConsoleFile = errorConsoleURI.prepareFile | ||
40 | this.statisticsConsoleFile = statisticsConsoleURI.prepareFile | ||
41 | } | ||
42 | |||
43 | public def writeMessage(String message) { | ||
44 | messageConsoleFile.writeToFile(message) | ||
45 | } | ||
46 | public def writeError(String message) { | ||
47 | errorConsoleFile.writeToFile(message) | ||
48 | } | ||
49 | public def writeStatistics(LinkedHashMap<String,? extends Object> statistics) { | ||
50 | val message = ''' | ||
51 | «FOR key : statistics.keySet SEPARATOR delimier»«key»«ENDFOR» | ||
52 | «FOR value : statistics.values SEPARATOR delimier»«value»«ENDFOR»''' | ||
53 | statisticsConsoleFile.writeToFile(message) | ||
54 | } | ||
55 | public def addStatistics(LinkedHashMap<String,? extends Object> statistics) { | ||
56 | for(key : statistics.keySet) { | ||
57 | this.statisticsHeaderBuffer.add(key); | ||
58 | } | ||
59 | this.statisticsDataBuffer.add(statistics) | ||
60 | } | ||
61 | public def flushStatistics() { | ||
62 | val message = ''' | ||
63 | «FOR key : statisticsHeaderBuffer SEPARATOR delimier»«key»«ENDFOR» | ||
64 | «FOR line : statisticsDataBuffer » | ||
65 | «FOR key : statisticsHeaderBuffer»«IF line.containsKey(key)»«empty»«ELSE»«line.get(key)»«ENDIF»«ENDFOR» | ||
66 | «ENDFOR» | ||
67 | ''' | ||
68 | statisticsConsoleFile.writeToFile(message) | ||
69 | } | ||
70 | /** | ||
71 | * Writes a line of text to a file and the console. Initializes a writer to the file for at the first message. | ||
72 | */ | ||
73 | private def writeToFile(File file, String text) { | ||
74 | if(file != null) { | ||
75 | val writer = if(this.file2Writer.containsKey(file)) { | ||
76 | this.file2Writer.get(file) | ||
77 | } else { | ||
78 | if(!file.exists) { | ||
79 | file.createNewFile | ||
80 | } | ||
81 | val writer = new PrintWriter(file, "UTF-8"); | ||
82 | this.file2Writer.put(file,writer) | ||
83 | writer | ||
84 | } | ||
85 | writer.println(text) | ||
86 | } | ||
87 | if(printToConsole) { | ||
88 | println(text) | ||
89 | } | ||
90 | } | ||
91 | |||
92 | private def prepareFile(URI uri) { | ||
93 | val fileString = uri.toFileString | ||
94 | val file = new File(fileString) | ||
95 | if(this.cleanFiles && file.exists) { | ||
96 | file.delete | ||
97 | } | ||
98 | return file | ||
99 | } | ||
100 | |||
101 | override close() throws IOException { | ||
102 | this.file2Writer.values.forEach[close] | ||
103 | } | ||
104 | } \ No newline at end of file | ||
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptExecutor.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptExecutor.xtend new file mode 100644 index 00000000..32d44540 --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptExecutor.xtend | |||
@@ -0,0 +1,111 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.execution | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript | ||
4 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.GenerationTask | ||
5 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.GraphPatternReference | ||
6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelReference | ||
7 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelSpecification | ||
8 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PartialModelReference | ||
9 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PartialModelSpecification | ||
10 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PatternSpecification | ||
11 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.Task | ||
12 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.FileSpecification | ||
13 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.FileReference | ||
14 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ScopeSpecification | ||
15 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ScopeReference | ||
16 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigSpecification | ||
17 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigReference | ||
18 | import java.util.LinkedHashMap | ||
19 | |||
20 | class ScriptExecutor { | ||
21 | |||
22 | def static void main(String[] args) { | ||
23 | println("generator") | ||
24 | } | ||
25 | |||
26 | public def executeScript(ConfigurationScript script) { | ||
27 | val tasks = script.commands.filter(Task) | ||
28 | for(task : tasks.filterNull) { | ||
29 | task.execute | ||
30 | } | ||
31 | } | ||
32 | |||
33 | def public dispatch execute(GenerationTask task) { | ||
34 | |||
35 | } | ||
36 | |||
37 | def public dispatch execute(Task task) { | ||
38 | throw new IllegalArgumentException('''Unsupported task type: «task.class.simpleName»!''') | ||
39 | } | ||
40 | |||
41 | def dispatch getMetamodelSpecification(MetamodelSpecification config) { | ||
42 | config | ||
43 | } | ||
44 | def dispatch getMetamodelSpecification(MetamodelReference config) { | ||
45 | config.referred.specification | ||
46 | } | ||
47 | def dispatch getMetamodelSpecification(Void config) { | ||
48 | null | ||
49 | } | ||
50 | |||
51 | def dispatch getPatternSpecification(PatternSpecification config) { | ||
52 | config | ||
53 | } | ||
54 | def dispatch getPatternSpecification(GraphPatternReference config) { | ||
55 | config.referred.specification | ||
56 | } | ||
57 | def dispatch getPatternSpecification(Void config) { | ||
58 | null | ||
59 | } | ||
60 | |||
61 | def dispatch getPartialModelSpecification(PartialModelSpecification config) { | ||
62 | config | ||
63 | } | ||
64 | def dispatch getPartialModelSpecification(PartialModelReference config) { | ||
65 | config.referred.specification | ||
66 | } | ||
67 | def dispatch getPartialModelSpecification(Void config) { | ||
68 | null | ||
69 | } | ||
70 | |||
71 | def dispatch getFileSpecification(FileSpecification config) { | ||
72 | config | ||
73 | } | ||
74 | def dispatch getFileSpecification(FileReference config) { | ||
75 | config.referred.specification | ||
76 | } | ||
77 | def dispatch getFileSpecification(Void config) { | ||
78 | null | ||
79 | } | ||
80 | |||
81 | def dispatch getScopeSpecification(ScopeSpecification config) { | ||
82 | config | ||
83 | } | ||
84 | def dispatch getScopeSpecification(ScopeReference config) { | ||
85 | config.referred.specification | ||
86 | } | ||
87 | def dispatch getScopeSpecification(Void config) { | ||
88 | null | ||
89 | } | ||
90 | |||
91 | def dispatch getConfiguration(ConfigSpecification config) { | ||
92 | config | ||
93 | } | ||
94 | def dispatch getConfiguration(ConfigReference config) { | ||
95 | config.config.specification | ||
96 | } | ||
97 | def dispatch getConfiguration(Void config) { | ||
98 | null | ||
99 | } | ||
100 | def transformToMap(ConfigSpecification config) { | ||
101 | val map = new LinkedHashMap | ||
102 | |||
103 | if(config != null) { | ||
104 | for(entry : config.entries) { | ||
105 | map.put(entry.key,entry.value) | ||
106 | } | ||
107 | } | ||
108 | |||
109 | return map | ||
110 | } | ||
111 | } \ No newline at end of file | ||
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/SolverLoader.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/SolverLoader.xtend new file mode 100644 index 00000000..dcd89981 --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/SolverLoader.xtend | |||
@@ -0,0 +1,28 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.execution | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.Solver | ||
4 | import java.util.Map | ||
5 | import hu.bme.mit.inf.dlsreasoner.alloy.reasoner.AlloySolver | ||
6 | import hu.bme.mit.inf.dslreasoner.smt.reasoner.SMTSolver | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner | ||
8 | import hu.bme.mit.inf.dlsreasoner.alloy.reasoner.AlloySolverConfiguration | ||
9 | import hu.bme.mit.inf.dslreasoner.smt.reasoner.SmtSolverConfiguration | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration | ||
11 | |||
12 | class SolverLoader { | ||
13 | def loadSolver(Solver solver, Map<String, String> config) { | ||
14 | switch(solver) { | ||
15 | case ALLOY_SOLVER: return new AlloySolver | ||
16 | case SMT_SOLVER: return new SMTSolver | ||
17 | case VIATRA_SOLVER: return new ViatraReasoner | ||
18 | } | ||
19 | } | ||
20 | |||
21 | def loadSolverConfig(Solver solver, Map<String, String> config) { | ||
22 | switch(solver) { | ||
23 | case ALLOY_SOLVER: return new AlloySolverConfiguration | ||
24 | case SMT_SOLVER: return new SmtSolverConfiguration | ||
25 | case VIATRA_SOLVER: return new ViatraReasonerConfiguration | ||
26 | } | ||
27 | } | ||
28 | } \ No newline at end of file | ||
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/util/VQLParser.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/util/VQLParser.xtend index 6eb9e3c8..e6d516f4 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/util/VQLParser.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/util/VQLParser.xtend | |||
@@ -3,7 +3,6 @@ package hu.bme.mit.inf.dslreasoner.application.execution.util | |||
3 | import com.google.inject.Guice | 3 | import com.google.inject.Guice |
4 | import com.google.inject.Injector | 4 | import com.google.inject.Injector |
5 | import com.google.inject.Module | 5 | import com.google.inject.Module |
6 | import hu.bme.mit.inf.dslreasoner.application.execution.Context | ||
7 | import java.util.LinkedHashMap | 6 | import java.util.LinkedHashMap |
8 | import java.util.List | 7 | import java.util.List |
9 | import org.eclipse.emf.common.util.URI | 8 | import org.eclipse.emf.common.util.URI |
@@ -21,6 +20,7 @@ import org.eclipse.viatra.query.patternlanguage.emf.eMFPatternLanguage.PatternMo | |||
21 | import org.eclipse.viatra.query.patternlanguage.emf.specification.SpecificationBuilder | 20 | import org.eclipse.viatra.query.patternlanguage.emf.specification.SpecificationBuilder |
22 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification | 21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification |
23 | import org.eclipse.xtext.resource.XtextResourceSet | 22 | import org.eclipse.xtext.resource.XtextResourceSet |
23 | import hu.bme.mit.inf.dslreasoner.application.execution.ScriptConsole | ||
24 | 24 | ||
25 | class MyModule extends EMFPatternLanguageRuntimeModule implements Module { | 25 | class MyModule extends EMFPatternLanguageRuntimeModule implements Module { |
26 | def public Class<? extends IAnnotationValidatorLoader> bindAnnotationValidatorLoader() { | 26 | def public Class<? extends IAnnotationValidatorLoader> bindAnnotationValidatorLoader() { |
@@ -58,7 +58,7 @@ class VQLParser { | |||
58 | * the linked patterns are loaded validated and translated to a {@link IQuerySpecification} object. | 58 | * the linked patterns are loaded validated and translated to a {@link IQuerySpecification} object. |
59 | * @returns uri -> (name -> pattern) | 59 | * @returns uri -> (name -> pattern) |
60 | */ | 60 | */ |
61 | public def parse(List<String> uris, ResourceSet resourceSet, Context context) { | 61 | public def parse(List<String> uris, ResourceSet resourceSet, ScriptConsole context) { |
62 | val res = new LinkedHashMap | 62 | val res = new LinkedHashMap |
63 | val uri2resource = new LinkedHashMap | 63 | val uri2resource = new LinkedHashMap |
64 | 64 | ||
@@ -91,7 +91,7 @@ class VQLParser { | |||
91 | return res | 91 | return res |
92 | } | 92 | } |
93 | 93 | ||
94 | def private validate(Resource resource, String URI, Context context) { | 94 | def private validate(Resource resource, String URI, ScriptConsole context) { |
95 | val errors = resource.errors | 95 | val errors = resource.errors |
96 | errors.forEach[context.writeError('''Error in loading pattern "«URI»": «it»''')] | 96 | errors.forEach[context.writeError('''Error in loading pattern "«URI»": «it»''')] |
97 | } | 97 | } |