From 98e0479f26ce0bc54016c4fba8e74e3223203b9a Mon Sep 17 00:00:00 2001 From: 20001LastOrder Date: Wed, 5 Jun 2019 11:38:23 -0400 Subject: plotting for metrics during generation --- .../metrics/calculator/io/GraphReader.xtend | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.xtend (limited to 'Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.xtend') diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.xtend new file mode 100644 index 00000000..fc56e142 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.xtend @@ -0,0 +1,81 @@ +package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io; + +import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.EMFGraph +import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric +import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MultiplexParticipationCoefficientMetric +import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.NodeActivityMetric +import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.OutDegreeMetric +import java.io.File +import java.io.FileNotFoundException +import java.util.ArrayList +import java.util.List +import org.eclipse.emf.common.util.URI +import org.eclipse.emf.ecore.EObject +import org.eclipse.emf.ecore.EPackage +import org.eclipse.emf.ecore.EReference +import org.eclipse.emf.ecore.resource.Resource +import org.eclipse.emf.ecore.resource.ResourceSet +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl +import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl + +class GraphReader{ + val ResourceSet resSet = new ResourceSetImpl(); + val referenceTypes = new ArrayList(); + + new(EPackage metaModel) { + Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("*",new XMIResourceFactoryImpl) + + //find all reference types in the meta model + metaModel.eAllContents.forEach[ + if(it instanceof EReference){ + referenceTypes.add(it.name); + } + ] + } + + def List readModels(String path){ + val dir = new File(path); + if(!dir.isDirectory){ + throw new Exception("expecting a directory"); + } + + val graphs = new ArrayList(); + + val metrics = new ArrayList(); + metrics.add(new OutDegreeMetric()); + metrics.add(new NodeActivityMetric()); + metrics.add(new MultiplexParticipationCoefficientMetric()); + + //check all files in the directory with xmi + for(String name : dir.list.filter[it| it.endsWith(".xmi")]){ + val file = new File(name); + val roots = readModel(EObject, path, file.name); + //add a list of metrics + val g = new EMFGraph(); + for(root : roots){ + g.init(root, metrics, name.replaceFirst(".xmi", ""), referenceTypes); + } + + graphs.add(g); + } + + return graphs; + } + + def List readModel(Class type, String path, String name) { + try { + val resource = resSet.getResource(getURI(path, name),true); + if(resource === null) throw new FileNotFoundException(getURI(path, name).toString) + else { + return resource.contents as List + } + } catch(Exception e) { + e.printStackTrace(); + throw new FileNotFoundException(getURI(path, name).toString + "reason: " + e.message) + } + } + + def static getURI(String path, String name) { + URI.createFileURI(path + "/" + name) + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf