aboutsummaryrefslogtreecommitdiffstats
path: root/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/RepMetricsReader.xtend
blob: 06e88efc669902e49bad0f3175c3bb8eb9222f62 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io

import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app.Domain
import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MetricSampleGroup
import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.impl.YakindummPackageImpl
import java.util.HashMap
import org.eclipse.emf.ecore.EReference
import org.eclipse.emf.ecore.impl.EcorePackageImpl

/**
 * Read the sample of the distribution of a metric provided the csv file of the metric
 */
class RepMetricsReader {
	static var Domain domain;
	static def read(Domain d){
		var GraphReader reader;
		if(d == Domain.Yakindumm){
			reader = new GraphReader(YakindummPackageImpl.eINSTANCE, '.xmi');
		}else if (d == Domain.Ecore){
			reader = new GraphReader(EcorePackageImpl.eINSTANCE, '.ecore');
		}else if (d == Domain.Github){
			// Initialize the reader with github package
		}
		
		domain = d;
		
		var domainRepPath = DataName.REP_PATH + d.name + '/';
		var rep = new MetricSampleGroup()
		var out_d = readMetrics(reader, domainRepPath + DataName.OUT_D_REP);
		var mpc = readMetrics(reader, domainRepPath + DataName.MPC_REP);
		rep.mpcSamples = mpc.mpcSamples;
		rep.outDegreeSamples = out_d.outDegreeSamples;
		rep.naSamples = readMetrics(reader, domainRepPath + DataName.NA_REP).naSamples;
		rep.typedOutDegreeSamples = out_d.typedOutDegreeSamples;
		rep.edgeTypeSamples = mpc.edgeTypeSamples;
		
		//TODO: Parameterize the prior node distribution
		var nodeTypeSamples = new HashMap<String, Double>();
		if(d == Domain.Yakindumm){
			nodeTypeSamples.put('Entry', 0.04257802080554814);
			nodeTypeSamples.put('Choice', 0.1267671379034409);
			nodeTypeSamples.put('State', 0.1596092291277674);
			nodeTypeSamples.put('Transition', 0.6138636969858629);
			nodeTypeSamples.put('Statechart', 0.010136036276340358);
			nodeTypeSamples.put('Region', 0.04467858095492131);
			nodeTypeSamples.put('Exit', 0.0018338223526273673);
			nodeTypeSamples.put('FinalState', 0.0005334755934915977);
		}else if(d ==Domain.Ecore){
			nodeTypeSamples.put('EAttribute', 0.23539778449144008);
			nodeTypeSamples.put('EClass', 0.33081570996978854);
			nodeTypeSamples.put('EReference', 0.30996978851963747);
			nodeTypeSamples.put('EPackage', 0.012789526686807653);
			nodeTypeSamples.put('EAnnotation', 0.002517623363544813);
			nodeTypeSamples.put('EEnumLiteral', 0.07275931520644502);
			nodeTypeSamples.put('EEnum', 0.013645518630412891);
			nodeTypeSamples.put('EDataType', 0.004028197381671702);
			nodeTypeSamples.put('EParameter', 0.005941591137965764);
			nodeTypeSamples.put('EGenericType', 0.002014098690835851);
			nodeTypeSamples.put('EOperation', 0.009415911379657605);
			nodeTypeSamples.put('ETypeParameter', 0.0007049345417925478);	
		}
		
		
		
		rep.nodeTypeSamples = nodeTypeSamples;
		return rep;
	}
	
	/**
	 * Read representative model
	 */
	private static def readMetrics(GraphReader r, String path){
		val model = r.readModels(path).head;
		if(domain == Domain.Ecore){
			var refsToRemove = EcorePackageImpl.eINSTANCE.eAllContents.filter(EReference).filter[
				it.name.equals('eGenericType') || it.name.equals('eGenericSuperTypes') || it.name.equals('eFactoryInstance') ||
				it.name.equals('eGenericExceptions') || it.name.equals('references') || it.name.equals('contents');
			];
			refsToRemove.forEach[model.removeReference(it)];
		}
		return model.evaluateAllMetricsToSamples();
	}
	
}

class DataName{
	public static val REP_PATH = 'data/';
	public static val MPC_REP = 'mpc_rep';
	public static val NA_REP = 'na_rep';
	public static val OUT_D_REP = 'out_d_rep';
}