diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.java')
-rw-r--r-- | Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.java | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.java b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.java new file mode 100644 index 00000000..0299fc0c --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.java | |||
@@ -0,0 +1,138 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io; | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.EMFGraph; | ||
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.EdgeTypeMetric; | ||
5 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric; | ||
6 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MultiplexParticipationCoefficientMetric; | ||
7 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.NodeActivityMetric; | ||
8 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.NodeTypeMetric; | ||
9 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.OutDegreeMetric; | ||
10 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.TypedOutDegree; | ||
11 | import java.io.File; | ||
12 | import java.io.FileNotFoundException; | ||
13 | import java.util.ArrayList; | ||
14 | import java.util.List; | ||
15 | import org.eclipse.emf.common.util.EList; | ||
16 | import org.eclipse.emf.common.util.URI; | ||
17 | import org.eclipse.emf.ecore.EObject; | ||
18 | import org.eclipse.emf.ecore.EPackage; | ||
19 | import org.eclipse.emf.ecore.EReference; | ||
20 | import org.eclipse.emf.ecore.resource.Resource; | ||
21 | import org.eclipse.emf.ecore.resource.ResourceSet; | ||
22 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; | ||
23 | import org.eclipse.xtext.xbase.lib.Conversions; | ||
24 | import org.eclipse.xtext.xbase.lib.Exceptions; | ||
25 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
26 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
27 | |||
28 | @SuppressWarnings("all") | ||
29 | public class GraphReader { | ||
30 | private final ResourceSet resSet = new ResourceSetImpl(); | ||
31 | |||
32 | private final ArrayList<EReference> referenceTypes = new ArrayList<EReference>(); | ||
33 | |||
34 | private String suffix; | ||
35 | |||
36 | public GraphReader(final EPackage metaModel, final String suffix) { | ||
37 | throw new Error("Unresolved compilation problems:" | ||
38 | + "\nXMIResourceFactoryImpl cannot be resolved."); | ||
39 | } | ||
40 | |||
41 | public List<EMFGraph> readModels(final String path) { | ||
42 | try { | ||
43 | final File dir = new File(path); | ||
44 | boolean _isDirectory = dir.isDirectory(); | ||
45 | boolean _not = (!_isDirectory); | ||
46 | if (_not) { | ||
47 | throw new Exception("expecting a directory"); | ||
48 | } | ||
49 | final ArrayList<EMFGraph> graphs = new ArrayList<EMFGraph>(); | ||
50 | final ArrayList<Metric> metrics = new ArrayList<Metric>(); | ||
51 | OutDegreeMetric _outDegreeMetric = new OutDegreeMetric(); | ||
52 | metrics.add(_outDegreeMetric); | ||
53 | NodeActivityMetric _nodeActivityMetric = new NodeActivityMetric(); | ||
54 | metrics.add(_nodeActivityMetric); | ||
55 | MultiplexParticipationCoefficientMetric _multiplexParticipationCoefficientMetric = new MultiplexParticipationCoefficientMetric(); | ||
56 | metrics.add(_multiplexParticipationCoefficientMetric); | ||
57 | TypedOutDegree _typedOutDegree = new TypedOutDegree(); | ||
58 | metrics.add(_typedOutDegree); | ||
59 | NodeTypeMetric _nodeTypeMetric = new NodeTypeMetric(); | ||
60 | metrics.add(_nodeTypeMetric); | ||
61 | EdgeTypeMetric _edgeTypeMetric = new EdgeTypeMetric(); | ||
62 | metrics.add(_edgeTypeMetric); | ||
63 | int count = 1; | ||
64 | final Function1<String, Boolean> _function = (String it) -> { | ||
65 | return Boolean.valueOf(it.endsWith(this.suffix)); | ||
66 | }; | ||
67 | Iterable<String> _filter = IterableExtensions.<String>filter(((Iterable<String>)Conversions.doWrapArray(dir.list())), _function); | ||
68 | for (final String name : _filter) { | ||
69 | { | ||
70 | final File file = new File(name); | ||
71 | final List<EObject> roots = this.<EObject>readModel(EObject.class, path, file.getName()); | ||
72 | final EMFGraph g = new EMFGraph(); | ||
73 | for (final EObject root : roots) { | ||
74 | g.init(root, metrics, name.replaceFirst(this.suffix, ""), this.referenceTypes); | ||
75 | } | ||
76 | count++; | ||
77 | graphs.add(g); | ||
78 | } | ||
79 | } | ||
80 | return graphs; | ||
81 | } catch (Throwable _e) { | ||
82 | throw Exceptions.sneakyThrow(_e); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | public EMFGraph readModel(final String path, final String filename) { | ||
87 | final ArrayList<Metric> metrics = new ArrayList<Metric>(); | ||
88 | OutDegreeMetric _outDegreeMetric = new OutDegreeMetric(); | ||
89 | metrics.add(_outDegreeMetric); | ||
90 | NodeActivityMetric _nodeActivityMetric = new NodeActivityMetric(); | ||
91 | metrics.add(_nodeActivityMetric); | ||
92 | MultiplexParticipationCoefficientMetric _multiplexParticipationCoefficientMetric = new MultiplexParticipationCoefficientMetric(); | ||
93 | metrics.add(_multiplexParticipationCoefficientMetric); | ||
94 | TypedOutDegree _typedOutDegree = new TypedOutDegree(); | ||
95 | metrics.add(_typedOutDegree); | ||
96 | NodeTypeMetric _nodeTypeMetric = new NodeTypeMetric(); | ||
97 | metrics.add(_nodeTypeMetric); | ||
98 | EdgeTypeMetric _edgeTypeMetric = new EdgeTypeMetric(); | ||
99 | metrics.add(_edgeTypeMetric); | ||
100 | final File file = new File(filename); | ||
101 | final List<EObject> roots = this.<EObject>readModel(EObject.class, path, file.getName()); | ||
102 | final EMFGraph g = new EMFGraph(); | ||
103 | for (final EObject root : roots) { | ||
104 | g.init(root, metrics, filename.replaceFirst(this.suffix, ""), this.referenceTypes); | ||
105 | } | ||
106 | return g; | ||
107 | } | ||
108 | |||
109 | public <RootType extends EObject> List<RootType> readModel(final Class<RootType> type, final String path, final String name) { | ||
110 | try { | ||
111 | try { | ||
112 | final Resource resource = this.resSet.getResource(GraphReader.getURI(path, name), true); | ||
113 | if ((resource == null)) { | ||
114 | String _string = GraphReader.getURI(path, name).toString(); | ||
115 | throw new FileNotFoundException(_string); | ||
116 | } else { | ||
117 | EList<EObject> _contents = resource.getContents(); | ||
118 | return ((List<RootType>) _contents); | ||
119 | } | ||
120 | } catch (final Throwable _t) { | ||
121 | if (_t instanceof Exception) { | ||
122 | final Exception e = (Exception)_t; | ||
123 | e.printStackTrace(); | ||
124 | String _string_1 = GraphReader.getURI(path, name).toString(); | ||
125 | throw new Exception(_string_1); | ||
126 | } else { | ||
127 | throw Exceptions.sneakyThrow(_t); | ||
128 | } | ||
129 | } | ||
130 | } catch (Throwable _e) { | ||
131 | throw Exceptions.sneakyThrow(_e); | ||
132 | } | ||
133 | } | ||
134 | |||
135 | public static URI getURI(final String path, final String name) { | ||
136 | return URI.createFileURI(((path + "/") + name)); | ||
137 | } | ||
138 | } | ||