diff options
author | 20001LastOrder <boqi.chen@mail.mcgill.ca> | 2019-05-27 15:50:05 -0400 |
---|---|---|
committer | 20001LastOrder <boqi.chen@mail.mcgill.ca> | 2019-05-27 15:50:05 -0400 |
commit | 6b751d1c3cf6294f589364acc1b8fe0f2d113bf4 (patch) | |
tree | 5fb0859d6bfd716a3fc8115203b7784662d67948 /Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/input | |
parent | add metrics data plot tool (diff) | |
download | VIATRA-Generator-6b751d1c3cf6294f589364acc1b8fe0f2d113bf4.tar.gz VIATRA-Generator-6b751d1c3cf6294f589364acc1b8fe0f2d113bf4.tar.zst VIATRA-Generator-6b751d1c3cf6294f589364acc1b8fe0f2d113bf4.zip |
add project for metric calculator
Diffstat (limited to 'Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/input')
2 files changed, 88 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/input/GraphReader.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/input/GraphReader.xtend new file mode 100644 index 00000000..56bf95a3 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/input/GraphReader.xtend | |||
@@ -0,0 +1,81 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.input | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.EMFGraph | ||
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric | ||
5 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MultiplexParticipationCoefficientMetric | ||
6 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.NodeActivityMetric | ||
7 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.OutDegreeMetric | ||
8 | import java.io.File | ||
9 | import java.io.FileNotFoundException | ||
10 | import java.util.ArrayList | ||
11 | import java.util.List | ||
12 | import org.eclipse.emf.common.util.URI | ||
13 | import org.eclipse.emf.ecore.EObject | ||
14 | import org.eclipse.emf.ecore.EPackage | ||
15 | import org.eclipse.emf.ecore.EReference | ||
16 | import org.eclipse.emf.ecore.resource.Resource | ||
17 | import org.eclipse.emf.ecore.resource.ResourceSet | ||
18 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl | ||
19 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | ||
20 | |||
21 | class GraphReader{ | ||
22 | val ResourceSet resSet = new ResourceSetImpl(); | ||
23 | val referenceTypes = new ArrayList<String>(); | ||
24 | |||
25 | new(EPackage metaModel) { | ||
26 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("*",new XMIResourceFactoryImpl) | ||
27 | |||
28 | //find all reference types in the meta model | ||
29 | metaModel.eAllContents.forEach[ | ||
30 | if(it instanceof EReference){ | ||
31 | referenceTypes.add(it.name); | ||
32 | } | ||
33 | ] | ||
34 | } | ||
35 | |||
36 | def List<EMFGraph> readModels(String path){ | ||
37 | val dir = new File(path); | ||
38 | if(!dir.isDirectory){ | ||
39 | throw new Exception("expecting a directory"); | ||
40 | } | ||
41 | |||
42 | val graphs = new ArrayList<EMFGraph>(); | ||
43 | |||
44 | val metrics = new ArrayList<Metric>(); | ||
45 | metrics.add(new OutDegreeMetric()); | ||
46 | metrics.add(new NodeActivityMetric()); | ||
47 | metrics.add(new MultiplexParticipationCoefficientMetric()); | ||
48 | |||
49 | //check all files in the directory with xmi | ||
50 | for(String name : dir.list.filter[it| it.endsWith(".xmi")]){ | ||
51 | val file = new File(name); | ||
52 | val roots = readModel(EObject, path, file.name); | ||
53 | //add a list of metrics | ||
54 | val g = new EMFGraph(); | ||
55 | for(root : roots){ | ||
56 | g.init(root, metrics, name.replaceFirst(".xmi", ""), referenceTypes); | ||
57 | } | ||
58 | |||
59 | graphs.add(g); | ||
60 | } | ||
61 | |||
62 | return graphs; | ||
63 | } | ||
64 | |||
65 | def <RootType extends EObject> List<RootType> readModel(Class<RootType> type, String path, String name) { | ||
66 | try { | ||
67 | val resource = resSet.getResource(getURI(path, name),true); | ||
68 | if(resource === null) throw new FileNotFoundException(getURI(path, name).toString) | ||
69 | else { | ||
70 | return resource.contents as List<RootType> | ||
71 | } | ||
72 | } catch(Exception e) { | ||
73 | e.printStackTrace(); | ||
74 | throw new FileNotFoundException(getURI(path, name).toString + "reason: " + e.message) | ||
75 | } | ||
76 | } | ||
77 | |||
78 | def static getURI(String path, String name) { | ||
79 | URI.createFileURI(path + "/" + name) | ||
80 | } | ||
81 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/input/PartialInterpretationReader.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/input/PartialInterpretationReader.xtend new file mode 100644 index 00000000..dbaf36b2 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/input/PartialInterpretationReader.xtend | |||
@@ -0,0 +1,7 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.input | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
4 | |||
5 | class PartialInterpretationReader { | ||
6 | |||
7 | } \ No newline at end of file | ||