diff options
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/MeasurePatternCoverage.xtend | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/MeasurePatternCoverage.xtend b/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/MeasurePatternCoverage.xtend new file mode 100644 index 00000000..99ea6e9d --- /dev/null +++ b/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/MeasurePatternCoverage.xtend | |||
@@ -0,0 +1,73 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.run | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummPackage | ||
4 | import java.io.File | ||
5 | import java.util.LinkedList | ||
6 | import java.util.List | ||
7 | import org.eclipse.emf.common.util.URI | ||
8 | import org.eclipse.emf.ecore.EObject | ||
9 | import org.eclipse.emf.ecore.resource.Resource | ||
10 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl | ||
11 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | ||
12 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine | ||
13 | import org.eclipse.viatra.query.runtime.emf.EMFScope | ||
14 | |||
15 | class MeasurePatternCoverage { | ||
16 | |||
17 | static def void init() { | ||
18 | YakindummPackage.eINSTANCE.eClass | ||
19 | Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl()); | ||
20 | } | ||
21 | |||
22 | static def List<String> loadAllModelPathsInDirectory(String path) { | ||
23 | val File directory = new File(path); | ||
24 | if(directory.exists() && directory.isDirectory()) { | ||
25 | val filePaths = new LinkedList | ||
26 | for(File f : directory.listFiles()) { | ||
27 | if(f.isFile()) { | ||
28 | val filePath = f.getPath(); | ||
29 | if(filePath.endsWith("xmi")) { | ||
30 | filePaths.add(filePath); | ||
31 | } | ||
32 | } | ||
33 | } | ||
34 | return filePaths; | ||
35 | } else { | ||
36 | throw new IllegalArgumentException("invalid path"); | ||
37 | } | ||
38 | } | ||
39 | |||
40 | static def EObject loadModel(String path) { | ||
41 | val rs = new ResourceSetImpl | ||
42 | val resource = rs.getResource(URI.createFileURI(path), true); | ||
43 | return resource.getContents().get(0); | ||
44 | } | ||
45 | |||
46 | |||
47 | def static void main(String[] args) { | ||
48 | init() | ||
49 | val allModelPaths = loadAllModelPathsInDirectory("D:\\Eclipse\\GIT\\fmhe-analysis\\models-renamed") | ||
50 | val wfPatternsWOSynch = hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.Patterns.instance.specifications | ||
51 | .filter[spec | | ||
52 | !YakinduLoader::patternsWithSynchronization.exists[spec.fullyQualifiedName.endsWith(it)] | ||
53 | ].filter[ | ||
54 | it.allAnnotations.exists[it.name== "Constraint"] | ||
55 | ].toList | ||
56 | |||
57 | println('''type;id;«FOR pattern : wfPatternsWOSynch SEPARATOR ";"»«pattern.fullyQualifiedName»«ENDFOR»''') | ||
58 | for(modelPath : allModelPaths) { | ||
59 | //println(modelPath) | ||
60 | val model = loadModel(modelPath) | ||
61 | val engine = ViatraQueryEngine.on(new EMFScope(model)) | ||
62 | val fileName = modelPath.split("\\\\") | ||
63 | val fileNameWOExtension = fileName.last.split("\\.").head | ||
64 | val fileNameSegments = fileNameWOExtension.split("_") | ||
65 | print('''«fileNameSegments.get(0)»;«fileNameSegments.get(1)»''') | ||
66 | for(pattern : wfPatternsWOSynch) { | ||
67 | val matcher = pattern.getMatcher(engine) | ||
68 | print(''';«matcher.countMatches»''') | ||
69 | } | ||
70 | println() | ||
71 | } | ||
72 | } | ||
73 | } \ No newline at end of file | ||