From 57fd631100fffc26da8a1de2de3cb8b00c4e8370 Mon Sep 17 00:00:00 2001 From: OszkarSemerath Date: Wed, 5 Jul 2017 16:39:07 +0200 Subject: Pattern coverage measuring program. --- .../dslreasoner/run/MeasurePatternCoverage.xtend | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/MeasurePatternCoverage.xtend (limited to 'Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit') 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 @@ +package hu.bme.mit.inf.dslreasoner.run + +import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummPackage +import java.io.File +import java.util.LinkedList +import java.util.List +import org.eclipse.emf.common.util.URI +import org.eclipse.emf.ecore.EObject +import org.eclipse.emf.ecore.resource.Resource +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl +import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine +import org.eclipse.viatra.query.runtime.emf.EMFScope + +class MeasurePatternCoverage { + + static def void init() { + YakindummPackage.eINSTANCE.eClass + Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl()); + } + + static def List loadAllModelPathsInDirectory(String path) { + val File directory = new File(path); + if(directory.exists() && directory.isDirectory()) { + val filePaths = new LinkedList + for(File f : directory.listFiles()) { + if(f.isFile()) { + val filePath = f.getPath(); + if(filePath.endsWith("xmi")) { + filePaths.add(filePath); + } + } + } + return filePaths; + } else { + throw new IllegalArgumentException("invalid path"); + } + } + + static def EObject loadModel(String path) { + val rs = new ResourceSetImpl + val resource = rs.getResource(URI.createFileURI(path), true); + return resource.getContents().get(0); + } + + + def static void main(String[] args) { + init() + val allModelPaths = loadAllModelPathsInDirectory("D:\\Eclipse\\GIT\\fmhe-analysis\\models-renamed") + val wfPatternsWOSynch = hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.Patterns.instance.specifications + .filter[spec | + !YakinduLoader::patternsWithSynchronization.exists[spec.fullyQualifiedName.endsWith(it)] + ].filter[ + it.allAnnotations.exists[it.name== "Constraint"] + ].toList + + println('''type;id;«FOR pattern : wfPatternsWOSynch SEPARATOR ";"»«pattern.fullyQualifiedName»«ENDFOR»''') + for(modelPath : allModelPaths) { + //println(modelPath) + val model = loadModel(modelPath) + val engine = ViatraQueryEngine.on(new EMFScope(model)) + val fileName = modelPath.split("\\\\") + val fileNameWOExtension = fileName.last.split("\\.").head + val fileNameSegments = fileNameWOExtension.split("_") + print('''«fileNameSegments.get(0)»;«fileNameSegments.get(1)»''') + for(pattern : wfPatternsWOSynch) { + val matcher = pattern.getMatcher(engine) + print(''';«matcher.countMatches»''') + } + println() + } + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf